-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add benchmarks & initial profiling (#177)
* add Nova benchmarks logic * abstract benchmarks, add HyperNova & ProtoGalaxy's IVC benchmarks * add profiler & flamegraph at benches * add bench compile to github CI
- Loading branch information
Showing
8 changed files
with
350 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# benchmarks | ||
*Note: we're starting to benchmark & profile Sonobe, current results are pre-optimizations.* | ||
|
||
- Benchmark | ||
- Run: `cargo bench` | ||
- To run a specific benchmark, for example Nova's benchmark, run: `cargo bench --bench=nova` | ||
- Profiling | ||
- eg. `cargo bench --bench=nova -- --profile-time 3` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use ark_ec::CurveGroup; | ||
use ark_ff::PrimeField; | ||
use criterion::*; | ||
|
||
use folding_schemes::{ | ||
frontend::{utils::CustomFCircuit, FCircuit}, | ||
Error, FoldingScheme, | ||
}; | ||
|
||
pub(crate) fn bench_ivc_opt< | ||
C1: CurveGroup, | ||
C2: CurveGroup, | ||
FS: FoldingScheme<C1, C2, CustomFCircuit<C1::ScalarField>>, | ||
>( | ||
c: &mut Criterion, | ||
name: String, | ||
n: usize, | ||
prep_param: FS::PreprocessorParam, | ||
) -> Result<(), Error> | ||
where | ||
C1: CurveGroup<BaseField = C2::ScalarField, ScalarField = C2::BaseField>, | ||
C2::BaseField: PrimeField, | ||
{ | ||
let fcircuit_size = 1 << n; // 2^n | ||
|
||
let f_circuit = CustomFCircuit::<C1::ScalarField>::new(fcircuit_size)?; | ||
|
||
let mut rng = rand::rngs::OsRng; | ||
|
||
// prepare the FS prover & verifier params | ||
let fs_params = FS::preprocess(&mut rng, &prep_param)?; | ||
|
||
let z_0 = vec![C1::ScalarField::from(3_u32)]; | ||
let mut fs = FS::init(&fs_params, f_circuit, z_0)?; | ||
|
||
// warmup steps | ||
for _ in 0..5 { | ||
fs.prove_step(rng, vec![], None)?; | ||
} | ||
|
||
let mut group = c.benchmark_group(format!( | ||
"{} - FCircuit: {} (2^{}) constraints", | ||
name, fcircuit_size, n | ||
)); | ||
group.significance_level(0.1).sample_size(10); | ||
group.bench_function("prove_step", |b| { | ||
b.iter(|| black_box(fs.clone()).prove_step(rng, vec![], None).unwrap()) | ||
}); | ||
|
||
// verify the IVCProof | ||
let ivc_proof = fs.ivc_proof(); | ||
group.bench_function("verify", |b| { | ||
b.iter(|| FS::verify(black_box(fs_params.1.clone()), black_box(ivc_proof.clone())).unwrap()) | ||
}); | ||
group.finish(); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use criterion::*; | ||
|
||
use ark_bn254::{constraints::GVar as bn_GVar, Fr as bn_Fr, G1Projective as bn_G}; | ||
use ark_grumpkin::{constraints::GVar as grumpkin_GVar, Projective as grumpkin_G}; | ||
use ark_pallas::{constraints::GVar as pallas_GVar, Fr as pallas_Fr, Projective as pallas_G}; | ||
use ark_vesta::{constraints::GVar as vesta_GVar, Projective as vesta_G}; | ||
|
||
use folding_schemes::{ | ||
commitment::pedersen::Pedersen, | ||
folding::{hypernova::HyperNova, nova::PreprocessorParam}, | ||
frontend::{utils::CustomFCircuit, FCircuit}, | ||
transcript::poseidon::poseidon_canonical_config, | ||
}; | ||
|
||
mod common; | ||
use common::bench_ivc_opt; | ||
|
||
fn bench_hypernova_ivc(c: &mut Criterion) { | ||
let poseidon_config = poseidon_canonical_config::<pallas_Fr>(); | ||
|
||
// iterate over the powers of n | ||
for n in [0_usize, 14, 16, 18, 19, 20, 21, 22].iter() { | ||
let fcircuit_size = 1 << n; // 2^n | ||
let fcircuit = CustomFCircuit::<pallas_Fr>::new(fcircuit_size).unwrap(); | ||
let prep_param = PreprocessorParam::new(poseidon_config.clone(), fcircuit); | ||
|
||
bench_ivc_opt::< | ||
pallas_G, | ||
vesta_G, | ||
HyperNova< | ||
pallas_G, | ||
pallas_GVar, | ||
vesta_G, | ||
vesta_GVar, | ||
CustomFCircuit<pallas_Fr>, | ||
Pedersen<pallas_G>, | ||
Pedersen<vesta_G>, | ||
1, | ||
1, | ||
false, | ||
>, | ||
>( | ||
c, | ||
"HyperNova - Pallas-Vesta curves".to_string(), | ||
*n, | ||
prep_param, | ||
) | ||
.unwrap(); | ||
} | ||
|
||
let poseidon_config = poseidon_canonical_config::<bn_Fr>(); | ||
for n in [0_usize, 14, 16, 18, 19, 20, 21, 22].iter() { | ||
let fcircuit_size = 1 << n; // 2^n | ||
let fcircuit = CustomFCircuit::<bn_Fr>::new(fcircuit_size).unwrap(); | ||
let prep_param = PreprocessorParam::new(poseidon_config.clone(), fcircuit); | ||
|
||
bench_ivc_opt::< | ||
bn_G, | ||
grumpkin_G, | ||
HyperNova< | ||
bn_G, | ||
bn_GVar, | ||
grumpkin_G, | ||
grumpkin_GVar, | ||
CustomFCircuit<bn_Fr>, | ||
Pedersen<bn_G>, | ||
Pedersen<grumpkin_G>, | ||
1, | ||
1, | ||
false, | ||
>, | ||
>( | ||
c, | ||
"HyperNova - BN254-Grumpkin curves".to_string(), | ||
*n, | ||
prep_param, | ||
) | ||
.unwrap(); | ||
} | ||
} | ||
|
||
criterion_group!(benches, bench_hypernova_ivc); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use criterion::*; | ||
use pprof::criterion::{Output, PProfProfiler}; | ||
|
||
use ark_bn254::{constraints::GVar as bn_GVar, Fr as bn_Fr, G1Projective as bn_G}; | ||
use ark_grumpkin::{constraints::GVar as grumpkin_GVar, Projective as grumpkin_G}; | ||
use ark_pallas::{constraints::GVar as pallas_GVar, Fr as pallas_Fr, Projective as pallas_G}; | ||
use ark_vesta::{constraints::GVar as vesta_GVar, Projective as vesta_G}; | ||
|
||
use folding_schemes::{ | ||
commitment::pedersen::Pedersen, | ||
folding::nova::{Nova, PreprocessorParam}, | ||
frontend::{utils::CustomFCircuit, FCircuit}, | ||
transcript::poseidon::poseidon_canonical_config, | ||
}; | ||
|
||
mod common; | ||
use common::bench_ivc_opt; | ||
|
||
fn bench_nova_ivc(c: &mut Criterion) { | ||
let poseidon_config = poseidon_canonical_config::<pallas_Fr>(); | ||
|
||
// iterate over the powers of n | ||
for n in [0_usize, 14, 16, 18, 19, 20, 21, 22].iter() { | ||
let fcircuit_size = 1 << n; // 2^n | ||
let fcircuit = CustomFCircuit::<pallas_Fr>::new(fcircuit_size).unwrap(); | ||
let prep_param = PreprocessorParam::new(poseidon_config.clone(), fcircuit); | ||
|
||
bench_ivc_opt::< | ||
pallas_G, | ||
vesta_G, | ||
Nova< | ||
pallas_G, | ||
pallas_GVar, | ||
vesta_G, | ||
vesta_GVar, | ||
CustomFCircuit<pallas_Fr>, | ||
Pedersen<pallas_G>, | ||
Pedersen<vesta_G>, | ||
false, | ||
>, | ||
>(c, "Nova - Pallas-Vesta curves".to_string(), *n, prep_param) | ||
.unwrap(); | ||
} | ||
|
||
let poseidon_config = poseidon_canonical_config::<bn_Fr>(); | ||
for n in [0_usize, 14, 16, 18, 19, 20, 21, 22].iter() { | ||
let fcircuit_size = 1 << n; // 2^n | ||
let fcircuit = CustomFCircuit::<bn_Fr>::new(fcircuit_size).unwrap(); | ||
let prep_param = PreprocessorParam::new(poseidon_config.clone(), fcircuit); | ||
|
||
bench_ivc_opt::< | ||
bn_G, | ||
grumpkin_G, | ||
Nova< | ||
bn_G, | ||
bn_GVar, | ||
grumpkin_G, | ||
grumpkin_GVar, | ||
CustomFCircuit<bn_Fr>, | ||
Pedersen<bn_G>, | ||
Pedersen<grumpkin_G>, | ||
false, | ||
>, | ||
>( | ||
c, | ||
"Nova - BN254-Grumpkin curves".to_string(), | ||
*n, | ||
prep_param, | ||
) | ||
.unwrap(); | ||
} | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); | ||
targets = bench_nova_ivc | ||
} | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use criterion::*; | ||
|
||
use ark_bn254::{constraints::GVar as bn_GVar, Fr as bn_Fr, G1Projective as bn_G}; | ||
use ark_grumpkin::{constraints::GVar as grumpkin_GVar, Projective as grumpkin_G}; | ||
use ark_pallas::{constraints::GVar as pallas_GVar, Fr as pallas_Fr, Projective as pallas_G}; | ||
use ark_vesta::{constraints::GVar as vesta_GVar, Projective as vesta_G}; | ||
|
||
use folding_schemes::{ | ||
commitment::pedersen::Pedersen, | ||
folding::protogalaxy::ProtoGalaxy, | ||
frontend::{utils::CustomFCircuit, FCircuit}, | ||
transcript::poseidon::poseidon_canonical_config, | ||
}; | ||
|
||
mod common; | ||
use common::bench_ivc_opt; | ||
|
||
fn bench_protogalaxy_ivc(c: &mut Criterion) { | ||
let poseidon_config = poseidon_canonical_config::<pallas_Fr>(); | ||
|
||
// iterate over the powers of n | ||
for n in [0_usize, 14, 16, 18, 19, 20, 21, 22].iter() { | ||
let fcircuit_size = 1 << n; // 2^n | ||
let fcircuit = CustomFCircuit::<pallas_Fr>::new(fcircuit_size).unwrap(); | ||
let prep_param = (poseidon_config.clone(), fcircuit); | ||
|
||
bench_ivc_opt::< | ||
pallas_G, | ||
vesta_G, | ||
ProtoGalaxy< | ||
pallas_G, | ||
pallas_GVar, | ||
vesta_G, | ||
vesta_GVar, | ||
CustomFCircuit<pallas_Fr>, | ||
Pedersen<pallas_G>, | ||
Pedersen<vesta_G>, | ||
>, | ||
>( | ||
c, | ||
"ProtoGalaxy - Pallas-Vesta curves".to_string(), | ||
*n, | ||
prep_param, | ||
) | ||
.unwrap(); | ||
} | ||
|
||
let poseidon_config = poseidon_canonical_config::<bn_Fr>(); | ||
for n in [0_usize, 14, 16, 18, 19, 20, 21, 22].iter() { | ||
let fcircuit_size = 1 << n; // 2^n | ||
let fcircuit = CustomFCircuit::<bn_Fr>::new(fcircuit_size).unwrap(); | ||
let prep_param = (poseidon_config.clone(), fcircuit); | ||
|
||
bench_ivc_opt::< | ||
bn_G, | ||
grumpkin_G, | ||
ProtoGalaxy< | ||
bn_G, | ||
bn_GVar, | ||
grumpkin_G, | ||
grumpkin_GVar, | ||
CustomFCircuit<bn_Fr>, | ||
Pedersen<bn_G>, | ||
Pedersen<grumpkin_G>, | ||
>, | ||
>( | ||
c, | ||
"ProtoGalaxy - BN254-Grumpkin curves".to_string(), | ||
*n, | ||
prep_param, | ||
) | ||
.unwrap(); | ||
} | ||
} | ||
|
||
criterion_group!(benches, bench_protogalaxy_ivc); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.