use blstrs::Scalar; use kzg::polynomial::Polynomial; use kzg::{setup, KZGParams, KZGProver, KZGVerifier}; use pairing::{group::ff::Field}; use rand::{rngs::SmallRng, Rng, SeedableRng}; use criterion::{black_box, criterion_group, criterion_main, Criterion}; pub fn csprng_setup() -> KZGParams { let s: Scalar = rand::random::().into(); setup(s, MAX_COEFFS) } fn bench_poly_verify(c: &mut Criterion) { let params = csprng_setup::(); let mut rng = SmallRng::from_seed([42; 32]); let mut coeffs = vec![Scalar::zero(); NUM_COEFFS]; for i in 0..NUM_COEFFS { coeffs[i] = rng.gen::().into(); } let polynomial = Polynomial::new_from_coeffs(coeffs, NUM_COEFFS - 1); let mut prover = KZGProver::new(¶ms); let verifier = KZGVerifier::new(¶ms); let commitment = prover.commit(polynomial.clone()); c.bench_function( format!("bench_verify_poly, degree {}", NUM_COEFFS - 1).as_str(), |b| { b.iter(|| { verifier.verify_poly(black_box(&commitment), black_box(&polynomial)); }) }, ); } criterion_group!(poly_verify, bench_poly_verify<10>, bench_poly_verify<50>, bench_poly_verify<100>, bench_poly_verify<200>); criterion_main!(poly_verify);