perf: twisted Edwards lattice-based double-base MSM - #1765
Conversation
ivokub
left a comment
There was a problem hiding this comment.
Audit notes from the twisted Edwards double-base scalar multiplication review. The main concern is that the optimized DoubleBaseScalarMulNonZero relation appears to characterize the result only modulo the prime-order subgroup, while the interface currently accepts generic on-curve twisted Edwards points.
|
@ivokub Addressed the review + a related bug found while fixing:
|
ivokub
left a comment
There was a problem hiding this comment.
It seems the snippets also disappeared during merge commit:
It looks like the stats snippets added for this PR were dropped during the merge from master. In
55799fa49,internal/stats/snippet.gostill registeredmsm_babyjubjub_2,msm_jubjub_2, andmsm_bandersnatch_2, andinternal/stats/latest_stats.csvhad the corresponding rows. At current HEAD these registrations and CSV rows are gone. The merge commit4842f113dmodified both stats files, likely resolving to the master-side map-to-curve stats changes and accidentally losing the MSM snippets. Could you restore the twisted Edwards MSM snippets and regenerate/updatelatest_stats.csv?
And it also seems that the hinted result checking is not complete as assumes hinted result being on-curve.
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 c5f1def. Configure here.

Description
This PR is stacked on #1763 and contains the native twisted Edwards MSM follow-up only. It adds lattice-based double-base scalar multiplication variants for native twisted Edwards curves:
DoubleBaseScalarMulNonZeroas the optimized non-degenerate path.DoubleBaseScalarMulremains complete for the public API and handles zero scalars / identity edge cases before dispatching to the optimized non-zero path. The branch also includes the review fixes that remove redundant hint outputs, wire scalar decomposition verification into the twisted Edwards scalar multiplication path, and bind the non-GLV MSM hint to a single result with the sound relation[x1]P1 + [x2]P2 - [z]R = O.This PR intentionally does not include the emulated G2 GLV+FakeGLV work; that is split into #1764.
Type of change
How has this been tested?
Focused test run:
go test -short ./std/algebra/native/twistededwards ./internal/statsSpecifically covered:
How has this been benchmarked?
internal/stats/latest_stats.csvwas regenerated with new MSM(2) snippets.msm_G1_bn254_2msm_P256_2msm_secp256k1_2msm_babyjubjub_2msm_jubjub_2msm_bandersnatch_2Checklist:
golangci-lintdoes not output errors locallygnark-crypto/algebra/lattice)Note
High Risk
Changes in-circuit elliptic-curve arithmetic and hint verification (subgroup binding, torsion resistance); incorrect constraints would be a proof soundness bug, though coverage targets known attacks.
Overview
Adds fast lattice-based double-base scalar multiplication for native twisted Edwards curves while keeping
DoubleBaseScalarMulcomplete by default;algopts.WithIncompleteArithmeticroutes toDoubleBaseScalarMulNonZero(3-MSM + LogUp on non-GLV curves, 6-MSM + GLV φ on Bandersnatch).Soundness hardening for hinted MSM/GLV paths:
assertInSubgroup([cofactor]S == Rplus on-curve preimageS), extendedscalarMulHint/ newdoubleBaseScalarMulHintand multi-rational reconstruction hints, and emulated-field decomposition checks inscalar_decomp.go(replacing redundant native checks and dropping the unusedkoutput fromrationalReconstruct).Regression tests cover trivial decompositions, forged partial MSM hints, 2-torsion forgeries (scalar mul and double-base, BN254 and Bandersnatch), and off-curve subgroup preimages.
Reviewed by Cursor Bugbot for commit 6908b38. Bugbot is set up for automated code reviews on this repo. Configure here.