feat: skip zeroes in msm#168
Merged
Merged
Conversation
99cf74a to
be7ce98
Compare
Contributor
Author
|
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. |
davidnevadoc
approved these changes
Jul 11, 2024
davidnevadoc
left a comment
Collaborator
There was a problem hiding this comment.
LGTM!
I am curious about how this new version performs against the cyclone version in different scalar ranges 🤔
kilic
approved these changes
Jul 14, 2024
| }; | ||
|
|
||
| let number_of_windows = C::Scalar::NUM_BITS as usize / c + 1; | ||
| let field_byte_size = coeffs[0].as_ref().len(); |
Contributor
There was a problem hiding this comment.
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 <davidnevadoc@users.noreply.github.com>
jonathanpwang
pushed a commit
to axiom-crypto/halo2curves
that referenced
this pull request
Aug 13, 2024
* feat: skip zeroes in msm * Update src/msm.rs Co-authored-by: David Nevado <davidnevadoc@users.noreply.github.com> --------- Co-authored-by: David Nevado <davidnevadoc@users.noreply.github.com>
jonathanpwang
pushed a commit
to axiom-crypto/halo2curves
that referenced
this pull request
Aug 13, 2024
* feat: skip zeroes in msm * Update src/msm.rs Co-authored-by: David Nevado <davidnevadoc@users.noreply.github.com> --------- Co-authored-by: David Nevado <davidnevadoc@users.noreply.github.com>
Vindaar
added a commit
to mratsim/constantine
that referenced
this pull request
Oct 25, 2024
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-ethereum/halo2curves#168
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change only affects the
multiexp_serialMSM 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_3andmsm/singlecore/256b_3these regressions seem acceptable because these cases take less than 500 µs.The
msm/singlecore/256b_12case 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_14to be worse thanmsm/singlecore/256b_12(and the same withmsm/singlecore/256b_16) but that's not the case.