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 10 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
Medium Risk
Adds new serialization APIs on core
groth16Proof/VerifyingKeyinterfaces and implements curve-specific JSON output; main risk is ecosystem breakage from expanded interfaces and potential incompatibilities with snarkjs expectations.Overview
Adds a new
backend/snarkjsinterface and extends the publicgroth16.Proofandgroth16.VerifyingKeyinterfaces to support exporting snarkjs-compatible JSON.Implements
ExportProof(proof JSON withpi_a/pi_b/pi_c+ optionalpublicSignals) andExportVerifyingKey(verification key JSON includingICandvk_alphabeta_12via pairing) for BN254 and BLS12-381, and explicitly returnsnot implementedfor BLS12-377 and **BW6-761` (including stub methods and imports).Reviewed by Cursor Bugbot for commit c40b866. Bugbot is set up for automated code reviews on this repo. Configure here.