Skip to content

Commit

Permalink
benchmarks evaluation domains
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jul 3, 2023
1 parent 2137e24 commit 6a7361c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions ferveo/benches/bench_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ criterion_main! {
// bench_batch_inverse,
// benchmarks::pairing::ec,
benchmarks::validity_checks::validity_checks,
benchmarks::eval_domain::eval_domain,
}
57 changes: 57 additions & 0 deletions ferveo/benches/benchmarks/eval_domain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#![allow(clippy::redundant_closure)]
#![allow(clippy::unit_arg)]

pub use ark_bls12_381::Bls12_381 as EllipticCurve;
use ark_ff::Field;
use ark_poly::EvaluationDomain;
use criterion::{black_box, criterion_group, BenchmarkId, Criterion};
use digest::crypto_common::rand_core::SeedableRng;
use ferveo_pre_release::*;
use rand::prelude::StdRng;

const NUM_SHARES_CASES: [usize; 6] = [2, 4, 8, 16, 32, 64];

pub fn bench_eval_domain(c: &mut Criterion) {
let mut group = c.benchmark_group("EVAL DOMAIN");
group.sample_size(10);

let rng = &mut StdRng::seed_from_u64(0);
let s = ark_bls12_381::Fr::from_random_bytes(&[0u8; 32]).unwrap();

for shares_num in NUM_SHARES_CASES {
let eval_radix2_eval_domain = {
let domain =
ark_poly::Radix2EvaluationDomain::new(shares_num).unwrap();
let phi = SecretPolynomial::<ark_bls12_381::Bls12_381>::new(
&s, shares_num, rng,
);

move || {
black_box(phi.0.evaluate_over_domain_by_ref(domain));
}
};

let eval_mixed_eval_domain = {
let domain =
ark_poly::MixedRadixEvaluationDomain::new(shares_num).unwrap();
let phi = SecretPolynomial::<ark_bls12_381::Bls12_381>::new(
&s, shares_num, rng,
);

move || {
black_box(phi.0.evaluate_over_domain_by_ref(domain));
}
};

group.bench_function(
BenchmarkId::new("eval_radix2_eval_domain", shares_num),
|b| b.iter(|| eval_radix2_eval_domain()),
);
group.bench_function(
BenchmarkId::new("eval_mixed_eval_domain", shares_num),
|b| b.iter(|| eval_mixed_eval_domain()),
);
}
}

criterion_group!(eval_domain, bench_eval_domain);
1 change: 1 addition & 0 deletions ferveo/benches/benchmarks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//pub mod block_proposer;
// pub mod pairing;
pub mod eval_domain;
pub mod validity_checks;
2 changes: 1 addition & 1 deletion ferveo/src/pvss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<E: Pairing> Default for PubliclyVerifiableParams<E> {

/// Secret polynomial used in the PVSS protocol
/// We wrap this in a struct so that we can zeroize it after use
struct SecretPolynomial<E: Pairing>(DensePolynomial<E::ScalarField>);
pub struct SecretPolynomial<E: Pairing>(pub DensePolynomial<E::ScalarField>);

impl<E: Pairing> SecretPolynomial<E> {
pub fn new(
Expand Down

0 comments on commit 6a7361c

Please sign in to comment.