Skip to content

Commit

Permalink
feat(msm): start running sum from max_bits
Browse files Browse the repository at this point in the history
The summation by parts at the end of each pippenger bucket is doing an
addition with identity unnecessarily for unused bits
  • Loading branch information
jonathanpwang committed Sep 1, 2023
1 parent e7d8a2b commit c085798
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions halo2_proofs/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn multiexp_serial<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C], acc: &mut
tmp as usize
}

let segments = (256 / c) + 1;
let segments = (C::Scalar::NUM_BITS as usize + c - 1) / c;

// this can be optimized
let mut coeffs_in_segments = Vec::with_capacity(segments);
Expand Down Expand Up @@ -125,8 +125,10 @@ fn multiexp_serial<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C], acc: &mut

let mut buckets: Vec<Bucket<C>> = vec![Bucket::None; (1 << c) - 1];

let mut max_bits = 0;
for (coeff, base) in coeffs_seg.into_iter().zip(bases.iter()) {
if coeff != 0 {
max_bits = cmp::max(max_bits, coeff);
buckets[coeff - 1].add_assign(base);
}
}
Expand All @@ -136,7 +138,7 @@ fn multiexp_serial<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C], acc: &mut
// (a) + b +
// ((a) + b) + c
let mut running_sum = C::Curve::identity();
for exp in buckets.into_iter().rev() {
for exp in buckets.into_iter().take(max_bits).rev() {
running_sum = exp.add(running_sum);
*acc = *acc + &running_sum;
}
Expand Down

0 comments on commit c085798

Please sign in to comment.