TL;DR
- You'll rebuild last post's "x is not y" circuit in Circom, prove it with snarkjs, and learn Circom's three arrow operators.
- Then you'll get a side-by-side Noir vs Circom comparison so you know when to reach for which.
In Post 4, Noir let us write assert(x != y) and move on with our lives. Circom doesn't have that luxury, and that turns out to be a great teacher. Circom makes you see what a circuit really is underneath.
Intuition: Noir is a translator, Circom is a phrasebook
Noir is like a translator: you speak normal-ish code and it figures out the math.
Circom is like a phrasebook: you're allowed to say exactly one kind of sentence, and if your thought doesn't fit that shape, you have to rephrase it yourself.
That sentence shape is:
(something linear) × (something linear) = (something linear)
That's a rank-1 constraint, and a Circom circuit compiles to a list of them, called an R1CS. Every check you want has to be bent into this form. Noir does the bending for you; in Circom, you do it.
The trick for "not equal"
"x ≠ y" isn't a multiplication. So we rephrase:
- If x ≠ y, then x − y isn't zero, so it has an inverse: some
invwith (x − y) × inv = 1. - If x = y, then x − y = 0, and 0 × anything = 0, never 1. No
invworks.
So "x ≠ y" becomes "there exists an inv such that (x − y) × inv = 1". That is A × B = C. 🎯
(This works because circuits use field arithmetic, where every non-zero number has an inverse. More on that in Post 6.)
Circom's three arrows
| Operator | Meaning | Adds a constraint? |
|---|---|---|
<-- |
"Compute this value" (a hint for the prover) | ❌ No |
=== |
"These must be equal" | ✅ Yes |
<== |
Both: compute and constrain | ✅ Yes |
Burn this table into your brain. Most Circom security bugs live in the gap between <-- and ===.
Hands-on
Full project: code/05-circom-hello.
pragma circom 2.1.6;
// "I know a secret x that is NOT equal to your public y."
template NotEqual() {
signal input x; // private by default
signal input y; // made public below
signal inv;
inv <-- 1 / (x - y); // hint: computed by the prover, NOT a constraint
(x - y) * inv === 1; // the actual constraint
}
component main {public [y]} = NotEqual();
Values in Circom are signals. Just like Noir, inputs are private unless you list them in {public [...]}.
Why can't we write inv <== 1 / (x - y)? Because division isn't allowed in a constraint: it isn't A × B = C. So we compute inv freely with <--, then check it with ===. Compute-then-check is the pattern you'll see everywhere in Circom.
Now the workflow, using snarkjs with the Groth16 proving system:
# 1. compile to R1CS + a WASM witness generator
mkdir -p build
circom not_equal.circom --r1cs --wasm --sym -o build
# 2. compute the witness from input.json: { "x": "1", "y": "2" }
node build/not_equal_js/generate_witness.js build/not_equal_js/not_equal.wasm input.json build/witness.wtns
# 3. trusted setup (phase 1 "powers of tau", phase 2 circuit-specific)
snarkjs powersoftau new bn128 8 build/pot_0.ptau
snarkjs powersoftau contribute build/pot_0.ptau build/pot_1.ptau --name=me -e="random"
snarkjs powersoftau prepare phase2 build/pot_1.ptau build/pot_final.ptau
snarkjs groth16 setup build/not_equal.r1cs build/pot_final.ptau build/key_0.zkey
snarkjs zkey contribute build/key_0.zkey build/key.zkey --name=me -e="more random"
snarkjs zkey export verificationkey build/key.zkey build/vk.json
# 4. prove and verify
snarkjs groth16 prove build/key.zkey build/witness.wtns build/proof.json build/public.json
snarkjs groth16 verify build/vk.json build/public.json build/proof.json
The repo wraps all of this in npm run all.
Yes, step 3 is a lot. That's the trusted setup: Groth16 needs some secret randomness generated once per circuit, and if anyone keeps it they can forge proofs. Here we're the only contributor, which is fine for learning and not fine for production. Post 13 explains why you might accept that deal anyway.
Noir vs Circom: my honest take
| Noir | Circom | |
|---|---|---|
| Feels like | Rust | A hardware description language |
!=, if, loops |
Just write them | You rephrase them as constraints |
| Default backend | Barretenberg (UltraHonk) | snarkjs (Groth16 / PLONK) |
| Trusted setup | Universal, done once for everyone | Per circuit for Groth16 |
| Footgun level | Lower (the compiler adds constraints for you) | Higher (<-- without ===) |
| Ecosystem | Newer, growing fast | Older, huge library (circomlib), lots of audited code |
My rule: learn on Noir, read Circom. Noir lets you think about the statement. Circom forces you to understand the constraints, and a huge amount of production ZK code (and audit reports) is written in it.
Gotcha: the <-- that compiled happily
My first draft of this circuit had only one line in the body:
inv <-- 1 / (x - y);
I thought: "if x = y, this divides by zero, so the prover can't make a witness. Done!" It compiled. It proved.
But <-- is only a hint. It runs in the honest prover's witness generator, and a malicious prover doesn't have to use that generator at all. They can put any value in inv. Without (x - y) * inv === 1, there were zero constraints in my circuit, so it would accept x = y (or anything else).
Check yourself: snarkjs r1cs info build/not_equal.r1cs prints the number of constraints. If it says 0, your circuit proves nothing.
Recap
- Circom circuits compile to R1CS: lots of A × B = C constraints.
-
<--computes,===constrains,<==does both. A<--with no matching===is a red flag. - Noir is friendlier to write; Circom teaches you what's really happening and dominates existing code.
Next up: we keep bumping into weird facts: no division in constraints, everything has an inverse, == isn't assignment. In Post 6, we finally explain field arithmetic and why you (sort of) can't use if.
Further reading
- Circom docs: especially "Signals" and "Constraint generation". (though, the domain's down recently)
- snarkjs README: the full Groth16 and PLONK walkthrough.
- RareSkills: R1CS: how any computation becomes A × B = C.
Series codebase
All the code from posts in this series will be in this GitHub repo: Zero-Knowledge from zero knowledge

Top comments (0)