Skip to content

Commit d4dd7d2

Browse files
committed
cleanup succinct arguments for batched verification
1 parent da501f4 commit d4dd7d2

5 files changed

+306
-107
lines changed

src/sonic/tests/sonics.rs

+24-22
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::{
3131
SynthesisError
3232
};
3333

34-
const MIMC_ROUNDS: usize = 2;
34+
const MIMC_ROUNDS: usize = 322;
3535

3636
fn mimc<E: Engine>(
3737
mut xl: E::Fr,
@@ -544,8 +544,8 @@ fn test_succinct_sonic_mimc() {
544544
let s1_srs = perm_structure.create_permutation_special_reference(&srs);
545545
let s2_srs = perm_structure.calculate_s2_commitment_value(&srs);
546546

547-
// let info = get_circuit_parameters_for_succinct_sonic::<Bls12, _>(circuit.clone()).expect("Must get circuit info");
548-
// println!("{:?}", info);
547+
let info = get_circuit_parameters_for_succinct_sonic::<Bls12, _>(circuit.clone()).expect("Must get circuit info");
548+
println!("{:?}", info);
549549

550550
println!("creating proof");
551551
let start = Instant::now();
@@ -609,36 +609,38 @@ fn test_succinct_sonic_mimc() {
609609
{
610610
use rand::{XorShiftRng, SeedableRng, Rand, Rng};
611611
let mut rng = &mut XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
612-
612+
let start = Instant::now();
613613
let (perm_commitments, s_prime_challenges, perm_proof, perm_arg_proof, z_prime, num_poly, s1_naive) = perm_structure.create_permutation_arguments(aggregate.w, aggregate.z, &mut rng, &srs);
614614
let s2_proof = perm_structure.calculate_s2_proof(aggregate.z, aggregate.w, &srs);
615615

616-
let n = perm_structure.n;
617-
let z = aggregate.z;
618-
let y = aggregate.w;
619-
let z_inv = z.inverse().unwrap();
620-
let z_inv_n_plus_1 = z_inv.pow([(n+1) as u64]);
621-
let z_n = z.pow([n as u64]);
622-
let y_n = y.pow([n as u64]);
616+
println!("Permutation argument done in {:?}", start.elapsed());
623617

624-
println!("S_1 naive = {}", s1_naive);
618+
// let n = perm_structure.n;
619+
// let z = aggregate.z;
620+
// let y = aggregate.w;
621+
// let z_inv = z.inverse().unwrap();
622+
// let z_inv_n_plus_1 = z_inv.pow([(n+1) as u64]);
623+
// let z_n = z.pow([n as u64]);
624+
// let y_n = y.pow([n as u64]);
625625

626-
let mut s_1 = s1_naive;
627-
s_1.mul_assign(&z_inv_n_plus_1);
628-
s_1.mul_assign(&y_n);
626+
// println!("S_1 naive = {}", s1_naive);
629627

630-
println!("S_1 multiplied = {}", s_1);
628+
// let mut s_1 = s1_naive;
629+
// s_1.mul_assign(&z_inv_n_plus_1);
630+
// s_1.mul_assign(&y_n);
631631

632-
let mut s_2 = s2_proof.c_value;
633-
s_2.add_assign(&s2_proof.d_value);
634-
s_2.mul_assign(&z_n);
632+
// println!("S_1 multiplied = {}", s_1);
635633

636-
s_1.sub_assign(&s_2);
637-
println!("S naive = {}", s_1);
634+
// let mut s_2 = s2_proof.c_value;
635+
// s_2.add_assign(&s2_proof.d_value);
636+
// s_2.mul_assign(&z_n);
637+
638+
// s_1.sub_assign(&s_2);
639+
// println!("S naive = {}", s_1);
638640

639641

640642
let mut verifier = SuccinctMultiVerifier::<Bls12, _, Permutation3, _>::new(AdaptorCircuit(circuit.clone()), &srs, rng).unwrap();
641-
println!("verifying 100 proofs with advice");
643+
println!("verifying 100 proofs with succinct advice");
642644
let start = Instant::now();
643645
{
644646
for (ref proof, ref advice) in &proofs {

src/sonic/unhelped/grand_product_argument.rs

+77
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use std::marker::PhantomData;
88

99
use crate::sonic::srs::SRS;
1010
use crate::sonic::util::*;
11+
use crate::sonic::transcript::{Transcript, TranscriptProtocol};
12+
use super::wellformed_argument::{WellformednessSignature, WellformednessArgument};
1113

1214
#[derive(Clone)]
1315
pub struct GrandProductArgument<E: Engine> {
@@ -27,7 +29,82 @@ pub struct GrandProductProof<E: Engine> {
2729
f_opening: E::G1Affine,
2830
}
2931

32+
#[derive(Clone)]
33+
pub struct GrandProductSignature<E: Engine> {
34+
pub a_commitments: Vec<E::G1Affine>,
35+
pub b_commitments: Vec<E::G1Affine>,
36+
pub c_commitments: Vec<(E::G1Affine, E::Fr)>,
37+
pub t_commitment: E::G1Affine,
38+
pub grand_product_openings: Vec<(E::Fr, E::G1Affine)>,
39+
// pub a_zy: Vec<E::Fr>,
40+
pub proof: GrandProductProof<E>,
41+
pub wellformedness_signature: WellformednessSignature<E>,
42+
}
43+
3044
impl<E: Engine> GrandProductArgument<E> {
45+
pub fn create_signature(
46+
grand_products: Vec<(Vec<E::Fr>, Vec<E::Fr>)>,
47+
y: E::Fr,
48+
z: E::Fr,
49+
srs: &SRS<E>,
50+
) -> GrandProductSignature<E> {
51+
let mut a_commitments = vec![];
52+
let mut b_commitments = vec![];
53+
54+
let mut transcript = Transcript::new(&[]);
55+
let mut grand_product_challenges = vec![];
56+
57+
for (a, b) in grand_products.iter() {
58+
let (c_a, c_b) = GrandProductArgument::commit_for_individual_products(& a[..], & b[..], &srs);
59+
{
60+
let mut transcript = Transcript::new(&[]);
61+
transcript.commit_point(&c_a);
62+
let challenge = transcript.get_challenge_scalar();
63+
grand_product_challenges.push(challenge);
64+
transcript.commit_point(&c_b);
65+
let challenge = transcript.get_challenge_scalar();
66+
grand_product_challenges.push(challenge);
67+
}
68+
a_commitments.push(c_a);
69+
b_commitments.push(c_b);
70+
transcript.commit_point(&c_a);
71+
transcript.commit_point(&c_b);
72+
}
73+
74+
let mut all_polys = vec![];
75+
for p in grand_products.iter() {
76+
let (a, b) = p;
77+
all_polys.push(a.clone());
78+
all_polys.push(b.clone());
79+
}
80+
81+
let wellformedness_signature = WellformednessArgument::create_signature(
82+
all_polys,
83+
&srs
84+
);
85+
86+
87+
let mut grand_product_argument = GrandProductArgument::new(grand_products);
88+
let c_commitments = grand_product_argument.commit_to_individual_c_polynomials(&srs);
89+
let t_commitment = grand_product_argument.commit_to_t_polynomial(&grand_product_challenges, y, &srs);
90+
let grand_product_openings = grand_product_argument.open_commitments_for_grand_product(y, z, &srs);
91+
let a_zy: Vec<E::Fr> = grand_product_openings.iter().map(|el| el.0.clone()).collect();
92+
let proof = grand_product_argument.make_argument(&a_zy, &grand_product_challenges, y, z, &srs);
93+
94+
GrandProductSignature {
95+
a_commitments,
96+
b_commitments,
97+
c_commitments,
98+
t_commitment,
99+
grand_product_openings,
100+
// a_zy,
101+
proof,
102+
wellformedness_signature
103+
}
104+
105+
}
106+
107+
31108
pub fn new(polynomials: Vec<(Vec<E::Fr>, Vec<E::Fr>)>) -> Self {
32109
assert!(polynomials.len() > 0);
33110

0 commit comments

Comments
 (0)