banner
social-twittersocial-githubsocial-github

A public coin, zero-knowledge Folding Scheme for Committed Relaxed R1CS

The canonical Nova paper introduced a few things:

  1. An "augmented" R1CS structure, called Committed Relaxed R1CS
  2. A "folding scheme" for Committed Relaxed R1CS
  3. A way to turn the folding scheme for Committed Relaxed R1CS into an IVC
  4. A nova-specific zkSNARK, built on top of Spartan to compress and have zero-knowledge IVC proofs; i.e. prove that you know a valid IVC proof without divulging it.

The zero-knowledge Folding Scheme for Committed Relaxed R1CS is the main cryptographic engine that makes the Nova IVC possible and corresponds to points 1 and 2. It is laid out within the paper's section 4, of which this post is a condensed summary.

Motivation

The motivation for folding stems from a prover P\mathcal{P} willing to convince a verifier V\mathcal{V} that he knows two instance-witness tuples which satisfy a particular R1CS structure. This should be done without P\mathcal{P} divulging those witnesses. We will review what this means below.

A trivial way for V\mathcal{V} to check whether the two purpoted witnesses of P\mathcal{P} are satisfying would be to check each of them. But this isn't satisfying, both from a computation and communication standpoint. Firstly, P\mathcal{P} would need to send 2 witnesses and V\mathcal{V} would have to check that the R1CS structure holds for both. Secondly, P\mathcal{P} would send V\mathcal{V} each of those witnesses, making this trivial solution non zero-knowledge.

A folding scheme for committed relaxed R1CS aims to patch this:

  1. It will turn the cost of the trivial solution consisting of checking each of those two witnesses into the cost of checking a single one, computed as a linear combination of the two.
  2. It will be zero-knowledge, keeping V\mathcal{V} from knowing what are the two folded witnesses.

Naive R1CS folding

Combining instance-witness pairs linearly

In R1CS, we say that Z=(W,x,1)Z = (W, x, 1) is a satisfying instance-witness pair when:

AZBZ=CZ\begin{equation} A \cdot Z \odot B \cdot Z = C \cdot Z \end{equation}

where A,B,CA, B, C compose the R1CS structure, WW is the witness and xx a vector of public inputs/outputs. The satisfying tuple ZZ has 11 as its last element, a "dummy" variable representing constants. This writeup from Vitalik is a nice introduction to what R1CS is.

In the context of folding, P\mathcal{P} will be in possession of two satisfying instance-witness pairs Z1=(W1,x1,1),Z2=(W2,x2,1)Z_1 = (W_1, x_1, 1), Z_2 = (W_2, x_2, 1).

A simple cryptographic technique available to VV to avoid PP from cheating is to send him randomness. This will be of help for folding two R1CS instances. Indeed, VV will require from PP to perform a random linear combination of the two instance-witness pairs. It will look like this:

xx1+rx2WW1+rW2\begin{equation} \begin{aligned} x \leftarrow x_1 + r \cdot x_2 \\ W \leftarrow W_1 + r \cdot W_2 \end{aligned} \end{equation}

where rr is some random scalar parameter sent by V\mathcal{V}. Now, P\mathcal{P} ends up with a new, single instance-witness pair Z=Z1+rZ2Z = Z_1 + r \cdot Z_2.

However, the newly folded ZZ does not satisfy the canonical R1CS equation of (1)(1) anymore! Indeed, naively plugging it into the R1CS equation yields:

AZBZ=A(Z1+rZ2)B(Z1+rZ2)=AZ1BZ1+r(AZ1BZ2+AZ2+BZ1)+r2(AZ2BZ2) \begin{aligned} A \cdot Z \odot B \cdot Z = A \cdot (Z_1 + r \cdot Z_2 ) \odot B \cdot (Z_1 + r \cdot Z_2 ) \\ = AZ_1 \odot BZ_1 + r \cdot (AZ_1 \odot BZ_2 + AZ_2 + BZ_1) + r^{2} \cdot (AZ_2 \odot BZ_2) \end{aligned}

Now, we end up with a cross-term and a quadratic term. This is not equal to the expected CZ=CZ1+rCZ2=AZ1BZ1+r(AZ2BZ2)CZ = CZ_1 + rCZ_2 = AZ_1 \odot BZ_1 + r ( AZ_2 \odot BZ_2).

Also, note that when we take a random linear combination of our two instance-witness tuples we end up with:

Z=Z1+rZ2=(W1,x1,1)+r(W2,x2,1)=(W1+rW2,x1+rx2,1+r)\begin{equation} \begin{aligned} Z &= Z_1 + r \cdot Z_2 \\ &= (W_1, x_1, 1) + r \cdot (W_2, x_2, 1) \\ &= (W_1 + r \cdot W_2, x_1 + r \cdot x_2, 1 + r) \\ \end{aligned} \end{equation}

An extra rr sneaked in our satisfying instance-witness tuple; the last element is not 11 anymore!

Absorbing the cross-term and rr

First, let's introduce an error vector E=r(AZ1BZ2+AZ2+BZ1)E = r \cdot (AZ_1 \odot BZ_2 + AZ_2 + BZ_1) to account for the corresponding cross-term. Our new R1CS equation is:

