tokamak-network / zvm

Zero Knowledge based Ethereum Virtual Machine in Circom language
MIT License
17 stars 5 forks source link
circom evm zero-knowledge

zvm

Zero Knowledge based Ethereum Virtual Machine in Circom language

Dependencies

You need node v14, snarkjs and circom.

You can easily install snarkjs and circom by entering the following commands after node v14 is successfully installed.

npm install -g circom@latest
npm install -g snarkjs@latest

Status

zvm is currently under busy construction. The circuit supports the EVM opcodes, the stack size upto eight (unsigned integers), memory size upto eight (unsigned integers) and sixteen input signals of array which represent the bytecodes of EVM.

Completion

The checked opcodes have been implemented.

Quick Start

You can simply do following things with zvm.sh

  1. Building trusted setups
  2. Compile Circom circuits
  3. Debug
  4. Generate and verify a proof
$ cd src
$ ./zvm.sh
Commands
1. Setup phase 1:          $ ./zvm.sh phase1
2. Setup phase 2:          $ ./zvm.sh phase2 [circuit name]
3. Debug with the witness: $ ./zvm.sh debug [circuit name] [input json file path]
4. Generate a proof:       $ ./zvm.sh generate-proof [proof file name] [public file name]
5. Verify a proof:         $ ./zvm.sh verify-proof [proof file path] [public file path] 

Please check snarkjs and circom if you need how it works.

Tutorial

This tutorial leads you how to play with zvm circuit.

Phase 1: General setup

In this phase, you start a new powers of tau ceremony, contribute to the ceremony and apply a random beacon.

$ cd src
$ ./zvm.sh phase1

... 

[DEBUG] snarkJS: betaTauG1: fft 12 join  12/12  1/1 0/2
[DEBUG] snarkJS: betaTauG1: fft 12 join  12/12  1/1 1/2

[NOTE] You can customize the randomness on this step by modifying the script.

Phase 2: Circuit specific setup

You compile a circuit, generate the reference zkey and contribute to the phase 2 ceremony, similar to the previous step. Finally, you export the verification key which is used for verifying a proof.

$ ./zvm.sh phase2 vm

... 

[INFO]  snarkJS: ZKey Ok!

Debug: Calculate a witness and debug the circuit

You execute the circuit with your input file and get debugging result.

$ cat vm-input.json
{"code": ["0x60","0x2","0x60","0x6","0x1","0x0","0x0","0x0","0x0","0x0","0x0","0x0","0x0","0x0","0x0","0x0"]}

...

[INFO] snarkJS: START: main [INFO] snarkJS: GET main.code[0] --> 96 [INFO] snarkJS: GET main.code[1] --> 2 [INFO] snarkJS: GET main.code[2] --> 96 [INFO] snarkJS: GET main.code[3] --> 6 [INFO] snarkJS: GET main.code[4] --> 1 [INFO] snarkJS: GET main.code[5] --> 0 [INFO] snarkJS: FINISH: main


## Generate a proof
You generate a proof using the calculated witness.

$ ./zvm.sh generate-proof proof public


## Verify the proof
You verify the proof and it prints the verification result.

$ ./zvm.sh verify-proof proof.json public.json [INFO] snarkJS: OK!



### Please create an issue if you have any questions.