# Zero Knowledge Proofs Workshop - Zokrates Tutorial

## Agenda

- Pre requisites
- A simple proof with Zokrates
- Next Steps
- Hackathon

## Pre requisites

```
docker run -v $PWD/code:/home/zokrates/code -ti zokrates/zokrates /bin/bash
```

## Zokrates Introduction

Zokrates Repo - https://github.com/Zokrates/ZoKrates

It has a DSL with python like syntax

## Zokrates Workflow

- Write and compile DSL - Compiles a .code file into ZoKrates internal representation of arithmetic circuits.
- Create setup - Generates a trusted setup for the compiled program
- Compute Witness - Computes a witness for the compiled program
- Generate Proof - Using the proving key, generates a proof for a computation of the compiled program
- Export Verifier - Using the verifying key at ./verifying.key, generates a Solidity contract which contains the
- generated verification key and a public function to verify a solution to the compiled program

## Zokrates DSL syntax

The python-like syntax is composed of

primitive uint types (positive numbers),

imperative algebraic statements,

for loops,

conditional if statements and function definitions.

The compiler transforms the conditions to a constraint system of an arithmetic circuit from which a zk-SNARK is generated.

The verification key can then be exported to a smart contract allowing for verification of proofs on the Ethereum blockchain.

The building blocks for the on-chain verification algorithm reside on the blockchain as pre-complied

contracts and the outcome of the verification algorithm on a provided proof can be used to further trigger

other on-chain activity (i.e., if true then …).

For documentation, see ZoKrates/zokrates_book

## Zokrates DSL in more detail

### Types

- field (private)
- bool
- field[n]

### Functions

- Functions need to be declared before they are called
- The function signature needs to be explicit
- Functions may return many values
- Function calls are not always zero-cost, so deep call chains should be avoided.

```
def main(private field a, field b) -> (field):
field result = if a * a == b then 1 else 0 fi
return result
```

Variables are mutable, and always passed by values to functions.

### Loops

```
def main() -> (field):
field res = 0
for field i in 0..4 do
res = res + i
endfor
return res
```

The bounds should be known at compile time, i.e. constant

For example code see :

https://github.com/Zokrates/ZoKrates/tree/develop/zokrates_cli/examples

### A simple example with workflow

```
mkdir code
docker run -v $PWD/code:/home/zokrates/code -ti zokrates/zokrates /bin/bash
```

Write root.code

```
def main(private field a, field b) -> (field):
field result = if a * a == b then 1 else 0 fi
return result
```

```
./zokrates compile -i root.code
```

```
./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
```

## Useful Resources

Gnosis Tutorial

Using Zokrates with Truffle Tutorial

zk-SNARKS and Zokrates Tutorial

Zokrates Repo

Zokrates Book

## Zero Knowledge Proofs Workshop - Zokrates Tutorial

## Agenda

## Pre requisites

## Zokrates Introduction

## Zokrates - A toolbox for zkSNARKS on Ethereum

Zokrates Repo - https://github.com/Zokrates/ZoKrates

It has a DSL with python like syntax

## Zokrates Workflow

## Zokrates DSL syntax

The python-like syntax is composed of

primitive uint types (positive numbers),

imperative algebraic statements,

for loops,

conditional if statements and function definitions.

The compiler transforms the conditions to a constraint system of an arithmetic circuit from which a zk-SNARK is generated.

The verification key can then be exported to a smart contract allowing for verification of proofs on the Ethereum blockchain.

The building blocks for the on-chain verification algorithm reside on the blockchain as pre-complied

contracts and the outcome of the verification algorithm on a provided proof can be used to further trigger

other on-chain activity (i.e., if true then …).

For documentation, see ZoKrates/zokrates_book

## Zokrates DSL in more detail

## Types

## Functions

Variables are mutable, and always passed by values to functions.

## Loops

The bounds should be known at compile time, i.e. constant

For example code see :

https://github.com/Zokrates/ZoKrates/tree/develop/zokrates_cli/examples

## A simple example with workflow

Write root.code

## perform the setup phase

## execute the program

## generate a proof of computation

## export a solidity verifier

## Useful Resources

Gnosis Tutorial

Using Zokrates with Truffle Tutorial

zk-SNARKS and Zokrates Tutorial

Zokrates Repo

Zokrates Book