mirror of
https://github.com/logos-storage/proof-aggregation.git
synced 2026-01-02 13:53:13 +00:00
improve bench for multiple params
This commit is contained in:
parent
af1c337555
commit
e9182cc1d9
@ -10,13 +10,20 @@ use proof_input::params::Params;
|
||||
/// Benchmark for building, proving, and verifying the Plonky2 tree recursion circuit.
|
||||
fn bench_cyclic_recursion<const N: usize>(c: &mut Criterion) -> anyhow::Result<()>{
|
||||
|
||||
let mut group = c.benchmark_group("Cyclic Recursion Benchmark");
|
||||
let mut group = c.benchmark_group(format!("Cyclic Recursion Benchmark for N={}",N));
|
||||
|
||||
// number of samples in each proof
|
||||
let n_samples = 10;
|
||||
|
||||
let mut params = Params::default();
|
||||
let inner_sampling_circuit = SamplingRecursion::<F,D,HF,C>::new(params.circuit_params);
|
||||
let mut input_params = params.input_params;
|
||||
input_params.n_samples = n_samples;
|
||||
let mut circuit_params = params.circuit_params;
|
||||
circuit_params.n_samples = n_samples;
|
||||
let inner_sampling_circuit = SamplingRecursion::<F,D,HF,C>::new(circuit_params);
|
||||
let mut circ_inputs = vec![];
|
||||
for _i in 0..N {
|
||||
circ_inputs.push(gen_testing_circuit_input::<F, D>(¶ms.input_params));
|
||||
circ_inputs.push(gen_testing_circuit_input::<F, D>(&input_params));
|
||||
}
|
||||
|
||||
let mut cyclic_circ = CyclicCircuit::<F,D,_,C>::build_circuit::<HF>(inner_sampling_circuit.clone())?;
|
||||
@ -28,6 +35,7 @@ fn bench_cyclic_recursion<const N: usize>(c: &mut Criterion) -> anyhow::Result<(
|
||||
|
||||
})
|
||||
});
|
||||
println!("cyclic circuit size = {:?}", cyclic_circ.cyclic_circuit_data.common.degree_bits());
|
||||
|
||||
let proof = cyclic_circ.prove_n_layers(circ_inputs.clone())?;
|
||||
|
||||
@ -37,9 +45,8 @@ fn bench_cyclic_recursion<const N: usize>(c: &mut Criterion) -> anyhow::Result<(
|
||||
let _proof = cyclic_circ.prove_n_layers(circ_inputs.clone());
|
||||
})
|
||||
});
|
||||
|
||||
println!("Proof size: {} bytes", proof.to_bytes().len());
|
||||
println!("num of pi = {}", proof.public_inputs.len());
|
||||
println!("pub input: {:?}", proof.public_inputs);
|
||||
|
||||
// Verifying Phase
|
||||
group.bench_function("verify cyclic circuit proof", |b| {
|
||||
@ -59,7 +66,9 @@ fn bench_cyclic_recursion<const N: usize>(c: &mut Criterion) -> anyhow::Result<(
|
||||
|
||||
fn bench_recursion(c: &mut Criterion){
|
||||
const N: usize = 2; // number of proofs to be aggregated
|
||||
bench_cyclic_recursion::<N>(c);
|
||||
bench_cyclic_recursion::<4>(c);
|
||||
bench_cyclic_recursion::<8>(c);
|
||||
bench_cyclic_recursion::<16>(c);
|
||||
}
|
||||
|
||||
/// Criterion benchmark group
|
||||
|
||||
@ -13,16 +13,16 @@ use proof_input::gen_input::{build_circuit, prove_circuit};
|
||||
|
||||
/// Benchmark for building, proving, and verifying the Plonky2 recursion circuit.
|
||||
/// Simple recursion approach - verify N proofs in-circuit
|
||||
fn bench_simple_recursion(c: &mut Criterion) -> Result<()>{
|
||||
let mut group = c.benchmark_group("Simple Recursion Benchmark");
|
||||
fn bench_simple_recursion<const N_INNER: usize>(c: &mut Criterion) -> Result<()>{
|
||||
let mut group = c.benchmark_group(format!("Simple Recursion Benchmark for N ={}", N_INNER));
|
||||
|
||||
// number of samples in each proof
|
||||
let n_samples = 5;
|
||||
let n_samples = 10;
|
||||
// params
|
||||
let mut circ_params = Params::default().circuit_params;
|
||||
circ_params.n_samples = n_samples;
|
||||
// number of inner proofs:
|
||||
const N_INNER: usize = 4;
|
||||
// const N_INNER: usize = 16;
|
||||
|
||||
let (data, pw) = build_circuit(n_samples, 3)?;
|
||||
let proof = prove_circuit(&data, &pw)?;
|
||||
@ -99,10 +99,16 @@ fn bench_simple_recursion(c: &mut Criterion) -> Result<()>{
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn bench_multiple_n(c: &mut Criterion){
|
||||
bench_simple_recursion::<32>(c);
|
||||
bench_simple_recursion::<64>(c);
|
||||
bench_simple_recursion::<128>(c);
|
||||
}
|
||||
|
||||
/// Criterion benchmark group
|
||||
criterion_group!{
|
||||
name = recursion;
|
||||
config = Criterion::default().sample_size(10);
|
||||
targets = bench_simple_recursion
|
||||
targets = bench_multiple_n
|
||||
}
|
||||
criterion_main!(recursion);
|
||||
|
||||
@ -11,16 +11,16 @@ use proof_input::gen_input::{build_circuit, prove_circuit};
|
||||
|
||||
/// Benchmark for building, proving, and verifying the Plonky2 recursion circuit.
|
||||
/// Simple recursion approach - verify N proofs in-circuit
|
||||
fn bench_recursion(c: &mut Criterion) -> Result<()>{
|
||||
let mut group = c.benchmark_group("Simple Recursion With Hashed Public Input Benchmark");
|
||||
fn bench_recursion<const N_INNER: usize>(c: &mut Criterion) -> Result<()>{
|
||||
let mut group = c.benchmark_group(format!("Simple Recursion With Hashed Public Input Benchmark for N={}",N_INNER));
|
||||
|
||||
// number of samples in each proof
|
||||
let n_samples = 5;
|
||||
let n_samples = 50;
|
||||
// params
|
||||
let mut circ_params = Params::default().circuit_params;
|
||||
circ_params.n_samples = n_samples;
|
||||
// number of inner proofs:
|
||||
const N_INNER: usize = 4;
|
||||
// const N_INNER: usize = 16;
|
||||
|
||||
let (data, pw) = build_circuit(n_samples, 3)?;
|
||||
let proof = prove_circuit(&data, &pw)?;
|
||||
@ -93,10 +93,21 @@ fn bench_recursion(c: &mut Criterion) -> Result<()>{
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn bench_multiple_n(c: &mut Criterion){
|
||||
bench_recursion::<4>(c);
|
||||
bench_recursion::<8>(c);
|
||||
bench_recursion::<16>(c);
|
||||
bench_recursion::<32>(c);
|
||||
bench_recursion::<64>(c);
|
||||
bench_recursion::<128>(c);
|
||||
// bench_recursion::<256>(c);
|
||||
}
|
||||
|
||||
|
||||
/// Criterion benchmark group
|
||||
criterion_group!{
|
||||
name = recursion;
|
||||
config = Criterion::default().sample_size(10);
|
||||
targets = bench_recursion
|
||||
targets = bench_multiple_n
|
||||
}
|
||||
criterion_main!(recursion);
|
||||
|
||||
@ -7,17 +7,17 @@ use proof_input::params::{C, D, F, HF, Params};
|
||||
use proof_input::gen_input::{build_circuit, prove_circuit};
|
||||
|
||||
/// Benchmark for building, proving, and verifying the Plonky2 recursion circuit.
|
||||
fn bench_tree_recursion(c: &mut Criterion) -> anyhow::Result<()>{
|
||||
fn bench_tree_recursion<const N_INNER:usize>(c: &mut Criterion) -> anyhow::Result<()>{
|
||||
|
||||
let mut group = c.benchmark_group("Simple Tree Recursion Benchmark");
|
||||
let mut group = c.benchmark_group(format!("Simple Tree Recursion Benchmark for N={}",N_INNER));
|
||||
|
||||
// number of samples in each proof
|
||||
let n_samples = 5;
|
||||
let n_samples = 10;
|
||||
// params
|
||||
let mut circ_params = Params::default().circuit_params;
|
||||
circ_params.n_samples = n_samples;
|
||||
// number of inner proofs:
|
||||
const N_INNER: usize = 4;
|
||||
// const N_INNER: usize = 4;
|
||||
// let mut data: Option<CircuitData<F, C, D>> = None;
|
||||
|
||||
let (data, pw) = build_circuit(n_samples, 3)?;
|
||||
@ -56,10 +56,16 @@ fn bench_tree_recursion(c: &mut Criterion) -> anyhow::Result<()>{
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn bench_multiple_n(c: &mut Criterion){
|
||||
bench_tree_recursion::<4>(c);
|
||||
bench_tree_recursion::<8>(c);
|
||||
bench_tree_recursion::<16>(c);
|
||||
}
|
||||
|
||||
/// Criterion benchmark group
|
||||
criterion_group!{
|
||||
name = recursion;
|
||||
config = Criterion::default().sample_size(10);
|
||||
targets = bench_tree_recursion
|
||||
targets = bench_multiple_n
|
||||
}
|
||||
criterion_main!(recursion);
|
||||
|
||||
@ -78,14 +78,14 @@ fn bench_node_recursion<const M: usize, const N: usize>(c: &mut Criterion) -> Re
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn bench_tree_recursion(c: &mut Criterion) -> Result<()>{
|
||||
let mut group = c.benchmark_group("bench tree recursion - approach 1");
|
||||
fn bench_tree_recursion<const M:usize, const N:usize, const DEPTH:usize, const TOTAL_INPUT:usize>(c: &mut Criterion) -> Result<()>{
|
||||
let mut group = c.benchmark_group(format!("bench tree recursion - approach 1 for N={}",TOTAL_INPUT));
|
||||
|
||||
const M: usize = 1;
|
||||
const N: usize = 2;
|
||||
const DEPTH: usize = 3;
|
||||
// const M: usize = 1;
|
||||
// const N: usize = 2;
|
||||
// const DEPTH: usize = 3;
|
||||
|
||||
const TOTAL_INPUT: usize = (N.pow(DEPTH as u32) - 1) / (N - 1);
|
||||
// const TOTAL_INPUT: usize = T;
|
||||
|
||||
// number of samples in each proof
|
||||
let n_samples = 5;
|
||||
@ -140,7 +140,22 @@ fn bench_tree_recursion_approach1(c: &mut Criterion){
|
||||
const M: usize = 1;
|
||||
const N: usize = 2;
|
||||
bench_node_recursion::<M,N>(c);
|
||||
bench_tree_recursion(c);
|
||||
// bench_tree_recursion(c);
|
||||
}
|
||||
|
||||
fn bench_multiple_params(c: &mut Criterion){
|
||||
const M: usize = 1;
|
||||
const N: usize = 2;
|
||||
const DEPTH1: usize = 2;
|
||||
const TOTAL_INPUT1: usize = (N.pow(DEPTH1 as u32) - 1) / (N - 1);
|
||||
const DEPTH2: usize = 3;
|
||||
const TOTAL_INPUT2: usize = (N.pow(DEPTH2 as u32) - 1) / (N - 1);
|
||||
const DEPTH3: usize = 4;
|
||||
const TOTAL_INPUT3: usize = (N.pow(DEPTH3 as u32) - 1) / (N - 1);
|
||||
|
||||
bench_tree_recursion::<M,N,DEPTH1,TOTAL_INPUT1>(c);
|
||||
bench_tree_recursion::<M,N,DEPTH2,TOTAL_INPUT2>(c);
|
||||
bench_tree_recursion::<M,N,DEPTH3,TOTAL_INPUT3>(c);
|
||||
}
|
||||
|
||||
|
||||
@ -148,6 +163,6 @@ fn bench_tree_recursion_approach1(c: &mut Criterion){
|
||||
criterion_group!{
|
||||
name = recursion;
|
||||
config = Criterion::default().sample_size(10);
|
||||
targets = bench_tree_recursion_approach1
|
||||
targets = bench_multiple_params
|
||||
}
|
||||
criterion_main!(recursion);
|
||||
|
||||
@ -16,7 +16,7 @@ use proof_input::params::Params;
|
||||
/// Benchmark for building, proving, and verifying the Plonky2 tree recursion circuit.
|
||||
fn bench_tree_recursion<const N: usize, const K: usize>(c: &mut Criterion) -> anyhow::Result<()>{
|
||||
|
||||
let mut group = c.benchmark_group("Tree Recursion - Approach 2 Benchmark");
|
||||
let mut group = c.benchmark_group(format!("Tree Recursion - Approach 2 Benchmark for N={}",K));
|
||||
|
||||
//------------ sampling inner circuit ----------------------
|
||||
// Circuit that does the sampling - default input
|
||||
@ -138,10 +138,98 @@ fn bench_tree_recursion<const N: usize, const K: usize>(c: &mut Criterion) -> an
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Benchmark for building, proving, and verifying the Plonky2 tree recursion circuit.
|
||||
fn bench_tree_recursion_node_only<const N: usize, const K: usize>(c: &mut Criterion) -> anyhow::Result<()>{
|
||||
|
||||
let mut group = c.benchmark_group(format!("Tree Recursion - Approach 2 Benchmark for N={}",K));
|
||||
|
||||
//------------ sampling inner circuit ----------------------
|
||||
// Circuit that does the sampling - default input
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let mut sampling_builder = CircuitBuilder::<F, D>::new(config);
|
||||
let mut params = Params::default();
|
||||
let one_circ_input = gen_testing_circuit_input::<F,D>(¶ms.input_params);
|
||||
let samp_circ = SampleCircuit::<F,D,HF>::new(params.circuit_params);
|
||||
let inner_tar = samp_circ.sample_slot_circuit_with_public_input(&mut sampling_builder)?;
|
||||
// get generate a sampling proof
|
||||
let mut pw = PartialWitness::<F>::new();
|
||||
samp_circ.sample_slot_assign_witness(&mut pw,&inner_tar,&one_circ_input);
|
||||
let inner_data = sampling_builder.build::<C>();
|
||||
let inner_proof = inner_data.prove(pw.clone())?;
|
||||
|
||||
// ------------------- leaf --------------------
|
||||
// leaf circuit that verifies the sampling proof
|
||||
let inner_circ = SamplingRecursion::<F,D,HF,C>::new(Params::default().circuit_params);
|
||||
let leaf_circuit = LeafCircuit::<F,D,_>::new(inner_circ);
|
||||
|
||||
let leaf_in = LeafInput{
|
||||
inner_proof,
|
||||
verifier_data: inner_data.verifier_data(),
|
||||
};
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let mut leaf_builder = CircuitBuilder::<F, D>::new(config);
|
||||
let leaf_targets = leaf_circuit.build::<C,HF>(&mut leaf_builder)?;
|
||||
let leaf_circ_data = leaf_builder.build::<C>();
|
||||
|
||||
let mut pw = PartialWitness::<F>::new();
|
||||
leaf_circuit.assign_targets::<C,HF>(&mut pw, &leaf_targets, &leaf_in)?;
|
||||
let leaf_proof = leaf_circ_data.prove(pw.clone())?;
|
||||
|
||||
|
||||
// ------------- Node/tree circuit ------------------
|
||||
// node circuit that verifies leafs or itself
|
||||
|
||||
let mut tree = TreeRecursion::<F,D,C,N>::build::<_,HF>(leaf_circuit.clone())?;
|
||||
|
||||
// Building phase
|
||||
group.bench_function("build tree circuit", |b| {
|
||||
b.iter(|| {
|
||||
let _tree = TreeRecursion::<F,D,C,N>::build::<_,HF>(leaf_circuit.clone());
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
let leaf_proofs: Vec<ProofWithPublicInputs<F, C, D>> = (0..K)
|
||||
.map(|_| {
|
||||
leaf_proof.clone()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let tree_root_proof = tree.prove_tree(leaf_proofs.clone()).unwrap();
|
||||
|
||||
// Proving Phase
|
||||
group.bench_function("prove tree circuit", |b| {
|
||||
b.iter(|| {
|
||||
let _tree_root_proof = tree.prove_tree(leaf_proofs.clone());
|
||||
})
|
||||
});
|
||||
|
||||
println!("tree circuit - Circuit size (degree bits): {:?}", tree.node.node_data.node_circuit_data.common.degree_bits());
|
||||
println!("tree circuit - num of public input = {}", tree_root_proof.public_inputs.len());
|
||||
|
||||
assert!(
|
||||
tree.verify_proof(tree_root_proof.clone(), N==K).is_ok(),
|
||||
"proof verification failed"
|
||||
);
|
||||
|
||||
// Verifying Phase
|
||||
group.bench_function("verify tree circuit", |b| {
|
||||
b.iter(|| {
|
||||
tree.verify_proof(tree_root_proof.clone(), N==K).expect("verify fail");
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
group.finish();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn bench_tree_recursion_approach2(c: &mut Criterion){
|
||||
const N: usize = 2; // number of child nodes
|
||||
const K: usize = 2; // number of proofs to be aggregated in the tree
|
||||
bench_tree_recursion::<N,K>(c);
|
||||
const K: usize = 4; // number of proofs to be aggregated in the tree
|
||||
bench_tree_recursion_node_only::<N,4>(c);
|
||||
bench_tree_recursion_node_only::<N,8>(c);
|
||||
bench_tree_recursion_node_only::<N,16>(c);
|
||||
}
|
||||
|
||||
/// Criterion benchmark group
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user