diff --git a/src/sonic/README.md b/src/sonic/README.md index 3aa27d3..5785310 100644 --- a/src/sonic/README.md +++ b/src/sonic/README.md @@ -15,8 +15,8 @@ Initial SONIC proof system integration using the code from the [original impleme - [x] Test with public inputs - [x] Test on BN256 - [x] Parallelize using existing primitives -- [ ] Implement polynomial parallelized evaluation +- [x] Implement polynomial parallelized evaluation - [x] Make custom transcriptor that is easy to transform into the smart-contract - [x] Basic Ethereum smart-contract -- [ ] Add blinding factors +- [x] Add blinding factors - [ ] Implement unhelped version \ No newline at end of file diff --git a/src/sonic/unhelped/s2_proof.rs b/src/sonic/unhelped/s2_proof.rs index fb2409e..a652d38 100644 --- a/src/sonic/unhelped/s2_proof.rs +++ b/src/sonic/unhelped/s2_proof.rs @@ -59,7 +59,7 @@ impl S2Eval { let (d, d_opening) = { let mut point = y.inverse().unwrap(); point.mul_assign(&x); - let val = evaluate_at_consequitive_powers(&poly[1..], E::Fr::one(), point); + let val = evaluate_at_consequitive_powers(&poly[1..], E::Fr::one(), point); poly[0] = val; poly[0].negate(); let opening = polynomial_commitment_opening(0, self.n, poly.iter(), point, &srs); diff --git a/src/sonic/unhelped/wellformed_argument.rs b/src/sonic/unhelped/wellformed_argument.rs index f9510f2..8c3b652 100644 --- a/src/sonic/unhelped/wellformed_argument.rs +++ b/src/sonic/unhelped/wellformed_argument.rs @@ -15,7 +15,6 @@ pub struct WellformednessArgument { #[derive(Clone)] pub struct WellformednessProof { - commitments: Vec, l: E::G1Affine, r: E::G1Affine } @@ -54,15 +53,9 @@ impl WellformednessArgument { } pub fn make_argument(self, challenges: Vec, srs: &SRS) -> WellformednessProof { - let commitments = self.commit(&srs); - - assert_eq!(commitments.len(), challenges.len()); - let mut polynomials = self.polynomials; let mut challenges = challenges; - - let mut p0 = polynomials.pop().unwrap(); let r0 = challenges.pop().unwrap(); let n = p0.len(); @@ -82,7 +75,7 @@ impl WellformednessArgument { // here the multiplier is x^-d, so largest negative power is -(d - 1), smallest negative power is -(d - n) let l = multiexp( - srs.g_negative_x[(d - n)..(d - 1)].iter().rev(), + srs.g_negative_x[(d - n)..d].iter().rev(), p0.iter() ).into_affine(); @@ -94,14 +87,12 @@ impl WellformednessArgument { ).into_affine(); WellformednessProof { - commitments: commitments, l: l, r: r } - } - pub fn verify(n: usize, challenges: Vec, proof: &WellformednessProof, srs: &SRS) -> bool { + pub fn verify(n: usize, challenges: &Vec, commitments: &Vec, proof: &WellformednessProof, srs: &SRS) -> bool { let d = srs.d; let alpha_x_d_precomp = srs.h_positive_x_alpha[d].prepare(); @@ -111,7 +102,7 @@ impl WellformednessArgument { let h_prep = h_prep.prepare(); let a = multiexp( - proof.commitments.iter(), + commitments.iter(), challenges.iter(), ).into_affine(); @@ -137,4 +128,58 @@ impl WellformednessArgument { true } +} + +#[test] +fn test_argument() { + use pairing::bls12_381::{Fr, G1Affine, G1, Bls12}; + use rand::{XorShiftRng, SeedableRng, Rand, Rng}; + use crate::sonic::srs::SRS; + + let srs_x = Fr::from_str("23923").unwrap(); + let srs_alpha = Fr::from_str("23728792").unwrap(); + let srs = SRS::::dummy(830564, srs_x, srs_alpha); + + let n: usize = 1 << 16; + let rng = &mut XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); + let coeffs = (0..n).map(|_| Fr::rand(rng)).collect::>(); + + let argument = WellformednessArgument::new(vec![coeffs]); + let challenges = (0..1).map(|_| Fr::rand(rng)).collect::>(); + + let commitments = argument.commit(&srs); + + let proof = argument.make_argument(challenges.clone(), &srs); + + let valid = WellformednessArgument::verify(n, &challenges, &commitments, &proof, &srs); + + assert!(valid); +} + +#[test] +fn test_argument_soundness() { + use pairing::bls12_381::{Fr, G1Affine, G1, Bls12}; + use rand::{XorShiftRng, SeedableRng, Rand, Rng}; + use crate::sonic::srs::SRS; + + let srs_x = Fr::from_str("23923").unwrap(); + let srs_alpha = Fr::from_str("23728792").unwrap(); + let srs = SRS::::dummy(830564, srs_x, srs_alpha); + + let n: usize = 1 << 16; + let rng = &mut XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); + let coeffs = (0..n).map(|_| Fr::rand(rng)).collect::>(); + + let argument = WellformednessArgument::new(vec![coeffs]); + let commitments = argument.commit(&srs); + + let coeffs = (0..n).map(|_| Fr::rand(rng)).collect::>(); + let argument = WellformednessArgument::new(vec![coeffs]); + let challenges = (0..1).map(|_| Fr::rand(rng)).collect::>(); + + let proof = argument.make_argument(challenges.clone(), &srs); + + let valid = WellformednessArgument::verify(n, &challenges, &commitments, &proof, &srs); + + assert!(!valid); } \ No newline at end of file