AZBZ=CZ+EA \cdot Z \odot B \cdot Z = C \cdot Z + E

You can see how EE will "absorb" the cross-term by plugging it in the above derivation for AZBZA \cdot Z \odot B \cdot Z.

Now, let's re-write what we have so far without this cross-term to see what remains to be dealt with:

AZBZ=AZ1BZ1+r2(AZ2BZ2)=CZ1+r2CZ2CZ1+rCZ2\begin{aligned} A \cdot Z \odot B \cdot Z &= AZ_1 \odot BZ_1 + r^{2} \cdot (AZ_2 \odot BZ_2) \\ &= CZ_1 + r^{2} \cdot CZ_2 \neq CZ_1 + r CZ_2 \end{aligned}

What's left is to absorb the remaining r2,rr^{2}, r terms of (6)(6) and the extra 1+r1+r element. To this end, let's introduce a new term, uu:

uu1+ru2\begin{equation} \begin{aligned} u &\leftarrow u_1 + r \cdot u_2 \end{aligned} \end{equation}

where uiFu_i \in \mathbb{F}.

Let's now see how EE and uu help us with folding.

Relaxed R1CS

A relaxed R1CS system will be basically R1CS, but equipped with the ability to take linear combinations of satisfying instance-witness pairs.

The relaxed R1CS equation is very similar to canonical R1CS. It says that given an error vector EE, an instance-witness tuple Z=(W,x,u)Z = (W, x, u) satisfies a relaxed R1CS equation when the following holds:

AZBZ=u(CZ)+E\begin{aligned} A \cdot Z \odot B \cdot Z = u \cdot (C \cdot Z) + E \end{aligned}

In this context, on top of folding two satisfying Z1Z_1, Z2Z_2, we will also need to combine two error vectors E1E_1, E2E_2 together to compute a new folded vector EE:

EE1+r(AZ1BZ2+AZ2BZ1u1CZ2+u2CZ1)+r2E2 \begin{aligned} E &\leftarrow E_1 + r \cdot (AZ_1 \odot BZ_2 + AZ_2 \odot BZ_1 - u_1CZ_2 + u_2CZ_1) + r^{2} \cdot E_2 \end{aligned}

As explained above, this folded EE will absorb the cross-term that pops up when naively plugging in a linear combination of the two instance-witness pairs Z1,Z2Z_1, Z_2 in the original R1CS equation.

Let's try again taking a random linear combination of two satisfying relaxed R1CS witness-instance pairs. Let's define Z1=(W1,x1,u1),Z2=(W2,x2,u2)Z_1 = (W_1, x_1, u_1), Z_2 = (W_2, x_2, u_2) to be two satisfying instance-witness pairs and set Z=Z1+rZ2Z = Z_1 + r \cdot Z_2. We get:

AZBZ=AZ1BZ1+r(AZ1BZ2+AZ2+BZ1)+r2(AZ2BZ2)=(u1CZ1+E1)+r(AZ1BZ2+AZ2+BZ1)+r2(u2CZ2+E2)=(u1+ru2)C(Z1+rZ2)+E=uCZ+E\begin{aligned} A \cdot Z \odot B \cdot Z &= AZ_1 \odot BZ_1 + r \cdot (AZ_1 \odot BZ_2 + AZ_2 + BZ_1) + r^{2} \cdot (AZ_2 \odot BZ_2) \\ &= (u_1CZ_1 + E_1) + r \cdot (AZ_1 \odot BZ_2 + AZ_2 + BZ_1) + r^{2} \cdot (u_2CZ_2 + E_2) \\ &= (u_1 + r \cdot u_2) \cdot C(Z_1 + rZ_2) + E \\ &= uCZ + E \end{aligned}

The pen-ultimate equality holds since EE has a term r([]ru1CZ2+ru2CZ1)r \cdot ([\dots] - ru_1CZ_2 + ru_2CZ_1). This makes it possible to write the factorization (u1+ru2)C(Z1+rZ2)(u_1 + r \cdot u_2) \cdot C(Z_1 + rZ_2).

You can now observe how the relaxed R1CS equation works, inserting EE and uu in (1)(1) and thus absorbing the cross and quadratic terms that pop up when taking random linear combinations of two satisfying instance-witness pairs.

Committed Relaxed R1CS

Assume P\mathcal{P} knows two satisfying instance-witness pairs Z1,Z2Z_1, Z_2 to a common particular relaxed R1CS structure. In the current state of things, checking that a relaxed R1CS holds requires to compute the EE term, which depends on Z1=(W1,x1,u1)Z_1 = (W_1, x_1, u_1) and Z2=(W1,x1,u1)Z_2 = (W_1, x_1, u_1).

This means that V\mathcal{V} will need both Z1Z_1 and Z2Z_2 to check that the folded instance-witness pair satisfies the equation AZBZ=uCZ+EA \cdot Z \odot B \cdot Z = uCZ + E. Thus, to make this scheme zero-knowledge, we will need to hide W1W_1 and W2W_2.

