1 of 42

“Gentle” Introduction to Zero Knowledge Proof for Blockchain Developers

Angel “Java” Lopez�@ajlopezhttps://github.com/ajlopez

2 of 42

Agenda

  • Ethereum Scalability
  • Off-chain Processing
  • From Code to Proof
  • Prover and Verifier
  • Some Workflows

3 of 42

4 of 42

5 of 42

6 of 42

7 of 42

Transactions in Ethereum

  • Execution (in every node)
  • Storage (in every node)
  • Limited quantity per block

Alice -> Bob 3 ETH�Bob -> Charlie 2 ETH�Charlie -> Dan 1 ETH

8 of 42

Moving Processing to Off-Chain

  • So the computation does not involve all the nodes
  • Avoid the use of distributed storage
  • Bitcoin Lightning Network
  • Ethereum Raiden
  • Zero Knowledge Proof
    • Giving a short proof of offline computation

9 of 42

First Paper

10 of 42

Zero Knowledge Proof

A Simple Use Case

11 of 42

Alice, Bob and the Balls

12 of 42

Alice View

13 of 42

Bob View

14 of 42

Bob and Alice

Alice

Bob

15 of 42

First Interaction

Alice

Bob

16 of 42

Bob and Alice

Alice

Bob

Same!

17 of 42

Bob and Alice

Alice

Bob

Different!

18 of 42

Result

  • Alice gives a proof that she can see the colors (based on repeated interactions)
  • Bob is convinced that Alice can see the colors
  • Bob still does not know the colors of the balls
  • Bob does not learn any method to distinguish the colors from Alice

19 of 42

Zero Knowledge Proof for Transactions

20 of 42

Rules for a Transaction

  • Account Balance > 0
  • Tx.in == Tx.out
  • Tx signature is valid

21 of 42

Transformations

  • Rules are transformed to Code
  • Code is transformed to Zero Knowledge Circuit (not trivial step)
  • A Prover is built: program that can generate a proof of knowledge for inputs that satisfies the circuit/rules
  • A Verifier is built: program that can verify any valid proof generated by the prover (without running the code, the transactions, and without learning details about the transaction)

22 of 42

From Rules to ZK Circuit to Prover and Verifier

Rules

Circuit

Prover

Verifier

23 of 42

From Transaction To Verification of Proof

Alice sends 2 ETH to Bob

Prover

Proof

Verifier

OK

24 of 42

Zero Knowledge Proof for Transactions in Blockchain

25 of 42

SNARK

  • Succint: the proof is significantly smaller than the data it represents and can be verified quickly
  • Non-interactive: only one set of information is sent by the prover to the verifier, thus there’s no back-and-forth interaction between them.
  • Argument of Knowledge: the proof is considered computationally sound— a malicious prover isn’t likely to cheat the system without possessing the knowledge to support its statement.
  • SNARKs used in scalablility solutions require a trusted setup between the prover and the verifier.

26 of 42

STARK

  • Transparent
  • Does not require trusted setup
  • Proof size is greater than SNARKs

27 of 42

Offline Processing

  • Executed in other machines (it could be a blockchain or not)
  • Transactions with predefined rules (ie no double spend)
  • Exchange of value (ie Tokens)
  • The initial value is locked on-chain
  • Any player could have off-line value
  • A player could want to withdraw the value on-chain

28 of 42

Initial Setup

Operator

Prover

Blockchain

zkRollup Smart Contract

Verifier

Alice’s Wallet�20 ETH

�zkRollup contract�0 ETH

29 of 42

Alice Transfers to zkRollup 15 ETH

Operator

Prover

Blockchain

zkRollup Smart Contract

Verifier

Alice’s Wallet�5 ETH

�zkRollup contract�15 ETH

30 of 42

Offline Operations

Operator

Prover

Blockchain

zkRollup Smart Contract

Verifier

Alice’s Wallet�5 ETH

�zkRollup contract�15 ETH

Alice -> Bob �3 ETH�Bob -> Charlie�2 ETH�Charlie’s exit�2 ETH

31 of 42

Charlie’s Proof

Operator

Prover

Blockchain

zkRollup Smart Contract

Verifier

Alice’s Wallet�5 ETH

�zkRollup contract�15 ETH

Alice -> Bob �3 ETH�Bob -> Charlie�2 ETH�Charlie’s exit�2 ETH

Proof

32 of 42

New State

Operator

Prover

Blockchain

zkRollup Smart Contract

Verifier

Alice’s Wallet�5 ETH

�zkRollup contract�15 ETH��Charlie’s Wallet�2 ETH

Alice -> Bob �3 ETH�Bob -> Charlie�2 ETH�Charlie’s exit�2 ETH

33 of 42

Not So “Gentle” Introduction

34 of 42

From Code to Proof and Beyond

35 of 42

The Circuit

a

b

c

+

*

*

(a+b)*b*c

36 of 42

Homomorphic Hiding (HH)

An HH E(x) of a number x is a function satisfying the following properties:

  • For most x’s, given E(x) it is hard to find x.
  • Different inputs lead to different outputs – so if x≠y, then E(x)≠E(y).
  • If someone knows E(x) and E(y), they can generate the HH of arithmetic expressions in x and y. For example, they can compute E(x+y) from E(x) and E(y).

37 of 42

Using E(x)

  • Suppose Alice wants to prove to Bob she knows numbers x,y such that x+y=7
  • Alice sends E(x) and E(y) to Bob
  • Bob computes E(x+y) from these values
  • Bob also computes E(7), and now checks whether E(x+y)=E(7)

38 of 42

Polynomial Evaluation

A Polynomial Over a Field

Evaluation at s

Evaluation at E(s)�P(s) = P(E(s))

39 of 42

From Computation to Polynomials

  • THE TRICKY PART
  • The circuit could be converted to polynomials, representing the code (one polynomial for left input, right input, and output)
  • Each multiplication operation is assigned a number: 1, 2, 3…. These are the “target points”
  • Alice, knowing a, b, c, can build a new polynomial P(x), combining the L, R, O polynomials and her inputs a,b,c. And additional polynomial H
  • Bob chooses a random point s
  • Alice computes E(L(s)), E(R(s)), E(O(s)), E(H(s))
  • Bob verifies a condition E(L(s)R(s) - O(s)) = E(T(s)H(s))

40 of 42

From Polynomials to Elliptic Curve Points

  • Calculate E(T(s)H(s)): it is not easy for a general HH function
  • Instead of a number field, start using elliptic curve points
  • Some elliptic curves has “pairings” (a mathematical property)
  • In those curves, given two HH E1(x), E2(y) we can compute E(xy)
  • In SNARKs there is a Common Reference String (CRS), containing E1 and E2 evaluation at various points
  • Alice proof is the evaluation of E1(P(s)) and E2(P(s)) using various points from the CRS
  • Bob verify the computation

41 of 42

42 of 42