perf: G2 lattice-based GLV+FakeGLV scalar-mul#1764
Conversation
ivokub
left a comment
There was a problem hiding this comment.
Two inline comments on BN254/BW6-761 default completeness.
ivokub
left a comment
There was a problem hiding this comment.
Inline comment on the trusted emulated sub-scalar bounds issue.
ivokub
left a comment
There was a problem hiding this comment.
Inline comment on documenting the G2 subgroup precondition.
ivokub
left a comment
There was a problem hiding this comment.
Inline comment on G2 scalar-mul edge-case test coverage.
ivokub
left a comment
There was a problem hiding this comment.
In general looks good, but please see inline comments. Particularly, the implementation should now be complete by default to follow the convention as for G1.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cd1ab5f. Configure here.

Description
This PR is stacked on #1763 and contains the G2 follow-up only. It adds lattice-based GLV+FakeGLV scalar multiplication for emulated G2 curves:
ScalarMulpath to the 4-dimensional GLV+FakeGLV decomposition.ScalarMulimplementation using the same GLV+FakeGLV structure.ScalarMulimplementation using the same GLV+FakeGLV structure.The implementation adds curve-specific scalar multiplication hints and lattice reconstruction hints, then verifies the hinted result in-circuit through the GLV/fakeGLV relation instead of trusting the hint output. It also adds stats snippets for the new G2 scalar multiplication paths.
This PR intentionally does not include the native twisted Edwards MSM work; that is split into #1765.
Type of change
How has this been tested?
Focused test run:
go test -short ./std/algebra/emulated/sw_bls12381 ./std/algebra/emulated/sw_bn254 ./std/algebra/emulated/sw_bw6761 ./internal/statsSpecifically covered:
How has this been benchmarked?
internal/stats/latest_stats.csvwas regenerated with new G2 scalar multiplication snippets.scalar_mul_G2_bls12381scalar_mul_G2_bn254scalar_mul_G2_bw6761Checklist:
golangci-lintdoes not output errors locallygnark-crypto/algebra/lattice)Note
High Risk
Updates core emulated
G2scalar-multiplication implementations (plus new hints) across multiple curves, which is correctness- and soundness-critical for circuit constraints. Incomplete-arithmetic mode introduces documented exceptional sets, so review should focus on edge-case handling and verification equations.Overview
Implements a new lattice-based GLV+FakeGLV scalar-multiplication path for emulated
G2curves.sw_bls12381.G2.ScalarMulnow routes through a 4-dimensional decomposition verified in-circuit, and similarScalarMulimplementations are added forsw_bn254andsw_bw6761.Adds curve-specific hint functions (
scalarMulG2Hint,rationalReconstructExtG2) and precomputed generator constants to support the new decomposition, plus unified/complete-mode handling for edge cases (zero scalar, ±1, and infinity convention) with an optionalWithIncompleteArithmeticfast-but-incomplete mode.Extends stats/bench infrastructure with new
scalar_mul_G2_*snippets and updateslatest_stats.csv, and adds targeted edge-case tests for G2 scalar-mul on BLS12-381, BN254, and BW6-761.Reviewed by Cursor Bugbot for commit 743973d. Bugbot is set up for automated code reviews on this repo. Configure here.