-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Reproducible KZG benches (#390)
* Use criterion for consistent benches * adapted poly-commit benchmarks * added the file... * fixed incorrect call to open instead of verify * fmt the bench * add copyright * remove old pcs bench * rename hcs -> pcs * remove extra comments * Added size benches Co-authored-by: Antonio Mejías Gil <[email protected]> * fixed build action by formatting * added KZG tests with the curve Bls12_381 * added KZG commitment/proof size benchmarks with the curve Bls12_381 * changed the range argument from a vector to an interator --------- Co-authored-by: Antonio Mejías Gil <[email protected]>
- Loading branch information
Showing
3 changed files
with
243 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#![cfg(feature = "test-srs")] | ||
|
||
use ark_bls12_381::Bls12_381; | ||
use ark_bn254::Bn254; | ||
use ark_ec::pairing::Pairing; | ||
use ark_ff::UniformRand; | ||
use ark_poly::{DenseMultilinearExtension, MultilinearExtension}; | ||
use ark_serialize::CanonicalSerialize; | ||
use jf_primitives::pcs::{ | ||
prelude::{MultilinearKzgPCS, PolynomialCommitmentScheme, MLE}, | ||
StructuredReferenceString, | ||
}; | ||
use jf_utils::test_rng; | ||
|
||
const MIN_NUM_VARS: usize = 10; | ||
const MAX_NUM_VARS: usize = 20; | ||
|
||
/// Report the size of a commitment | ||
pub fn commitment_size<E: Pairing>(num_vars: usize) -> usize { | ||
let rng = &mut test_rng(); | ||
let pp = MultilinearKzgPCS::<E>::gen_srs_for_testing(rng, num_vars).unwrap(); | ||
|
||
let (ml_ck, _ml_vk) = pp.0.trim(num_vars).unwrap(); | ||
let (uni_ck, _uni_vk) = pp.1.trim(num_vars).unwrap(); | ||
let ck = (ml_ck, uni_ck); | ||
|
||
let poly = MLE::from(DenseMultilinearExtension::rand(num_vars, rng)); | ||
|
||
let commitment = MultilinearKzgPCS::commit(&ck, &poly).unwrap(); | ||
commitment.serialized_size(ark_serialize::Compress::No) | ||
} | ||
|
||
/// Report the size of a proof | ||
pub fn proof_size<E: Pairing>(num_vars: usize) -> usize { | ||
let rng = &mut test_rng(); | ||
let pp = MultilinearKzgPCS::<E>::gen_srs_for_testing(rng, num_vars).unwrap(); | ||
|
||
let (ml_ck, _ml_vk) = pp.0.trim(num_vars).unwrap(); | ||
let (uni_ck, _uni_vk) = pp.1.trim(num_vars).unwrap(); | ||
let ck = (ml_ck, uni_ck); | ||
|
||
let poly = MLE::from(DenseMultilinearExtension::rand(num_vars, rng)); | ||
let point: Vec<_> = (0..num_vars).map(|_| E::ScalarField::rand(rng)).collect(); | ||
|
||
let (proof, _) = MultilinearKzgPCS::open(&ck, &poly, &point).unwrap(); | ||
|
||
proof.serialized_size(ark_serialize::Compress::No) | ||
} | ||
|
||
fn main() { | ||
println!("\nKZG on BN-254: Commitment size"); | ||
for num_vars in (MIN_NUM_VARS..MAX_NUM_VARS).step_by(2) { | ||
println!( | ||
"\tnum_vars: {}, size: {} B", | ||
num_vars, | ||
commitment_size::<Bn254>(num_vars) | ||
); | ||
} | ||
|
||
println!("\nKZG on BN-254: Proof size"); | ||
for num_vars in (MIN_NUM_VARS..MAX_NUM_VARS).step_by(2) { | ||
println!( | ||
"\tnum_vars: {}, size: {} B", | ||
num_vars, | ||
proof_size::<Bn254>(num_vars) | ||
); | ||
} | ||
|
||
println!("\nKZG on BLS-381: Commitment size"); | ||
for num_vars in (MIN_NUM_VARS..MAX_NUM_VARS).step_by(2) { | ||
println!( | ||
"\tnum_vars: {}, size: {} B", | ||
num_vars, | ||
commitment_size::<Bls12_381>(num_vars) | ||
); | ||
} | ||
|
||
println!("\nKZG on BLS-381: Proof size"); | ||
for num_vars in (MIN_NUM_VARS..MAX_NUM_VARS).step_by(2) { | ||
println!( | ||
"\tnum_vars: {}, size: {} B", | ||
num_vars, | ||
proof_size::<Bls12_381>(num_vars) | ||
); | ||
} | ||
} |