From de0c66b440bb2dc24f647284d380bf62d4edc6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Wed, 17 Jan 2024 12:50:11 -0500 Subject: [PATCH] fix: convert to zip_with syntax --- src/provider/non_hiding_kzg.rs | 35 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/provider/non_hiding_kzg.rs b/src/provider/non_hiding_kzg.rs index 128a4ec27..b58ac9a9c 100644 --- a/src/provider/non_hiding_kzg.rs +++ b/src/provider/non_hiding_kzg.rs @@ -1,7 +1,9 @@ //! Non-hiding variant of KZG10 scheme for univariate polynomials. +use crate::zip_with_for_each; use abomonation_derive::Abomonation; use ff::{Field, PrimeField, PrimeFieldBits}; use group::{prime::PrimeCurveAffine, Curve, Group as _}; +use itertools::Itertools as _; use pairing::{Engine, MillerLoopResult, MultiMillerLoop}; use rand_core::{CryptoRng, RngCore}; use rayon::iter::{IntoParallelIterator, ParallelIterator}; @@ -397,23 +399,22 @@ where // Instead of multiplying g and gamma_g in each turn, we simply accumulate // their coefficients and perform a final multiplication at the end. let mut g_multiplier = E::Fr::ZERO; - for (((c, z), v), proof) in multi_commitment - .iter() - .zip(points) - .zip(values) - .zip(batch_proof) - { - let w = proof.proof; - let mut temp = w.mul(*z); - temp += &c.0; - let c = temp; - g_multiplier += &(randomizer * v.0); - total_c += &c.mul(randomizer); - total_w += &w.mul(randomizer); - // We don't need to sample randomizers from the full field, - // only from 128-bit strings. - randomizer = E::Fr::from_u128(rand::Rng::gen::(rng)); - } + zip_with_for_each!( + into_iter, + (multi_commitment, points, values, batch_proof), + |c, z, v, proof| { + let w = proof.proof; + let mut temp = w.mul(*z); + temp += &c.0; + let c = temp; + g_multiplier += &(randomizer * v.0); + total_c += &c.mul(randomizer); + total_w += &w.mul(randomizer); + // We don't need to sample randomizers from the full field, + // only from 128-bit strings. + randomizer = E::Fr::from_u128(rand::Rng::gen::(rng)); + } + ); total_c -= &verifier_params.g.mul(g_multiplier); let mut affine_points = vec![E::G1Affine::identity(); 2];