-
Notifications
You must be signed in to change notification settings - Fork 17
Batch ring proof #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Batch ring proof #64
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ef6d617
a test revamped
swasilyev c80853f
kzg batch test
swasilyev 9a2cb65
kzg acc
swasilyev c342132
fmt
swasilyev f8a5278
agg_commitment computed via the final msm
swasilyev bbf51e3
lin_comm computed via the final msm
swasilyev 5eff645
muls by the generator aggregated
swasilyev 6834565
final rs fixed
swasilyev d64e792
cleanup
swasilyev ce33c64
fmt
swasilyev aa033f1
disabled evm stuff
swasilyev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| use crate::piop::VerifierPiop; | ||
| use crate::verifier::Challenges; | ||
| use crate::{ColumnsCommited, ColumnsEvaluated, Proof}; | ||
| use ark_ec::pairing::Pairing; | ||
| use ark_ec::{CurveGroup, VariableBaseMSM}; | ||
| use ark_ff::{PrimeField, Zero}; | ||
| use ark_std::rand::Rng; | ||
| use w3f_pcs::pcs::kzg::params::KzgVerifierKey; | ||
| use w3f_pcs::pcs::kzg::{AccumulatedOpening, KZG}; | ||
| use w3f_pcs::pcs::PCS; | ||
|
|
||
| // Accumulates KZG openning claims for Plonk proofs. | ||
| // Somewhat similar to https://eprint.iacr.org/2020/499.pdf, section 8. | ||
| // With a difference that this accumulates opennings lazily, | ||
| // and runs `2` MSMs of size `O(k)` at the final stage, | ||
| // that gives an asymptotic saving (thanks to Pippenger) | ||
| // at the cost of linear accumulator size. | ||
|
|
||
| pub struct KzgAccumulator<E: Pairing> { | ||
| // acc_points[0] = G1 | ||
| acc_points: Vec<E::G1Affine>, | ||
| // acc_scalars[0] = 0 | ||
| acc_scalars: Vec<E::ScalarField>, | ||
| kzg_proofs: Vec<E::G1Affine>, | ||
| randomizers: Vec<E::ScalarField>, | ||
| kzg_vk: KzgVerifierKey<E>, | ||
| } | ||
|
|
||
| impl<E: Pairing> KzgAccumulator<E> { | ||
| pub fn new(kzg_vk: KzgVerifierKey<E>) -> Self { | ||
| //TODO: capacity | ||
| Self { | ||
| acc_points: vec![kzg_vk.g1], | ||
| acc_scalars: vec![E::ScalarField::zero()], | ||
| kzg_proofs: vec![], | ||
| randomizers: vec![], | ||
| kzg_vk, | ||
| } | ||
| } | ||
|
|
||
| // `p(z) = v <=> q(X) = p(X)-v / X-z <=> q(X)(X-z) = p(X)-v <=> q(X)X = p(X) + q(X)z - v`. | ||
| // Raising | ||
| // `p(X) -> p(tau)G1 =: C`, | ||
| // `q(X) -> q(tau)G1 =: pi`, | ||
| // `X -> tau.G2`, | ||
| // `v -> v.G1`, | ||
| // and taking the pairing gives: | ||
| // `e(pi, tau.G2) + e(C + z.pi - v.G1, -G2) = 0`. | ||
|
|
||
| // Combining `k` such equations using random coefficients `ri` results in | ||
| // `e(agg_pi, tau.G2) + e(acc, -G2) = 0`, where | ||
|
|
||
| // `agg_pi := r1.pi_1 + ... + rk.pi_k` and | ||
|
|
||
| // `acc := sum[r1.(C1 + z1.pi_1 - v1.G1), i = 1,...,k] = | ||
| // = -(r1.v1 + ... + rk.vk).G1 + (r1.C1 + ... + rk.Ck) + (r1.z1.pi_1 + ... + rk.zk.pi_k)`. | ||
|
|
||
| // `agg_pi` is a `k`-MSM. | ||
| // In a common case when a batch proof `pi_i` attests opennings of multiple (`ni`) commitments at the same point `zi`, | ||
| // `Ci = ai_1.Ci_1 + ... + ai_ni.Ci_ni, i = 1,...,k`, | ||
| // `acc` is a `1+k+(n1+...+nk)`-MSM. | ||
|
|
||
| /// Accumulates | ||
| pub fn accumulate<F, Piop, Commitments, Evaluations, R: Rng>( | ||
| &mut self, | ||
| piop: Piop, | ||
| proof: Proof<F, KZG<E>, Commitments, Evaluations>, | ||
| challenges: Challenges<F>, | ||
| rng: &mut R, | ||
| ) where | ||
| F: PrimeField, | ||
| E: Pairing<ScalarField = F>, | ||
| Piop: VerifierPiop<F, <KZG<E> as PCS<F>>::C>, | ||
| Commitments: ColumnsCommited<F, <KZG<E> as PCS<F>>::C>, | ||
| Evaluations: ColumnsEvaluated<F>, | ||
| { | ||
| let r = F::rand(rng); | ||
| let r2 = r.square(); | ||
| let zeta = challenges.zeta; | ||
|
|
||
| // TODO: it could be a method unless `to_vec(self)` | ||
| let q_zeta = piop.evaluate_q_at_zeta(&challenges.alphas, proof.lin_at_zeta_omega); | ||
| let mut columns_at_zeta = proof.columns_at_zeta.to_vec(); | ||
| columns_at_zeta.push(q_zeta); | ||
| let agg_at_zeta: F = columns_at_zeta | ||
| .into_iter() | ||
| .zip(challenges.nus.iter()) | ||
| .map(|(y, r)| y * r) | ||
| .sum(); | ||
|
|
||
| let zeta_omega = zeta * piop.domain_evaluated().omega(); | ||
| let lin_comm = piop.lin_poly_commitment(&challenges.alphas); | ||
|
|
||
| // Openning at `z` | ||
| // TODO: try to get rid of the commitment wrapper in flonk | ||
| self.acc_points.extend( | ||
| piop.precommitted_columns() | ||
| .iter() | ||
| .map(|c| c.0) | ||
| .collect::<Vec<_>>(), | ||
| ); | ||
| self.acc_points.extend( | ||
| proof | ||
| .column_commitments | ||
| .to_vec() | ||
| .iter() | ||
| .map(|c| c.0) | ||
| .collect::<Vec<_>>(), | ||
| ); | ||
| self.acc_points.push(proof.quotient_commitment.clone().0); | ||
| self.acc_scalars | ||
| .extend(challenges.nus.iter().map(|nu| *nu * r).collect::<Vec<_>>()); // numbers should match here | ||
|
|
||
| self.acc_points.push(proof.agg_at_zeta_proof); | ||
| self.acc_scalars.push(zeta * r); | ||
| self.acc_scalars[0] -= agg_at_zeta * r; | ||
|
|
||
| // Openning at `z.w` | ||
| // TODO: see above | ||
| self.acc_points | ||
| .extend(lin_comm.1.iter().map(|c| c.0).collect::<Vec<_>>()); | ||
| self.acc_scalars | ||
| .extend(lin_comm.0.into_iter().map(|c| c * r2).collect::<Vec<_>>()); | ||
| self.acc_points.push(proof.lin_at_zeta_omega_proof); | ||
| self.acc_scalars.push(zeta_omega * r2); | ||
| self.acc_scalars[0] -= proof.lin_at_zeta_omega * r2; | ||
|
|
||
| self.kzg_proofs.push(proof.agg_at_zeta_proof); | ||
| self.kzg_proofs.push(proof.lin_at_zeta_omega_proof); | ||
| self.randomizers.push(r); | ||
| self.randomizers.push(r2); | ||
| } | ||
|
|
||
| pub fn verify(&self) -> bool { | ||
| let acc = (-E::G1::msm(&self.acc_points, &self.acc_scalars).unwrap()).into_affine(); | ||
| let proof = E::G1::msm(&self.kzg_proofs, &self.randomizers) | ||
| .unwrap() | ||
| .into_affine(); | ||
| KZG::<E>::verify_accumulated(AccumulatedOpening { acc, proof }, &self.kzg_vk) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.