diff --git a/bench-templates/src/lib.rs b/bench-templates/src/lib.rs index bb200f7e..552f5924 100644 --- a/bench-templates/src/lib.rs +++ b/bench-templates/src/lib.rs @@ -30,8 +30,10 @@ pub fn bench_pcs_method< &PCS::VerifierKey, usize, fn(usize, &mut ChaCha20Rng) -> P, + fn(usize, &mut ChaCha20Rng) -> P::Point, ) -> Duration, rand_poly: fn(usize, &mut ChaCha20Rng) -> P, + rand_point: fn(usize, &mut ChaCha20Rng) -> P::Point, ) { let mut group = c.benchmark_group(msg); let rng = &mut ChaCha20Rng::from_rng(test_rng()).unwrap(); @@ -47,7 +49,7 @@ pub fn bench_pcs_method< b.iter_custom(|i| { let mut time = Duration::from_nanos(0); for _ in 0..i { - time += method(&ck, &vk, *num_vars, rand_poly); + time += method(&ck, &vk, *num_vars, rand_poly, rand_point); } time }); @@ -68,6 +70,7 @@ pub fn commit< _vk: &PCS::VerifierKey, num_vars: usize, rand_poly: fn(usize, &mut ChaCha20Rng) -> P, + _rand_point: fn(usize, &mut ChaCha20Rng) -> P::Point, ) -> Duration { let rng = &mut ChaCha20Rng::from_rng(test_rng()).unwrap(); @@ -108,12 +111,12 @@ pub fn open( _vk: &PCS::VerifierKey, num_vars: usize, rand_poly: fn(usize, &mut ChaCha20Rng) -> P, + rand_point: fn(usize, &mut ChaCha20Rng) -> P::Point, ) -> Duration where F: PrimeField, P: Polynomial, PCS: PolynomialCommitment>, - P::Point: UniformRand, { let rng = &mut ChaCha20Rng::from_rng(test_rng()).unwrap(); @@ -121,7 +124,7 @@ where LabeledPolynomial::new("test".to_string(), rand_poly(num_vars, rng), None, None); let (coms, randomness) = PCS::commit(&ck, [&labeled_poly], Some(rng)).unwrap(); - let point = P::Point::rand(rng); + let point = rand_point(num_vars, rng); let start = Instant::now(); let _ = PCS::open( @@ -179,12 +182,12 @@ pub fn verify( vk: &PCS::VerifierKey, num_vars: usize, rand_poly: fn(usize, &mut ChaCha20Rng) -> P, + rand_point: fn(usize, &mut ChaCha20Rng) -> P::Point, ) -> Duration where F: PrimeField, P: Polynomial, PCS: PolynomialCommitment>, - P::Point: UniformRand, { let rng = &mut ChaCha20Rng::from_rng(test_rng()).unwrap(); @@ -192,7 +195,7 @@ where LabeledPolynomial::new("test".to_string(), rand_poly(num_vars, rng), None, None); let (coms, randomness) = PCS::commit(&ck, [&labeled_poly], Some(rng)).unwrap(); - let point = P::Point::rand(rng); + let point = rand_point(num_vars, rng); let claimed_eval = labeled_poly.evaluate(&point); let proof = PCS::open( &ck, @@ -249,7 +252,7 @@ fn test_sponge() -> PoseidonSponge { #[macro_export] macro_rules! bench_method { - ($c:expr, $method:ident, $scheme_type:ty, $rand_poly:ident) => { + ($c:expr, $method:ident, $scheme_type:ty, $rand_poly:ident, $rand_point:ident) => { let scheme_type_str = stringify!($scheme_type); let bench_name = format!("{} {}", stringify!($method), scheme_type_str); bench_pcs_method::<_, _, $scheme_type>( @@ -258,6 +261,7 @@ macro_rules! bench_method { &bench_name, $method::<_, _, $scheme_type>, $rand_poly::<_>, + $rand_point::<_>, ); }; } @@ -265,12 +269,12 @@ macro_rules! bench_method { #[macro_export] macro_rules! bench { ( - $scheme_type:ty, $rand_poly:ident + $scheme_type:ty, $rand_poly:ident, $rand_point:ident ) => { fn bench_pcs(c: &mut Criterion) { - bench_method!(c, commit, $scheme_type, $rand_poly); - bench_method!(c, open, $scheme_type, $rand_poly); - bench_method!(c, verify, $scheme_type, $rand_poly); + bench_method!(c, commit, $scheme_type, $rand_poly, $rand_point); + bench_method!(c, open, $scheme_type, $rand_poly, $rand_point); + bench_method!(c, verify, $scheme_type, $rand_poly, $rand_point); } criterion_group!(benches, bench_pcs); diff --git a/poly-commit/benches/ligero.rs b/poly-commit/benches/ligero.rs index 69a7dc1e..91809c74 100644 --- a/poly-commit/benches/ligero.rs +++ b/poly-commit/benches/ligero.rs @@ -2,10 +2,7 @@ use std::{borrow::Borrow, marker::PhantomData}; use ark_ff::PrimeField; use ark_poly::{DenseMultilinearExtension, MultilinearExtension}; -use ark_std::{ - rand::{Rng, RngCore}, - test_rng, -}; +use ark_std::{rand::RngCore, test_rng}; use ark_crypto_primitives::{ crh::{CRHScheme, TwoToOneCRHScheme}, @@ -51,6 +48,7 @@ pub fn poseidon_parameters_for_test() -> PoseidonConfig { } use ark_bn254::Fr as Fr254; +use rand_chacha::ChaCha20Rng; // We introduce the wrapper only for the purpose of `setup` function not panicing with unimplemented struct PoseidonWrapper(PhantomData); @@ -165,8 +163,15 @@ type Ligero = LinearCodePCS< const MIN_NUM_VARS: usize = 12; const MAX_NUM_VARS: usize = 22; -fn rand_ml_poly(num_vars: usize, rng: &mut impl Rng) -> MLE { - MLE::rand(num_vars, rng) +fn rand_poly_ligero_ml( + num_vars: usize, + rng: &mut ChaCha20Rng, +) -> DenseMultilinearExtension { + DenseMultilinearExtension::rand(num_vars, rng) +} + +fn rand_point_ligero_ml(num_vars: usize, rng: &mut ChaCha20Rng) -> Vec { + (0..num_vars).map(|_| F::rand(rng)).collect() } -bench!(Ligero, rand_ml_poly); +bench!(Ligero, rand_poly_ligero_ml, rand_point_ligero_ml); diff --git a/poly-commit/benches/pcs.rs b/poly-commit/benches/pcs.rs index 77ab04f7..27b4d3ba 100644 --- a/poly-commit/benches/pcs.rs +++ b/poly-commit/benches/pcs.rs @@ -22,7 +22,11 @@ fn rand_poly_ipa_pc(degree: usize, rng: &mut ChaCha20Rng) -> Dens DenseUnivariatePoly::rand(degree, rng) } +fn rand_point_ipa_pc(_: usize, rng: &mut ChaCha20Rng) -> F { + F::rand(rng) +} + const MIN_NUM_VARS: usize = 10; const MAX_NUM_VARS: usize = 20; -bench!(IPA_JubJub, rand_poly_ipa_pc); +bench!(IPA_JubJub, rand_poly_ipa_pc, rand_point_ipa_pc);