Skip to main content
Create, compile, and test a simple Circom scheme and verify a ZK-proof using the zk-SNARK Groth16 protocol.

Prerequisites

Initialize a project

1

Create a new project

2

Install dependencies

Create the Circom circuit

1

Create the circuit directory

Run the commands from the following steps in the circuits/Multiplier directory, or adjust the paths accordingly if running from the project root.
2

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
3

Compile the circuit

The compiler generates the following files:
  • Multiplier.r1cs — circuit constraints (R1CS)
  • Multiplier.sym — symbolic signal map
  • Multiplier_js/Multiplier.wasm — artifact for generating proof
4

Check the constraints

snarkjs output

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.
Choose the “power of tau” parameter (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.
1

Execute the first phase

2

Execute the second phase

3

Export the verification key

4

Clean up artifacts

Run the commands from the following steps in the project root.

Export the verifier contract

1

Export the verifier contract

2

Generate TypeScript wrappers

These TypeScript wrappers enable type-safe interaction with the verifier contract.

Test and verify the proof

1

Import dependencies

./tests/ZkSimple.spec.ts
2

Implement local verification

./tests/ZkSimple.spec.ts
3

Implement on-chain verification

./tests/ZkSimple.spec.ts

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: generate proof.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.
1

Create a new project

2

Implement the circuit

Implement the circuit logic using Arkworks primitives, similar to a Circom circuit.
3

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

Export the proof and verification key

The following script will create the directory and files automatically.
Rust
5

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

Create a new project

2

Install the dependencies

3

Export the proof and verification key

Go
4

Export the verifier contract

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