Skip to content

Commit

Permalink
verification benchmarks (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-barrett authored Nov 13, 2024
1 parent 34d3839 commit 5d0dbad
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
31 changes: 31 additions & 0 deletions benches/fib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ fn trace_generation(c: &mut Criterion) {
});
}

fn verification(c: &mut Criterion) {
let arg = get_fib_arg();
c.bench_function(&format!("fib-verification-{arg}"), |b| {
let (toplevel, ..) = build_lurk_toplevel_native();
let (args, lurk_main, mut record) = setup(arg, &toplevel);
toplevel
.execute(lurk_main.func(), &args, &mut record, None)
.unwrap();
let config = BabyBearPoseidon2::new();
let machine = StarkMachine::new(
config,
build_chip_vector(&lurk_main),
record.expect_public_values().len(),
);
let (pk, vk) = machine.setup(&LairMachineProgram);
let mut challenger_p = machine.config().challenger();
let opts = SphinxCoreOpts::default();
let shard = Shard::new(&record);
let proof = machine.prove::<LocalProver<_, _>>(&pk, shard, &mut challenger_p, opts);

b.iter_batched(
|| machine.config().challenger(),
|mut challenger| {
machine.verify(&vk, &proof, &mut challenger).unwrap();
},
BatchSize::SmallInput,
)
});
}

fn e2e(c: &mut Criterion) {
let arg = get_fib_arg();
c.bench_function(&format!("fib-e2e-{arg}"), |b| {
Expand Down Expand Up @@ -140,6 +170,7 @@ criterion_group! {
targets =
evaluation,
trace_generation,
verification,
e2e,
}

Expand Down
32 changes: 32 additions & 0 deletions benches/lcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,37 @@ fn trace_generation(c: &mut Criterion) {
});
}

fn verification(c: &mut Criterion) {
let args = get_lcs_args();
c.bench_function("lcs-verification", |b| {
let (toplevel, ..) = build_lurk_toplevel_native();
let (args, lurk_main, mut record) = setup(args.0, args.1, &toplevel);

toplevel
.execute(lurk_main.func(), &args, &mut record, None)
.unwrap();
let config = BabyBearPoseidon2::new();
let machine = StarkMachine::new(
config,
build_chip_vector(&lurk_main),
record.expect_public_values().len(),
);
let (pk, vk) = machine.setup(&LairMachineProgram);
let mut challenger_p = machine.config().challenger();
let opts = SphinxCoreOpts::default();
let shard = Shard::new(&record);
let proof = machine.prove::<LocalProver<_, _>>(&pk, shard, &mut challenger_p, opts);

b.iter_batched(
|| machine.config().challenger(),
|mut challenger| {
machine.verify(&vk, &proof, &mut challenger).unwrap();
},
BatchSize::SmallInput,
)
});
}

fn e2e(c: &mut Criterion) {
let args = get_lcs_args();
c.bench_function("lcs-e2e", |b| {
Expand Down Expand Up @@ -144,6 +175,7 @@ criterion_group! {
targets =
evaluation,
trace_generation,
verification,
e2e,
}

Expand Down
32 changes: 32 additions & 0 deletions benches/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@ fn trace_generation(c: &mut Criterion) {
});
}

fn verification(c: &mut Criterion) {
let arg = get_sum_arg();
c.bench_function(&format!("sum-verification-{arg}"), |b| {
let (toplevel, ..) = build_lurk_toplevel_native();
let (args, lurk_main, mut record) = setup(arg, &toplevel);

toplevel
.execute(lurk_main.func(), &args, &mut record, None)
.unwrap();
let config = BabyBearPoseidon2::new();
let machine = StarkMachine::new(
config,
build_chip_vector(&lurk_main),
record.expect_public_values().len(),
);
let (pk, vk) = machine.setup(&LairMachineProgram);
let mut challenger_p = machine.config().challenger();
let opts = SphinxCoreOpts::default();
let shard = Shard::new(&record);
let proof = machine.prove::<LocalProver<_, _>>(&pk, shard, &mut challenger_p, opts);

b.iter_batched(
|| machine.config().challenger(),
|mut challenger| {
machine.verify(&vk, &proof, &mut challenger).unwrap();
},
BatchSize::SmallInput,
)
});
}

fn e2e(c: &mut Criterion) {
let arg = get_sum_arg();
c.bench_function(&format!("sum-e2e-{arg}"), |b| {
Expand Down Expand Up @@ -145,6 +176,7 @@ criterion_group! {
targets =
evaluation,
trace_generation,
verification,
e2e,
}

Expand Down

0 comments on commit 5d0dbad

Please sign in to comment.