-
Notifications
You must be signed in to change notification settings - Fork 493
Description
Is your feature request related to a problem? Please describe.
Hi! I needed to integrate proofs generated in gnark with the Circom + snarkjs stack on curves BLS12-381 (and also BN254).
I couldn’t find any existing issues covering the gnark → snarkjs direction.
Therefore, I would like to add to gnark the ability to generate JSON files for the verification key and proof, compatible with snarkjs.
Describe the solution you'd like
I forked gnark and implemented export of:
verification_key.json(compatible withsnarkjs groth16 verify),proof.json(RAW → JSON in snarkjs format) for curves BLS12-381 and BN254. I would like this improvement to be merged into the main repository.
Proposed API (example)
// Export VK to snarkjs JSON format
func (vk *VerifyingKey) ExportVerifyingKey(w io.Writer) error
// Export Proof to snarkjs JSON format
func (proof *Proof) ExportProof(publicSignals []string, w io.Writer) error Describe alternatives you've considered
- Generating TON contracts directly from gnark (my original plan), but for production they still require further development and optimization.
- Using external tools for format conversion, which adds extra steps and potential points of failure.
Additional context
I am working on zk-integration for the TON blockchain. On the library side I use circom + snarkjs, and for TON I generate verifier contracts (I have a separate npm package for that).
To connect this with gnark, I first implemented export to snarkjs-compatible JSON: this allows quick and reliable proof verification with a single command snarkjs groth16 verify, and then the verification key can be used to generate a smart contract for the TON blockchain.
Step-by-step description of the improvement
- Added a snarkjs backend for Groth16.
- Implemented 2 interfaces:
ProofwithExportProof([]string, io.Writer) errorVerifyingKeywithExportVerifyingKey(io.Writer) error
- Added implementations in
prove.goandverify.gofor each curve:- Generation of files for BLS12-381 and BN254
- Stubs for other curves
- Covered with integration tests: via
go testwe generateverification_key.jsonandproof.json, and then callawait groth16.verify(vkey, publicSignals, proof); go fmtgo vet
Current behavior vs Expected behavior
- Current: It is not possible to obtain
verification_key.json/proof.jsoncompatible with snarkjs directly from gnark. - Expected: It should be possible to call export functions in gnark and immediately verify with
snarkjs groth16 verify vk.json public.json proof.json.
Why this is useful to others
- Many projects have their pipelines built around snarkjs. Direct export from gnark will reduce glue code, minimize risk of errors, and speed up integration across ecosystems. It will also allow proofs generated in gnark to be verified directly in the browser.
- Support for BLS12-381 and BN254 covers the vast majority of Groth16 use cases.
OS / Testing
- OS: Windows 10
- Testing: In the demo repository at mysteryon88/gnark-example/cubic, the
cubiccircuit from gnark examples is used. After running tests,keys/verification_key.jsonandproofs/proof.jsonare generated, which can be verified usingsnarkjs groth16 verify(seeverify-snarkjs.test.ts). - Used:
replace github.com/consensys/gnark => C:/.../GitHub/gnark(gnark-fork) or the package: https://github.com/mysteryon88/gnark-to-snarkjs (main)
I’ll be glad to get feedback. I haven’t created a PR yet, but you can already check the finished code in the forked repository mysteryon88/gnark.