Prerequisites
Initialize a project
Create the Circom circuit
Implement the circuit
This circuit proves knowledge of two numbers
a and b, whose product is equal to the public output c, without revealing a and b themselves../circuits/Multiplier/Multiplier.circom
Compile the circuit
Multiplier.r1cs— circuit constraints (R1CS)Multiplier.sym— symbolic signal mapMultiplier.wasm— artifact for generating proof
Initialize trusted setup
The trusted setup is a one-time ceremony that generates the proving and verification keys for a circuit. It is called trusted because if the setup parameters are compromised, proofs could be forged.- For production use, participate in a multi-party trusted setup ceremony.
- For local development and testing, a simplified single-party setup is sufficient.
10) as low as possible, because it affects execution time, but not too low, because the more constraints in the scheme, the higher the parameter required.
Export the verifier contract
Test and verify the proof
Other languages
This tutorial follows the path: Circom → snarkjs → export-ton-verifier → TON. The same workflow applies to other stacks, the key requirement is to obtain a proof and a verification key in the snarkjs format. The idea is always the same: generateproof.json and verification_key.json in the snarkjs format, then perform the verification in TON with the export-ton-verifier.
The zk-ton-examples repository contains templates for Noname, gnark, and Arkworks. It is possible to generate proofs in any of these stacks, then convert them to the snarkjs format and verify them both locally and on-chain.
Rust
Use the Arkworks library to generate the proof and verification key, then convert them into snarkjs format with ark-snarkjs.Implement the circuit
Implement the circuit logic using Arkworks primitives, similar to a Circom circuit.
Compile, generate proof, perform trusted setup
Follow the same workflow as in the Circom section and the trusted setup section, but implement the logic in Rust with Arkworks instead of Circom. The resulting proof and verification key will be in Arkworks format, which can be converted to snarkjs format with ark-snarkjs.
Export the proof and verification key
The following script will create the directory and files automatically.
Rust
Go
Use the gnark library to generate the proof and verification key, then convert them to the snarkjs format with gnark-to-snarkjs.Useful Links
- The zk-ton-examples repository contains additional examples of zk-SNARK circuits and their integration with TON.
- The export-ton-verifier repository is a library that generates TON-compatible verifier contracts from snarkjs verification keys.
- The snarkjs repository is a JavaScript library for generating and verifying zk-SNARK proofs, as well as performing trusted setup ceremonies.
- The ark-snarkjs repository is a utility that converts Arkworks proofs and verification keys into a format compatible with snarkjs.
- The gnark-to-snarkjs repository is a utility that converts gnark proofs and verification keys into a format compatible with snarkjs.
- The Noname repository is a high-level language for writing zk-SNARK circuits, which can be compiled to a format compatible with snarkjs.
- The gnark repository is a Go library for writing zk-SNARK circuits and generating proofs.
- The Arkworks homepage is a Rust ecosystem for zk-SNARKs, providing libraries for writing circuits, generating proofs, and performing trusted setup ceremonies.