From c7e8adec6101f0c51a042fa73f0e31dc344d1ab4 Mon Sep 17 00:00:00 2001 From: Pratyush Mishra Date: Sat, 14 Oct 2023 22:10:43 -0400 Subject: [PATCH] Bump versions and misc tweaks (#51) --- Cargo.toml | 2 +- benches/bench.rs | 25 ++++++++++++++++--------- src/generator.rs | 2 +- src/prover.rs | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d45ef82..8db5d6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ark-groth16" -version = "0.3.0" +version = "0.4.0" authors = [ "arkworks contributors" ] description = "An implementation of the Groth 2016 zkSNARK proof system" homepage = "https://arkworks.rs" diff --git a/benches/bench.rs b/benches/bench.rs index 0ff84d2..4c3a8be 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -16,8 +16,10 @@ use ark_relations::{ }; use ark_std::ops::Mul; -const NUM_PROVE_REPEATITIONS: usize = 10; -const NUM_VERIFY_REPEATITIONS: usize = 50; +const NUM_PROVE_REPETITIONS: usize = 1; +const NUM_VERIFY_REPETITIONS: usize = 50; +const NUM_CONSTRAINTS: usize = (1 << 20) - 100; +const NUM_VARIABLES: usize = (1 << 20) - 100; #[derive(Copy)] struct DummyCircuit { @@ -69,22 +71,27 @@ macro_rules! groth16_prove_bench { let c = DummyCircuit::<$bench_field> { a: Some(<$bench_field>::rand(rng)), b: Some(<$bench_field>::rand(rng)), - num_variables: 10, - num_constraints: 65536, + num_variables: NUM_VARIABLES, + num_constraints: NUM_CONSTRAINTS, }; let (pk, _) = Groth16::<$bench_pairing_engine>::circuit_specific_setup(c, rng).unwrap(); let start = ark_std::time::Instant::now(); - for _ in 0..NUM_PROVE_REPEATITIONS { + for _ in 0..NUM_PROVE_REPETITIONS { let _ = Groth16::<$bench_pairing_engine>::prove(&pk, c.clone(), rng).unwrap(); } println!( "per-constraint proving time for {}: {} ns/constraint", stringify!($bench_pairing_engine), - start.elapsed().as_nanos() / NUM_PROVE_REPEATITIONS as u128 / 65536u128 + start.elapsed().as_nanos() / (NUM_PROVE_REPETITIONS as u128 * NUM_CONSTRAINTS as u128) + ); + println!( + "wall-clock proving time for {}: {} s", + stringify!($bench_pairing_engine), + start.elapsed().as_secs_f64() / NUM_PROVE_REPETITIONS as f64 ); }; } @@ -96,7 +103,7 @@ macro_rules! groth16_verify_bench { a: Some(<$bench_field>::rand(rng)), b: Some(<$bench_field>::rand(rng)), num_variables: 10, - num_constraints: 65536, + num_constraints: NUM_CONSTRAINTS, }; let (pk, vk) = Groth16::<$bench_pairing_engine>::circuit_specific_setup(c, rng).unwrap(); @@ -106,14 +113,14 @@ macro_rules! groth16_verify_bench { let start = ark_std::time::Instant::now(); - for _ in 0..NUM_VERIFY_REPEATITIONS { + for _ in 0..NUM_VERIFY_REPETITIONS { let _ = Groth16::<$bench_pairing_engine>::verify(&vk, &vec![v], &proof).unwrap(); } println!( "verifying time for {}: {} ns", stringify!($bench_pairing_engine), - start.elapsed().as_nanos() / NUM_VERIFY_REPEATITIONS as u128 + start.elapsed().as_nanos() / NUM_VERIFY_REPETITIONS as u128 ); }; } diff --git a/src/generator.rs b/src/generator.rs index 9e8a63c..f45c3ab 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -133,7 +133,7 @@ impl Groth16 { end_timer!(g2_time); // Compute the B-query in G2 - let b_g2_time = start_timer!(|| "Calculate B G2"); + let b_g2_time = start_timer!(|| format!("Calculate B G2 of size {}", b.len())); let b_g2_query = FixedBase::msm::(scalar_bits, g2_window, &g2_table, &b); drop(g2_table); end_timer!(b_g2_time); diff --git a/src/prover.rs b/src/prover.rs index 692bb5e..cfb7277 100644 --- a/src/prover.rs +++ b/src/prover.rs @@ -63,7 +63,7 @@ impl Groth16 { let h_assignment = cfg_into_iter!(h) .map(|s| s.into_bigint()) .collect::>(); - let h_acc = E::G1::msm_bigint(&pk.h_query, &h_assignment); + let h_acc = E::G1::msm_bigint(&pk.h_query, &h_assignment[..h_assignment.len() - 1]); drop(h_assignment); // Compute C