DEV Community

Cover image for Building and securing KZG implementations
0xluk3
0xluk3

Posted on Originally published at luk3.tech

Building and securing KZG implementations

Every Ethereum blob and most PLONK proofs come down to the one check below. If it passes, the verifier accepts a value of a polynomial it has never seen. The math behind it is solid. The real breaks, such as Frozen Heart, came from the code around it.

Click any symbol or protocol step to see what it is, who computes it and what it hides. The rest of the post builds this check from scratch, then shows where implementations broke.

The KZG verification equation, interactive on luk3.tech

Interactive version (click any symbol or step): luk3.tech

In this post: how KZG works, what PLONK and EIP-4844 add, public bugs, a 22-item checklist and runnable Rust code. The checklist is also a single README on GitHub, 0xluk3/kzg-security, written to be pasted into an AI assistant together with the code under review.

1. What KZG is and why it exists

KZG lets a prover prove that a polynomial fixed earlier has a given value at a given point, without revealing the polynomial. The prover fixes the polynomial by publishing one curve point CC , called the commitment: once it is sent, the prover can no longer change the polynomial. Later, for any point zz , the prover can send the value y=f(z)y = f(z) together with a short opening proof π\pi that this value really comes from the polynomial behind CC .

KZG is not a proof system on its own. It is a mechanism inside SNARKs such as PLONK:

  • arithmetisation turns a system of equations (the circuit) into a statement about polynomials,
  • those polynomials are large and contain the witness, so the prover does not send them: it sends commitments, and later opening proofs,
  • the verifier checks the statement at a random point, and KZG guarantees that the values it receives come from the polynomials fixed by the commitments.

As a result the proof has constant size and verification costs a few pairings, whatever the size of the circuit.

KZG is also used on its own: Ethereum commits to every blob with it (EIP-4844). Section 3 lists where it shows up in an audit.

2. KZG step by step

This section builds the interactive version, in which the verifier sends a random point. Section 2.8 replaces that message with a hash. We start from the claim the verifier wants to check and transform it, one step at a time, into the equation the verifier actually computes.

KZG flow

2.1 The claim

Let F\mathbb{F} be a finite field: the integers modulo a large prime (the math cheatsheet covers the basics). Every number below is an element of F\mathbb{F} .

Let ff be the prover's polynomial,

f(X)=f0+f1X+⋯+fnXn f(X) = f_0 + f_1 X + \dots + f_n X^n

with coefficients f0,…,fn∈Ff_0, \dots, f_n \in \mathbb{F} (in code, just the vector (f0,…,fn)(f_0, \dots, f_n) ). f(a)f(a) is its value at X=aX = a .

The verifier picks a random z∈Fz \in \mathbb{F} and asks for the value of ff there. The prover answers with a number yy . The claim to check is

f(z)=y(1) f(z) = y \qquad (1)

The verifier cannot simply recompute f(z)f(z) , because it does not see ff .

2.2 From a value to a root

Moving yy to the left gives a statement about one number: f(z)−y=0f(z) - y = 0 . To turn it into a statement about a polynomial, subtract yy from the whole polynomial instead. Let

g(X)=f(X)−y g(X) = f(X) - y

the same coefficients as ff , except the constant term, which becomes f0−yf_0 - y . Its value at zz is g(z)=f(z)−yg(z) = f(z) - y , so claim (1) says

g(z)=0 g(z) = 0

that is, zz is a root of gg .

2.3 From a root to a factor

We know that zz is a root of gg . What does that say about gg as a whole? Divide gg by (X−z)(X - z) (for example, by long division). The result is a quotient polynomial q(X)q(X) and a remainder rr :

g(X)=q(X)⋅(X−z)+r g(X) = q(X)\cdot(X - z) + r

The remainder is always a polynomial of lower degree than the divisor. Here the divisor (X−z)(X - z) has degree 1, so the remainder has degree 0: it is a constant, a single number. Substitute X=zX = z :

g(z)=q(z)⋅(z−z)+r=r g(z) = q(z)\cdot(z - z) + r = r

So the remainder is exactly g(z)g(z) . Since zz is a root, g(z)=0g(z) = 0 , the remainder is zero, and

g(X)=q(X)⋅(X−z) g(X) = q(X)\cdot(X - z)

A polynomial with root zz contains the factor (X−z)(X - z) , and qq is what is left after taking it out. This is the factor theorem.

