zk-SNARK: Nonlinear Function
Created: October 22, 2022
Modified: October 23, 2022

zk-SNARK

This page is from my personal notes, and has not been specifically reviewed for public consumption. It might be incomplete, wrong, outdated, or stupid. Caveat lector.

A zk-SNARK, or zero knowledge Succinct Non-interactive Argument of Knowledge, is a zero knowledge proof system that is non-interactive (proofs are one-shot messages) and succinct (proofs are short and cheap to verify).

Formally we consider a prover P who wants to prove knowledge of a witness ww such that z=f(x,w)z = f(x, w) where xx is a publicly known input to the publicly known function ff. The resulting proof π\pi must have constant size Oλ(1)O_\lambda(1) for any given value of a security parameter λ\lambda, and must be verifiable in time O(f+x+z)O(|f| + |x| + |z|). This succinctness condition is quite strong: note that even explicitly revealing ww (breaking zero knowledge) would not satisfy it, since it has non-constant size and verification would require computing f(x,w)f(x, w) which may be expensive.

Classic zero-knowledge proofs are interactive protocols between a prover and verifier, which work to convince the verifier, but do not necessarily convince a third-party observer. The existence of non-interactive protocols is transformative, because such a proof can be processed by an arbitrary number of verifiers: it works as a one-to-many argument that does convince verifiers who weren't around at its inception. Such a proof can reside on a blockchain, demonstrating secret knowledge in a way that's open to public verification (and that even creates common knowledge).

Example construction

TODO: this section is unfinished and a mess. Read http://chriseth.github.io/notes/articles/zksnarks/zksnarks.pdf instead.

An example of a scheme for demonstrating that the prover can compute some polynomial function ff, known to have degree at most dd.

We'll first choose a group and generator gg, specifying a discrete logarithm encryption scheme E(x)=gxE(x) = g^x.

A verifier chooses secret group elements ss and zz, and publicly posts a common reference string (CRS) containing the encrypted values

E(s0),E(s1),,E(sd)E(zs0),E(zs1),,E(zsd),\begin{align*}&E(s^0), E(s^1), \ldots, E(s^d)\\&E(zs^0), E(zs^1), \ldots, E(zs^d),\end{align*}

noting that these in particular contain the generators E(s0)=gE(s^0) = g and E(zs0)=gzE(zs^0) = g^z.

Because the dd-degree polynomial ff must be a sum of powers of ss, and the encryption scheme using exponentiation simply converts sums into products, the prover can use these terms to compute the encrypted values m=E(f(s))m = E(f(s)) and n=E(zf(s))n = E(z\cdot f(s)). For example, if f(s)=s2+sf(s) = s^2 + s, then

E(f(s))=gs2+s=gs2gs=E(s2)E(s)\begin{align*}E(f(s)) &= g^{s^2 + s}\\&=g^{s^2}\cdot g^s\\&=E(s^2)\cdot E(s)\end{align*}

and similarly for E(zf(s))E(z\cdot f(s)). For security reasons the prover will in fact computes these values and returns them shifted by a secret random offset ψ\psi , so that the proof is of the form

π=(m,n)=(E(ψ+f(s)),E(z(ψ+f(s)))\pi = (m', n') = (E(\psi + f(s)), E(z(\psi + f(s)))

.

It is not obvious how a verifier should check this proof given that it knows neither the polynomial ff nor the original secrets (s,z)(s, z). The trick is to use a pairing function pp, chosen such that

p(gx,gy)=p(g,g)xyp(g^x, g^y) = p(g, g)^{xy}

holds for all inputs x,yx, y. Given such a function, the verifier checks that the two computations

p(m,gz)=p(gf(s),gz)=p(g,g)zf(s)p(n,g)=p(gzf(s),g)=p(g,g)zf(s)\begin{align*} p(m, g^z) = p(g^{f(s)}, g^z) = p(g, g)^{zf(s)}\\ p(n, g) = p(g^{zf(s)}, g) = p(g, g)^{zf(s)} \end{align*}

give matching results. This checks that that mm and nn would decrypt to values that differ by a factor of zz, even though we can't efficiently decrypt them and we no longer know zz explicitly. The only clear way to generate such values is to have evaluated some product of the paired terms provided as part of the common reference strong, representing a polynomial function of ss.

Note that this verification does not depend on the complexity of ff; it can proceed even if ff is some very complex high-degree polynomial.

q1: what is the pairing function? q2: what are we trying to prove about f?

References