Appearance
Selectors and Interpolation
A trivial way for the verifier to check if the constraints on the circuit hold would be to get copies of
If this was possible, then the processor
This polynomial has the property that for all indexes
Additionally, the validator needs to check that:
is zero for
Selectors
In order to simplify those checks, PLONK introduces the so-called selector columns (and their respective polynomials as follows). Consider three boolean vectors
This polynomial should now be 0 for all
Wiring constraints
Moreover, we could also encode the missing constraints as follows:
These two should also be zero at all but the last two indexes,
which should hold for
So by encoding the vectors
Although mathematically the Fibonacci function is defined over the naturals
Exercise 3
Represent the vectors
This prime number is the order of the bn254 elliptic curve, which will be useful in the following. To interpolate the polynomials use Lagrange interpolation as follows. Given a set of points
python
def interpolate(I, Y):
"""
Given two lists I and Y of the same length n:
I = [x1, x2, ..., x_n]
Y = [y1, y2, ..., y_n]
where all x_i are distinct, return the Lagrange interpolation polynomial f(x)
such that f(x_i) = y_i for each i.
"""
#Solve here!
return f
p = 21888242871839275222246405745257275088548364400416034343698204186575808495617
F = GF(p)
R.<x> = PolynomialRing(F, 'x')
SL= {1:1,2:1,3:1,4:0} #Similar as before, we use dictionaries to map 1..4 to selectors for each gate
SR=
SM=
qL = interpolate(I,list(SL.values())) #We interpolate over indexes i in I and the images SL[i]
qR =
qM =
a =
b =
c =
If computed correctly you should be able to check the following properties on the polynomials:
- They are all polynomials of degree 3 over
- When evaluated over the indexes
you get the expected values as defined by . - When defining
you get 0 over the indexes .
For example, the first polynomial is:
python
#Is a(x) correctly interpolated?
for i in I:
assert (a(i) == LI[i])
#Is b(x) correctly interpolated?
for i in I:
assert b(i) == RI[i]
#Is c(x) correctly interpolated?
for i in I:
assert (c(i) == O[i])
t = qM*a*b + qL*a+qR*b-c
#Do gate constraints hold?
for i in I:
assert (t(i) == 0)
At this point we can also check the recursive constraints.
python
#Constraint f1
f1 = a(x+1)-b(x)
for i in I:
if (i !=3) and (i != 4):
assert f1(i) == 0
#Constraint f1
f2 = b(x+1)-c(x)
for i in I:
if (i !=3) and (i != 4):
assert f2(i) == 0