Why divide at all? The division gives two things. The remainder tells whether the claim is true: r=g(z)=f(z)−yr = g(z) = f(z) - y is zero exactly when y=f(z)y = f(z) . The quotient qq is the object the prover will later hide in its proof: the evidence that the division came out exact.

Substituting g(X)=f(X)−yg(X) = f(X) - y back, claim (1) is equivalent to

f(X)−y=q(X)⋅(X−z)(2) f(X) - y = q(X)\cdot(X - z) \qquad (2)

Key idea. This is the KZG equation. A claim about one number, (1), has become an identity between polynomials, (2). If yy is false, the division leaves the remainder f(z)−y≠0f(z) - y \neq 0 and no polynomial qq satisfies (2).

2.4 From an identity to one point

Two different polynomials of degree at most nn agree on at most nn points. So to check identity (2), it is enough to compare both sides at a single random point, provided the prover did not know that point when it chose ff and qq .

Let τ∈F\tau \in \mathbb{F} be such a point: chosen at random by a setup ceremony, then deleted, so that nobody knows it. Substituting X=τX = \tau into (2):

f(τ)−y=q(τ)⋅(τ−z)(3) f(\tau) - y = q(\tau)\cdot(\tau - z) \qquad (3)

If (3) holds, then with overwhelming probability (2) holds, and therefore (1) holds.

Key idea. The check happens at τ\tau , but it proves something about zz . The two points play different roles: zz is public and is where the question is asked, while τ\tau is secret and is where the answer is checked. The only requirement is τ≠z\tau \neq z , which fails with negligible probability.

Equation (3) is a statement about three numbers, f(τ)f(\tau) , q(τ)q(\tau) and τ−z\tau - z , that nobody can compute, because nobody knows τ\tau . The rest of KZG is a way to check (3) without anyone knowing them.

2.5 Hiding the numbers in curve points

Let G1G_1 and G2G_2 be the two groups of points of a pairing-friendly elliptic curve (BN254 or BLS12-381), with generators GG and HH . For a number aa , let

[a]1=a⋅G∈G1[a]2=a⋅H∈G2 [a]_1 = a\cdot G \in G_1 \qquad [a]_2 = a\cdot H \in G_2

Everyone can see the point, but nobody can recover aa from it (the discrete-log problem, explained in private keys and elliptic curves). Points can be added and multiplied by known numbers: [a]1+[b]1=[a+b]1[a]_1 + [b]_1 = [a + b]_1 and k⋅[a]1=[k a]1k\cdot[a]_1 = [k\,a]_1 .

Let e(P,Q)e(P, Q) be the pairing of P∈G1P \in G_1 and Q∈G2Q \in G_2 . Its key property is bilinearity: numbers multiplying the points move into the exponent,

e([a]1,[b]2)=e(a⋅G, b⋅H)=e(G,H)a⋅b e([a]_1, [b]_2) = e(a\cdot G,\ b\cdot H) = e(G, H)^{a\cdot b}

so the result depends only on the product a⋅ba\cdot b . An equation between two pairings therefore checks one multiplication of hidden numbers.

Setup. The ceremony computes the powers of τ\tau , hides them in points, and deletes τ\tau . Let the SRS (structured reference string) be the published points

[1]1,[τ]1,[τ2]1,…,[τn]1∈G1 [1]2,[τ]2∈G2 \begin{aligned} &[1]_1, [\tau]_1, [\tau^2]_1, \dots, [\tau^n]_1 \in G_1 \ &[1]_2, [\tau]_2 \in G_2 \end{aligned}

The numbers τ,τ2,…\tau, \tau^2, \dots are secret. The points are public. The deleted τ\tau is the toxic waste: whoever knows it can forge any proof. Real ceremonies chain many participants, each multiplying the kk -th point by sks^k for its own secret ss , so one honest participant is enough. The SRS does not depend on any polynomial, so it serves every polynomial up to degree nn .

Hiding f(τ)f(\tau) . Using the SRS, the prover computes, without knowing τ\tau ,

C=f0⋅[1]1+f1⋅[τ]1+⋯+fn⋅[τn]1 =[f0+f1τ+⋯+fnτn]1 =[f(τ)]1 \begin{aligned} C &= f_0\cdot[1]_1 + f_1\cdot[\tau]_1 + \dots + f_n\cdot[\tau^n]_1 \ &= [f_0 + f_1\tau + \dots + f_n\tau^n]_1 \ &= [f(\tau)]_1 \end{aligned}

