Repository navigation
feat(kzg): add canonical G1 transform - #840
Open
peter941221 wants to merge 2 commits into
Open
peter941221 wants to merge 2 commits into
peter941221 wants to merge 2 commits into
Conversation
Signed-off-by: Arya Tabaie <arya.pourtabatabaie@gmail.com>
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.
Closes #755.
This is the smallest first step for the existing G1 transform path discussed in the issue. It keeps the current
ToLagrangeG1API and adds the reverse direction asToCanonicalG1, without introducing a direction enum or a broader ECNTT surface.The implementation stays generator-driven. It extracts a shared internal helper in the KZG template, reuses the same G1 FFT path for both directions, and only applies inverse scaling on the inverse/Lagrange direction. Because KZG is generated, the same API appears in all generated KZG curve packages, but the motivating use case remains the BN254 multiproof workflow behind #755.
I regenerated the generated KZG files and validated the change with
go test ./internal/generator/kzgandgo test ./ecc/bn254/kzg ./ecc/bls12-377/kzg ./ecc/bls12-381/kzg ./ecc/bls24-315/kzg ./ecc/bls24-317/kzg ./ecc/bw6-633/kzg ./ecc/bw6-761/kzg.Note
Medium Risk
Changes KZG G1 FFT transform logic shared by SRS basis conversion; incorrect direction or scaling would break cryptographic correctness, though behavior is guarded by round-trip and reference tests.
Overview
Adds
ToCanonicalG1as the inverse ofToLagrangeG1, converting power-of-two G1 vectors from Lagrange evaluations back to canonical (monomial) form via forward FFT on the existing G1 FFT path.ToLagrangeG1is refactored to delegate to a sharedtransformG1(..., inverse)helper; twiddle setup moves tocomputeTwiddles(size, inverse), and the 1/n scaling runs only on the inverse (Lagrange) direction. The KZG generator templates are updated and the same API lands in every generated curvekzgpackage.New tests cover canonical conversion (against scalar FFT reference), Lagrange↔canonical round-trip, non-power-of-two rejection, plus
BenchmarkToCanonicalG1.Reviewed by Cursor Bugbot for commit a51914e. Bugbot is set up for automated code reviews on this repo. Configure here.