-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: skip zeroes in msm #168
Conversation
99cf74a
to
be7ce98
Compare
I forgot to commit the change in the msm when I created this PR (there was only the changes in the benches). The msm change is now committed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I am curious about how this new version performs against the cyclone version in different scalar ranges 🤔
src/msm.rs
Outdated
@@ -297,7 +297,25 @@ pub fn multiexp_serial<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C], acc: & | |||
(f64::from(bases.len() as u32)).ln().ceil() as usize | |||
}; | |||
|
|||
let number_of_windows = C::Scalar::NUM_BITS as usize / c + 1; | |||
let field_byte_size = coeffs[0].as_ref().len(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe div_ceil by 8 is better option here because we don't force consumer to send non empty vectors
Co-authored-by: David Nevado <[email protected]>
* feat: skip zeroes in msm * Update src/msm.rs Co-authored-by: David Nevado <[email protected]> --------- Co-authored-by: David Nevado <[email protected]>
* feat: skip zeroes in msm * Update src/msm.rs Co-authored-by: David Nevado <[email protected]> --------- Co-authored-by: David Nevado <[email protected]>
For scalar field elements modulo p, if all coefficients `a_i` are smaller than some value x < p, their binary representations will have leading zero bits. In this case, we can skip processing the windows corresponding to these leading zeros in the bucket calculation since they would not contribute to the final result. This follows the same idea as in the implementation: privacy-scaling-explorations/halo2curves#168
This change only affects the
multiexp_serial
MSM implementation (and not cyclone).In the multiexp serial MSM algorithm, skip the windows that pick the most significant bits whenever those bits are zeroes in all coefficients. This is done by finding the max number of bits used by the coefficients.
Extend the msm benchmark to use coefficients of different bit sizes.
Closes #150
Supersede #152 (bench comparison of this PR approach and previous PR approach: #152 (comment)
Bench results compared to main branch
From the benchmarks only 3 cases have regressed:
For
msm/multicore/256b_3
andmsm/singlecore/256b_3
these regressions seem acceptable because these cases take less than 500 µs.The
msm/singlecore/256b_12
case is just+1.8255%
so it's not too bad, compared to the significant gains we obtain for bit sizes <= 128. Also I think this result is due to noise. In all the cases as k grows the improvement decreases. So I would expect the change inmsm/singlecore/256b_14
to be worse thanmsm/singlecore/256b_12
(and the same withmsm/singlecore/256b_16
) but that's not the case.