Lecture5 2023
Lecture5 2023
ZKP MOOC
First, a review of polynomial commitments
(≤𝑑)
Prover commits to a polynomial 𝑓(𝑋) in 𝔽𝑝 𝑋
eval: for public 𝑢, 𝑣 ∈ 𝔽𝑝 , prover can convince the verifier that
committed poly satisfies
𝑓(𝑢) = 𝑣 and deg 𝑓 ≤ 𝑑. verifier has (𝑑, comf , 𝑢, 𝑣)
ZKP MOOC
The KZG poly-commit scheme (Kate-Zaverucha-Goldberg’2010)
Group 𝔾 ≔ { 0, 𝐺, 2 ⋅ 𝐺, 3 ⋅ 𝐺 , … , 𝑝 − 1 ⋅ 𝐺 } of order 𝑝.
setup(1𝜆 ) ⇾ gp:
Sample random 𝜏 ∈ 𝔽𝑝
gp =
delete 𝜏 !! (trusted setup)
commit(gp, 𝑓) ⇾ comf where comf ≔ 𝑓 𝜏 ⋅ G ∈ 𝔾
𝑓 𝑋 = 𝑓0 + 𝑓1 𝑋 + ⋯ + 𝑓𝑑 𝑋 𝑑 ⇒ comf = 𝑓0 ⋅ 𝐻0 + ⋯ + 𝑓𝑑 ⋅ 𝐻𝑑
ZKP MOOC
The KZG poly-commit scheme (Kate-Zaverucha-Goldberg’2010)
Group 𝔾 ≔ { 0, 𝐺, 2 ⋅ 𝐺, 3 ⋅ 𝐺 , … , 𝑝 − 1 ⋅ 𝐺 } of order 𝑝.
setup(1𝜆 ) ⇾ gp: a binding commitment,
Sample random 𝜏 ∈ 𝔽𝑝 but not hiding
gp =
delete 𝜏 !! (trusted setup)
commit(gp, 𝑓) ⇾ comf where comf ≔ 𝑓 𝜏 ⋅ G ∈ 𝔾
𝑓 𝑋 = 𝑓0 + 𝑓1 𝑋 + ⋯ + 𝑓𝑑 𝑋 𝑑 ⇒ comf = 𝑓0 ⋅ 𝐻0 + ⋯ + 𝑓𝑑 ⋅ 𝐻𝑑
ZKP MOOC
The KZG poly-commit scheme (Kate-Zaverucha-Goldberg’2010)
ZKP MOOC
The KZG poly-commit scheme (Kate-Zaverucha-Goldberg’2010)
ZKP MOOC
The KZG poly-commit scheme (Kate-Zaverucha-Goldberg’2010)
How to prove
commit(gp, 𝑓) ⇾ that
com this
f
iswhere
a secure PCS?
comf Not
= f today
𝜏 ⋅ G… ∈ 𝔾
eval: Prover(gp, f, u, v) Verifier(gp, comf , u, v)
Goal: prove 𝑓(𝑢) = 𝑣
An expensive computation
𝑓(𝑢) =
for𝑣large
⇔ 𝑑 𝑢 is a root of 𝑓 Verifier
≔ f−𝑣 does⇔ not know
(X-𝑢) 𝜏 ⇒𝑓uses a “pairing”
divides
⇔ exists (and
q ∈ 𝔽only
𝑝[𝑋] s.t. 𝐻
needs 0 , 𝐻1 from
q(X)⋅(X-𝑢) = gp)
f(X)−𝑣
ZKP MOOC
The KZG poly-commit scheme (Kate-Zaverucha-Goldberg’2010)
Generalizations:
Can also use KZG to commit to k-variate polynomials [PST’13]
Batch proofs:
suppose verifier has commitments comf1 , … comfn
prover wants to prove 𝑓𝑖 𝑢𝑖,𝑗 = 𝑣𝑖,𝑗 for 𝑖 ∈ [𝑛], 𝑗 ∈ [𝑚]
ZKP MOOC
Properties of KZG: linear time commitment
(≤𝑑)
Two ways to represent a polynomial 𝑓(𝑋) in 𝔽𝑝 𝑋 :
Point-value representation: 𝑎0 , 𝑓 𝑎0 , … , 𝑎𝑑 , 𝑓 𝑎𝑑
computing comf naively: construct coefficients 𝑓0 , 𝑓1 , … , 𝑓𝑑
⇒ time 𝑂(𝑑 log 𝑑) using Num. Th. Transform (NTT)
ZKP MOOC
Properties of KZG: linear time commitment
Point-value representation: a better way to compute comf
𝑑
Lagrange interpolation: 𝑓(𝜏) = 𝑖=0 𝜆𝑖 𝜏 ∙ 𝑓(𝑎𝑖 ) where
ZKP MOOC
KZG fast multi-point proof generation
(≤𝑑)
Prover has some 𝑓(𝑋) in 𝔽𝑝 𝑋 . Let Ω ⊆ 𝔽𝑝 and |Ω| = 𝑑
ZKP MOOC
The Dory polynomial commitment (eprint/2020/1274)
Difficulties with KZG: trusted setup for gp, and gp size is linear in d.
Dory:
transparent setup: no secret randomness in setup
comf is a single group element (independent of degree 𝑑)
(≤𝑑)
eval proof size for 𝑓 ∈ 𝔽𝑝 𝑋 is O(log 𝑑) group elements
eval verify time is O(log 𝑑) Prover time: 𝑂(𝑑)
ZKP MOOC
PCS have many applications
Example: vector commitment (a drop-in replacement for Merkle trees)
(≤𝑑)
Bob: vector 𝑢1 , … , 𝑢𝑘 ∈ 𝔽𝑝 Alice
ZKP MOOC
Proving properties of
committed polynomials
ZKP MOOC
Credit: Faithie/Shutterstock
Proving properties of committed polynomials
ZKP MOOC
Recall: polynomial equality testing
Suppose 𝑝 ≈ 2256 and 𝑑 ≤ 240 so that 𝑑/𝑝 is negligible
(≤𝑑)
Let 𝑓, 𝑔 ∈ 𝔽𝑝 [𝑋].
ZKP MOOC
Review: the proof system as an IOP
Prover Verifier
𝒇, 𝒈 𝑓 𝑔
$
𝑟 ⇽ 𝔽𝑝
query 𝑓(X) and 𝑔 𝑋 at 𝑟
learn 𝑓 𝑟 , g(𝑟)
accept if:
𝑓 𝑟 = g(𝑟)
ZKP MOOC
Review: the compiled proof system
Prover Verifier
𝒇, 𝒈 𝑓 𝑔
𝑟 𝑟 ⇽ 𝔽𝑝
$
𝑦 ⇽ 𝑓(𝑟)
𝑦 ′ ⇽ 𝑔(𝑟)
𝑦, 𝜋𝑓 𝑦′, 𝜋𝑔 accept if:
(i) 𝑦 = 𝑦’, and
(ii) 𝜋𝑓, 𝜋𝑔 are
proof that proof that valid
𝑦 = 𝑓(𝑟) 𝑦′ = 𝑔(𝑟)
ZKP MOOC
Review: the compiled proof system
Prover Make Verifier
A public coin
𝒇, 𝒈 non-interactive 𝑓 𝑔
protocol
using Fiat-Shamir
𝑟 𝑟 ⇽ 𝔽𝑝
$
𝑦 ⇽ 𝑓(𝑟)
𝑦 ′ ⇽ 𝑔(𝑟)
𝑦, 𝜋𝑓 𝑦′, 𝜋𝑔 accept if:
(i) 𝑦 = 𝑦’, and
(ii) 𝜋𝑓, 𝜋𝑔 are
proof that proof that valid
𝑦 = 𝑓(𝑟) 𝑦′ = 𝑔(𝑟)
ZKP MOOC
Polynomial equality testing with KZG
For KZG: 𝑓 = 𝑔 ⟺ com𝑓 = com𝑔
⇒ verifier can tell if 𝑓 = 𝑔 on its own
ZKP MOOC
Important proof gadgets for univariates
Let Ω be some subset of 𝔽𝑝 of size 𝑘.
(≤𝑑)
Let 𝑓 ∈ 𝔽𝑝 [𝑋] (𝑑 ≥ 𝑘) Verifier has 𝑓
ZKP MOOC
The vanishing polynomial
Let Ω be some subset of 𝔽𝑝 of size 𝑘.
ZKP MOOC
(1) ZeroTest on Ω (Ω = { 1, 𝜔, 𝜔2, …, 𝜔𝑘-1 } )
Prover P(𝑓) Verifier V( 𝑓 )
𝑞(𝑋) ⇽ 𝑓(𝑋)/𝑍Ω (𝑋) (≤𝑑)
𝑞 ∈ 𝔽𝑝 𝑋 verifier evaluates
$
𝑟 ⇽ 𝔽𝑝 𝑍Ω (𝑟) by itself
query 𝑞(𝑋) and 𝑓(𝑋) at 𝑟
learn 𝑞 𝑟 , 𝑓(𝑟)
ZKP MOOC
(1) ZeroTest on Ω (Ω = { 1, 𝜔, 𝜔2, …, 𝜔𝑘-1 } )
Prover P(𝑓) Verifier V( 𝑓 )
𝑞(𝑋) ⇽ 𝑓(𝑋)/𝑍Ω (𝑋) (≤𝑑)
𝑞 ∈ 𝔽𝑝 𝑋 verifier evaluates
𝑟 ⇽$ 𝔽𝑝 𝑍Ω (𝑟) by itself
query 𝑞(𝑋) and 𝑓(𝑋) at 𝑟
learn 𝑞 𝑟 , 𝑓(𝑟)
accept if 𝑓 𝑟 ≟ 𝑞(𝑟) ⋅ 𝑍Ω (𝑟)
Verifier time: O(log 𝑘) and two poly queries (but can be done in one)
Prover time: dominated by the time to compute 𝑞(𝑋) and then commit to 𝑞(𝑋)
ZKP MOOC
(3) Product check on Ω : 𝑎∈Ω 𝑓(𝑎) =1
(≤𝑘)
Set 𝑡 ∈ 𝔽𝑝 [𝑋] to be the degree-𝑘 polynomial:
𝑠
𝑡(1) = 𝑓(1), 𝑡(𝜔s) = i
𝑖=0 𝑓( 𝜔 ) for 𝑠 = 1, … , 𝑘 − 1
ZKP MOOC
(3) Product check on Ω : 𝑎∈Ω 𝑓(𝑎) =1
(≤𝑘)
Set 𝑡 ∈ 𝔽𝑝 [𝑋] to be the degree-𝑘 polynomial:
𝑠
𝑡(1) = 𝑓(1), 𝑡(𝜔s) = i
𝑖=0 𝑓( 𝜔 ) for 𝑠 = 1, … , 𝑘 − 1
ZKP MOOC
(3) Product check on Ω (unoptimized)
Prover P(𝑓) Verifier V( 𝑓 )
(≤𝑘)
construct 𝑡 𝑋 ∈ 𝔽𝑝 and 𝑡1(𝑋) = 𝑡(𝜔 ⋅ 𝑋) − 𝑡(𝑋) ⋅ 𝑓(𝜔 ⋅ 𝑋)
(≤𝑑)
set q(𝑋) = 𝑡1(𝑋)/(𝑋 𝑘 − 1) ∈ 𝔽𝑝 𝑡1 (𝑋) should be zero on Ω
𝑡 𝑞
𝑟 ⇽$ 𝔽𝑝
query 𝑡(𝑋) at 𝜔𝑘−1 , 𝑟, 𝜔𝑟
learn 𝑡(𝜔𝑘−1 ), t(r), 𝑡(𝜔𝑟), 𝑞(𝑟), 𝑓(𝜔𝑟)
query 𝑞 𝑋 at 𝑟 , and 𝑓(𝑋) at 𝜔𝑟
accept if 𝑡(𝜔𝑘−1 ) ≟ 1 and
proves that 𝑡1(Ω) = 0: 𝑡 𝜔𝑟 − 𝑡(𝑟)𝑓(𝜔𝑟) ≟ 𝑞(𝑟) ⋅ (𝑟 𝑘 − 1)
ZKP MOOC
(3) Product check on Ω (unoptimized)
Prover P(𝑓) Verifier V( 𝑓 )
(≤𝑘)
construct 𝑡 𝑋 ∈ 𝔽𝑝 and 𝑡1(𝑋) = 𝑡(𝜔 ⋅ 𝑋) − 𝑡(𝑋) ⋅ 𝑓(𝜔 ⋅ 𝑋)
(≤𝑑)
set q(𝑋) = 𝑡1(𝑋)/(𝑋 𝑘 − 1) ∈ 𝔽𝑝 A public coin
𝑡 𝑞 protocol
$
𝑟⇽ 𝔽𝑝
query 𝑡(𝑋) at 𝜔𝑘−1 , 𝑟, 𝜔𝑟
learn 𝑡(𝜔𝑘−1 ), t(r), 𝑡(𝜔𝑟), 𝑞(𝑟), 𝑓(𝜔𝑟)
query 𝑞 𝑋 at 𝑟 , and 𝑓(𝑋) at 𝜔𝑟
Proof size: two commits, five evals. Verifier time: 𝑂 log 𝑘 . Prover time: 𝑂(𝑘 log 𝑘).
ZKP MOOC
Same works for rational functions: 𝑎∈Ω(𝑓/𝑔)(𝑎) =1
Prover P(𝑓, 𝑔) Verifier V( 𝑓 , 𝑔 )
(≤𝑘)
Set 𝑡 ∈ 𝔽𝑝 [𝑋] to be the degree-𝑘 polynomial:
𝑠
𝑡(1) = 𝑓(1)/𝑔(1), 𝑡(𝜔s) = i i
𝑖=0 𝑓( 𝜔 )/𝑔(𝜔 ) for 𝑠 = 1, … , 𝑘 − 1
ZKP MOOC
(4) Another useful gadget: permutation check
(≤𝑑)
Let 𝑓, 𝑔 be polynomials in 𝔽𝑝 𝑋. Verifier has 𝑓 , 𝑔 .
ZKP MOOC
(4) Another useful gadget: permutation check
Prover P(𝑓, 𝑔) Verifier V( 𝑓 , 𝑔 )
ZKP MOOC
(5) final gadget: prescribed permutation check
𝑊: Ω ⇾ Ω is a permutation of Ω if ∀𝑖 ∈ 𝑘 : 𝑊(𝜔𝑖 ) = 𝜔 𝑗 is a bijection
example (𝑘 = 3): 𝑊 𝜔0 = 𝜔2 , 𝑊 𝜔1 = 𝜔0 , 𝑊(𝜔2 ) = 𝜔1
(≤𝑑)
Let 𝑓, 𝑔 be polynomials in 𝔽𝑝 [𝑋] . Verifier has 𝑓 , 𝑔 , 𝑊 .
ZKP MOOC
Prescribed permutation check
How? Use a zero-test to prove 𝑓 𝑦 − 𝑔 𝑊 𝑦 = 0 on Ω
ZKP MOOC
Prescribed permutation check
Observation:
if 𝑊(𝑎), 𝑓 𝑎 𝑎∈Ω
is a permutation of 𝑎, 𝑔 𝑎 𝑎∈Ω
ZKP MOOC
Prescribed permutation check
Prover P(𝑓, 𝑔, 𝑊) Verifier V( 𝑓 , 𝑔 , W )
𝑔 𝑋, 𝑌 = 𝑎∈Ω (𝑋 − 𝑌 ∙ 𝑎 − 𝑔 𝑎 )
ZKP MOOC
The complete protocol
Prover P(𝑓, 𝑔, 𝑊) Verifier V( 𝑓 , 𝑔 , W )
𝑟, 𝑠 𝑟, 𝑠 ⇽$ 𝔽𝑝
prove that 𝑓 𝑟, 𝑠 = 𝑔 𝑟, 𝑠 :
by Schwartz-
ProdCheck: Zippel
implies 𝑓 𝑋, 𝑌 = 𝑔 𝑋, 𝑌 w.h.p
ZKP MOOC
Summary of proof gadgets
polynomial equality testing
zero test on Ω
permutation check
ZKP MOOC
The PLONK IOP
for general circuits
eprint/2019/953
ZKP MOOC
Credit: Faithie/Shutterstock
PLONK: widely used in practice
polynomial commitment scheme SNARK system
FRI Plonky2
(hashing) (no trusted setup)
ZKP MOOC
PLONK: a poly-IOP for a general circuit 𝐶(𝑥, 𝑤)
Step 1: compile circuit to a computation trace (gate fan-in = 2)
(𝑥1 + 𝑥2)(𝑥2 + 𝑤1) The computation trace (arithmetization):
77 inputs: 5, 6, 1
(Gate 2)
× Gate 0: 5, 6, 11
11 7
Gate 1: 6, 1, 7
(Gate 1)
(Gate 0) + + Gate 2: 11, 7, 77
5 6 1
6
𝑥1 𝑥2 𝑤1
left right outputs
5 6 1 example input inputs inputs
ZKP MOOC
Encoding the trace as a polynomial
|𝐶| ≔ total # of gates in 𝐶 , |𝐼| ≔ |𝐼𝑥 | + |𝐼𝑤 | = # inputs to 𝐶
ZKP MOOC
Encoding the trace as a polynomial
(≤𝑑)
The plan: Prover interpolates 𝑇 ∈ 𝔽𝑝 [X] such that
(1) 𝑻 encodes all inputs: T(𝜔 −𝑗 ) = input #𝑗 for 𝑗 = 1, …, |𝐼|
(2) 𝑻 encodes all wires: ∀ 𝑙 = 0, … , 𝐶 − 1:
T(𝜔3𝑙): left input to gate #𝑙 inputs: 5, 6, 1
Gate 0: 5, 6, 11
T(𝜔3𝑙+1): right input to gate #𝑙 Gate 1: 6, 1, 7
Gate 2: 11, 7, 77
T(𝜔3𝑙+2): output of gate #𝑙
ZKP MOOC
Encoding the trace as a polynomial
In our example, Prover interpolates 𝑇(𝑋) such that:
inputs: T(𝜔−1 ) = 5, T(𝜔−2 ) = 6, T(𝜔−3 ) = 1,
gate 0: T(𝜔0 ) = 5, T(𝜔1 ) = 6, T(𝜔2 ) = 11, degree(𝑇) = 11
gate 1: T(𝜔3 ) = 6, T(𝜔4 ) = 1, T(𝜔5 ) = 7,
gate 2: T(𝜔6 ) = 11, T(𝜔7 ) = 7, T(𝜔8 ) = 77
inputs: 5, 6, 1
Prover can use FFT to compute the coefficients of T Gate 0: 5, 6, 11
in time O(𝑑 log 𝑑) Gate 1: 6, 1, 7
Gate 2: 11, 7, 77
ZKP MOOC
Step 2: proving validity of T
Prover P(𝑆𝑝, 𝒙, 𝐰) Verifier V(𝑆𝑣 , 𝒙)
(≤𝑑)
𝑇
build T(𝑋) ∈ 𝔽𝑝 [X]
ZKP MOOC
Proving (1): T encodes the correct inputs
(≤|𝐼𝑥 |)
Both prover and verifier interpolate a polynomial 𝑣(𝑋) ∈ 𝔽𝑝 [X]
that encodes the 𝑥-inputs to the circuit:
for 𝑗 = 1, . . . , |𝐼𝑥 |: 𝑣(𝜔 −𝑗 ) = input #j
ZKP MOOC
Proving (1): T encodes the correct inputs
(≤|𝐼𝑥 |)
Both prover and verifier interpolate a polynomial 𝑣(𝑋) ∈ 𝔽𝑝 [X]
that encodes the 𝑥-inputs to the circuit:
for 𝑗 = 1, . . . , |𝐼𝑥 |: 𝑣(𝜔 −𝑗 ) = input #j
ZKP MOOC
Proving (2): every gate is evaluated correctly
Idea: encode gate types using a selector polynomial S(X)
(≤𝑑)
define S(X) ∈ 𝔽𝑝 [X] such that ∀ 𝑙 = 0, … , 𝐶 − 1:
S(𝜔3𝑙 ) = 1 if gate #𝑙 is an addition gate
S(𝜔3𝑙 ) = 0 if gate #𝑙 is a multiplication gate
× (Gate 2)
inputs: 5, 6, 1 𝑆(𝑋)
(Gate 0) + + (Gate 1) Gate 0 (𝜔0): 5 , 6 , 11 1 (+)
Gate 1 (𝜔3): 6 , 1 , 7 1 (+)
𝑥1 𝑥2 𝑤1 Gate 2 (𝜔6): 11, 7, 77 0 (×)
ZKP MOOC
Proving (2): every gate is evaluated correctly
Idea: encode gate types using a selector polynomial S(X)
(≤𝑑)
define S(X) ∈ 𝔽𝑝 [X] such that ∀ 𝑙 = 0, … , 𝐶 − 1:
S(𝜔3𝑙 ) = 1 if gate #𝑙 is an addition gate
S(𝜔3𝑙 ) = 0 if gate #𝑙 is a multiplication gate
ZKP MOOC
Proving (2): every gate is evaluated correctly
Setup(𝐶) ⇾ 𝑝𝑝≔S and 𝑣𝑝≔ ( S )
ZKP MOOC
Proving (3): the wiring is correct
Step 4: encode the wires of 𝐶: example: x1=5, x2=6 , 𝑤1=1
T(𝜔-2) = T(𝜔1) = T(𝜔3) 𝜔-1, 𝜔-2, 𝜔-3 : 5, 6, 1
T(𝜔-1) = T(𝜔0) 0: 𝜔0, 𝜔1, 𝜔2 : 5, 6, 11
T(𝜔2) = T(𝜔6) 1: 𝜔3, 𝜔4, 𝜔5 : 6, 1, 7
T(𝜔-3) = T(𝜔4) 2: 𝜔6, 𝜔7, 𝜔8 : 11, 7, 77
Define a polynomial W: Ω ⇾ Ω that implements a rotation:
W(𝜔-2, 𝜔1 , 𝜔3) = (𝜔1, 𝜔3, 𝜔-2 ) , W(𝜔-1, 𝜔0) = (𝜔0 , 𝜔-1) , …
Lemma: ∀ 𝑦∈Ω : T(𝑦) = T(W(𝑦)) ⇒ wire constraints are satisfied
ZKP MOOC
Proving (3): the wiring is correct
Step 4: encode the wires of 𝐶: example: x1=5, x2=6 , 𝑤1=1
T(𝜔-2) = T(𝜔1) = T(𝜔3) 𝜔-1, 𝜔-2, 𝜔-3 : 5, 6, 1
T(𝜔-1) = T(𝜔0) 0: 𝜔0, 𝜔1, 𝜔2 : 5, 6, 11
T(𝜔 2) = T(𝜔6)
Proved using a prescribed permutation
1: 𝜔3, 𝜔check
4, 𝜔 5 : 6, 1, 7
ZKP MOOC
The complete Plonk Poly-IOP (and SNARK)
ZKP MOOC
The complete Plonk Poly-IOP (and SNARK)
ZKP MOOC
Many extensions …
Plonk proof: a short proof (O(1) commitments), fast verifier
The SNARK can easily be made into a zk-SNARK
ZKP MOOC
A generalization: plonkish arithmetization
Plonk for circuits with gates other than + and × on rows:
u1 v1 w1 t1 r1 s1
Plonkish computation trace: (also used in AIR) u2 v2 w2 t2 r2 s2
u3 v3 w3 t3 r3 s3
An example custom gate:
u4 v4 w4 t4 r4 s4
∀ 𝑦 ∈ Ωgates : 𝑣 𝑦𝜔 + 𝑤(𝑦) ∙ 𝑡(𝑦) − 𝑡 𝑦𝜔 = 0 u5 v5 w5 t5 r5 s5
ZKP MOOC
END OF LECTURE
Next lecture:
More polynomial commitments
ZKP MOOC
Credit: Faithie/Shutterstock