From 8c91c6d864b99fee4704aa1a4706f2621eab3c92 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Wed, 10 Apr 2024 10:18:28 +0200 Subject: [PATCH] split the setup of Komodo and the serde benchmarks --- benches/setup.rs | 81 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/benches/setup.rs b/benches/setup.rs index 226d52de..82fd8e12 100644 --- a/benches/setup.rs +++ b/benches/setup.rs @@ -18,13 +18,47 @@ where P: DenseUVPolynomial<F>, for<'a, 'b> &'a P: Div<&'b P, Output = P>, { - let mut group = c.benchmark_group("setup"); - let rng = &mut rand::thread_rng(); - group.bench_function(&format!("setup (komodo) {} on {}", degree, curve), |b| { + c.bench_function(&format!("setup (komodo) {} on {}", degree, curve), |b| { b.iter(|| zk::setup::<_, F, G>(degree, rng).unwrap()) }); +} + +fn ark_setup_template<E, P>(c: &mut Criterion, degree: usize, curve: &str) +where + E: Pairing, + P: DenseUVPolynomial<E::ScalarField>, + for<'a, 'b> &'a P: Div<&'b P, Output = P>, +{ + let rng = &mut rand::thread_rng(); + + c.bench_function( + &format!("setup (arkworks) {} bytes on {}", degree, curve), + |b| { + b.iter(|| { + let setup = KZG10::<E, P>::setup(degree, false, rng).unwrap(); + let powers_of_g = setup.powers_of_g[..=degree].to_vec(); + let powers_of_gamma_g = (0..=degree).map(|i| setup.powers_of_gamma_g[&i]).collect(); + kzg10::Powers::<E> { + powers_of_g: ark_std::borrow::Cow::Owned(powers_of_g), + powers_of_gamma_g: ark_std::borrow::Cow::Owned(powers_of_gamma_g), + } + }) + }, + ); +} + +fn serde_template<F, G, P>(c: &mut Criterion, degree: usize, curve: &str) +where + F: PrimeField, + G: CurveGroup<ScalarField = F>, + P: DenseUVPolynomial<F>, + for<'a, 'b> &'a P: Div<&'b P, Output = P>, +{ + let mut group = c.benchmark_group("setup"); + + let rng = &mut rand::thread_rng(); let setup = zk::setup::<_, F, G>(degree, rng).unwrap(); @@ -103,37 +137,30 @@ where group.finish(); } -fn ark_setup_template<E, P>(c: &mut Criterion, degree: usize, curve: &str) -where - E: Pairing, - P: DenseUVPolynomial<E::ScalarField>, - for<'a, 'b> &'a P: Div<&'b P, Output = P>, -{ - let rng = &mut rand::thread_rng(); +fn setup(c: &mut Criterion) { + fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>( + c: &mut Criterion, + degree: usize, + curve: &str, + ) { + setup_template::<F, G, DensePolynomial<F>>(c, black_box(degree), curve); + } - c.bench_function( - &format!("setup (arkworks) {} bytes on {}", degree, curve), - |b| { - b.iter(|| { - let setup = KZG10::<E, P>::setup(degree, false, rng).unwrap(); - let powers_of_g = setup.powers_of_g[..=degree].to_vec(); - let powers_of_gamma_g = (0..=degree).map(|i| setup.powers_of_gamma_g[&i]).collect(); - kzg10::Powers::<E> { - powers_of_g: ark_std::borrow::Cow::Owned(powers_of_g), - powers_of_gamma_g: ark_std::borrow::Cow::Owned(powers_of_gamma_g), - } - }) - }, - ); + for n in [1, 2, 4, 8, 16] { + aux::<ark_bls12_381::Fr, ark_bls12_381::G1Projective>(c, n, "BLS-12-381"); + aux::<ark_bn254::Fr, ark_bn254::G1Projective>(c, n, "BN-254"); + aux::<ark_pallas::Fr, ark_pallas::Projective>(c, n, "PALLAS"); + } } -fn setup(c: &mut Criterion) { + +fn serde(c: &mut Criterion) { fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>( c: &mut Criterion, degree: usize, curve: &str, ) { - setup_template::<F, G, DensePolynomial<F>>(c, black_box(degree), curve); + serde_template::<F, G, DensePolynomial<F>>(c, black_box(degree), curve); } for n in [1, 2, 4, 8, 16] { @@ -159,6 +186,6 @@ criterion_group!( config = Criterion::default() .warm_up_time(Duration::from_secs_f32(0.5)) .sample_size(10); - targets = setup, ark_setup + targets = setup, ark_setup, serde ); criterion_main!(benches); -- GitLab