diff --git a/benches/range_proof.rs b/benches/range_proof.rs index 65f7923..0f89c15 100644 --- a/benches/range_proof.rs +++ b/benches/range_proof.rs @@ -2,8 +2,8 @@ use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion use k256::elliptic_curve::Group; use k256::elliptic_curve::rand_core::OsRng; -use k256::ProjectivePoint; -use bp_pp::range_proof; +use k256::{ProjectivePoint, Scalar}; +use bp_pp::{range_proof, wnla}; use bp_pp::range_proof::u64_proof::{G_VEC_FULL_SZ, H_VEC_FULL_SZ}; fn bench_range_proof(ct: &mut Criterion) { @@ -25,7 +25,6 @@ fn bench_range_proof(ct: &mut Criterion) { h_vec, }; - // Benching proofs generation ct.bench_function("prove", |b| { b.iter_batched( @@ -53,5 +52,55 @@ fn bench_range_proof(ct: &mut Criterion) { }); } +fn bench_wnla(ct: &mut Criterion) { + const N: i32 = 4; + let mut rand = OsRng::default(); + + // Preparing Base points + + let g = k256::ProjectivePoint::random(&mut rand); + let g_vec = (0..N).map(|_| k256::ProjectivePoint::random(&mut rand)).collect(); + let h_vec = (0..N).map(|_| k256::ProjectivePoint::random(&mut rand)).collect(); + let c = (0..N).map(|_| k256::Scalar::generate_biased(&mut rand)).collect(); + let rho = k256::Scalar::generate_biased(&mut rand); + + let wnla = wnla::WeightNormLinearArgument { + g, + g_vec, + h_vec, + c, + rho, + mu: rho.mul(&rho), + }; + + let l = vec![Scalar::from(1 as u32), Scalar::from(2 as u32), Scalar::from(3 as u32), Scalar::from(4 as u32)]; + let n = vec![Scalar::from(8 as u32), Scalar::from(7 as u32), Scalar::from(6 as u32), Scalar::from(5 as u32)]; + let commit = wnla.commit(&l, &n); + + // Benching proofs generation + ct.bench_function("prove WNLA", |b| { + b.iter_batched( + || { + (merlin::Transcript::new(b"wnla test"), commit.clone(), l.clone(), n.clone()) + }, + |(mut pt, commit, l, n)| wnla.prove(&commit, &mut pt, l, n), + BatchSize::SmallInput, + ) + }); + + // Preparing proof to bench verification + let proof = wnla.prove(&commit, &mut merlin::Transcript::new(b"wnla test"), l, n); + + ct.bench_function("verify WNLA", |b| { + b.iter_batched( + || { + (merlin::Transcript::new(b"wnla test"), proof.clone()) + }, + |(mut vt, proof)| assert!(wnla.verify(&commit, &mut vt, proof)), + BatchSize::SmallInput, + ) + }); +} + criterion_group!(benches, bench_range_proof); criterion_main!(benches); \ No newline at end of file