Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add benchmarks for pedersen and schnorr verification #5056

Merged
merged 2 commits into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions acvm-repo/bn254_blackbox_solver/benches/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use criterion::{criterion_group, criterion_main, Criterion};
use std::{hint::black_box, time::Duration};

use acir::FieldElement;
use bn254_blackbox_solver::poseidon2_permutation;
use acvm_blackbox_solver::BlackBoxFunctionSolver;
use bn254_blackbox_solver::{poseidon2_permutation, Bn254BlackBoxSolver};

use pprof::criterion::{Output, PProfProfiler};

Expand All @@ -12,10 +13,58 @@ fn bench_poseidon2(c: &mut Criterion) {
c.bench_function("poseidon2", |b| b.iter(|| poseidon2_permutation(black_box(&inputs), 4)));
}

fn bench_pedersen_commitment(c: &mut Criterion) {
let inputs = [FieldElement::one(); 2];
let solver = Bn254BlackBoxSolver::new();

c.bench_function("pedersen_commitment", |b| {
b.iter(|| solver.pedersen_commitment(black_box(&inputs), 0))
});
}

fn bench_pedersen_hash(c: &mut Criterion) {
let inputs = [FieldElement::one(); 2];
let solver = Bn254BlackBoxSolver::new();

c.bench_function("pedersen_hash", |b| b.iter(|| solver.pedersen_hash(black_box(&inputs), 0)));
}

fn bench_schnorr_verify(c: &mut Criterion) {
let solver = Bn254BlackBoxSolver::new();

let pub_key_x = FieldElement::from_hex(
"0x04b260954662e97f00cab9adb773a259097f7a274b83b113532bce27fa3fb96a",
)
.unwrap();
let pub_key_y = FieldElement::from_hex(
"0x2fd51571db6c08666b0edfbfbc57d432068bccd0110a39b166ab243da0037197",
)
.unwrap();
let sig_bytes: [u8; 64] = [
1, 13, 119, 112, 212, 39, 233, 41, 84, 235, 255, 93, 245, 172, 186, 83, 157, 253, 76, 77,
33, 128, 178, 15, 214, 67, 105, 107, 177, 234, 77, 48, 27, 237, 155, 84, 39, 84, 247, 27,
22, 8, 176, 230, 24, 115, 145, 220, 254, 122, 135, 179, 171, 4, 214, 202, 64, 199, 19, 84,
239, 138, 124, 12,
];

let message: &[u8] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

c.bench_function("schnorr_verify", |b| {
b.iter(|| {
solver.schnorr_verify(
black_box(&pub_key_x),
black_box(&pub_key_y),
black_box(&sig_bytes),
black_box(message),
)
})
});
}

criterion_group!(
name = benches;
config = Criterion::default().sample_size(40).measurement_time(Duration::from_secs(20)).with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
targets = bench_poseidon2
targets = bench_poseidon2, bench_pedersen_commitment, bench_pedersen_hash, bench_schnorr_verify
);

criterion_main!(benches);
Loading