Skip to content

Commit

Permalink
Fixed sipp tests; tidied up linear combination syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
rozbb committed Oct 26, 2023
1 parent 5bbf251 commit eae6162
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions sipp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
#![deny(warnings, unused, missing_docs)]
#![forbid(unsafe_code)]

use std::marker::PhantomData;

use ark_ec::{
pairing::{Pairing, PairingOutput},
scalar_mul::variable_base::VariableBaseMSM,
CurveGroup,
};
use ark_ff::{Field, One, UniformRand};
use ark_serialize::CanonicalSerialize;
use ark_std::Zero;
use digest::{generic_array::typenum::U32, Digest};
use rayon::prelude::*;
use std::marker::PhantomData;

/// Fiat-Shamir Rng
pub mod rng;
Expand Down Expand Up @@ -85,23 +87,15 @@ where
let a_proj = a_l
.par_iter()
.zip(a_r)
.map(|(a_l, &a_r)| {
let mut temp = a_r * x;
temp += a_l;
temp
})
.map(|(a_l, &a_r)| a_r * x + a_l)
.collect::<Vec<_>>();
a = E::G1::normalize_batch(&a_proj);

let x_inv = x.inverse().unwrap();
let b_proj = b_l
.par_iter()
.zip(b_r)
.map(|(b_l, &b_r)| {
let mut temp = b_r * x_inv;
temp += b_l;
temp
})
.map(|(b_l, &b_r)| b_r * x_inv + b_l)
.collect::<Vec<_>>();
b = E::G2::normalize_batch(&b_proj);
}
Expand Down Expand Up @@ -161,7 +155,7 @@ where
.zip(&x_s)
.zip(&x_invs)
.map(|(((z_l, z_r), x), x_inv)| (*z_l * x) + (*z_r * x_inv))
.reduce(|| PairingOutput::<E>::default(), |a, b| a + b);
.reduce(|| PairingOutput::<E>::zero(), |a, b| a + b);

let mut s: Vec<E::ScalarField> = vec![E::ScalarField::one(); length];
let mut s_invs: Vec<E::ScalarField> = vec![E::ScalarField::one(); length];
Expand Down Expand Up @@ -229,16 +223,15 @@ mod tests {
b.push(G2Projective::rand(&mut rng).into_affine());
r.push(Fr::rand(&mut rng));
}
println!("a == {:?}", a);

let z = product_of_pairings_with_coeffs::<Bls12_377>(&a, &b, &r);
println!("z == {:?}", z);

let proof = SIPP::<Bls12_377, Blake2s>::prove(&a, &b, &r, z);
assert!(proof.is_ok());
let proof = proof.unwrap();

let accept = SIPP::<Bls12_377, Blake2s>::verify(&a, &b, &r, z, &proof);

assert!(accept.is_ok());
assert!(accept.unwrap());
}
Expand Down

0 comments on commit eae6162

Please sign in to comment.