Background info:
Clone a fork of zokrates with scout support:
git clone -b scout https://github.com/s1na/ZoKrates.git
Compile ZoKrates with the scout
feature enabled (from zokrates_cli
directory):
cd ZoKrates/zokrates_cli
cargo +nightly build --release --features scout
cd target/release
Clone scout:
git clone https://github.com/ewasm/scout.git
Add a directory under scout/scripts
for the stateless contract we'll be creating.
You'll first need to implement a circuit of your choice, compile it, set it up and export witnesses for it. To do this, follow the ZoKrates documentation.
As an example let's imagine we have the following circuit (as mul.code
) which verifies result of multiplication of a private number and a public one:
def main(private field a, field b) -> (field):
return a * b
Now run the following commands:
# compile
./zokrates compile -i mul.code
# perform the setup phase
./zokrates setup
# execute the program (32 is private, 8 is public, result will be 256)
./zokrates compute-witness -a 32 8
Now to generate a verifier which runs as a stateless contract via scout:
# export a solidity verifier
./zokrates scout-verifier -o lib.rs
Note the result is a rust file which you can copy to scout/scripts/zkmul/src/lib.rs
. This generated verifier assumes there are two public inputs, the first one should equal to pre_state_root
and if the verification succeeds, it'll set post_state_root
to the second public input. Feel free to change the rust file to implement your custom logic.
This gist contains also an example Cargo.toml
file for the script.
To test that your verifier works, you need to generate a proof:
./zokrates scout-proof -j proof
The proof
file will contain a hex string which you can add to a new scout yaml test file, like the example provided.
Build scout and the script:
cargo build --release
cd scripts/zkmul && cargo build --release && chisel run --config chisel.toml
And test it via:
target/release/phase2-scout zkmul.yaml
There shouldn't be an error if the verification succeeds.