mirror of
https://github.com/arnaucube/hyperplonk.git
synced 2026-01-12 00:51:27 +01:00
a generic Trait for both ml and uni KZG (#43)
This commit is contained in:
@@ -2,7 +2,10 @@ use ark_bls12_381::{Bls12_381, Fr};
|
||||
use ark_ff::UniformRand;
|
||||
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
|
||||
use ark_std::test_rng;
|
||||
use pcs::{KZGMultilinearPC, MultilinearCommitmentScheme, PCSErrors};
|
||||
use pcs::{
|
||||
prelude::{KZGMultilinearPCS, PCSErrors, PolynomialCommitmentScheme},
|
||||
StructuredReferenceString,
|
||||
};
|
||||
use std::time::Instant;
|
||||
|
||||
fn main() -> Result<(), PCSErrors> {
|
||||
@@ -13,7 +16,7 @@ fn bench_pcs() -> Result<(), PCSErrors> {
|
||||
let mut rng = test_rng();
|
||||
|
||||
// normal polynomials
|
||||
let uni_params = KZGMultilinearPC::<Bls12_381>::setup(&mut rng, 18)?;
|
||||
let uni_params = KZGMultilinearPCS::<Bls12_381>::gen_srs_for_testing(&mut rng, 18)?;
|
||||
|
||||
for nv in 4..19 {
|
||||
let repetition = if nv < 10 {
|
||||
@@ -25,14 +28,18 @@ fn bench_pcs() -> Result<(), PCSErrors> {
|
||||
};
|
||||
|
||||
let poly = DenseMultilinearExtension::rand(nv, &mut rng);
|
||||
let (ck, vk) = uni_params.trim(nv)?;
|
||||
let (ml_ck, ml_vk) = uni_params.0.trim(nv)?;
|
||||
let (uni_ck, uni_vk) = uni_params.1.trim(nv)?;
|
||||
let ck = (ml_ck, uni_ck);
|
||||
let vk = (ml_vk, uni_vk);
|
||||
|
||||
let point: Vec<_> = (0..nv).map(|_| Fr::rand(&mut rng)).collect();
|
||||
|
||||
// commit
|
||||
let com = {
|
||||
let start = Instant::now();
|
||||
for _ in 0..repetition {
|
||||
let _commit = KZGMultilinearPC::commit(&ck, &poly)?;
|
||||
let _commit = KZGMultilinearPCS::commit(&ck, &poly)?;
|
||||
}
|
||||
|
||||
println!(
|
||||
@@ -41,14 +48,14 @@ fn bench_pcs() -> Result<(), PCSErrors> {
|
||||
start.elapsed().as_nanos() / repetition as u128
|
||||
);
|
||||
|
||||
KZGMultilinearPC::commit(&ck, &poly)?
|
||||
KZGMultilinearPCS::commit(&ck, &poly)?
|
||||
};
|
||||
|
||||
// open
|
||||
let proof = {
|
||||
let (proof, value) = {
|
||||
let start = Instant::now();
|
||||
for _ in 0..repetition {
|
||||
let _open = KZGMultilinearPC::open(&ck, &poly, &point)?;
|
||||
let _open = KZGMultilinearPCS::open(&ck, &poly, &point)?;
|
||||
}
|
||||
|
||||
println!(
|
||||
@@ -56,16 +63,16 @@ fn bench_pcs() -> Result<(), PCSErrors> {
|
||||
nv,
|
||||
start.elapsed().as_nanos() / repetition as u128
|
||||
);
|
||||
KZGMultilinearPC::open(&ck, &poly, &point)?
|
||||
KZGMultilinearPCS::open(&ck, &poly, &point)?
|
||||
};
|
||||
let value = poly.evaluate(&point).unwrap();
|
||||
|
||||
// verify
|
||||
|
||||
{
|
||||
let start = Instant::now();
|
||||
for _ in 0..repetition {
|
||||
assert!(KZGMultilinearPC::verify(&vk, &com, &point, &value, &proof)?);
|
||||
assert!(KZGMultilinearPCS::verify(
|
||||
&vk, &com, &point, &value, &proof
|
||||
)?);
|
||||
}
|
||||
println!(
|
||||
"KZG verify for {} variables: {} ns",
|
||||
|
||||
Reference in New Issue
Block a user