DA: kzg main testing parallelize proofs checks (#803)
This commit is contained in:
parent
66fc046091
commit
563bf6f948
@ -25,6 +25,7 @@ rayon = { version = "1.10", optional = true }
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
divan = "0.1"
|
divan = "0.1"
|
||||||
|
rayon = "1.10"
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "kzg"
|
name = "kzg"
|
||||||
@ -52,5 +53,4 @@ parallel = [
|
|||||||
"ark-poly-commit/parallel",
|
"ark-poly-commit/parallel",
|
||||||
"ark-ec/parallel",
|
"ark-ec/parallel",
|
||||||
"ark-ec/rayon",
|
"ark-ec/rayon",
|
||||||
"ark-bls12-381-ext/parallel"
|
"ark-bls12-381-ext/parallel"]
|
||||||
]
|
|
@ -67,7 +67,7 @@ pub fn verify_element_proof(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::common::{bytes_to_evaluations, bytes_to_polynomial};
|
use crate::common::bytes_to_polynomial;
|
||||||
use crate::kzg::{commit_polynomial, generate_element_proof, verify_element_proof};
|
use crate::kzg::{commit_polynomial, generate_element_proof, verify_element_proof};
|
||||||
use ark_bls12_381::{Bls12_381, Fr};
|
use ark_bls12_381::{Bls12_381, Fr};
|
||||||
use ark_poly::univariate::DensePolynomial;
|
use ark_poly::univariate::DensePolynomial;
|
||||||
@ -75,6 +75,8 @@ mod test {
|
|||||||
use ark_poly_commit::kzg10::{UniversalParams, KZG10};
|
use ark_poly_commit::kzg10::{UniversalParams, KZG10};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use rand::{thread_rng, Fill};
|
use rand::{thread_rng, Fill};
|
||||||
|
use rayon::iter::{IndexedParallelIterator, ParallelIterator};
|
||||||
|
use rayon::prelude::IntoParallelRefIterator;
|
||||||
|
|
||||||
const COEFFICIENTS_SIZE: usize = 16;
|
const COEFFICIENTS_SIZE: usize = 16;
|
||||||
static GLOBAL_PARAMETERS: Lazy<UniversalParams<Bls12_381>> = Lazy::new(|| {
|
static GLOBAL_PARAMETERS: Lazy<UniversalParams<Bls12_381>> = Lazy::new(|| {
|
||||||
@ -103,33 +105,40 @@ mod test {
|
|||||||
let mut bytes: [u8; 310] = [0; 310];
|
let mut bytes: [u8; 310] = [0; 310];
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
bytes.try_fill(&mut rng).unwrap();
|
bytes.try_fill(&mut rng).unwrap();
|
||||||
let evaluations = bytes_to_evaluations::<31>(&bytes, *DOMAIN).evals;
|
|
||||||
let (eval, poly) = bytes_to_polynomial::<31>(&bytes, *DOMAIN).unwrap();
|
let (eval, poly) = bytes_to_polynomial::<31>(&bytes, *DOMAIN).unwrap();
|
||||||
let commitment = commit_polynomial(&poly, &GLOBAL_PARAMETERS).unwrap();
|
let commitment = commit_polynomial(&poly, &GLOBAL_PARAMETERS).unwrap();
|
||||||
let proofs: Vec<_> = (0..10)
|
let proofs: Vec<_> = (0..10)
|
||||||
.map(|i| generate_element_proof(i, &poly, &eval, &GLOBAL_PARAMETERS, *DOMAIN).unwrap())
|
.map(|i| generate_element_proof(i, &poly, &eval, &GLOBAL_PARAMETERS, *DOMAIN).unwrap())
|
||||||
.collect();
|
.collect();
|
||||||
for (i, (element, proof)) in evaluations.iter().zip(proofs.iter()).enumerate() {
|
|
||||||
// verifying works
|
eval.evals
|
||||||
assert!(verify_element_proof(
|
.par_iter()
|
||||||
i,
|
.zip(proofs.par_iter())
|
||||||
element,
|
.enumerate()
|
||||||
&commitment,
|
.for_each(|(i, (element, proof))| {
|
||||||
proof,
|
for ii in i..10 {
|
||||||
*DOMAIN,
|
if ii == i {
|
||||||
&GLOBAL_PARAMETERS
|
// verifying works
|
||||||
));
|
assert!(verify_element_proof(
|
||||||
// verification fails for other items
|
ii,
|
||||||
for ii in i + 1..10 {
|
element,
|
||||||
assert!(!verify_element_proof(
|
&commitment,
|
||||||
ii,
|
proof,
|
||||||
element,
|
*DOMAIN,
|
||||||
&commitment,
|
&GLOBAL_PARAMETERS
|
||||||
proof,
|
));
|
||||||
*DOMAIN,
|
} else {
|
||||||
&GLOBAL_PARAMETERS
|
// Verification should fail for other points
|
||||||
));
|
assert!(!verify_element_proof(
|
||||||
}
|
ii,
|
||||||
}
|
element,
|
||||||
|
&commitment,
|
||||||
|
proof,
|
||||||
|
*DOMAIN,
|
||||||
|
&GLOBAL_PARAMETERS
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user