Creating simple zero-knowledge verifier contract with ZoKrates (0.5.0) solidity (0.5.0)

Alvaro Andres Pinzon Cortes
2 min readMay 5, 2022

--

Prerequisites

Step by step guide

  1. Create a folder named code to put the code
  2. Create the square.code file with this content:
def main(private field a, field b) -> (field):
field result = if a * a == b then 1 else 0 fi
return result

3. Start docker

4. Open the terminal run this command:

docker run -v <PATH_TO_FOLDER>:/home/zokrates/code -ti zokrates/zokrates:0.5.0 /bin/bash

In my case that PATH_TO_FOLDER is were I created the square.code file which is:

docker run -v /Users/andi/Downloads/UdacityGithubNeu-master/zokrates/code:/home/zokrates/code -ti zokrates/zokrates:0.5.0 /bin/bash

5. Change directory to code:

cd code

6. Run this commands to create the proof and verifier

# compile
~/zokrates compile -i square.code
# perform the setup phase
~/zokrates setup
# execute the program
~/zokrates compute-witness -a 3 9
# generate a proof of computation
~/zokrates generate-proof
# export a solidity verifier
~/zokrates export-verifier

6. Open remix IDE, create a contract and copy paste the contents of verifier.sol:

7. Compile

8. Deploy

9. Call the verifyTx function:

--

--

No responses yet