diff --git a/src/arithmetic.rs b/src/arithmetic.rs index 750c9fb1..a7193a87 100644 --- a/src/arithmetic.rs +++ b/src/arithmetic.rs @@ -182,7 +182,6 @@ fn multiexp_serial(coeffs: &[C::Scalar], bases: &[C], acc: &mut /// Performs a small multi-exponentiation operation. /// Uses the double-and-add algorithm with doublings shared across points. - pub fn small_multiexp(coeffs: &[C::Scalar], bases: &[C]) -> C::Projective { let coeffs: Vec<[u8; 32]> = coeffs.iter().map(|a| a.to_bytes()).collect(); let mut acc = C::Projective::zero(); @@ -195,8 +194,8 @@ pub fn small_multiexp(coeffs: &[C::Scalar], bases: &[C]) -> C::P // for each coeff for coeff_idx in 0..coeffs.len() { let byte = coeffs[coeff_idx][byte_idx]; - if (byte >> bit_idx & 1) != 0 { - acc = acc + &bases[coeff_idx].to_projective(); + if ((byte >> bit_idx) & 1) != 0 { + acc += bases[coeff_idx]; } } } diff --git a/src/poly/commitment/prover.rs b/src/poly/commitment/prover.rs index 0349b28f..c66fe827 100644 --- a/src/poly/commitment/prover.rs +++ b/src/poly/commitment/prover.rs @@ -1,8 +1,8 @@ use super::super::{Coeff, Polynomial}; use super::{Blind, OpeningProof, Params}; use crate::arithmetic::{ - best_multiexp, compute_inner_product, get_challenge_scalar, small_multiexp, Challenge, Curve, - CurveAffine, Field, + best_multiexp, compute_inner_product, get_challenge_scalar, parallelize, small_multiexp, + Challenge, Curve, CurveAffine, Field, }; use crate::transcript::Hasher; @@ -220,11 +220,14 @@ fn parallel_generator_collapse( challenge_inv: C::Scalar, ) { let len = g.len() / 2; - let (g_lo, g_hi) = g.split_at_mut(len); + let (mut g_lo, g_hi) = g.split_at_mut(len); - let mut tmp = Vec::with_capacity(g_lo.len()); - for (g_lo, g_hi) in g_lo.iter().zip(g_hi.iter()) { - tmp.push(small_multiexp(&[challenge_inv, challenge], &[*g_lo, *g_hi])); - } - C::Projective::batch_to_affine(&tmp, g_lo); + parallelize(&mut g_lo, |g_lo, start| { + let g_hi = &g_hi[start..]; + let mut tmp = Vec::with_capacity(g_lo.len()); + for (g_lo, g_hi) in g_lo.iter().zip(g_hi.iter()) { + tmp.push(small_multiexp(&[challenge_inv, challenge], &[*g_lo, *g_hi])); + } + C::Projective::batch_to_affine(&tmp, g_lo); + }); }