From a3d3207cd35dfbfddd11e54e1f04d9b66af36bfd Mon Sep 17 00:00:00 2001 From: Ralph Giles Date: Thu, 2 May 2024 10:38:05 -0700 Subject: [PATCH 1/3] t256: Remove spurious dep criterion is already a dev-dependency. It's not necessary to include it was a direct dependency as well. --- t256/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/t256/Cargo.toml b/t256/Cargo.toml index b579319..dffd370 100644 --- a/t256/Cargo.toml +++ b/t256/Cargo.toml @@ -19,7 +19,6 @@ rand = { version = "0.8.5" } rand_core = { version = "0.6.4" } merlin = { version = "3.0.0" } ark-ff-macros = { version = "0.4.2", default-features = false } -criterion = "0.5.1" sha2 = "0.10.8" [dev-dependencies] From cc5c52af0ec03c7079d2e3968b6dfe538f359aaa Mon Sep 17 00:00:00 2001 From: Ralph Giles Date: Thu, 2 May 2024 10:40:44 -0700 Subject: [PATCH 2/3] bulletproofs: update to criterion 0.5.1 Port to the latest release of the criterion benchmark framework. The `benchmark_function_with_inputs` API has been deprecated since v0.3 and is removed in v0.4 and v0.5 so benchmarks are ported to the new `BenchmarkGroup::bench_with_input` method. Addresses `cargo audit` warnings about transitive dependencies. --- bulletproofs/Cargo.toml | 2 +- bulletproofs/benches/generators.rs | 25 ++++++--------- bulletproofs/benches/r1cs_secq256k1.rs | 42 +++++++++----------------- 3 files changed, 26 insertions(+), 43 deletions(-) diff --git a/bulletproofs/Cargo.toml b/bulletproofs/Cargo.toml index b0ed141..9345797 100644 --- a/bulletproofs/Cargo.toml +++ b/bulletproofs/Cargo.toml @@ -54,7 +54,7 @@ version = '0.4.0' default-features = false [dev-dependencies] -criterion = "0.3" +criterion = "0.5.1" rand_chacha = "0.3" bincode = "1" diff --git a/bulletproofs/benches/generators.rs b/bulletproofs/benches/generators.rs index 46b6f7f..e4c612d 100644 --- a/bulletproofs/benches/generators.rs +++ b/bulletproofs/benches/generators.rs @@ -2,10 +2,8 @@ use ark_bulletproofs::{BulletproofGens, PedersenGens}; use ark_secq256k1::Affine; - -#[macro_use] -extern crate criterion; -use criterion::Criterion; +use criterion::BenchmarkId; +use criterion::{criterion_group, criterion_main, Criterion}; fn pc_gens(c: &mut Criterion) { c.bench_function("PedersenGens::new", |b| { @@ -14,17 +12,14 @@ fn pc_gens(c: &mut Criterion) { } fn bp_gens(c: &mut Criterion) { - c.bench_function_over_inputs( - "BulletproofGens::new", - |b, size| b.iter(|| BulletproofGens::::new(*size, 1)), - (0..10).map(|i| 2 << i), - ); -} - -criterion_group! { - bp, - bp_gens, - pc_gens, + let mut group = c.benchmark_group("BulletproofGens::new"); + for size in (0..10).map(|i| 2 << i) { + group.bench_with_input(BenchmarkId::from_parameter(size), &size, + |b, &size| { + b.iter(|| BulletproofGens::::new(size, 1)) + }); + } } +criterion_group!(bp, bp_gens, pc_gens); criterion_main!(bp); diff --git a/bulletproofs/benches/r1cs_secq256k1.rs b/bulletproofs/benches/r1cs_secq256k1.rs index 4407784..8cd7ffd 100644 --- a/bulletproofs/benches/r1cs_secq256k1.rs +++ b/bulletproofs/benches/r1cs_secq256k1.rs @@ -1,11 +1,7 @@ #![allow(non_snake_case)] -#![allow(deprecated)] - -#[macro_use] -extern crate criterion; - use ark_std::UniformRand; -use criterion::Criterion; +use criterion::BenchmarkId; +use criterion::{criterion_group, criterion_main, Criterion}; // Code below copied from ../tests/r1cs.rs // @@ -16,10 +12,6 @@ use criterion::Criterion; // someone wants to figure a way to use #[path] attributes or // something to avoid the duplication. -extern crate ark_bulletproofs; -extern crate merlin; -extern crate rand; - use ark_bulletproofs::r1cs::*; use ark_bulletproofs::{BulletproofGens, PedersenGens}; use ark_secq256k1::{Affine, Fr}; @@ -158,9 +150,10 @@ fn bench_kshuffle_prove(c: &mut Criterion) { let pc_gens = PedersenGens::default(); let bp_gens = BulletproofGens::new(2 * MAX_SHUFFLE_SIZE, 1); - c.bench_function_over_inputs( - "k-shuffle proof creation", - move |b, k| { + let mut group = c.benchmark_group("k-shuffle proof creation"); + for size in (1..=LG_MAX_SHUFFLE_SIZE).map(|i| 1 << i) { + group.bench_with_input(BenchmarkId::from_parameter(size), &size, + |b, k| { // Generate inputs and outputs to kshuffle let mut rng = rand::thread_rng(); let (min, max) = (0u64, u64::MAX); @@ -181,12 +174,9 @@ fn bench_kshuffle_prove(c: &mut Criterion) { &output, ) .unwrap(); - }) - }, - (1..=LG_MAX_SHUFFLE_SIZE) - .map(|i| 1 << i) - .collect::>(), - ); + }); + }); + } } criterion_group! { @@ -203,9 +193,10 @@ fn bench_kshuffle_verify(c: &mut Criterion) { let pc_gens = PedersenGens::default(); let bp_gens = BulletproofGens::new(2 * MAX_SHUFFLE_SIZE, 1); - c.bench_function_over_inputs( - "k-shuffle proof verification", - move |b, k| { + let mut group = c.benchmark_group("k-shuffle proof verification"); + for size in (1..=LG_MAX_SHUFFLE_SIZE).map(|i| 1 << i) { + group.bench_with_input(BenchmarkId::from_parameter(size), &size, + |b, k| { // Generate the proof in its own scope to prevent reuse of // prover variables by the verifier let (proof, input_commitments, output_commitments) = { @@ -242,11 +233,8 @@ fn bench_kshuffle_verify(c: &mut Criterion) { ) .unwrap(); }) - }, - (1..=LG_MAX_SHUFFLE_SIZE) - .map(|i| 1 << i) - .collect::>(), - ); + }); + } } criterion_group! { From 26aecec86000d0e1a034defad444abded6f8d3f4 Mon Sep 17 00:00:00 2001 From: Ralph Giles Date: Thu, 2 May 2024 10:47:02 -0700 Subject: [PATCH 3/3] cargo fmt --- bulletproofs/benches/generators.rs | 7 +++---- bulletproofs/benches/r1cs_secq256k1.rs | 6 ++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/bulletproofs/benches/generators.rs b/bulletproofs/benches/generators.rs index e4c612d..44c944e 100644 --- a/bulletproofs/benches/generators.rs +++ b/bulletproofs/benches/generators.rs @@ -14,10 +14,9 @@ fn pc_gens(c: &mut Criterion) { fn bp_gens(c: &mut Criterion) { let mut group = c.benchmark_group("BulletproofGens::new"); for size in (0..10).map(|i| 2 << i) { - group.bench_with_input(BenchmarkId::from_parameter(size), &size, - |b, &size| { - b.iter(|| BulletproofGens::::new(size, 1)) - }); + group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &size| { + b.iter(|| BulletproofGens::::new(size, 1)) + }); } } diff --git a/bulletproofs/benches/r1cs_secq256k1.rs b/bulletproofs/benches/r1cs_secq256k1.rs index 8cd7ffd..82501ad 100644 --- a/bulletproofs/benches/r1cs_secq256k1.rs +++ b/bulletproofs/benches/r1cs_secq256k1.rs @@ -152,8 +152,7 @@ fn bench_kshuffle_prove(c: &mut Criterion) { let mut group = c.benchmark_group("k-shuffle proof creation"); for size in (1..=LG_MAX_SHUFFLE_SIZE).map(|i| 1 << i) { - group.bench_with_input(BenchmarkId::from_parameter(size), &size, - |b, k| { + group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, k| { // Generate inputs and outputs to kshuffle let mut rng = rand::thread_rng(); let (min, max) = (0u64, u64::MAX); @@ -195,8 +194,7 @@ fn bench_kshuffle_verify(c: &mut Criterion) { let mut group = c.benchmark_group("k-shuffle proof verification"); for size in (1..=LG_MAX_SHUFFLE_SIZE).map(|i| 1 << i) { - group.bench_with_input(BenchmarkId::from_parameter(size), &size, - |b, k| { + group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, k| { // Generate the proof in its own scope to prevent reuse of // prover variables by the verifier let (proof, input_commitments, output_commitments) = {