feat(groth16): support export of verification key and proof to snarkjs-compatible JSON#1584
feat(groth16): support export of verification key and proof to snarkjs-compatible JSON#1584mysteryon88 wants to merge 11 commits into
Conversation
🚨 Bugbot Trial ExpiredYour team's Bugbot trial has expired. Please contact your team administrator to turn on the paid plan to continue using Bugbot. A team admin can activate the plan in the Cursor dashboard. |
|
Thanks for the submission. |
…s-compatible JSON - added ExportVerifyingKey(io.Writer) for VerifyingKey - added ExportProof([]string, io.Writer) for Proof - supported curves: BLS12-381 and BN254
|
|
||
| enc := json.NewEncoder(w) | ||
| enc.SetIndent("", " ") | ||
| return enc.Encode(out) |
There was a problem hiding this comment.
ExportVerifyingKey silently exports incorrect data with commitments
Medium Severity
ExportVerifyingKey lacks the commitment check that ExportProof has. When vk.PublicAndCommitmentCommitted is non-empty, NbPublicWitness() returns a count that includes commitment hash elements, and the IC array includes extra commitment-related points. This silently produces an incorrect snarkjs-incompatible verification key with no error.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 1f3423a. Configure here.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ 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 c40b866. Configure here.
|
|
||
| out := map[string]any{ | ||
| "protocol": "groth16", | ||
| "curve": "bn254", |
There was a problem hiding this comment.
BN254 curve name incompatible with snarkjs format
High Severity
The curve name is set to "bn254", but snarkjs uses "bn128" as the curve identifier for this curve. snarkjs's own verification_key.json output uses "curve": "bn128", and its getCurveFromName function references bn128 (e.g., globalThis.curve_bn128). Since this PR's goal is to produce snarkjs-compatible JSON, using "bn254" may cause snarkjs verification to fail or produce output that isn't interoperable with other snarkjs-based tools.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit c40b866. Configure here.


Description
Issue: #1582
Type of change
How has this been tested?
For testing, I’m using the package: https://github.com/mysteryon88/gnark-to-snarkjs.
To verify the changes I implemented the following integration test workflow:
npmdependencies (for snarkjs tests)gnarkwith the updated version (containing the new export methods). (only for branch gnark-fork)Either by using the fork/branch directly in
go.mod:After this step, the following files are produced:
npm testHow has this been benchmarked?
The newly added export functions are only used when explicitly called and do not affect the core proving or verification logic. They perform simple serialization to JSON and therefore should not impact the overall performance of the library.
Environment:
Checklist:
golangci-lintdoes not output errors locallyNote
Low Risk
Changes are opt-in serialization only; core prove/verify paths are untouched, though exported JSON must match snarkjs expectations for off-chain verification to succeed.
Overview
Adds optional snarkjs-compatible JSON export for Groth16 proofs and verifying keys, wired through a new
backend/snarkjspackage and embedded on the publicgroth16.Proof/groth16.VerifyingKeyinterfaces.BN254 and BLS12-381 get real implementations:
ExportProofwritespi_a/pi_b/pi_c(and optionalpublicSignals), andExportVerifyingKeywrites VK fields includingvk_alphabeta_12from a pairing of α and β. Proofs that include Pedersen commitments are rejected at export time because snarkjs cannot verify them.BLS12-377 and BW6-761 only add stubs that return
not implemented, so every curve still satisfies the new interfaces.Reviewed by Cursor Bugbot for commit ee3372c. Bugbot is set up for automated code reviews on this repo. Configure here.