We do this using a commitment scheme. On top of hiding, we will also need our commitment scheme to be additively homomorphic. Briefly, the property that an additively homomorphic commitment scheme verifies is if τ(W1),τ(W2)\tau(W_1), \tau(W_2) are commmitments to witnesses W1,W2W_1, W_2, then the equality τ(W1)+rτ(W2)=τ(W1+rW2)\tau(W_1) + r\cdot \tau(W_2) = \tau(W_1 + r\cdot W_2) holds. This will make V\mathcal{V} able to check that the linear combination of Z1,Z2Z_1, Z_2 has been performed correctly, but using committed witnesses.

Thus, a committed relaxed R1CS is a relaxed R1CS to which P\mathcal{P} commits to using an additively homomorphic commitment scheme. A committed relaxed R1CS instance (Eˉ,u,Wˉ,x)(\bar{E}, u, \bar{W}, x) is satisfied if there exists a relaxed R1CS witness (E,W)(E, W) such that AZBZ=uCZ+EA \cdot Z \odot B \cdot Z = uCZ + E holds, where Z=(W,x,u)Z=(W, x, u) and Eˉ=τ(E),Wˉ=τ(W)\bar{E} = \tau(E), \bar{W} = \tau(W) - i.e. EE and WW have been correctly committed to.

A public-coin, zero-knowledge Folding Scheme for Committed Relaxed R1CS

We can now build a zero-knowledge protocol for folding committed relaxed R1CS witnesses. We describe it using the interactive version but we can make this non interactive using the fiat-shamir trick.

A prover P\mathcal{P} wants to convince a verifier V\mathcal{V} that he knows two relaxed R1CS witnesses (E1,W1)(E_1, W_1) and (E2,W2)(E_2, W_2) satisfying two committed relaxed R1CS instances (Eˉ1,u1,Wˉ1,x1)(\bar{E}_1, u_1, \bar{W}_1, x_1) and (Eˉ2,u2,Wˉ2,x2)(\bar{E}_2, u_2, \bar{W}_2, x_2).

We want to do this in zero-knowledge. So, while both P\mathcal{P} and V\mathcal{V} know instances (Eˉ1,u1,Wˉ1,x1),(Eˉ2,u2,Wˉ2,x2)(\bar{E}_1, u_1, \bar{W}_1, x_1), (\bar{E}_2, u_2, \bar{W}_2, x_2), only P\mathcal{P} knows the two satisfying witnesses (E1,W1),(E2,W2)(E_1, W_1), (E_2, W_2).

The protocol is the following:

  1. P\mathcal{P} computes T=AZ1BZ2+AZ2BZ1u1CZ2+u2CZ1T=AZ_1 \odot BZ_2 + AZ_2 \odot BZ_1 - u_1CZ_2 + u_2CZ_1 and sends Tˉτ(T)\bar{T} \leftarrow \tau(T) to V\mathcal{V}.
  2. The verifier V\mathcal{V} samples a challenge rr and sends it to P\mathcal{P}
  3. Both P\mathcal{P} and V\mathcal{V} compute the folded committed relaxed R1CS instance (Eˉ,u,Wˉ,x)(\bar{E}, u, \bar{W}, x), with:
EˉEˉ1+rEˉ2uu1+ru2WˉW1ˉ+rW2ˉxx1+rx2\begin{aligned} \bar{E} \leftarrow \bar{E}_1 + r \cdot \bar{E}_2 \\ u \leftarrow u_1 + r \cdot u_2 \\ \bar{W} \leftarrow \bar{W_1} + r \cdot \bar{W_2} \\ x \leftarrow x_1 + r \cdot x_2 \end{aligned}
  1. P\mathcal{P} sends the folded witness to V\mathcal{V}:
EE1+rT+r2E2WW1+rW2\begin{aligned} E \leftarrow E_1 + r \cdot T + r^2 \cdot E_2 \\ W \leftarrow W_1 + r \cdot W_2 \\ \end{aligned}

V\mathcal{V} can now do the following checks:

  1. τ(E)=?Eˉ\tau(E) \stackrel{?}{=} \bar{E}
  2. τ(W)=?Wˉ\tau(W) \stackrel{?}{=} \bar{W}
  3. AZBZ=?uCZ+EA \cdot Z \odot B \cdot Z \stackrel{?}{=} uCZ + E, where Z=(W,x,u)Z=(W, x, u)

If all of those checks pass, V\mathcal{V} accepts (E,W)(E, W) as a satisfying folding of two satisfying witnesses of instances (Eˉ1,u1,Wˉ1,x1),(Eˉ2,u2,Wˉ2,x2)(\bar{E}_1, u_1, \bar{W}_1, x_1), (\bar{E}_2, u_2, \bar{W}_2, x_2)

We see that V\mathcal{V} had to check a single folded witness instead of two!

Side note: why Nova is not post-quantum

The additively homomorphic commitment scheme which Nova instantiates is pedersen commitments. But in a post-quantum context the hiding property breaks, as the hardness of the discrete logarithm fails. As of today, there is no existing quantum-resistant, additively homomorphic and succint commitment scheme. This is the sole piece missing to Nova being post-quantum ready.