Prerequisites
Initialize a project
Create a new project
Install dependencies
Create the Circom circuit
Create the circuit directory
circuits/Multiplier directory, or adjust the paths accordingly if running from the project root.Implement the circuit
a and b, whose product is equal to the public output c, without revealing a and b themselves.Compile the circuit
Multiplier.r1cs— circuit constraints (R1CS)Multiplier.sym— symbolic signal mapMultiplier_js/Multiplier.wasm— artifact for generating proof
Check the constraints
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.
Execute the first phase
Execute the second phase
Export the verification key
Clean up artifacts
Export the verifier contract
Export the verifier contract
Generate TypeScript wrappers
Test and verify the proof
Import dependencies
Implement local verification
Implement on-chain verification
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.Create a new project
Implement the circuit
Compile, generate proof, perform trusted setup
Export the proof and verification key
Export the verifier contract
Go
Use the gnark library to generate the proof and verification key, then convert them to the snarkjs format with gnark-to-snarkjs.Create a new project
Install the dependencies
Export the proof and verification key
Export the verifier contract
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.