R1CS
Last updated
Last updated
The Rank 1 Constraint System (R1CS) is one of the common arithmetization techniques used today. In short, it uses 3 matrices to constrain two inputs to the gate and 1 output of the gate.
If the equation above is valid for a given constraint matrices, we consider a valid witness (also known as trace).
So how do we get these constraint matrices for a target computation? For the sake of simplicity, let's say we want to prove that we know a solution to .
First we convert our program into simple statements which typically look like or . So can be flattened to:
In this step we convert the equations above into an R1CS matrix representation. At each row of R1CS matrices, we have 3 row vectors which we multiply with column vector . This solution vector should satisfy
This gives us the R1CS matrix representation:
Each vector's length is equal to the number of variables in our program plus 1 for constant 1. So in the case above, we have so we need vectors of size 6. We need the extra constant or identity multiplier to deal with situations involving addition in our scheme as well as to add constants. So in total for our case above we have:
The reason for having three vectors is due to the nature of the constraints R1CS is designed to represent. Remember, in circuit computation, we have conceptual gates. These gates have a left input, a right input, and one output. So, basically, the vector represents the left input, the vector represents the right input, and the vector represents the output.
To express , what we need to say is input 1 and input 2 is and result is
Similarly, to express :
For , we have:
And for , we have:
So by knowing , you prove that you know the solution since it satisfies all the constraints.
Written by from