This is a multi-scalar multiplication (MSM): the scalars are the coefficients of ff , the points come from the SRS. Let CC be the commitment. It is a public point, but the number f(τ)f(\tau) inside it is secret from everyone, including the prover. It has to be: if f(τ)f(\tau) were public, anyone who knows ff could solve f(X)−f(τ)=0f(X) - f(\tau) = 0 for candidates of τ\tau .

Hiding q(τ)q(\tau) . In the same way, from the coefficients of qq :

π=q0⋅[1]1+q1⋅[τ]1+⋯+qn−1⋅[τn−1]1 =[q(τ)]1 \begin{aligned} \pi &= q_0\cdot[1]1 + q_1\cdot[\tau]_1 + \dots + q{n-1}\cdot[\tau^{n-1}]_1 \ &= [q(\tau)]_1 \end{aligned}

Let π\pi be the opening proof. "Opening" because the prover reveals one value of the polynomial, y=f(z)y = f(z) , and π\pi proves that this value is consistent with CC . The polynomial itself stays hidden.

Hiding τ−z\tau - z . The verifier computes it from the SRS: [τ]2−z⋅[1]2=[τ−z]2[\tau]_2 - z\cdot[1]_2 = [\tau - z]_2 .

Because the prover can only combine SRS points, CC and π\pi always hide the values at τ\tau of some polynomials of degree at most nn , fixed at the moment the points are sent. That is what makes the random-point argument of 2.4 apply.

2.6 The verification equation

The general pairing check. For points P1,P2∈G1P_1, P_2 \in G_1 and Q1,Q2∈G2Q_1, Q_2 \in G_2 , a pairing check is an equation

e(P1⏟G1, Q1⏟G2)=e(P2⏟G1, Q2⏟G2) e(\underbrace{P_1}{G_1},\ \underbrace{Q_1}{G_2}) = e(\underbrace{P_2}{G_1},\ \underbrace{Q_2}{G_2})

If the points hide numbers, P1=[a]1P_1 = [a]_1 , Q1=[b]2Q_1 = [b]_2 , P2=[c]1P_2 = [c]_1 , Q2=[d]2Q_2 = [d]_2 , then by the pairing property

e([a]1,[b]2)=e([c]1,[d]2)  ⟺  a⋅b=c⋅d e([a]_1, [b]_2) = e([c]_1, [d]_2) \iff a\cdot b = c\cdot d

So one pairing check verifies an equation of the form "product of two hidden numbers = product of two hidden numbers", where the first number of each product is hidden in G1G_1 and the second in G2G_2 .

Substituting equation (3). Write (3) in that form:

(f(τ)−y)⏟a⋅1⏟b=q(τ)⏟c⋅(τ−z)⏟d \underbrace{(f(\tau) - y)}{a}\cdot\underbrace{1}{b} = \underbrace{q(\tau)}{c}\cdot\underbrace{(\tau - z)}{d}

Each number is hidden in a point that someone can compute:

Number Hidden as Group Computed by
a=f(τ)−ya = f(\tau) - y P1=C−y⋅[1]1P_1 = C - y\cdot[1]_1 G1G_1 verifier, from CC and yy
b=1b = 1 Q1=[1]2Q_1 = [1]_2 G2G_2 SRS
c=q(τ)c = q(\tau) P2=πP_2 = \pi G1G_1 prover
d=τ−zd = \tau - z Q2=[τ]2−z⋅[1]2Q_2 = [\tau]_2 - z\cdot[1]_2 G2G_2 verifier, from the SRS and zz

P1P_1 works because [f(τ)−y]1=[f(τ)]1−y⋅[1]1=C−y⋅[1]1[f(\tau) - y]_1 = [f(\tau)]_1 - y\cdot[1]_1 = C - y\cdot[1]_1 , and Q2Q_2 because [τ−z]2=[τ]2−z⋅[1]2[\tau - z]_2 = [\tau]_2 - z\cdot[1]_2 . Substituting into the general check:

