Zero Knowledge Proofs
& Computational Complexity

ZK Prereqs Workshop 1 of 6

Foundations: What ZKPs are, what they can do, and the math framework behind them

๐Ÿ” The Password Paradox

Every time you log in to a website, you prove you know the password...

...by revealing the password.

What if you could prove you know it
without ever sending it?

That's Zero Knowledge Proofs in one sentence.

Agenda

TimeTopic
0:00What Are Zero Knowledge Proofs?
0:10Computational Complexity: P, NP, PSPACE
0:25Witnesses & Verification
0:35Boolean Circuits
0:45Arithmetic Circuits
0:55Wrap-up & Practice Problems

Part 1: What Are Zero Knowledge Proofs?

~10 minutes

The Core Idea

A Zero Knowledge Proof lets a prover convince a verifier that a statement is true —

without revealing any information about why it's true.

Analogy: Prove to a bouncer you're over 21 — without showing your ID, name, address, or exact age.

Why ZKPs Matter in Web3

Use CaseWhat's ProvenWhat Stays Hidden
Privacy mixers"I deposited funds earlier"Which deposit is yours
zkRollups"All transactions are valid"Transaction details
Private voting"I'm eligible and this is my vote"Who you voted for
Identity"I meet the criteria"Personal data

Three Properties of ZKPs

  • Completeness — If the statement is true and both parties are honest, the verifier will be convinced
  • Soundness — If the statement is false, no cheating prover can trick the verifier (except with negligible probability)
  • Zero Knowledge — The verifier learns nothing beyond the truth of the statement
Discussion: Can you think of a situation in smart contracts where you'd want to prove something without revealing the underlying data?

Part 2: Computational Complexity

P, NP, PSPACE โ€” ~15 minutes

To understand what ZK proofs can and cannot do, we need to classify problems by difficulty.

Solving vs. Checking: The Key Difference

Before we classify problems, understand one idea:

๐Ÿ” Solving

Finding the answer from scratch.

Like doing a jigsaw puzzle with no picture on the box.

โœ… Checking

Verifying someone else's answer is correct.

Like looking at a completed jigsaw and confirming all pieces fit.

Some problems are easy to both solve and check.
Some are hard to solve but easy to check.
Some are hard to even check!
ZK proofs only work when checking is easy.

Problems in P — "Practical"

Easy to solve AND easy to check.

ProblemSolveCheck
Sorting a listCompare & swap — fast for millionsScan left to right: each item ≥ previous?
Finding a nameScan through the whole list"Alice is at pos 42" → look at pos 42
Drive City A → B?Try different routes until one worksFollow the directions — do you arrive?
P = "Practical" — Both solving and checking finish in reasonable time, even for huge inputs.

Problems in NP

Hard to solve but easy to verify.

Sudoku

  • Solve: Exponential search through combinations
  • Verify: O(n²) — check rows, columns, subgrids

3-coloring a map

  • Solve: Brute-force through exponential color assignments
  • Verify: O(n) — check each pair of neighbors
Key insight: All P problems are also NP problems. P ⊆ NP

Problems in PSPACE — "Impossible to Check"

Hard to solve AND hard to check.

ProblemWhy checking is hard
๐Ÿ†Best move in chessMust explore every opponent response & counter-move — no shortcut
๐ŸŽฎUnbeatable game strategyMust simulate every possible game against every opponent

No "receipt" exists — nothing anyone can show you makes checking fast.

No ZK proofs possible here — if you can't check the answer quickly, you can't create a proof for it.

The Hierarchy

PSPACE

Hard to solve, hard to verify

NP

Hard to solve, easy to verify

P

Easy to solve, easy to verify

Summary Table

ClassTime to SolveTime to Verify
PPolynomialPolynomial
NPNo requirement (often exponential)Polynomial
PSPACENo requirementNo requirement
ZK Proofs only work for P and NP problems — problems where the solution can be verified efficiently. If you can't verify it efficiently, you can't create a ZK proof for it.

โšก Quick Check: Classify These!

Vote with your hands: 1 finger = P, 2 fingers = NP, 3 fingers = PSPACE

ProblemYour VoteAnswer
Binary search in a sorted list๐Ÿค”P โ€” O(log n) solve & verify
Solving a 9ร—9 Sudoku๐Ÿค”NP โ€” hard to solve, easy to check
Finding the best chess move๐Ÿค”PSPACE โ€” can't even verify efficiently
"Is 997 prime?"๐Ÿค”P โ€” AKS primality test

Part 3: Witnesses & Verification

~10 minutes

What is a Witness?

A witness = the evidence that lets you quickly check a solution. Like a receipt ๐Ÿงพ.

