mirror of
https://github.com/pseXperiments/clookup.git
synced 2026-01-08 23:28:10 -05:00
Add benchmark for parallelized version
This commit is contained in:
@@ -1,46 +1,85 @@
|
||||
use std::{cmp::max, io::Cursor};
|
||||
|
||||
use clookup::{
|
||||
core::{precomputation::Table, prover::Prover, verifier::Verifier},
|
||||
pcs::{multilinear::kzg::MultilinearKzg, PolynomialCommitmentScheme},
|
||||
utils::{
|
||||
core::{precomputation::Table, prover::Prover, verifier::Verifier}, pcs::{multilinear::kzg::MultilinearKzg, PolynomialCommitmentScheme}, sumcheck::{classic::ClassicSumcheck, parallel::ParallelSumcheck}, utils::{
|
||||
end_timer, random_fe, start_timer,
|
||||
transcript::{InMemoryTranscript, Keccak256Transcript},
|
||||
ProtocolError,
|
||||
},
|
||||
}
|
||||
};
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use halo2curves::bn256::{Bn256, Fr};
|
||||
use itertools::Itertools;
|
||||
|
||||
type ClookupProver = Prover<Fr, MultilinearKzg<Bn256>>;
|
||||
type ClookupVerifier = Verifier<Fr, MultilinearKzg<Bn256>>;
|
||||
type ClookupProverClassic = Prover<Fr, MultilinearKzg<Bn256>, ClassicSumcheck>;
|
||||
type ClookupVerifierClassic = Verifier<Fr, MultilinearKzg<Bn256>, ClassicSumcheck>;
|
||||
|
||||
pub fn test_clookup() -> Result<(), ProtocolError> {
|
||||
let table_dim = 16;
|
||||
let witness_dim = 8;
|
||||
type ClookupProverPar = Prover<Fr, MultilinearKzg<Bn256>, ParallelSumcheck>;
|
||||
type ClookupVerifierPar = Verifier<Fr, MultilinearKzg<Bn256>, ParallelSumcheck>;
|
||||
|
||||
fn set_env(table_dim: usize, witness_dim: usize) -> (Table<Fr>, Vec<Fr>) {
|
||||
let table_vec: Vec<Fr> = (0..1 << table_dim).map(|_| random_fe()).collect_vec();
|
||||
let witness_vec = table_vec
|
||||
.iter()
|
||||
.take(1 << witness_dim)
|
||||
.cloned()
|
||||
.collect_vec();
|
||||
let table: Table<Fr> = table_vec.try_into()?;
|
||||
let table: Table<Fr> = table_vec.try_into().unwrap();
|
||||
(table, witness_vec)
|
||||
}
|
||||
|
||||
pub fn test_clookup_classic() -> Result<(), ProtocolError> {
|
||||
let table_dim = 16;
|
||||
let witness_dim = 8;
|
||||
|
||||
let (table, witness_vec) = set_env(table_dim, witness_dim);
|
||||
|
||||
let max_degree = 1 + max(2, table_dim);
|
||||
let (pp, vp) = {
|
||||
let rng = rand::thread_rng();
|
||||
let param = ClookupProver::setup(&table, &witness_vec, rng)?;
|
||||
let param = ClookupProverClassic::setup(&table, &witness_vec, rng)?;
|
||||
MultilinearKzg::trim(¶m, 1 << witness_dim, 1).unwrap()
|
||||
};
|
||||
let timer = start_timer(|| "clookup prover");
|
||||
let proof = {
|
||||
let mut transcript = Keccak256Transcript::<Cursor<Vec<u8>>>::default();
|
||||
ClookupProver::prove(&pp, &mut transcript, &table, &witness_vec)?;
|
||||
ClookupProverClassic::prove(&pp, &mut transcript, &table, &witness_vec)?;
|
||||
transcript.into_proof()
|
||||
};
|
||||
end_timer(timer);
|
||||
let mut transcript = Keccak256Transcript::<Cursor<Vec<u8>>>::from_proof((), proof.as_slice());
|
||||
ClookupVerifier::verify(
|
||||
ClookupVerifierClassic::verify(
|
||||
&vp,
|
||||
&mut transcript,
|
||||
table_dim + 2,
|
||||
table_dim,
|
||||
witness_dim,
|
||||
max_degree,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn test_clookup_par() -> Result<(), ProtocolError> {
|
||||
let table_dim = 16;
|
||||
let witness_dim = 8;
|
||||
|
||||
let (table, witness_vec) = set_env(table_dim, witness_dim);
|
||||
|
||||
let max_degree = 1 + max(2, table_dim);
|
||||
let (pp, vp) = {
|
||||
let rng = rand::thread_rng();
|
||||
let param = ClookupProverPar::setup(&table, &witness_vec, rng)?;
|
||||
MultilinearKzg::trim(¶m, 1 << witness_dim, 1).unwrap()
|
||||
};
|
||||
let timer = start_timer(|| "clookup prover");
|
||||
let proof = {
|
||||
let mut transcript = Keccak256Transcript::<Cursor<Vec<u8>>>::default();
|
||||
ClookupProverPar::prove(&pp, &mut transcript, &table, &witness_vec)?;
|
||||
transcript.into_proof()
|
||||
};
|
||||
end_timer(timer);
|
||||
let mut transcript = Keccak256Transcript::<Cursor<Vec<u8>>>::from_proof((), proof.as_slice());
|
||||
ClookupVerifierPar::verify(
|
||||
&vp,
|
||||
&mut transcript,
|
||||
table_dim + 2,
|
||||
@@ -52,7 +91,7 @@ pub fn test_clookup() -> Result<(), ProtocolError> {
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("e2e-clookup", |b| b.iter(|| test_clookup()));
|
||||
c.bench_function("e2e-clookup", |b| b.iter(|| test_clookup_classic()));
|
||||
}
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
|
||||
@@ -15,3 +15,7 @@ impl SumcheckSystem {
|
||||
|
||||
fn bench(&self, k: usize) {}
|
||||
}
|
||||
|
||||
fn parse_args() {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user