e(C−y⋅[1]1⏟G1, [1]2⏟G2)=e(π⏟G1, [τ]2−z⋅[1]2⏟G2)(4) e\big(\underbrace{C - y\cdot[1]1}{G_1},\ \underbrace{[1]2}{G_2}\big) = e\big(\underbrace{\pi}{G_1},\ \underbrace{[\tau]_2 - z\cdot[1]_2}{G_2}\big) \qquad (4)

This is the verification equation. Every term in it is known to the verifier. CC , yy and π\pi come from the prover, [1]1[1]_1 , [1]2[1]_2 and [τ]2[\tau]_2 from the SRS, and zz from the verifier itself. This is why the setup publishes [τ]2[\tau]_2 : the factor τ−z\tau - z has to be in G2G_2 . The cost is two pairings, whatever the degree of ff .

The whole chain is

(1)f(z)=y   ⟺   (2)f(X)−y=q(X)⋅(X−z) ⟸ (3)f(τ)−y=q(τ)⋅(τ−z)   ⟺   (4)e(C−y⋅[1]1, [1]2)=e(π, [τ]2−z⋅[1]2) \begin{aligned} &(1) && f(z) = y \ \iff\ &(2) && f(X) - y = q(X)\cdot(X - z) \ \Longleftarrow\ &(3) && f(\tau) - y = q(\tau)\cdot(\tau - z) \ \iff\ &(4) && e\big(C - y\cdot[1]_1,\ [1]_2\big) = e\big(\pi,\ [\tau]_2 - z\cdot[1]_2\big) \end{aligned}

where the middle implication holds with overwhelming probability because τ\tau is random and unknown.

This is the equation from the widget at the top. Every symbol in it now has a derivation. Scroll back up and click through it again.

2.7 A worked example, as a conversation

The same steps with small numbers. In real life τ\tau and zz are random 255-bit numbers. Here they are tiny so that everything can be checked by hand. Each step shows what is said, then the general formula next to the same thing with numbers.

Ceremony

I pick a secret τ\tau , publish its powers hidden in points, and delete τ\tau . Anyone can see the points, but nobody can read the numbers out of them.

In symbols:

G1: [1]1, [τ]1, [τ2]1 G2: [1]2, [τ]2 \begin{aligned} G_1&:\ [1]_1,\ [\tau]_1,\ [\tau^2]_1 \ G_2&:\ [1]_2,\ [\tau]_2 \end{aligned}

With numbers:

G1: G, 5⋅G, 25⋅G G2: H, 5⋅H \begin{aligned} G_1&:\ G,\ 5\cdot G,\ 25\cdot G \ G_2&:\ H,\ 5\cdot H \end{aligned}

with τ=5\tau = 5 , GG and HH the generators.


Prover

My polynomial is f(X)=X2+2X+3f(X) = X^2 + 2X + 3 . I don't know τ\tau , but I can combine the published points with my coefficients. Here is my commitment CC . It hides f(τ)f(\tau) , a number I never see: I only add points.

In symbols:

C=f0[1]1+f1[τ]1+f2[τ2]1 =[f(τ)]1 \begin{aligned} C &= f_0[1]_1 + f_1[\tau]_1 + f_2[\tau^2]_1 \ &= [f(\tau)]_1 \end{aligned}

With numbers:

C=3⋅G+2⋅5G+1⋅25G =38⋅G \begin{aligned} C &= 3\cdot G + 2\cdot 5G + 1\cdot 25G \ &= 38\cdot G \end{aligned}

and 38=f(5)38 = f(5) .

Sends to the verifier → C=38⋅GC = 38\cdot G


Verifier

Got CC . Now tell me the value of your polynomial at z=2z = 2 .

In symbols:

zz : random, picked after CC arrives.

With numbers:

z=2 z = 2

Sends to the prover → z=2z = 2


Prover

f(2)=11f(2) = 11 . To prove it, I divide f(X)−11f(X) - 11 by (X−2)(X - 2) . It divides exactly, so the quotient qq exists, and I hide it like ff . Here are yy and π\pi .

In symbols:

y=f(z) q(X)=f(X)−yX−z π=[q(τ)]1 \begin{aligned} y &= f(z) \ q(X) &= \frac{f(X) - y}{X - z} \ \pi &= [q(\tau)]_1 \end{aligned}

With numbers:

