Circom in Remix Part 2: User Guide

Rob Stupay
Remix Project
Published in
6 min readDec 19, 2023

The Remix Circom plugin is a great tool for getting started with writing ZK circuits in Circom. The Remix innovation here is that we’ve got the Circom compiler working in the browser. This makes playing with Circom easier because… well, because it’s Remix, so no setup is needed. Just keep in mind that the plugin is in alpha, so it’s not for production use yet.

Under the hood, the Remix Circom plugin’s GUI (graphical user interface) organizes your data into the correct parameters for the methods in snarks.js, so you don’t need to dig too deep there unless you want to. And if you want to, we also have scripts you can adapt that use snarks.js and ethers.js.

Link to Part 1

Part 1 Circom in Remix article (the definitions)

Components of the Proof

At a high level, to make a proof with a ZK system, you need:

  1. The inputs — both private and public
  2. The circuit
  3. The witness
  4. The constraint system
  5. The signals ( the inputs, outputs, and intermediary steps of the circuit)
  6. A special set of random numbers (from the trusted setup- the Perpetual Powers of Tau ceremony)

If these components don’t make sense, please see Part 1 of this series.

The proof can be generated and verified, and it can be submitted for on-chain verification via a Solidity file which we will be generating later in this article.

Let’s take a walk through the Circom compiler plugin.

Remix’s Simplest ZK Snark Example

Let’s choose a very basic example to start with. Remix has added some Workspace Templates for Circom. When you choose one of these templates, the Circom compiler will automatically activate.

To see these templates, create a new Workspace by clicking on the hamburger menu in the File Explorer and choosing the Create option. Then, in the modal that comes up, click the Choose a template pulldown menu, and the following list will come up:

The most basic Circom example file is the simple.circom file which is located in the Semphore template. So to start, choose this template.

Here’s the compiler:

In order to use the plugin you will need to have a .circom file active in the File Explorer, so choose simple.circom.

Then go to the Circom compiler and the compile button can be used.

Note: If the active file in the Editor is not a Circom file, the compile button in the plugin cannot be clicked.

You can either hit the Compile button or use the Ctrl+S keyboard shortcut as shown above in the tool-tip. The compilation result will be stored in a .wasm file in the .bin directory that is inside the circuits folder.

Next, create the R1CS constraint file by clicking the button.

Generate R1CS button with tooltip

This creates the simple.r1cs file in the .bin directory. Generating the R1CS file can take longer than compiling the .circom file.

Compute Witness

The prover inputs their private info for the circuit in this section.

Now dial down the Compute Witness caret.

I’ve input the following:

So my private info is 3 & 4.

When I hit the compute button, a .wtn file is created in the .bin folder.

Files Generated So Far

We now have:

  • simple.wasm (the compilation result)
  • simple.r1cs (the constraint file)
  • simple.wtn (the witness file)

Notice there is no proof file, nor have we generated a Solidity file for doing an on-chain verification of the proof.

Currently in the Remix Circom plugin, these steps can only be done by running scripts.

Using the Scripts in the Circom Compiler

Let’s switch to a different Workspace Template to go through the run_setup and run_verification scripts.

Hash Checker template has fewer parameters in its scripts than the Semphore template does.

So load this template up.

Before running a script

Scripts need a compiled circom file to work with. So before running a script in this plugin, compile calculate_hash.circom (by making it the active file in the Editor and then in the Circom plugin’s GUI, by clicking the compile button).

This will generate the file calculate_hash.wasm in the ./circuits/.bin folder.

Running run_setup.ts

1. Makes the r1cs file

The run_setup.ts script creates the .r1cs file in the circuits/.bin directory, just like the Generate R1CS button did.

The setup script will then take the special randomness of the Powers of Tau ceremony, and will contribute to it and then will add its phase2 as described in the snarks.js docs and in the Circom docs.

The trusted setup consists of two parts:

• The powers of tau, which is independent of the circuit
• The phase 2, which depends on the circuit

- from Circom Docs

2. Makes the verification keys

The verification keys will be used for verifying the proof.
The script generates and stores them in this file:
zk/build/verification_key.json

3. Makes the file for onchain verification

The run_setup.ts script will also generate the Solidity file for verifying the proof. It will also be saved in this directory.

4. Makes zk_setup.txt

Finally the zk_setup.txt will be generated and saved in this directory, which will be used for getting the zkey_final parameter when running run_verification.ts.

Here’s what the build folder will contain after running run_setup.ts:

Running run_verification.ts

This script makes the proof and then will run the verification.

The inputs for the proof include:

  1. The private information: these are hard coded on lines 31–34
  2. The other preliminary files that were created in run_setup.ts, including: calculate_hash.r1cs, calculate_hash.wasm, zk_setup.txt, verification_key.json

It will create the proof as well as the public signals with this line:

    const { proof, publicSignals } = await snarkjs.groth16.prove(zkey_final, wtns);

And then, it will take the proof, the public Signals, and will verify them with this line:

 const verified = await snarkjs.groth16.verify(vKey, publicSignals, proof, logger);

From here, see if you can use the zk_verifier.sol file. Also, try inputting a wrong value into the proof (see line 36) to see what will happen.

Comments Welcome and Needed

The Remix Circom plugin is in Alpha, so please send your comments.

One of our next updates to the plugin will a button for generating a proof. More Remix Circom Workspace templates are also coming.

Join our Discord server and comment there, or send us an email to remix@ethereum.org! We will have articles about each of the Circom Remix Workspaces: Semaphore, Hash Checker, and the Rate Limiting Nullifier later in this series.

--

--