Verifying and proving a circuit
This tutorial shows how to verify a new circuit using the EVM Placeholder proof system verifier, which is an application for in-EVM verification of zero-knowledge proofs compatible with Placeholder.
Download and compile the verifier
Prior to installing the verifier, make sure to install Node.js and npm
.
Execute the following commands to download and install evm-placeholder-verification
.
git clone https://github.com/NilFoundation/evm-placeholder-verification.git
cd evm-placeholder-verification/
npm install
npx hardhat compile
Verify a circuit
During the previous tutorial, zkLLVM has generated a folder containing the contracts file and related files for the new circuit.
Copy and paste this folder into ./evm-placeholder-verification/contracts/zkllvm
.
Afterward, run the following command in the root directory of evm-placeholder-verification
.
npx hardhat deploy
This will deploy all circuits in the ./evm-placeholder-verification/contracts/**
directory including the new circuit to a local EVM network.
To verify the new circuit, use the below command.
npx hardhat verify-circuit-proof --test {name_of_circuit_directory}
, where {name_of_circuit_directory}
is the name of the directory containing the transpiler ouputs for the new circuit.
The following message should appear in the terminal.
Run modular verifier for: {name_of_circuit_directory}
Verify : ../contracts/zkllvm/{name_of_circuit_directory}/proof.bin
[ 999n, 5n ]
⛽Gas used: 5097062
Events received:
✅ProofVerified
With this, the new circuit is fully verified!
Generate a proof using proof-producer
The final step in this tutorial is to use proof-producer
to generate a proof for the new circuit and see if it aligns with the proof created by zkLLVM. This step is optional and is only needed if there is a mismatch between proof-generator
and the version of proof-generator
used in evm-placeholder-verification
.
Set up proof-producer
First, clone the proof-producer
repository and its sub-mobules.
git clone --recurse-submodules https://github.com/NilFoundation/proof-producer.git
Then, install the dependencies required to run proof-producer
.
sudo apt-get install build-essential libsctp-dev libssl-dev libicu-dev lsb-release gnutls-dev pkg-config
Create a build
directory and switch to it.
mkdir build && cd build
Re-configure cmake
and compile proof-generator
.
cmake .. -DCMAKE_BUILD_TYPE=Release -DZK_PLACEHOLDER_PROFILING_ENABLED=TRUE -DBLUEPRINT_PLACEHOLDER_PROOF_GEN=True
make -j $(nproc)
Afterward, the ./build/bin/proof-generator
directory should include two versions of proof-generator
.
proof-generator-multi-threaded
proof-generator-single-threaded
This tutorial will use proof-generator-single-threaded
to generate proof.
Generate proof
During the previous tutorial, zkLLVM should have generated the .tbl
and .crct
files for the new circuit.
If these files are not located within the zkllvm/build/examples/cpp
directory, run the following commands in the zkLLVM directory.
cmake --build build -t {name_of_build_target}_crct
cmake --build build -t {name_of_build_target}_tbl
To generate new proof, execute the following command from the proof-producer/build/bin/proof-generator
directory.
./proof-generator-single-threaded -t /path/to/assignment_{name_of_build_target}.tbl --circuit /path/to/circuit_{name_of_build_target}.crct
proof-generator
should place the proof.bin
file with the new proof into the current directoryy.
Validate the new proof
Copy the new proof.bin
file and paste it into the /evm-placeholder-verification/contracts/zkllvm/transpiler_output_{name_of_build_target}
directory.
Replace the already existing proof.bin
file with the new proof and re-run the below command.
npx hardhat verify-circuit-proof --test {name_of_circuit_directory}
The output should be exactly the same as the output for running evm-placeholder-verifier
on the proof generated by zkLLVM.