f(X)=X2+2X+3 y=f(2)=4+4+3=11 X2+2X−8=(X+4)(X−2) q(X)=X+4 π=4⋅G+1⋅5G=9⋅G \begin{aligned} f(X) &= X^2 + 2X + 3 \ y = f(2) &= 4 + 4 + 3 = 11 \ X^2 + 2X - 8 &= (X + 4)(X - 2) \ q(X) &= X + 4 \ \pi &= 4\cdot G + 1\cdot 5G = 9\cdot G \end{aligned}

Sends to the verifier → y=11y = 11 and π=9⋅G\pi = 9\cdot G


Verifier

I build my two points and compare two pairings. I only handle points, never the numbers inside, but by bilinearity each pairing equals e(G,H)e(G, H) raised to the product of the hidden numbers. Both sides match, so I accept: f(2)=11f(2) = 11 .

In symbols:

e(C−y[1]1, [1]2) =e(π, [τ]2−z[1]2) \begin{aligned} &e\big(C - y[1]_1,\ [1]_2\big) \ &\quad = e\big(\pi,\ [\tau]_2 - z[1]_2\big) \end{aligned}

With numbers:

Received: C=38⋅GC = 38\cdot G , then y=11y = 11 and π=9⋅G\pi = 9\cdot G .

C−11⋅G=27⋅G 5⋅H−2⋅H=3⋅H e(27⋅G, H)=e(G,H)27⋅1 e(9⋅G, 3⋅H)=e(G,H)9⋅3 \begin{aligned} C - 11\cdot G &= 27\cdot G \ 5\cdot H - 2\cdot H &= 3\cdot H \ e(27\cdot G,\ H) &= e(G, H)^{27\cdot 1} \ e(9\cdot G,\ 3\cdot H) &= e(G, H)^{9\cdot 3} \end{aligned}

Both are e(G,H)27e(G, H)^{27} .


A cheating prover

What if I claim f(2)=12f(2) = 12 ? The division leaves a remainder, so there is no quotient qq to hide. I can still send some point π=k⋅G\pi = k\cdot G , but the verifier's pairing check rejects it. The two sides match only for one kk , and finding it needs τ\tau , which was deleted. The division is where I get stuck. The pairing check is where the verifier catches me.

In symbols:

e(C−y[1]1, [1]2) ≠e(π, [τ]2−z[1]2) \begin{aligned} &e\big(C - y[1]_1,\ [1]_2\big) \ &\quad \neq e\big(\pi,\ [\tau]_2 - z[1]_2\big) \end{aligned}

unless

π=[f(τ)−yτ−z]1 \pi = \Big[\tfrac{f(\tau) - y}{\tau - z}\Big]_1

With numbers:

X2+2X−9=(X+4)(X−2)−1 C−12⋅G=26⋅G e(26⋅G, H)=e(G,H)26 e(k⋅G, 3⋅H)=e(G,H)3k \begin{aligned} X^2 + 2X - 9 &= (X + 4)(X - 2) - 1 \ C - 12\cdot G &= 26\cdot G \ e(26\cdot G,\ H) &= e(G, H)^{26} \ e(k\cdot G,\ 3\cdot H) &= e(G, H)^{3k} \end{aligned}

Passing needs 3k=263k = 26 . We see that only because we know τ=5\tau = 5 and f(τ)=38f(\tau) = 38 . The cheater does not: τ\tau was deleted and CC only hides 38. So its kk is wrong, the two pairings differ, and the verifier rejects. The verifier never sees 26 or kk , only two pairings that do not match.

Sends to the verifier → y=12y = 12 and some π=k⋅G\pi = k\cdot G


The order matters: zz is picked after CC is sent, so the prover could not choose ff with zz in mind.

What is proven: the polynomial behind CC has the value yy at the point zz . Nothing more. KZG says nothing about other points, about where ff came from, or about whether ff is the "right" polynomial. That is the job of the protocol built on top.

2.8 Making it non-interactive: Fiat–Shamir

So far the verifier sent zz . In practice there is no conversation: the prover sends one message, (C,y,π)(C, y, \pi) , and nobody sends zz . Instead, both sides compute it with a hash function fixed by the protocol:

z=Hash(C) z = \mathrm{Hash}(C)

This is the Fiat–Shamir transform, the same trick that turns the Schnorr identification protocol into a signature. This post explains it from scratch.

How a hash becomes a number. A hash function outputs bytes: SHA-256 gives 32 bytes, i.e. 256 bits. Read those bytes as one large integer and reduce it modulo the field prime pp :

