diff --git a/nomos-da/kzgrs/Cargo.toml b/nomos-da/kzgrs/Cargo.toml index 8d192805..3c004123 100644 --- a/nomos-da/kzgrs/Cargo.toml +++ b/nomos-da/kzgrs/Cargo.toml @@ -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"] \ No newline at end of file diff --git a/nomos-da/kzgrs/src/kzg.rs b/nomos-da/kzgrs/src/kzg.rs index 8ff0230e..0dc73aa8 100644 --- a/nomos-da/kzgrs/src/kzg.rs +++ b/nomos-da/kzgrs/src/kzg.rs @@ -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> = Lazy::new(|| { @@ -103,33 +105,40 @@ 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() { - // verifying works - assert!(verify_element_proof( - i, - element, - &commitment, - proof, - *DOMAIN, - &GLOBAL_PARAMETERS - )); - // verification fails for other items - for ii in i + 1..10 { - assert!(!verify_element_proof( - ii, - element, - &commitment, - proof, - *DOMAIN, - &GLOBAL_PARAMETERS - )); - } - } + + 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( + ii, + element, + &commitment, + proof, + *DOMAIN, + &GLOBAL_PARAMETERS + )); + } else { + // Verification should fail for other points + assert!(!verify_element_proof( + ii, + element, + &commitment, + proof, + *DOMAIN, + &GLOBAL_PARAMETERS + )); + } + } + }); } }