perf: implement wNAF width=5 GLV scalar mul on G1/2#788
Merged
Conversation
This reverts commit 08363be.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes GLV scalar multiplication performance by switching from a 2-bit joint sliding window method to an interleaved wNAF (width Non-Adjacent Form) with window size 5. The changes affect 9 elliptic curves and introduce a new WnafDecomposition utility function.
- Replaces the 15-entry joint precomputation table with two separate 8-entry odd-multiple tables (one per split scalar)
- Introduces
ecc.WnafDecompositionto compute signed wNAF representations with configurable window size - Maintains the existing GLV scalar splitting approach while changing only the multiplication algorithm
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| ecc/utils.go | Adds new WnafDecomposition function to compute wNAF with configurable window size |
| internal/generator/ecc/template/point.go.tmpl | Updates mulGLV template to use wNAF approach with window=5 and separate odd-multiple tables |
| ecc/bls12-377/g1.go | Generated: applies wNAF GLV implementation for BLS12-377 G1 |
| ecc/bls12-377/g2.go | Generated: applies wNAF GLV implementation for BLS12-377 G2 |
| ecc/bls12-381/g1.go | Generated: applies wNAF GLV implementation for BLS12-381 G1 |
| ecc/bls12-381/g2.go | Generated: applies wNAF GLV implementation for BLS12-381 G2 |
| ecc/bls24-315/g1.go | Generated: applies wNAF GLV implementation for BLS24-315 G1 |
| ecc/bls24-315/g2.go | Generated: applies wNAF GLV implementation for BLS24-315 G2 |
| ecc/bls24-317/g1.go | Generated: applies wNAF GLV implementation for BLS24-317 G1 |
| ecc/bls24-317/g2.go | Generated: applies wNAF GLV implementation for BLS24-317 G2 |
| ecc/bn254/g1.go | Generated: applies wNAF GLV implementation for BN254 G1 |
| ecc/bn254/g2.go | Generated: applies wNAF GLV implementation for BN254 G2 |
| ecc/bw6-633/g1.go | Generated: applies wNAF GLV implementation for BW6-633 G1 |
| ecc/bw6-633/g2.go | Generated: applies wNAF GLV implementation for BW6-633 G2 |
| ecc/bw6-761/g1.go | Generated: applies wNAF GLV implementation for BW6-761 G1 |
| ecc/bw6-761/g2.go | Generated: applies wNAF GLV implementation for BW6-761 G2 |
| ecc/grumpkin/g1.go | Generated: applies wNAF GLV implementation for Grumpkin G1 |
| ecc/secp256k1/g1.go | Generated: applies wNAF GLV implementation for secp256k1 G1 |
YaoJGalteland
previously approved these changes
Jan 19, 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
Switch GLV scalar multiplication to interleaved wNAF with window size 5, using
ecc.WnafDecompositionand precomputed odd‑multiple tables for decomposed subscalars. This reduces addition density versus the 2‑bit joint window GLV while keeping the scalar split unchanged.Fixes #132
Type of change
How has this been tested?
Same tests pass.
How has this been benchmarked?
Checklist:
golangci-lintdoes not output errors locallyNote
Implements interleaved wNAF (window=5) GLV scalar multiplication across all G1/G2 implementations and updates the generator template accordingly.
mulGLVwith wNAF-5 usingecc.WnafDecomposition, per-signed-digit loops, and odd-multiple precompute tables (q1=Q, q2=ϕ(Q)) across curves (bls12-377/381, bls24-315/317, bn254, bw6-633/761, grumpkin, secp256k1)ecc.WnafDecompositionhelper inecc/utils.gointernal/generator/ecc/template/point.go.tmplto emit the new wNAF-GLV logicWritten by Cursor Bugbot for commit 2716692. This will update automatically on new commits. Configure here.