Try   HackMD

Folding for Arbitrary Polynomial Custom Gates and Lookups

Yan X Zhang and Aard Vark

(with thanks to Yi Sun, Jonathan Wang, Lev Soukhanov, Nicolas Mohnblatt)

This hasn't been checked. Use at your own risk.

Nova introduced a folding scheme for R1CS circuits. A folding scheme is a way to aggregate multiple satisfying witnesses to a constraint system (in Nova's case, an R1CS circuit), so that multiple verifications can be combined into one. Under the hood, folding works by taking a random linear combination of the witnesses; the R1CS equations need to be generalized to "relaxed R1CS" constraints, which are stable under linear combination.

Our goal here is to show how Nova-style folding can be generalized to any polynomial "custom gate". The idea is sketched in Sangria in Section 3.3. In addition, we provide a useful special case that has not yet been done: folding lookups. (We also have a separate writeup of folding lookups at Origami.)

1. Preliminaries

A bit of algebra

We'll start with a general algebraic identity.

Let

p(x) be a homogenous polynomial of degree
d
in
n
variables (where
x=(x1,x2,xn)
).

Then there are

d1 polynomials
Δ1p,Δ2p,,Δn1p
of degree at most
d
in
2n
variables such that
p(x+ry)=p(x)+rdp(y)+k=1d1rkΔkp(x,y).

The construction is simple. Write

p(x) as a linear combination of monomials
xi1xi2xid
:
p(x)=ai1,i2,,idxi1xi2xid.

(It's OK if some of the indices are equal to each other. For example, the monomial
x12
has
i1=i2=1
. Also, this expression is not unique, and that's OK too. For example,
x1x2
could be rewritten as
x2x1
or even
2x1x2x2x1
.)

The polynomial

Δkp(x) can be computed as follows: for any monomial,
Δk(xi1xi2xid)
is the sum of the
(dk)
terms obtained by replacing
k
of the
d
variables
xij
with
yij
. For example:
Δ1(x1x2)=x1y2+y1x2Δ2(x1x2x3)=x1y2y3+y1x2y3+y1y2x3Δ1(x13)=Δ1(x1x1x1)=x1y1y1+y1x1y1+y1y1x1.

What if

p is not homogenous? To match the notation in Nova, we'll homogenize by introducing an extra variable.

For any polynomial

p(x) of degree at most
d
in
n
variables, we'll define a homogenous polynomial
phomog(x,u)
of degree
d
in
n+1
variables, as follows.

Write

p(x)=d=0dpd(x), where
pd(x)
is homogenous of degree
d
. In other words,
pd(x)
is just the sum of all the degree-
d
terms in
p(x)
. Then define
phomog(x,u)=d=0duddpd(x).

In other words, to make

phomog(x,u) from
p(x)
, just multiply each term of
p(x)
by whatever power of
u
is needed to make the degree come out to
d
.

For future reference, it's worth noting that

p(x)=phomog(x,1).

TODO: an example that reformulates Sangria in this notation.

Commitments

We'll assume a hiding, binding, additively homomorphic commitment scheme

Com(pp,x,ρ). We'll denote a commitment to a vector
V
by
V=Com(pp,V,ρ)
. For clarity of notation, sometimes we will write
Com(V):=Com(pp,V,ρ)
when the arguments are obvious from context.

2. The Protocol

We'll describe a folding scheme for AIRs, a form of polynomial constraint system. An AIR

P is a collection of polynomials
f1,,f
in
2w
variables over a finite field
F
. An execution trace
T
for
P
is an array of elements
Tr,c
of
F
, with
n
rows, each of width
w
. In order for the trace
T
to be valid, it is required that, when we substitute into any
fi
the
2w
elements of any two consecutive rows of
T
, the result equals zero:
fi(Tj,1,Tj,2,,Tj,w,Tj+1,1,Tj+1,2,,Tj+1,w)=0.

The folding scheme we're about to describe works for more general polynomial constraint systems as well. All that matters is that a valid trace be defined by some fixed collection of polynomial equations in the entries. It is not necessary that each polynomial only involve entries from two consecutive rows. Nonetheless, we'll continue working within the AIR framework.

To start, we introduce the main object, a relaxed AIR, in the style of Sangria. The main idea of a relaxed AIR, like the relaxed R1CS analogue from Nova, is a polynomial constraint that involves a "slack term."

Relaxed AIR

We'll write

fi(T) for the length-
n
vector whose
j
-th entry is
fi
applied to rows
j
and
j+1
of
T
:
fi(Tj,1,Tj,2,,Tj,w,Tj+1,1,Tj+1,2,,Tj+1,w).

(Rows wrap around, so row
n
is the same as row
0
.)

A relaxed AIR instance is satisfied by a trace

T (i.e. an
n
-by-
w
array of elements of
F
), vectors
E1,E2,,EFn
, and a scalar
uF
, if
fihomog(Tj,1,Tj,2,,Tj,w,Tj+1,1,Tj+1,2,,Tj+1,w,u)=(Ei)j,
for each
i
and
j
.

We'll write

fihomog(T,u) for the vector whose
j
-th entry is
fihomog(Tj,1,Tj,2,,Tj,w,Tj+1,1,Tj+1,2,,Tj+1,w,u).

Since

fihomog is a polynomial in
2w+1
variables, the construction at the top of the page defines polynomials
Δkfihomog
in
2(2w+1)
variables. We'll write
Δkfihomog(T1,u1;T2,u2)
for the vector whose
j
-th entry is
Δkfihomog(Tj,11,,Tj+1,w1,u1,Tj,12,,Tj+1,w2,u2).

A relaxed AIR instance

(Ei,u) consists of slack vectors
E1,,EFn
and a scalar
uF
. A witness for such an instance is an
n
-by-
w
matrix
T
of field elements such that
fihomog(T,u)=Ei,
for all
i
.

Clearly, any AIR instance can be promoted to a relaxed AIR instance by setting

u=1 and
E=0
. The main idea in folding AIR instances is that by converting them to relaxed AIR instances, the computations can be more easily combined.

Committed relaxed AIR

A committed relaxed AIR instance

(fi,ρ,Ei,u,T) consists of polynomials
f1,,f
, randomness
ρ
(to be used by the commitment scheme) a commitment to a slack vector
E=(E1,,E)
, a scalar
u
, and a commitment
T
to an
n
-by-
w
matrix of scalars. A witness to the committed relaxed AIR instance
(fi,Ei,T)
is a tuple
(E,T,ρ)
of

  • a slack vector
    E
    and
  • an
    n
    -by-
    w
    matrix
    T
    ,

such that

T=Com(pp,T,ρ),
E=Com(pp,E,ρ)
, and
fihomog(T,u)=Ei
.

The Folding Scheme

We'll describe a folding scheme for relaxed AIR instances. Suppose a prover and a verifier have an AIR

P, i.e. they both know the collection of polynomials
fi
. The prover is given two relaxed AIR instances
(T1,E1,u1)
and
(T2,E2,u2)
. The verifier knows only the scalars
u1
and
u2
.

Let

di be the degree of the polynomial
fi
, and let
Δkfihomog
be as defined above.

The prover

P and the verifier
V
carry out the following protocol.

Protocol 1

  1. P computes commitments
    X
    for
    X{T1,T2,Ei1,Ei2}
    and their openings
    ρX
    (meaning that for all
    X
    ,
    X=Com(pp,X,ρX)
    holds) and sends them to
    V
    .

  2. For each constraint polynomial

    fi, and each degree
    1kdi1
    ,
    P
    also computes the cross term
    Bi,k=Δkfihomog(T1,u1;T2,u2)
    (a vector of length
    n
    ).
    P
    computes commitments and openings for
    Bi,k
    and sends them to
    V
    .

  3. V samples a random folding challenge
    rF
    , and sends
    r
    to
    P
    .

  4. P computes
    T=T1+rT2
    and, for each
    i
    ,
    Ei=Ei1+rdiEi2+k=1di1rkBi,k.
    These values
    T
    and
    Ei
    give a folded relaxed AIR witness.

  5. Both

    P and
    V
    compute
    u=u1+ru2,
    T=T1+rT2,
    and, for each
    i
    ,
    Ei1+rdiEi2+k=1di1rkBi,k.

Like Nova, this folding process can be iterated. Steps 2-5 allow two committed relaxed AIR instances to be folded into one, at the cost of sending just

4+i=1d11 commitments to the verifier. One can iterate the procedure to fold an arbitrary number of committed relaxed AIR instances together, one by one. At the end, the prover only has to convince the verifier that the final
(E,T)
is a witness to the folded instance.

3. Application: Lookups

In Origami, we apply our procedure to Halo2 lookup checks.

Technically speaking, this is not an exact special case of the protocol since

β and
γ
play the role of verifier-supplied randomness that does not fit in the framework. Instead, lookups are a special case of a slight generalization of Protocol 1 that includes verifier randomness.

Appendix

A.1 Knowledge Soundness

Here we'll argue that the folding procedure satisfies knowledge soundness. In other words, a prover can't convince a verifier to accept a proof (with more than negligible probability) unless the prover itself knows witnesses

(E1,T1) and
(E2,T2)
.

We'll prove this by a "rewinding" argument. Imagine an "extractor" that is allowed to interact with the prover by rewinding it to a previous state. In practice, the extractor will feed the prover different random challenges

r and see what response it gives to each.

Let

d be the largest of the
di
's, so that all the constraint polynomials
fi
have degree at most
d
. Suppose we are given two committed relaxed AIR instances
(fi,Ei1,u1,T1)
and
(fi,Ei2,u2,T2)
(for the same AIR
P=(f1,,f)
). We are also given
d+1
transcripts of the prover-verifier interaction, with
d+1
different values of
r
, say
r(1),,r(d+1)
.

Each transcript contains the same commitments

Bi,k. Furthermore, each transcript gives witnesses
E(r(j))
,
T(r(j))
, and
u(r(j))=u1+r(j)u2,
that satisfy the relaxed AIR condition:
fihomog(T(r(j)),u(r(j)))=Ei(r(j)).

Furthermore, these witnesses are consistent with the commitments

Ei1,T1,Ei2,T2, in that
T(r(j))=T1+r(j)T2

and
E(r(j))=Ei1+r(j)diEi2+k=1di1r(j)kBi,k.

From this, the extractor needs to extract satisfying witnesses

Ei1,T1,Ei2,T2 to the original relaxed AIR. As in Nova, the extractor works by interpolation.

By linear interpolation, the extractor can find

T1 and
T2
such that
T(r(j))=T1+r(j)T2

for
j=1,2
. Since the commitment scheme is linear, the
T1
the extractor finds will satisfy
Com(pp,T1,ρT1)=T1
, and similarly for
T2
. Therefore, for every
j
we have
T(r(j))=T1+r(j)T2=Com(T(r(j))),

so by the binding property of commitment, we have (with high probability) that
T(r(j))=T1+r(j)T2
for all
j
.

Similarly, we'll recover

Ei1,Ei2 and
Bi,k
by Lagrange interpolation. Recall that the coefficients of any degree-
d
polynomial in one variable can be recovered from the value of the polynomial at
d+1
distinct points. (This is purely a question of linear algebra, so the extractor can do it efficiently.) We are looking for
Ei1,Ei2
and
Bi,k
such that
Ei(r(j))=Ei1+r(j)diEi2+k=1di1r(j)kBi,k.

Well, this is simply an interpolation problem for a polynomial of degree
did
in the variable
r
; the unknowns
Ei1,Ei2
and
Bi,k
play the role of coefficients. Thus, for each
i
, we can find
Ei1,Ei2
and
Bi,k
by Lagrange interpolation on the first
di+1
values
r(j)
.

We know that

E(r(j))=Ei1+r(j)diEi2+k=1di1r(j)kBi,k, so by linearity of commitment and linearity of Lagrange interpolation,
Com(pp,Ei1,ρEi1)=Ei1
,
Com(pp,Ei2,ρEi2)=Ei2
, and
Com(pp,Bi,k,ρBi,k)=Bi,k
in other words, the values
Ei1,Ei2,Bi,k
that the extractor finds are consistent with the given commitments.

Just like with

T(r(j)) above, the hiding property of the commitment scheme then guarantees that (with all but negligible probability) we have
Ei(r(j))=Ei1+r(j)diEi2+k=1di1r(j)kBi,k.
for all
j
.

Finally, we need to show that

(Ei1,u1,T1) and
(Ei2,u2,T2)
are satisfying witnesses for the original AIR. To this end, consider the equality
fihomog(T1+rT2,u1+ru2)=Ei1+rdiEi2+k=1di1rkBi,k.

This is an equality of polynomials of degree

di in
r
that is known to hold for
di+1
values of
r
. Therefore, the equality holds for all
r
. In particular, it holds for
r=0
, so
fihomog(T1,u1)=Ei1.

On the other hand, since

fihomog is homogenous of degree
di
, we see that
fihomog(sT1+T2,su1+u2)=sdiEi1+Ei2+k=1di1sdikBi,k
holds for
di+1
values of
s
, namely
s=r(j)1
. Therefore, this equality holds for all
s
, in particular for
s=0
, so
fihomog(T2,u2)=Ei2.

This shows that the extractor can recover the two satisfying witnesses.

Knowledge Soundness for Lookups

It's worth explaining why folded lookup arguments satisfy knowledge soundness as well. Recall the overall shape of the lookup argument:

  • P
    commits to
    Ai
    ,
    Si
    ,
    Api
    ,
    Spi
  • V
    sends challenges
    β
    and
    γ
    for the grand product
  • P
    computes grand products
    Zi
    and
    Wi
    , depending on
    βi
    and
    γi

Then the folding happens. To fold the instance into

Icml:

  • P
    commits to cross-terms
    Bj
  • V
    sends a challenge
    r
  • P
    updates the folded instance
    Icml
    .

In the proof of knowledge soundness above, the extractor rewinds to just before

V sends the challenge
r
. The earlier challenges
β
and
γ
remain untouched. The conclusion is that the prover knows a witness
(ui,βi,γi,Ai,Si,Api,Spi,Zi,Wi)
that satisfies the seven polynomial relations
f1,,f7
.

A separate argument (knowledge soundness for Halo2 lookups) shows that in fact the prover knows

Ai and
Si
satisfying the lookup condition.

A.2 Comparing with Nova and Sangria

Nova is a folding scheme for R1CS circuits. The R1CS structure is a special case of an AIR, where there is a single constraint polynomial

f1, of degree 2, having a specific form. Because the polynomial is of degree
d=2
, there is only a single cross-term
B=B1,1
. The folding scheme described here generalizes Nova: if you apply this scheme to R1CS systems, you recover the original Nova folding scheme.

The idea that Nova-style folding can be generalized to arbitrary custom gates was introduced in Section 3.3 of Sangria.