feat(kzg): add canonical G1 transform#840
Open
peter941221 wants to merge 1 commit into
Open
Conversation
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
Adds a new G1 FFT direction (
ToCanonicalG1) and refactors the existing transform path across all generated KZG curve packages; while covered by tests/benchmarks, it touches performance- and correctness-sensitive cryptographic code.Overview
Adds
ToCanonicalG1(Lagrange evals → canonical coeffs) alongside the existingToLagrangeG1in all generated KZG curve packages.Refactors the shared G1 FFT code into a single
transformG1(points, inverse)helper and generalizes twiddle generation to support both forward and inverse transforms, applying the1/nscaling only for the inverse/Lagrange direction.Expands generated tests to cover canonical conversion, round-trips, and non-power-of-two rejection, and adds a
BenchmarkToCanonicalG1plus small scalar/point helpers to build deterministic transform fixtures.Reviewed by Cursor Bugbot for commit c7e29dc. Bugbot is set up for automated code reviews on this repo. Configure here.