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 be a homogenous polynomial of degree in variables (where ).
Then there are polynomials of degree at most in variables such that
The construction is simple. Write as a linear combination of monomials : (It's OK if some of the indices are equal to each other. For example, the monomial has . Also, this expression is not unique, and that's OK too. For example, could be rewritten as or even .)
The polynomial can be computed as follows: for any monomial, is the sum of the terms obtained by replacing of the variables with . For example:
What if is not homogenous? To match the notation in Nova, we'll homogenize by introducing an extra variable.
For any polynomial of degree at most in variables, we'll define a homogenous polynomial of degree in variables, as follows.
Write where is homogenous of degree . In other words, is just the sum of all the degree- terms in . Then define
In other words, to make from , just multiply each term of by whatever power of is needed to make the degree come out to .
For future reference, it's worth noting that
TODO: an example that reformulates Sangria in this notation.
Commitments
We'll assume a hiding, binding, additively homomorphic commitment scheme . We'll denote a commitment to a vector by . For clarity of notation, sometimes we will write 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 is a collection of polynomials in variables over a finite field . An execution trace for is an array of elements of , with rows, each of width . In order for the trace to be valid, it is required that, when we substitute into any the elements of any two consecutive rows of , the result equals zero:
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 for the length- vector whose -th entry is applied to rows and of : (Rows wrap around, so row is the same as row .)
A relaxed AIR instance is satisfied by a trace (i.e. an -by- array of elements of ), vectors , and a scalar , if for each and .
We'll write for the vector whose -th entry is
Since is a polynomial in variables, the construction at the top of the page defines polynomials in variables. We'll write for the vector whose -th entry is
A relaxed AIR instance consists of slack vectors and a scalar . A witness for such an instance is an -by- matrix of field elements such that for all .
Clearly, any AIR instance can be promoted to a relaxed AIR instance by setting and . 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 consists of polynomials , randomness (to be used by the commitment scheme) a commitment to a slack vector, a scalar , and a commitment to an -by- matrix of scalars. A witness to the committed relaxed AIR instance is a tuple of
a slack vector and
an -by- matrix ,
such that , , and .
The Folding Scheme
We'll describe a folding scheme for relaxed AIR instances. Suppose a prover and a verifier have an AIR , i.e. they both know the collection of polynomials . The prover is given two relaxed AIR instances and . The verifier knows only the scalars and .
Let be the degree of the polynomial , and let be as defined above.
The prover and the verifier carry out the following protocol.
Protocol 1
computes commitments for and their openings (meaning that for all , holds) and sends them to .
For each constraint polynomial , and each degree , also computes the cross term (a vector of length ). computes commitments and openings for and sends them to .
samples a random folding challenge, and sends to .
computes and, for each , These values and give a folded relaxed AIR witness.
Both and compute and, for each ,
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 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 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 and .
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 and see what response it gives to each.
Let be the largest of the 's, so that all the constraint polynomials have degree at most . Suppose we are given two committed relaxed AIR instances and (for the same AIR ). We are also given transcripts of the prover-verifier interaction, with different values of , say .
Each transcript contains the same commitments . Furthermore, each transcript gives witnesses , , and that satisfy the relaxed AIR condition:
Furthermore, these witnesses are consistent with the commitments , in that and
From this, the extractor needs to extract satisfying witnesses to the original relaxed AIR. As in Nova, the extractor works by interpolation.
By linear interpolation, the extractor can find and such that for . Since the commitment scheme is linear, the the extractor finds will satisfy , and similarly for . Therefore, for every we have so by the binding property of commitment, we have (with high probability) that for all .
Similarly, we'll recover and by Lagrange interpolation. Recall that the coefficients of any degree- polynomial in one variable can be recovered from the value of the polynomial at distinct points. (This is purely a question of linear algebra, so the extractor can do it efficiently.) We are looking for and such that Well, this is simply an interpolation problem for a polynomial of degree in the variable ; the unknowns and play the role of coefficients. Thus, for each , we can find and by Lagrange interpolation on the first values .
We know that so by linearity of commitment and linearity of Lagrange interpolation, , , and – in other words, the values that the extractor finds are consistent with the given commitments.
Just like with above, the hiding property of the commitment scheme then guarantees that (with all but negligible probability) we have for all .
Finally, we need to show that and are satisfying witnesses for the original AIR. To this end, consider the equality
This is an equality of polynomials of degree in that is known to hold for values of . Therefore, the equality holds for all . In particular, it holds for , so
On the other hand, since is homogenous of degree , we see that holds for values of , namely . Therefore, this equality holds for all , in particular for , so
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:
commits to , , ,
sends challenges and for the grand product
computes grand products and , depending on and
Then the folding happens. To fold the instance into :
commits to cross-terms
sends a challenge
updates the folded instance .
In the proof of knowledge soundness above, the extractor rewinds to just before sends the challenge . The earlier challenges and remain untouched. The conclusion is that the prover knows a witness that satisfies the seven polynomial relations .
A separate argument (knowledge soundness for Halo2 lookups) shows that in fact the prover knows and 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 , of degree 2, having a specific form. Because the polynomial is of degree , there is only a single cross-term . 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.