Conversation
|
@yelhousni - can you explain why we would need these frontend implementations in gnark? Usually for large-field case (i.e. grumpkin) we want to be able to prove the circuit in PLONK/Groth16, but afaik Grumpkin is not proving friendly? And Goldilocks would just be super inefficient, our Unless you have some interesting ideas using folding etc. to have new backends, then I don't currently see the benefit of adding support for new curves for compiling the circuits. |
I need this for some bn254/grumpkin constraints benchmarks, but I'll how I can do that cleanly. |
# Conflicts: # internal/gkr/test_vectors/testdata/gkr_circuit_bn254.scs
Remove goldilocks and unrelated changes, keeping only the minimal Grumpkin curve support needed for witness/compile. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
ivokub
left a comment
There was a problem hiding this comment.
In principle looks good. But why not use code generation in internal/generator/backend? For example following configuration would work and generate the same thing:
grumpkin := templateData{
CSPath: "../../../constraint/grumpkin/",
Curve: "Grumpkin",
CurveID: "GRUMPKIN",
noBackend: true,
NoGKR: true,
ElementType: "U64",
}
ivokub
left a comment
There was a problem hiding this comment.
To avoid generating the tests which would fail imo we could just check if the curve is in gnark.Curves() and then omit generating the test file. Imo that list is a good list of "supported curves" and we could consider everything out of that as experimental.
Description
This PR adds support for the Grumpkin curve (
ecc.GRUMPKIN) in gnark. Grumpkin is an elliptic curve defined over the BN254 base field, commonly used in folding schemes (e.g. Nova, HyperNova) and cycle-of-curves constructions.Changes
Constraint System
New curve-typed constraint system implementation (R1CS and SparseR1CS):
constraint/grumpkin/— coefficient table, marshal, solver, system backed bygnark-crypto/ecc/grumpkin/frFrontend Builders
frontend/cs/r1cs/builder.goandfrontend/cs/scs/builder.godispatch to the new Grumpkin constraint system when the target field matchesecc.GRUMPKIN.Witness
backend/witness/vector.gohandles Grumpkin field elements in witness encoding/decoding.Curves Registry
doc.go—ecc.GRUMPKINadded tognark.Curves().Type of change
How has this been tested?
Also tested end-to-end with a circuit compiled over
ecc.GRUMPKIN(native BN254 map-to-curve).Checklist
golangci-lintdoes not output errors locallygnark-cryptoGrumpkin packages are availableNote
Medium Risk
Adds a new curve-typed constraint system and solver/serialization path for
ecc.GRUMPKIN, which touches core proving inputs (witness encoding) and constraint solving logic. Risk is mainly around correctness/compatibility of the new field-specific implementations and dispatching by modulus.Overview
Adds Grumpkin (
ecc.GRUMPKIN) support end-to-end by introducing a newconstraint/grumpkinimplementation (coeff table, solver, and marshal/system glue) backed bygnark-crypto/ecc/grumpkin/fr.Updates witness handling (
backend/witness) and frontend builders (frontend/cs/r1csandfrontend/cs/scs) to recognize the Grumpkin scalar field modulus and route vector allocation/serialization and constraint-system construction accordingly.Extends generic field-type selection (
constraint/FitsElement) to accept the Grumpkin modulus, and updates the backend generator to include Grumpkin codegen metadata while skipping autogenerated tests via a newNoTestsflag.Written by Cursor Bugbot for commit 8ee6053. This will update automatically on new commits. Configure here.