This repository demonstrates how to build and test a simple Zero-Knowledge Virtual Machine (ZKVM) using Circom for circuit design and SnarkJS for generating and verifying zk-SNARK proofs.
Ensure you have the following installed:
-
Node.js (>= 16.x)
-
npm (comes with Node.js)
-
Circom v2 (installation guide)
-
SnarkJS (install globally)
Sudo npm install -g snarkjs
-
Vim or any text editor (for editing
input.json)
Clone this repo and install dependencies:
git clone <your-repo-url>
cd <your-repo>zkvm.circom # The main Circom circuit file
input.json # Input values for witness generation
README.md # This documentation
Example zkvm.circom:
include "node_modules/circomlib/comparators.circom";
// Simple stack-based VM logic here
component main = ... ;circomlib), make sure they are installed:
npm install circomlibCreate an input.json file with Vim or another editor:
vim input.jsonExample content:
{
"instr": [1,3,1,6,1,2,3,0,3,0]
}Save and exit with :wq.
circom zkvm.circom --r1cs --wasm --sym -l node_modules/circomlib/circuitsThis generates:
zkvm.r1cs→ circuit constraintszkvm_js/→ witness generation codezkvm.sym→ symbols file
Run:
node zkvm_js/generate_witness.js zkvm_js/zkvm.wasm input.json witness.wtnsInitialize:
snarkjs powersoftau new bn128 12 pot12_0000.ptau -vContribute:
snarkjs powersoftau contribute pot12_0000.ptau pot12_0001.ptau --name="First contribution" -vPrepare for phase 2:
snarkjs powersoftau prepare phase2 pot12_0001.ptau pot12_final.ptau -vsnarkjs groth16 setup zkvm.r1cs pot12_final.ptau zkvm_0000.zkeyAdd contribution:
snarkjs zkey contribute zkvm_0000.zkey zkvm_final.zkey --name="Key Contributor" -vExport verification key:
snarkjs zkey export verificationkey zkvm_final.zkey verification_key.jsonsnarkjs groth16 prove zkvm_final.zkey witness.wtns proof.json public.jsonsnarkjs groth16 verify verification_key.json public.json proof.jsonExpected output:
OK!
snarkjs zkey export solidityverifier zkvm_final.zkey Verifier.solCompile and deploy Verifier.sol to Ethereum or compatible chains to perform on-chain verification.
-
EACCES: permission denied, mkdir '/usr/local/lib/node_modules'→ Install withsudoor configure npm prefix:mkdir ~/.npm-global npm config set prefix '~/.npm-global' export PATH=~/.npm-global/bin:$PATH
-
The file circomlib/comparators.circom not found→ Add include path-l node_modules/circomlib/circuits -
[ERROR] snarkJS: Powers of tau is not prepared→ Run Phase 1 & Phase 2 trusted setup first.
🚀 You now have a working ZKVM setup with Circom + SnarkJS!