feat(groth16): support export of verification key and proof to snarkjs-compatible JSON
Description
Issue: https://github.com/Consensys/gnark/issues/1582
- added snarkjs backend
- added ExportVerifyingKey(io.Writer) for VerifyingKey
- added ExportProof([]string, io.Writer) for Proof
- supported curves: BLS12-381 and BN254
Type of change
- [x] New feature (non-breaking change which adds functionality)
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:
- Clone the demo repository
git clone https://github.com/mysteryon88/gnark-example
- Install
npmdependencies (for snarkjs tests)
npm install
- Replace
gnarkwith the updated version (containing the new export methods). (only for branch gnark-fork)
Either by using the fork/branch directly in go.mod:
replace github.com/consensys/gnark => github.com/<your-username>/gnark
- Run Go tests to generate JSON files
go test ./cubic -v -run TestCubicBLS12_381
go test ./cubic -v -run TestCubicBN254
After this step, the following files are produced:
- keys/verification_key_
.json - proofs/proof_
.json
- Run npm test to verify proofs with snarkjs
npm test
How 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:
- Windows 10 Pro (64-bit)
- Intel i7-12700H
- 32 GB RAM
Checklist:
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] I did not modify files generated from templates
- [x]
golangci-lintdoes not output errors locally - [x] New and existing unit tests pass locally with my changes
- [x] Any dependent changes have been merged and published in downstream modules
🚨 Bugbot Trial Expired
Your 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.