ProblemWitness ("receipt")How to check
Sorting a listThe sorted listScan: each item โ‰ฅ previous?
Finding "Alice""Position 42"Look at pos 42
Drive city Aโ†’B?Turn-by-turn directionsFollow them — arrive?
SudokuFilled gridRows, cols, boxes: all 1-9?
3-coloringColor per regionEach border: neighbors differ?

PSPACE problems (chess, game strategies) have NO useful witness — no receipt exists.

The "Knowledge" in Zero Knowledge

The "knowledge" in ZKP = knowledge of the witness.

Concrete example — Sudoku:
Claim:     "I solved this Sudoku puzzle"
Witness:   The completed grid (SECRET โ€” only the prover knows this)
ZK Proof:  Convinces the verifier the grid is valid
               ...WITHOUT ever showing the actual numbers

The ZK pipeline (how it works under the hood):

  1. Express the problem as a circuit (math equations) — we'll learn this today
  2. The prover plugs in their witness (the secret solution)
  3. Cryptographic magic generates a proof
  4. The verifier checks the proof — without ever seeing the witness

ZKPs Can't Do Everything

  • ZKPs cannot help you find a solution — only prove you have one
  • ZKPs cannot work for PSPACE problems — no efficient checking
  • ZKPs can work for any P or NP problem — anything where checking is fast
Think of ZKPs like a notary stamp: the notary confirms a document is valid, but doesn't create the document for you.

Real Example: Merkle Proof

You've likely seen this in Solidity — let's connect it to what we just learned.

                   ROOT HASH  (stored on-chain)
                  /          \
           Hash(A+B)      Hash(C+D)
            /     \          /     \
       Hash A  Hash B  Hash C  Hash D
          |       |       |       |
       Leaf A  Leaf B  Leaf C  Leaf D
                 โ†‘
        YOU WANT TO PROVE THIS LEAF IS IN THE TREE
Statement"Leaf B is part of this Merkle tree"
WitnessLeaf B + Hash A + Hash(C+D)   (the sibling hashes along the path)
CheckingHash the leaf up the tree → does the result match the root?
This is NP: Hard to guess which leaves exist, but easy to verify a claimed leaf with just 2-3 hashes!

Part 4: Boolean Circuits

~10 minutes

We need a universal language to express any verifiable problem.
Boolean circuits give us that.

Boolean Operators

OperatorSymbolDescription
ANDTrue only when both inputs are true
ORTrue when at least one input is true
NOT¬Flips true ↔ false

Example formula with variables x1, x2, x3, x4:

out = (x1 ∨ ¬x2 ∨ ¬x3) ∧ (¬x2 ∨ x3 ∨ x4)

Verifying a Boolean Formula

Given: out = (x1 ∨ ¬x2 ∨ ¬x3) ∧ (¬x2 ∨ x3 ∨ x4)

Proposed witness: x1=T, x2=F, x3=T, x4=F

Plug in: (T ∨ T ∨ F) ∧ (T ∨ T ∨ F)

= T ∧ T

= TRUE ✓

Finding the assignment → may be exponential
Verifying a proposed assignment → polynomial (just plug in!)

3-Coloring as a Boolean Circuit

WA SA NT No two neighbors share a color โœ“

Each territory gets Boolean variables per color: WA_G, WA_B, WA_R

Color constraint — exactly one color per territory:

(WA_G ∧ ¬WA_B ∧ ¬WA_R) ∨ (¬WA_G ∧ WA_B ∧ ¬WA_R) ∨ (¬WA_G ∧ ¬WA_B ∧ WA_R)

Boundary constraint — neighbors differ:

¬(WA_G ∧ SA_G) ∧ ¬(WA_B ∧ SA_B) ∧ ¬(WA_R ∧ SA_R)

The Problem with Boolean Circuits

Boolean circuits are overly long for number operations. Express 8 + 4 = 12:

NumberBinaryBoolean vars
81000aโ‚=1, aโ‚‚=0, aโ‚ƒ=0, aโ‚„=0
40100bโ‚=0, bโ‚‚=1, bโ‚ƒ=0, bโ‚„=0
121100cโ‚=1, cโ‚‚=1, cโ‚ƒ=0, cโ‚„=0

โœ— Boolean: 12 vars + carry logic

aโ‚ XOR bโ‚ = cโ‚ (with carry)
aโ‚‚ XOR bโ‚‚ XOR carry = cโ‚‚
... MANY more lines

โœ“ Arithmetic: 3 vars, 1 equation

a + b === c
// That's it. Done.
This is why ZK systems use arithmetic circuits.

Part 5: Arithmetic Circuits

