Step‑by‑Step Guide to Run the co‑snarks tools
| Tool / Library | Installation Command (Linux/macOS) | Notes |
|---|---|---|
| Rust toolchain (stable) | ```bash\ncurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\nsource $HOME/.cargo/env\n``` |
| Git | bash\nsudo apt-get install -y git # Debian/Ubuntu\n# or\nbrew install git # macOS\n |
Needed to clone the repo. |
| Node.js & npm (v20+) | ```bash\ncurl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -\nsudo apt-get install -y nodejs # Debian/Ubuntu\n# or\nbrew install node # macOS\n``` |
| circom (circuit compiler) | bash\nnpm install -g circom\n |
|
| snarkjs (proof verifier) | bash\nnpm install -g snarkjs\n |
|
| Python 3.9+ (optional helpers) | bash\nsudo apt-get install -y python3 python3-pip # Debian/Ubuntu\n |
|
| OpenSSL development headers | bash\nsudo apt-get install -y libssl-dev # Debian/Ubuntu\n |
Needed for some Rust crates. |
| Build‑essential tools (gcc, make, etc.) | bash\nsudo apt-get install -y build-essential # Debian/Ubuntu\n |
macOS users need Xcode Command Line Tools (xcode-select --install). |
Verify installations:
rustc --version # e.g., rustc 1.78.0
cargo --version
node -v
npm -v
circom --version
snarkjs --versiongit clone https://github.com/0xgetz/co-snarks.git
cd co-snarksThe repo layout (relevant parts):
co-snarks/
├─ coCircom/
│ ├─ co-circom/ # Rust binary for Circom‑based MPC
│ └─ circom-mpc-vm/ # VM implementation
├─ coNoir/
│ └─ co-noir/ # Rust binary for Noir‑based MPC
├─ mpc-core/
└─ mpc-net/
cd coCircom/co-circom
cargo build --releaseThe compiled binary will be at target/release/co-circom. Add it to your PATH for convenience:
export PATH=$PWD/target/release:$PATH # add to ~/.bashrc or ~/.zshrc for persistencecd ../../coNoir/co-noir
cargo build --releaseAgain, add the binary to your PATH:
export PATH=$PWD/target/release:$PATHTip: If you plan to call these binaries from other languages (Python, Go, etc.), you can also build a shared library (
cd … && cargo build --release --features python) – see the repo’sREADMEfor optional features.
Create a simple multiplication circuit example.circom:
pragma circom 2.0.0;
template Multiplier() {
signal input a;
signal input b;
signal output c;
c <== a * b;
}
component main = Multiplier();Compile it with circom:
circom example.circom --r1cs --wasm --symYou will obtain:
example.r1cs– the arithmetic circuitexample.wasm– witness generatorexample.sym– symbol file (optional)
Run the co-circom setup command on the generated R1CS file:
co-circom setup example.r1csWhat happens:
- The tool splits the witness generation into shares for each participant.
- It creates key shares (proving and verification keys) that can be distributed.
- Output files (e.g.,
example.co.r1cs,vk_*.json,pk_*.json) are placed in the same folder.
co-circom provides two binary modes:
- coordinator – optional central node that only forwards messages.
- participant – each party that holds a private input share.
You can run a simple 2‑party demo locally.
co-circom coordinator --port 9000 &
COORD_PID=$!The coordinator just relays encrypted messages between participants.
co-circom participant \
--host localhost \
--port 9000 \
--id 1 \
--input a=5,b=7 &co-circom participant \
--host localhost \
--port 9000 \
--id 2 \
--input a=5,b=7 &Both participants will:
- Generate their share of the witness using the
example.wasmfile. - Run the MPC‑VM to compute the multiplication securely.
- Produce a SNARK proof (e.g., Groth16 or PLONK, depending on the setup).
- Write proof files (
proof.json,public.json) to the working directory.
You can verify with either snarkjs or the built‑in verifier:
snarkjs verify verification_key.json proof.json public.json
# or
co-circom verify \
--vk verification_key.json \
--proof proof.json \
--public public.jsonA successful verification prints true.
Save the following as run_cosnark_demo.sh and make it executable (chmod +x run_cosnark_demo.sh).
#!/usr/bin/env bash
set -e
# 1. Compile the circuit
circom example.circom --r1cs --wasm --sym
# 2. Distributed setup
co-circom setup example.r1cs
# 3. Start coordinator (background)
co-circom coordinator --port 9000 &
COORD_PID=$!
# 4. Participant 1 (background)
co-circom participant --host localhost --port 9000 --id 1 --input a=3,b=4 &
P1_PID=$!
# 5. Participant 2 (background)
co-circom participant --host localhost --port 9000 --id 2 --input a=3,b=4 &
P2_PID=$!
# 6. Wait for both participants to finish
wait $P1_PID $P2_PID
# 7. Verify the generated proof
snarkjs verify verification_key.json proof.json public.json
# 8. Clean up coordinator process
kill $COORD_PIDRun it:
./run_cosnark_demo.shIf everything works, you’ll see true at the verification step.
fn main(a: Field, b: Field) -> Field {
a * b
}cargo install noir # if you haven’t installed it yet
noir compile example.nrThis produces example.circuit (or similar) and a proving key.
co-noir setup example.circuitThe rest of the flow (coordinator → participants → verify) mirrors the co-circom steps, just swapping the binary name.
| Symptom | Likely Cause | Fix |
|---|---|---|
cargo: command not found |
$HOME/.cargo/bin not in $PATH |
Add export PATH=$HOME/.cargo/bin:$PATH to your shell rc file. |
Build fails with openssl errors |