gnark icon indicating copy to clipboard operation
gnark copied to clipboard

feat(groth16): support export of verification key and proof to snarkjs-compatible JSON

Open mysteryon88 opened this issue 4 months ago • 2 comments

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:

  1. Clone the demo repository
git clone https://github.com/mysteryon88/gnark-example
  1. Install npm dependencies (for snarkjs tests)
npm install
  1. Replace gnark with 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
  1. 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
  1. 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-lint does 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

mysteryon88 avatar Aug 21 '25 04:08 mysteryon88

🚨 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.

cursor[bot] avatar Aug 21 '25 04:08 cursor[bot]

Thanks for the submission.

ivokub avatar Sep 11 '25 10:09 ivokub