perf: use NAF decomposition in mulWindow#787
Merged
Conversation
Collaborator
|
nice would be nice if we could have a version with no big int for the naf decomposition to avoid allocs (i.e. if scalar < modulus, use the non-big-int version) ? |
Collaborator
Author
The scalar decomposition can output negative integers which would be mod-reduced and the bit-length would increase beyond the |mod|/2 bound. |
YaoJGalteland
previously approved these changes
Jan 20, 2026
YaoJGalteland
approved these changes
Jan 26, 2026
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.
Description
Use
ecc.NafDecompositioninutils.goinmulWindowed.Fixes #132
Type of change
How has this been tested?
Same tests pass.
How has this been benchmarked?
e.g. BLS12-377:
Checklist:
golangci-lintdoes not output errors locallyNote
Implements NAF-based scalar multiplication across all curves and updates codegen.
mulWindowed, addingmulWindowedMixed(affine input) and an affine wrapper; handles zero/negative scalars and reduces scalars modfrwhere neededScalarMultiplication/ScalarMultiplicationBaseto use new paths and return early, using affine generators (*GenAff) in non-GLV casesFromAffineonly when needed) and identical changes applied to G1/G2 for bls12-377, bls12-381, bls24-315/317, bn254, bw6-633/761, grumpkin, secp256k1internal/generator/ecc/template/point.go.tmplto generate the new logicWritten by Cursor Bugbot for commit 833801b. This will update automatically on new commits. Configure here.