Skip to content

Commit

Permalink
small benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfloatersu committed Feb 18, 2025
1 parent 89bc736 commit 4467581
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
4 changes: 4 additions & 0 deletions poly_commit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ criterion.workspace = true
[[bench]]
name = "orion"
harness = false

[[bench]]
name = "hyrax"
harness = false
106 changes: 106 additions & 0 deletions poly_commit/benches/hyrax.rs
Original file line number Diff line number Diff line change
@@ -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::<BN254Fr>::random(num_vars, &mut rng);

let srs =
HyraxPCS::<G1Affine, BytesHashTranscript<BN254Fr, Keccak256hasher>>::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<BN254Fr, Keccak256hasher>,
>::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::<BN254Fr, Keccak256hasher>::new();
let mut scratch_pad = Vec::new();

for num_vars in lowest_num_vars..=highest_num_vars {
let poly = MultiLinearPoly::<BN254Fr>::random(num_vars, &mut rng);

let srs =
HyraxPCS::<G1Affine, BytesHashTranscript<BN254Fr, Keccak256hasher>>::gen_srs_for_testing(
&num_vars, &mut rng,
);
let eval_point: Vec<_> = (0..num_vars)
.map(|_| BN254Fr::random_unsafe(&mut rng))
.collect();

let _ = HyraxPCS::<G1Affine, BytesHashTranscript<BN254Fr, Keccak256hasher>>::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<BN254Fr, Keccak256hasher>,
>::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);

0 comments on commit 4467581

Please sign in to comment.