z=int(Hash(bytes(C))) mod p z = \mathrm{int}\big(\mathrm{Hash}(\mathrm{bytes}(C))\big) \bmod p

CC is hashed through its canonical byte encoding (a compressed curve point). Because pp is a ~255-bit prime and not a power of two, reducing exactly 256 bits would make some field elements slightly more likely than others. Implementations therefore hash to 64 bytes (512 bits) first, which makes the bias negligible.

What changes in the protocol. Only step 2:

Step Who Computes
1. Commit prover C=[f(τ)]1C = [f(\tau)]_1
2. Challenge prover z=Hash(C) mod pz = \mathrm{Hash}(C) \bmod p
3. Open prover yy , qq , π\pi , sends (C,y,π)(C, y, \pi)
4. Verify verifier recomputes z=Hash(C) mod pz = \mathrm{Hash}(C) \bmod p , then equation (4)

Who chooses zz ? Nobody. The prover computes it, but cannot choose it: the hash depends on CC , which is already fixed. To get a convenient zz , the prover would have to try polynomial after polynomial and hope one of them hashes to a useful point, which is hopeless with a good hash function. The verifier does not need to send anything, because it recomputes the same hash from the CC it received.

What the hash must contain. In real protocols the hash input is not just CC but everything public so far: a domain separator, the verifier key or a digest of the SRS, the public inputs, and every commitment the prover has sent. If anything the prover controls is left out, the prover learns zz before fixing that part, which is exactly the bug class in section 4.

3. What real systems add

Where you meet KZG in an audit.

  • PLONK-family verifiers (gnark, Halo2 with KZG, custom verifiers in Solidity, Go or Rust): every polynomial the prover sends is a KZG commitment, and every evaluation the verifier uses should be backed by an opening.
  • Ethereum blobs (EIP-4844, EIP-7594): committed with KZG over BLS12-381. The precompile at 0x0A lets contracts check f(z)=yf(z) = y .
  • zkVMs and precompile emulation that re-implement pairings.

Key idea. KZG itself is the part you trust. What you audit is everything that feeds it.

Curves. KZG works on any pairing-friendly curve. Only sizes and costs change. BN254 dominates on-chain verifiers because the EVM has had cheap precompiles for it since 2017. BLS12-381 has a larger security margin and is what Ethereum uses for blobs.

Plain KZG proves "the committed polynomial has value yy at zz ". Protocols need more than that, and every addition is a place for bugs.

Fiat–Shamir, beyond one commitment. Section 2.8 derived zz from CC . A full proof system derives many challenges, one after each prover message, all from one running transcript. KZG only tells you f(z)=yf(z) = y . The conclusion that a polynomial identity holds comes from the random-point argument, which needs every challenge to be derived after everything it depends on. The order of absorbing and squeezing is part of soundness.

Same-point batching. To open f1,f2,f3f_1, f_2, f_3 at zz with one proof, open g=f1+vf2+v2f3g = f_1 + v f_2 + v^2 f_3 . The verifier folds commitments and values itself, using Cf+vCg=Cf+vgC_f + v C_g = C_{f+vg} . The weight vv must come after the evaluations.

Two-point batching. PLONK opens at ζ\zeta and ζω\zeta\omega and merges the two checks with a weight uu :

e(W1+uW2, [τ]2)=e(z1W1+uz2W2+(C1−y1[1]1)+u(C2−y2[1]1), [1]2) e\big(W_1 + u W_2,\ [\tau]_2\big) = e\big(z_1 W_1 + u z_2 W_2 + (C_1 - y_1[1]_1) + u(C_2 - y_2[1]_1),\ [1]_2\big)

The weight uu must come after W1W_1 and W2W_2 .

Blinding. KZG is deterministic and each opening reveals one evaluation, so polynomials that carry witness data get random terms such as (b1X+b2)⋅ZH(X)(b_1X + b_2)\cdot Z_H(X) .

4. What went wrong in public

Frozen Heart (Trail of Bits, 2022). Several PLONK implementations computed Fiat–Shamir challenges without hashing all public values. A missing input gives the prover freedom to choose it after seeing the challenge, which is enough to forge proofs.

