tl;dr: A quadratic arithmetic program (QAP), a Rank-1 Constraint System (R1CS), and an NP relation are equivalent ways of representing a hard problem (or computation) whose solution can be verified in polynomial-time.
In particular, R1CS is just a reformulation of QAPs as linear equations and, these days, it is used widely when formalizing computations that can be “proved in zero-knowledge.”
QAPs were first introduced by Gennaro et al.[^GGPR13] in their groundbreaking result on NIZKs without PCPs.
They were later reformulated by Setty et al.[^SBVplus12e], who observed that the n polynomial equations in a QAP can be rewritten as a bunch of matrix-vector products:
Later on, Ben-Sasson et al.[^BCTV14] baptized this reformulation as R1CS.
Rank-1 Constraint Systems (R1CS)
Any NP relation R(\stmt;\witn) can (more or less [^technically]) be represented as a Rank-1 Constraint System (R1CS): a set of quadratic equations that encode the same checks done by R.
This is not exactly an easy claim to understand.
First, remember that NP relations represent the NP class of computations.
Second, remember that [arithmetic] circuit satisfiability is NP-complete.
Therefore, any NP relation has an arithmetic circuit representation.
Third, recall that arithmetic circuits can only add and multiply.
As we’ll see, R1CS systems allow one to encode a circuit’s additions and multiplications.
Now, (you will have to take my word for it, but) the computation in any NP relation can be represented as three R1CS matrices that encode n equations over m+1 variables:
m is typically called the number of (R1CS) variables.
n is typically called the number of (R1CS) constraints or equations (equal to the # of multiplications needed to compute R)
Yet another way to view R1CS is as a⊤U⊤∘a⊤V⊤=a⊤W⊤, where the matrices are transposed to be in \F(m+1)×n and the vector a⊤∈\F1×(m+1) is now a row-vector.
tl;dr: R1CS satisfiability (Eq. \refeq:r1cs−sum−eq, \refeq:r1cs−vec−eq or \refeq:r1cs−mat−eq) ⇔R(\stmt;\witn) satisfiability.
Sparsity
When “compiling” an NP relation to an R1CS of n equations and m variables, if done right, the matrices are sparse: they only have O(n) non-zero entries.
Quadratic Arithmetic Programs (QAPs)
From our R1CS discussion, we know that any NP relationR can be turned into an R1CS constraint system defined by matrices (\matU,\matV,\matW) from Eq. \refeq:r1cs−mat.
In this section, we explain how an NP relation R can be represented (or viewed) as a QAP[^GGPR13]: a set of m+1 polynomials of degree n−1 each:
(1) We are assuming the same a=1∣∣\stmt∣∣\witn∈\Fm notation from Eq. \refeq:a.
(2) Let (ω,ω2,…,ωn) denote the nth roots of unity[^rou] in the finite field \F such that the Xn−1 polynomial from Eq. \refeq:qap−modulo above can be factored as Xn−1=∏i=0n(X−ωi).
The key idea is to encode each column j∈[0,m] of the R1CS matrices \matU,\matV,\matW as polynomials \guj(X),\rvj(X),\bwj(X), respectively, such that:
Note that each polynomial \guj,\rvj,\bwj is interpolated from n points and thus has degree ≤n−1.
Typically, roots-of-unity are used as the evaluation domain since they either (1) enable quickly-interpolating each polynomial using an O(nlogn) inverse FFT or (2) make polynomial operations, such as multiplication, faster.
Now, we can rewrite our n R1CS constraint equations (from Eq. \refeq:r1cs−sum−eq) as polynomial equations:
This last equation just says that the polynomial on the left-hand side has roots at all ωi’s.
This is equivalent to saying that it is divisible by (X−ω)(X−ω2)⋯(X−ωn)=Xn−1[^xn1]:
Since a QAP is just a polynomial representation of an R1CS, a similar sparsity property holds: the number of non-zero entries interpolated by the (\guj,\rvj,\bwj)j∈[0,m) polynomials is O(n).
As a result, computing for example, ∑j=0m\guj(X)aj (in FFT basis) can be done in O(n) time.
[^GGPR13]: Quadratic Span Programs and Succinct NIZKs without PCPs, by Gennaro, Rosario and Gentry, Craig and Parno, Bryan and Raykova, Mariana, in Advances in Cryptology – EUROCRYPT 2013, 2013
[^SBVplus12e]: Resolving the conflict between generality and plausibility in verified computation, by Srinath Setty and Benjamin Braun and Victor Vu and Andrew J. Blumberg and Bryan Parno and Michael Walfish, in Cryptology {ePrint} Archive, Paper 2012/622, 2012, [URL]
[^BCTV14]: Scalable Zero Knowledge via Cycles of Elliptic Curves, by Ben-Sasson, Eli and Chiesa, Alessandro and Tromer, Eran and Virza, Madars, in CRYPTO’14, 2014
[^technically]: I am glancing over the fact that NP relations are defined over arbitrarily-sized inputs \stmt and \witn, whereas R1CS relations are defined for fixed-size \stmt and \witn. Furthermore, there may be extra witness variables added in the transformation (i.e., R(\stmt,\witn)=1 iff. ∃aux such that a=\stmt∣∣\witn∣∣aux satisfies the R1CS equations in Eq. \refeq:r1cs−mat−eq). So, there’s probably a more formal way of saying this that I do not want to get into for the sake of brevity.
[^rou]: Recall that, in order to have a primitive nth root of unity ω, it must be that n divides p−1, where p is the order of \F (and p−1 is the size of the multiplicative subgroup of \F).
[^xn1]: This follows from the fact that the nth roots of unity in \F are precisely the solutions to the equation Xn=1 over \F.