Circuit Compilation

Given that the majority of a circuit's use is driven by SnarkJS, the section on Circuit compilation in the context of the Circom language is very short. You should continue in the SnarkJS Circuit Generation section.

Minimum Circuit Artifacts

Using the circom binary installed to your machine, you can generate various artifacts of your circuits. We will show the bare minimum used in BattleZips' board proof:

circom zk/circuits/board.circom -o zk/ --r1cs --wasm

circom zk/circuits/board.circom targets the circom file to compile from the top level of the BattleZips directory. This command has three consequences:

  • A 'Rank-1 Constraint System' representing the circuit will be written to board.r1cs

  • The 'witness calculator' used with the .zkey to generate proofs given inputs, written to board_js/board.wasm

  • Both of these files will be written to the folder zk in the top level BattleZips directory

The .r1cs file will be further used by SnarkJS to create the circuit's zkey.

We choose to generate our witness calculator in WebAssembly since this is the most portable version of the witness calculator we can generate. It can be used both by servers/ your IDE as well as being served to a client in a browser. If you are building something like a rollup that will only sit on a backend server, you can gain increased efficiency in witness calculation by compiling to C++ instead of WebAssembly.

TODO: LINK TO SNARKJS

Last updated