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]
|
||||
divan = "0.1"
|
||||
rayon = "1.10"
|
||||
|
||||
[[bench]]
|
||||
name = "kzg"
|
||||
@ -52,5 +53,4 @@ parallel = [
|
||||
"ark-poly-commit/parallel",
|
||||
"ark-ec/parallel",
|
||||
"ark-ec/rayon",
|
||||
"ark-bls12-381-ext/parallel"
|
||||
]
|
||||
"ark-bls12-381-ext/parallel"]
|
@ -67,7 +67,7 @@ pub fn verify_element_proof(
|
||||
|
||||
#[cfg(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 ark_bls12_381::{Bls12_381, Fr};
|
||||
use ark_poly::univariate::DensePolynomial;
|
||||
@ -75,6 +75,8 @@ mod test {
|
||||
use ark_poly_commit::kzg10::{UniversalParams, KZG10};
|
||||
use once_cell::sync::Lazy;
|
||||
use rand::{thread_rng, Fill};
|
||||
use rayon::iter::{IndexedParallelIterator, ParallelIterator};
|
||||
use rayon::prelude::IntoParallelRefIterator;
|
||||
|
||||
const COEFFICIENTS_SIZE: usize = 16;
|
||||
static GLOBAL_PARAMETERS: Lazy<UniversalParams<Bls12_381>> = Lazy::new(|| {
|
||||
@ -103,24 +105,30 @@ mod test {
|
||||
let mut bytes: [u8; 310] = [0; 310];
|
||||
let mut rng = thread_rng();
|
||||
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 commitment = commit_polynomial(&poly, &GLOBAL_PARAMETERS).unwrap();
|
||||
let proofs: Vec<_> = (0..10)
|
||||
.map(|i| generate_element_proof(i, &poly, &eval, &GLOBAL_PARAMETERS, *DOMAIN).unwrap())
|
||||
.collect();
|
||||
for (i, (element, proof)) in evaluations.iter().zip(proofs.iter()).enumerate() {
|
||||
|
||||
eval.evals
|
||||
.par_iter()
|
||||
.zip(proofs.par_iter())
|
||||
.enumerate()
|
||||
.for_each(|(i, (element, proof))| {
|
||||
for ii in i..10 {
|
||||
if ii == i {
|
||||
// verifying works
|
||||
assert!(verify_element_proof(
|
||||
i,
|
||||
ii,
|
||||
element,
|
||||
&commitment,
|
||||
proof,
|
||||
*DOMAIN,
|
||||
&GLOBAL_PARAMETERS
|
||||
));
|
||||
// verification fails for other items
|
||||
for ii in i + 1..10 {
|
||||
} else {
|
||||
// Verification should fail for other points
|
||||
assert!(!verify_element_proof(
|
||||
ii,
|
||||
element,
|
||||
@ -131,5 +139,6 @@ mod test {
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user