The Last Challenge Attack (Ciobotaru, Peter, Velichkov, ePrint 2024/398, gnark advisory). Found in an audit of the Linea PLONK verifier: the two-point batching challenge uu did not depend on the opening proofs. That is not a small weakness. It is a total break. Let d=(f1−y1)+u(f2−y2)d = (f_1 - y_1) + u(f_2 - y_2) for any claimed y1,y2y_1, y_2 . Because (X−z1)−(X−z2)=z2−z1(X - z_1) - (X - z_2) = z_2 - z_1 is a nonzero constant,

a=dz2−z1,b=−du (z2−z1) a = \frac{d}{z_2 - z_1}, \qquad b = -\frac{d}{u\,(z_2 - z_1)}

satisfy a⋅(X−z1)+u b⋅(X−z2)=da\cdot(X - z_1) + u\, b\cdot(X - z_2) = d , which is exactly the combined check. Commit to aa and bb as W1,W2W_1, W_2 , and both polynomials open to whatever values you like. If uu depends on W1,W2W_1, W_2 , this is circular and fails.

Unbound evaluations (OtterSec, dusk-plonk, 2026). The proof carried four selector evaluations that went into the transcript and into the final equation, but not into the batched opening. Absorbing a value does not bind it to anything. The prover solved for one of them after seeing the challenge, and the PoC minted tokens from nothing on a local testnet. The post also notes the same pattern in Espresso's Jellyfish, with 9 of 15 Plookup evaluations unbound. The invariant to remember: every scalar in the final equation is either computed by the verifier or backed by an opening.

Library-level bugs (zkSecurity, PeerDAS KZG audit, 2025). Across c-kzg-4844, rust-eth-kzg, go-eth-kzg and blst: a batch verifier whose random combiner omitted the proofs and used the wrong integer width (High), an infinity point that corrupted batch normalisation, scalars above the group order giving wrong results, and FK20 evaluation lengths that were neither validated nor hashed individually.

Pairing shortcuts (zkSecurity, openvm-pairing, 2026). An optimised pairing check accepted a prover-supplied hint that was only checked for being non-zero. With the right hint, any pairing equation "holds", which on BLS12-381 means forged KZG openings.

Where KZG bugs live

5. The checklist (AI-ready)

The full version, with why, where to look and public findings for every item, is one README on GitHub: 0xluk3/kzg-security. Every item uses the same fields (Check / Why / Look at / Seen in), so the file works both as a reading list and as context for an AI assistant. Paste it together with the verifier you are reviewing and ask:

Go through KZG-01 to KZG-22 one by one. For each item, quote the lines of the code that satisfy or violate it, or say "not applicable" with a reason. List violations first.

Treat what comes back as leads to confirm by hand, not as findings. The short form:

ID Check
SRS
KZG-01 Production SRS comes from a real multi-party ceremony, with no test SRS and no τ in code
KZG-02 SRS structure is verified on load, or the file hash is pinned
KZG-03 Degree bounds are enforced and nothing is truncated silently
KZG-04 One curve, one SRS, one point encoding across prover and verifier
Transcript
KZG-05 Every prover message is absorbed before the next challenge
KZG-06 Transcript includes a domain separator, the verifier key and all public inputs
KZG-07 The final batching challenge u is derived after the opening proofs
KZG-08 Canonical, length-prefixed encoding, with vector lengths validated
KZG-09 Challenges are full-width and the evaluation point is outside the domain
Verifier equation
KZG-10 Every scalar in the final equation is computed by the verifier or opened
KZG-11 One source of truth per evaluation
KZG-12 The verifier builds y·[1]₁, z·[1]₂ and folded commitments itself
KZG-13 The pairing check is complete and hints are fully validated
Points and scalars
KZG-14 On-curve and subgroup checks on every external point
KZG-15 The point at infinity is handled on purpose
KZG-16 Scalars are canonical (< p), never reduced silently
Batching
KZG-17 Same-point weight v comes after the evaluations
KZG-18 Batch verification of many proofs uses fresh, unpredictable weights
ZK and integration
KZG-19 Witness polynomials are blinded
KZG-20 EIP-4844: versioned hash matches the commitment, success and return data are checked
KZG-21 API and FFI boundaries validate lengths, empties and parameter relations
KZG-22 Differential fuzzing and adversarial test vectors

6. Example code