~10 minutes

A simpler, more compact way to express problems for ZK proofs.

What is an Arithmetic Circuit?

A system of equations using only three operations:

  • Addition (+)
  • Multiplication (×)
  • Equality (===)

First example:

6 === xโ‚ + xโ‚‚
9 === xโ‚ * xโ‚‚

Satisfied by xโ‚ = 3, xโ‚‚ = 3

=== means assert equal, not assign.
Think: assertEq(left, right)

Constraining Values

How do we force a signal to be 0 or 1?

x(x - 1) === 0

Only x = 0 or x = 1 satisfies this!

How do we force a signal to be one of {1, 2, 3}?

0 === (1 - x) * (2 - x) * (3 - x)

A polynomial that has roots at exactly 1, 2, and 3.

3-Coloring with Arithmetic Circuits

Instead of 3 Boolean variables per territory → 1 signal with values {1, 2, 3}

// Color constraints โ€” each territory is colored 1, 2, or 3
0 === (1 - WA) * (2 - WA) * (3 - WA)
0 === (1 - SA) * (2 - SA) * (3 - SA)
0 === (1 - NT) * (2 - NT) * (3 - NT)
// ... one per territory

// Boundary constraints โ€” neighbors have different colors
// If x โ‰  y and both โˆˆ {1,2,3}, then x*y โˆˆ {2, 3, 6}
0 === (2 - WA*SA) * (3 - WA*SA) * (6 - WA*SA)
0 === (2 - WA*NT) * (3 - WA*NT) * (6 - WA*NT)
// ... one per border
Same 15 constraints as Boolean, but ⅓ the variables.

Boolean ↔ Arithmetic Translation

Every Boolean gate has an arithmetic equivalent
(when inputs are constrained to 0 or 1):

BooleanArithmetic
NOT u → tt === 1 - u
u AND v → tt === u * v
u OR v → tt === u + v - u*v

Conversion Example

Boolean: out = (x ∧ ¬y) ∨ z

Step by step → Arithmetic:

// Constrain inputs to 0 or 1
x(x - 1) === 0
y(y - 1) === 0
z(z - 1) === 0

// ยฌy       โ†’  (1 - y)
// x โˆง ยฌy   โ†’  x * (1 - y)
// ... โˆจ z  โ†’  x*(1-y) + z - x*(1-y)*z

// Final:
out === x - x*y + z - x*z + x*y*z

The ZK Pipeline

Real-world problem

Arithmetic Circuit (system of constraints)

Prover: "I know a witness that satisfies all constraints"

ZK Proof: Verifier confirms without seeing the witness

All problems in P and NP can be expressed as arithmetic circuits.
This is the foundation everything else is built on.

Live Demo: Boolean vs Arithmetic

Prove (x AND NOT y) OR z equals its arithmetic version for ALL inputs.

def boolean_circuit(x, y, z):          # Python keywords
    return (x and not y) or z

def arithmetic_circuit(x, y, z):       # Only +, *, integers
    assert x*(x-1) == 0 and y*(y-1) == 0 and z*(z-1) == 0
    return x - x*y + z - x*z + x*y*z  # NOT=(1-y), OR=a+b-ab

for x in [0,1]:                        # Test all 8 combos
    for y in [0,1]:
        for z in [0,1]:
            b = 1 if boolean_circuit(x,y,z) else 0
            a = arithmetic_circuit(x,y,z)
            assert b == a
            print(f"x={x}, y={y}, z={z} -> {a}")
print("All 8 match!")

Key Takeaways

  1. ZKPs let you prove you know something without revealing it
  2. Only P and NP problems can have ZK proofs (solutions must be efficiently verifiable)
  3. Witnesses are the secret knowledge the prover has
  4. Arithmetic circuits are systems of equations (add, multiply, equals) that model any NP problem
  5. Arithmetic circuits are more compact than Boolean circuits for most ZK applications

Practice Problems

  1. Classify as P, NP, or PSPACE: shortest path in a graph, prime factorization, best Go move, primality testing
  2. Create an arithmetic circuit satisfied when all signals x1...xn are 1
  3. Create an arithmetic circuit satisfied when at least one signal is 0
  4. Convert this Boolean formula to arithmetic: out = (a ∨ b) ∧ ¬c
  5. Design a 2-coloring circuit for a bipartite graph (hint: adjust the 3-coloring scheme)

Next Workshop

Finite Fields & Modular Arithmetic

  • How arithmetic circuits handle division and overflow
  • Modular arithmetic — the number system ZK proofs operate in
  • Additive and multiplicative inverses
  • Polynomials over finite fields

This is the number system that makes ZK proofs possible.