Skip to content

perf: implement wNAF width=5 GLV scalar mul on G1/2#788

Merged
yelhousni merged 8 commits intomasterfrom
perf/mulGLV
Jan 26, 2026
Merged

perf: implement wNAF width=5 GLV scalar mul on G1/2#788
yelhousni merged 8 commits intomasterfrom
perf/mulGLV

Conversation

@yelhousni
Copy link
Copy Markdown
Collaborator

@yelhousni yelhousni commented Jan 6, 2026

Description

Switch GLV scalar multiplication to interleaved wNAF with window size 5, using ecc.WnafDecomposition and 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

  • New feature (non-breaking change which adds functionality)

How has this been tested?

Same tests pass.

How has this been benchmarked?

  • bls12-381:
BenchmarkG1AffineScalarMultiplication/method=GLV-wNAF/w=5-32     77120         72460         -6.04%
BenchmarkG2AffineScalarMultiplication/method=GLV-wNAF/w=5-32     203601        186164        -8.56%
  • bw6-761:
BenchmarkG1AffineScalarMultiplication/method=GLV-wNAF/w=5-32     366127        318295        -13.06%
BenchmarkG2AffineScalarMultiplication/method=GLV-wNAF/w=5-32     366178        318220        -13.10

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Note

Implements interleaved wNAF (window=5) GLV scalar multiplication across all G1/G2 implementations and updates the generator template accordingly.

  • Replace prior 2‑bit joint-window GLV in mulGLV with wNAF-5 using ecc.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)
  • Add ecc.WnafDecomposition helper in ecc/utils.go
  • Update internal/generator/ecc/template/point.go.tmpl to emit the new wNAF-GLV logic

Written by Cursor Bugbot for commit 2716692. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.WnafDecomposition to 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
YaoJGalteland previously approved these changes Jan 19, 2026
@yelhousni yelhousni merged commit b5cf053 into master Jan 26, 2026
14 checks passed
@yelhousni yelhousni deleted the perf/mulGLV branch January 26, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2-NAF in G1/G2 scalar multiplication

3 participants