Skip to content

Commit

Permalink
Merge pull request #1351 from kantp/fix-benchmarks
Browse files Browse the repository at this point in the history
Update criterion benchmarks for kimchi
  • Loading branch information
dannywillems authored Nov 29, 2023
2 parents a9b4adb + e87baa8 commit a1d9861
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion kimchi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Kimchi is based on [plonk](https://eprint.iacr.org/2019/953.pdf), a zk-SNARK pro

To bench kimchi, we have two types of benchmark engines.

[Criterion](https://bheisler.github.io/criterion.rs/) is used to benchmark time:
[Criterion](https://bheisler.github.io/criterion.rs/) is used to benchmark time. If you have installed [cargo-criterion](https://github.com/bheisler/cargo-criterion) and [gnuplot](http://www.gnuplot.info), you can run the benchmarks via

```console
$ cargo criterion -p kimchi --bench proof_criterion
Expand Down
46 changes: 29 additions & 17 deletions kimchi/benches/proof_criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,38 @@ pub fn bench_proof_creation(c: &mut Criterion) {
let mut group = c.benchmark_group("Proof creation");
group.sample_size(10).sampling_mode(SamplingMode::Flat); // for slow benchmarks

let ctx = BenchmarkCtx::new(10);
group.bench_function(
format!("proof creation (SRS size 2^{})", ctx.srs_size()),
|b| b.iter(|| black_box(ctx.create_proof())),
);
for size in [10, 14] {
let ctx = BenchmarkCtx::new(size);

let ctx = BenchmarkCtx::new(14);
group.bench_function(
format!("proof creation (SRS size 2^{})", ctx.srs_size()),
|b| b.iter(|| black_box(ctx.create_proof())),
);

let proof_and_public = ctx.create_proof();
group.bench_function(
format!(
"proof creation (SRS size 2^{{{}}}, {} gates)",
ctx.srs_size(),
ctx.num_gates
),
|b| b.iter(|| black_box(ctx.create_proof())),
);
}
}

pub fn bench_proof_verification(c: &mut Criterion) {
let mut group = c.benchmark_group("Proof verification");
group.sample_size(100).sampling_mode(SamplingMode::Auto);
group.bench_function(
format!("proof verification (SRS size 2^{})", ctx.srs_size()),
|b| b.iter(|| ctx.batch_verification(black_box(&vec![proof_and_public.clone()]))),
);

for size in [10, 14] {
let ctx = BenchmarkCtx::new(size);
let proof_and_public = ctx.create_proof();

group.bench_function(
format!(
"proof verification (SRS size 2^{{{}}}, {} gates)",
ctx.srs_size(),
ctx.num_gates
),
|b| b.iter(|| ctx.batch_verification(black_box(&vec![proof_and_public.clone()]))),
);
}
}

criterion_group!(benches, bench_proof_creation);
criterion_group!(benches, bench_proof_creation, bench_proof_verification);
criterion_main!(benches);
2 changes: 1 addition & 1 deletion kimchi/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type BaseSponge = DefaultFqSponge<VestaParameters, SpongeParams>;
type ScalarSponge = DefaultFrSponge<Fp, SpongeParams>;

pub struct BenchmarkCtx {
num_gates: usize,
pub num_gates: usize,
group_map: BWParameters<VestaParameters>,
index: ProverIndex<Vesta, OpeningProof<Vesta>>,
verifier_index: VerifierIndex<Vesta, OpeningProof<Vesta>>,
Expand Down
2 changes: 1 addition & 1 deletion kimchi/src/precomputed_srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub const SERIALIZED_SRS_SIZE: u32 = 16;

/// The path of the serialized SRS.
fn get_srs_path<G: KimchiCurve>() -> PathBuf {
let base_path = std::env::var("CARGO_MANIFEST_DIR").expect("failed to get manifest path");
let base_path = env!("CARGO_MANIFEST_DIR");
PathBuf::from(base_path)
.join("../srs")
.join(format!("{}.srs", G::NAME))
Expand Down

0 comments on commit a1d9861

Please sign in to comment.