From 44675815f93bebfa49f9b0945851fa3c3c32be22 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Tue, 18 Feb 2025 18:16:39 -0500 Subject: [PATCH] small benchmarking --- poly_commit/Cargo.toml | 4 ++ poly_commit/benches/hyrax.rs | 106 +++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 poly_commit/benches/hyrax.rs diff --git a/poly_commit/Cargo.toml b/poly_commit/Cargo.toml index 92f43d47..ac86b2f6 100644 --- a/poly_commit/Cargo.toml +++ b/poly_commit/Cargo.toml @@ -30,3 +30,7 @@ criterion.workspace = true [[bench]] name = "orion" harness = false + +[[bench]] +name = "hyrax" +harness = false diff --git a/poly_commit/benches/hyrax.rs b/poly_commit/benches/hyrax.rs new file mode 100644 index 00000000..0f819171 --- /dev/null +++ b/poly_commit/benches/hyrax.rs @@ -0,0 +1,106 @@ +use arith::{BN254Fr, Field}; +use ark_std::test_rng; +use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; +use halo2curves::bn256::G1Affine; +use poly_commit::{HyraxPCS, PolynomialCommitmentScheme}; +use polynomials::MultiLinearPoly; +use transcript::{BytesHashTranscript, Keccak256hasher, Transcript}; + +fn hyrax_committing_benchmark_helper( + c: &mut Criterion, + lowest_num_vars: usize, + highest_num_vars: usize, +) { + let mut group = c.benchmark_group("Hyrax PCS committing"); + + let mut rng = test_rng(); + let mut scratch_pad = Vec::new(); + + for num_vars in lowest_num_vars..=highest_num_vars { + let poly = MultiLinearPoly::::random(num_vars, &mut rng); + + let srs = + HyraxPCS::>::gen_srs_for_testing( + &num_vars, &mut rng, + ); + + group + .bench_function( + BenchmarkId::new(format!("{num_vars} variables"), num_vars), + |b| { + b.iter(|| { + _ = black_box(HyraxPCS::< + G1Affine, + BytesHashTranscript, + >::commit( + &num_vars, &srs, &poly, &mut scratch_pad + )) + }) + }, + ) + .sample_size(10); + } +} + +fn hyrax_committing_benchmark(c: &mut Criterion) { + hyrax_committing_benchmark_helper(c, 8, 15) +} + +fn hyrax_opening_benchmark_helper( + c: &mut Criterion, + lowest_num_vars: usize, + highest_num_vars: usize, +) { + let mut group = c.benchmark_group("Hyrax PCS opening"); + + let mut rng = test_rng(); + let mut transcript = BytesHashTranscript::::new(); + let mut scratch_pad = Vec::new(); + + for num_vars in lowest_num_vars..=highest_num_vars { + let poly = MultiLinearPoly::::random(num_vars, &mut rng); + + let srs = + HyraxPCS::>::gen_srs_for_testing( + &num_vars, &mut rng, + ); + let eval_point: Vec<_> = (0..num_vars) + .map(|_| BN254Fr::random_unsafe(&mut rng)) + .collect(); + + let _ = HyraxPCS::>::commit( + &num_vars, + &srs, + &poly, + &mut scratch_pad, + ); + + group + .bench_function( + BenchmarkId::new(format!("{num_vars} variables"), num_vars), + |b| { + b.iter(|| { + _ = black_box(HyraxPCS::< + G1Affine, + BytesHashTranscript, + >::open( + &num_vars, + &srs, + &poly, + &eval_point, + &scratch_pad, + &mut transcript, + )) + }) + }, + ) + .sample_size(10); + } +} + +fn hyrax_opening_benchmark(c: &mut Criterion) { + hyrax_opening_benchmark_helper(c, 8, 15) +} + +criterion_group!(bench, hyrax_committing_benchmark, hyrax_opening_benchmark); +criterion_main!(bench);