Minor fixes

This commit is contained in:
therealyingtong 2020-09-16 09:02:58 +08:00
parent a63602df2a
commit ced73c2bf7
No known key found for this signature in database
GPG Key ID: 179F32A1503D607E
2 changed files with 13 additions and 11 deletions

View File

@ -182,7 +182,6 @@ fn multiexp_serial<C: CurveAffine>(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<C: CurveAffine>(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<C: CurveAffine>(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];
}
}
}

View File

@ -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<C: CurveAffine>(
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);
});
}