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.
ivokub
left a comment
There was a problem hiding this comment.
The previous issues are addressed. Now there is only one small issue still left.
ivokub
left a comment
There was a problem hiding this comment.
Thanks! All perfect now!

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
Large changes to in-circuit elliptic-curve scalar multiplication and hint soundness; incorrect decomposition, verification, or edge-case handling could break proof soundness for pairing/G2-heavy circuits.
Overview
Adds lattice-based GLV+FakeGLV in-circuit G2
ScalarMulfor emulated BLS12-381, BN254, and BW6-761, replacing BLS12-381’s prior 2D Halo/GLV default and introducing the path on BN254/BW6 where it was missing.The new flow hints
R = [s]Q, decomposes −s into four ~r^(1/4) sub-scalars viarationalReconstructExtG2, and verifies[v1]R + [v2]Φ(R) + [u1]Q + [u2]Φ(Q) = Owith a biased accumulator check against precomputed generator constants—not trusting hints alone. Complete mode usesAddUnified, unified doubling, and explicit handling of s ∈ {0, ±1} and infinity;WithIncompleteArithmeticis now a real faster path (previously ignored on BLS12-381 G2).Also wires
MultiScalarMulthrough the new scalar mul on BLS12-381, registers G2 hint functions, adds stats snippets and updatedlatest_stats.csv, and extends edge-case tests per curve.Reviewed by Cursor Bugbot for commit c635573. Bugbot is set up for automated code reviews on this repo. Configure here.