Skip to content

Commit

Permalink
abstract benchmarks, add HyperNova & ProtoGalaxy's IVC benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaucube committed Nov 22, 2024
1 parent 7186cfa commit 07a3f34
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 92 deletions.
2 changes: 1 addition & 1 deletion benches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Run: `cargo bench`

To run a specific benchmark, for example Nova benchmark, run: `cargo bench nova`
To run a specific benchmark, for example Nova benchmark, run: `cargo bench --bench=nova`
57 changes: 57 additions & 0 deletions benches/common.rs
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(())
}
83 changes: 83 additions & 0 deletions benches/hypernova.rs
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);
139 changes: 48 additions & 91 deletions benches/nova.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use ark_ec::CurveGroup;
use ark_ff::PrimeField;
use criterion::*;

use ark_bn254::{constraints::GVar as bn_GVar, Fr as bn_Fr, G1Projective as bn_G};
Expand All @@ -12,105 +10,64 @@ use folding_schemes::{
folding::nova::{Nova, PreprocessorParam},
frontend::{utils::CustomFCircuit, FCircuit},
transcript::poseidon::poseidon_canonical_config,
Error, FoldingScheme,
};

mod common;
use common::bench_ivc_opt;

fn bench_nova_ivc(c: &mut Criterion) {
bench_nova_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())
.unwrap();
let poseidon_config = poseidon_canonical_config::<pallas_Fr>();

bench_nova_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())
.unwrap();
}
fn bench_nova_ivc_opt<
C1: CurveGroup,
C2: CurveGroup,
FS: FoldingScheme<
C1,
C2,
CustomFCircuit<C1::ScalarField>,
PreprocessorParam = PreprocessorParam<
C1,
C2,
CustomFCircuit<C1::ScalarField>,
Pedersen<C1>,
Pedersen<C2>,
false,
>,
>,
>(
c: &mut Criterion,
name: String,
) -> Result<(), Error>
where
C1: CurveGroup<BaseField = C2::ScalarField, ScalarField = C2::BaseField>,
C2::BaseField: PrimeField,
{
// iterate over the powers of n
for n in [10, 14, 15, 16, 17, 18, 19, 20].iter() {
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);

let f_circuit = CustomFCircuit::<C1::ScalarField>::new(fcircuit_size)?;

let poseidon_config = poseidon_canonical_config::<C1::ScalarField>();
let mut rng = rand::rngs::OsRng;

// prepare the Nova prover & verifier params
let prep_param: FS::PreprocessorParam =
PreprocessorParam::new(poseidon_config.clone(), f_circuit);
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)?;
}
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 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(|| fs.prove_step(rng, vec![], None).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);

// verify the IVCProof
let ivc_proof = fs.ivc_proof();
group.bench_function("verify", |b| {
b.iter(|| FS::verify(fs_params.1.clone(), ivc_proof.clone()).unwrap())
});
group.finish();
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();
}
Ok(())
}

criterion_group!(benches, bench_nova_ivc);
Expand Down
77 changes: 77 additions & 0 deletions benches/protogalaxy.rs
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);
Loading

0 comments on commit 07a3f34

Please sign in to comment.