The whole scheme from section 2 in about 80 lines of Rust with arkworks on BN254: setup, commit, open, verify, and the forgery from KZG-01 for whoever knows τ\tau . It uses the worked example from 2.7.

# Cargo.toml
[dependencies]
ark-bn254 = "0.5"
ark-ec = "0.5"
ark-ff = "0.5"
Enter fullscreen mode Exit fullscreen mode
use ark_bn254::{Bn254, Fr, G1Projective as G1, G2Projective as G2};
use ark_ec::{PrimeGroup, pairing::Pairing};
use ark_ff::{Field, One, Zero};

struct Srs {
    g1: Vec<G1>, // [1]1, [t]1, ..., [t^n]1
    g2: [G2; 2], // [1]2, [t]2
}

// Setup. For the demo only: in reality nobody knows tau.
fn setup(tau: Fr, n: usize) -> Srs {
    let (g1, g2) = (G1::generator(), G2::generator());
    let mut pows = Vec::with_capacity(n + 1);
    let mut t = Fr::one();
    for _ in 0..=n {
        pows.push(g1 * t);
        t *= tau;
    }
    Srs {
        g1: pows,
        g2: [g2, g2 * tau],
    }
}

// C = f0·[1] + f1·[t] + ... = [f(t)]1   (f = [f0, f1, ...])
fn commit(srs: &Srs, f: &[Fr]) -> G1 {
    assert!(f.len() <= srs.g1.len(), "degree larger than the SRS supports");
    f.iter().zip(&srs.g1).map(|(c, p)| *p * *c).sum()
}

fn evaluate(f: &[Fr], z: Fr) -> Fr {
    f.iter().rev().fold(Fr::zero(), |acc, c| acc * z + c)
}

// (f - f(z)) / (X - z), Horner
fn quotient(f: &[Fr], z: Fr) -> Vec<Fr> {
    let mut q = vec![Fr::zero(); f.len() - 1];
    let mut carry = Fr::zero();
    for k in (1..f.len()).rev() {
        carry = f[k] + carry * z;
        q[k - 1] = carry;
    }
    q
}

fn open(srs: &Srs, f: &[Fr], z: Fr) -> (Fr, G1) {
    (evaluate(f, z), commit(srs, &quotient(f, z)))
}

// e(C - y[1]1, [1]2) == e(pi, [t]2 - z[1]2)
fn verify(srs: &Srs, c: G1, z: Fr, y: Fr, pi: G1) -> bool {
    let lhs = Bn254::pairing(c - srs.g1[0] * y, srs.g2[0]);
    let rhs = Bn254::pairing(pi, srs.g2[1] - srs.g2[0] * z);
    lhs == rhs
}

// KZG-01: whoever knows tau can open C to any value
fn forge(srs: &Srs, tau: Fr, c: G1, z: Fr, y_fake: Fr) -> G1 {
    (c - srs.g1[0] * y_fake) * (tau - z).inverse().unwrap()
}

fn main() {
    let fr = |x: u64| Fr::from(x);
    let srs = setup(fr(5), 2);
    let f = [fr(3), fr(2), fr(1)]; // 3 + 2X + X^2
    let z = fr(2);

    let c = commit(&srs, &f);
    let (y, pi) = open(&srs, &f, z);
    let q: Vec<String> = quotient(&f, z).iter().map(|x| x.to_string()).collect();

    println!("y = {y}, q = {q:?}");
    println!("honest:  {}", verify(&srs, c, z, y, pi));
    println!("y = 12:  {}", verify(&srs, c, z, fr(12), pi));
    let fake = forge(&srs, fr(5), c, z, fr(12));
    println!("forged with tau: {}", verify(&srs, c, z, fr(12), fake));
    assert_eq!(c, G1::generator() * fr(38));
    assert_eq!(pi, G1::generator() * fr(9));
}
Enter fullscreen mode Exit fullscreen mode
$ cargo run --release
y = 11, q = ["4", "1"]
honest:  true
y = 12:  false
forged with tau: true
Enter fullscreen mode Exit fullscreen mode

Each function is one step: setup (step 0), commit (step 1), quotient and open (step 3), verify (step 4, equation (4)). forge shows why the setup must delete τ\tau : with it, a false y=12y = 12 verifies. Swapping ark_bn254 and Bn254 for ark_bls12_381 and Bls12_381 runs the same code on BLS12-381.

7. Recommended reading

Top comments (0)