Skip to content

Commit

Permalink
adding bench tests for WNLA
Browse files Browse the repository at this point in the history
  • Loading branch information
olegfomenko committed May 21, 2024
1 parent 10b5f57 commit c7485fe
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions benches/range_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -25,7 +25,6 @@ fn bench_range_proof(ct: &mut Criterion) {
h_vec,
};


// Benching proofs generation
ct.bench_function("prove", |b| {
b.iter_batched(
Expand Down Expand Up @@ -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);

0 comments on commit c7485fe

Please sign in to comment.