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

Prerequisites

Step by step guide

  1. Create a folder named code to put the code
def main(private field a, field b):
assert(a * a == b)
return

3. Start docker

4. Open the terminal run this command:

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

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

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

5. Change directory to code:

cd code

6. Run this commands to create the proof and verifier

# compile
zokrates compile -i square.zok
# perform the setup phase
zokrates setup
# execute the program
zokrates compute-witness -a 337 113569
# 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. The function verifyTx requires an array because structs in solidity map to arrays in the ABI:

Make sure to encapsulate the proof inside [ ] just like in the image.

10. Call the verifyTx function:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store