Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions algorithms/src/msm/variable_base/batched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use rayon::prelude::*;

#[cfg(target_arch = "x86_64")]
use crate::{prefetch_slice, prefetch_slice_write};
use std::ops::AddAssign;

#[derive(Copy, Clone, Debug)]
pub struct BucketPosition {
Expand Down Expand Up @@ -359,14 +360,14 @@ fn batched_window<G: AffineCurve>(

let buckets = batch_add(num_buckets, bases, &mut bucket_positions);

let mut res = G::Projective::zero();
let mut running_sum = G::Projective::zero();
let mut res = G::Projective::zero_bucket();
let mut running_sum = G::Projective::zero_bucket();
for b in buckets.into_iter().rev() {
running_sum.add_assign_mixed(&b);
running_sum.add_assign(&b.to_projective());
res += &running_sum;
}

(res, window_size)
(res.into(), window_size)
}

pub fn msm<G: AffineCurve>(bases: &[G], scalars: &[<G::ScalarField as PrimeField>::BigInteger]) -> G::Projective {
Expand Down
12 changes: 6 additions & 6 deletions algorithms/src/msm/variable_base/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn update_buckets<G: AffineCurve>(
mut scalar: <G::ScalarField as PrimeField>::BigInteger,
w_start: usize,
c: usize,
buckets: &mut [G::Projective],
buckets: &mut [<G::Projective as ProjectiveCurve>::Bucket],
) {
// We right-shift by w_start, thus getting rid of the lower bits.
scalar.divn(w_start as u32);
Expand All @@ -36,7 +36,7 @@ fn update_buckets<G: AffineCurve>(
// If the scalar is non-zero, we update the corresponding bucket.
// (Recall that `buckets` doesn't have a zero bucket.)
if scalar != 0 {
buckets[(scalar - 1) as usize].add_assign_mixed(base);
buckets[(scalar - 1) as usize].into().add_assign_mixed(base);
}
}

Expand All @@ -58,19 +58,19 @@ fn standard_window<G: AffineCurve>(

// We don't need the "zero" bucket, so we only have 2^c - 1 buckets
let window_size = if (w_start % c) != 0 { w_start % c } else { c };
let mut buckets = vec![G::Projective::zero(); (1 << window_size) - 1];
let mut buckets = vec![G::Projective::zero_bucket(); (1 << window_size) - 1];
scalars
.iter()
.zip(bases)
.filter(|&(&s, _)| s > fr_one)
.for_each(|(&scalar, base)| update_buckets(base, scalar, w_start, c, &mut buckets));
// G::Projective::batch_normalization(&mut buckets);

for running_sum in buckets.into_iter().rev().scan(G::Projective::zero(), |sum, b| {
*sum += b;
for running_sum in buckets.into_iter().rev().scan(G::Projective::zero_bucket(), |sum, b| {
*sum += &b;
Some(*sum)
}) {
res += running_sum;
res += running_sum.into();
}

(res, window_size)
Expand Down
Loading