Define a decision function such that the associated language
$L_{Exercise_1}$ consists of all solutions to the equation$5x + 4 = 28 + 2x$ over$\mathbb{F}_{13}$ .Provide a constructive proof for the claim: "There exists a word in
$L_{Exercise_1}$ " and verify the proof.
The decision function can be written as follows:
We can find the solution
- Moving
$x$ to left-side and others to the right:$3x = 24$ - Taking modulo 13 to get:
$3x = 11$ - Inverse of
$3$ is$9$ in this field, so we have$x = 11 * 9$ which is$x = 8$ in mod 13.
So, the string
Consider modular 6 arithmetic
$(\mathbb{Z}_6)$ , the alphabet$\Sigma = \mathbb{Z}_6$ and the following decision function:
$$ R_{example_{11}} : \Sigma^\ast \to {true, false} ; $$
$$ \langle x_1, \ldots, x_n \rangle \mapsto \begin{cases} true & n = 1 \text{ and } 3x_1 + 3 = 0 \\ false & else \end{cases} $$ Compute all words in the associated language
$L_{example_{11}}$ , provide a constructive proof for the statement "There exist a word in$L_{example_{11}}$ " and verify the proof.
Looking at words with
Consider modular 6 arithmetic
$(\mathbb{Z}_6)$ , the alphabets$\Sigma_I$ and$\Sigma_W$ and the following decision function:
$$ R_{linear} : \Sigma^\ast \times \Sigma^\ast \to {true, false} ; $$
$$ (i; w) \mapsto \begin{cases} true & |i| = 3 \text{ and } |w| = 1 \text{ and } i_1 \cdot w_1 + i_2 = i_3 \\ false & else \end{cases} $$ Which of the following instances has a proof of knowledge in
$R_{linear}$ ?
$(3, 3, 0)$ $(2, 1, 0)$ $(4, 4, 2)$
- Witness is
$1$ for$(3, 3, 0)$ , - Witness is
$1$ for$(4, 4, 2)$ , - There is no witness for
$(2, 1, 0)$ , as we cant find a$w$ that makes the equation hold.
Consider the TinyJubJub curve together with its twisted Edwards addition law. Define an instance alphabet
$\Sigma_I$ , a witness alphabet$\Sigma_W$ and a decision function$R_{add}$ with associated language$L_{add}$ such that a string$(i;w) \in \Sigma_I^\ast \times \Sigma_W^\ast$ is a word in$L_{add}$ if and only if$i$ is a pair of curve points on the TinyJubJub curve in Edwards form, and$w$ is the sum of those curve points.With that, give example of an instance with a proof, and another example with an instance with no proof.
Twisted Edwards addition law for TinyJubJub is the following
for
Both alphabets are thus field elements:
$\Sigma_I = \mathbb{F}_{13}$ $\Sigma_W = \mathbb{F}_{13}$
Perhaps we could set our alphabet to equal a pair of field elements, that is
To make things easier, we will also re-use
With that, our grammar
$$ R_{add} : (\mathbb{F}{13})^\ast \times (\mathbb{F}{13})^\ast \to {true, false} ; $$
$$ (i ; w) \mapsto \begin{cases} true & &(\langle i_1, i_2 \rangle) \in L_{tiny-jj} \ & \text{ and } &(\langle i_3, i_4 \rangle) \in L_{tiny-jj} \ & \text{ and } &(w_1, w_2) = \left( \frac {i_1i_4 + i_2i_3} {1 + 8i_1i_3i_2i_4} , \frac {i_2i_4 - 3i_1i_3} {1 - 8i_1i_3i_2i_4} \right) \
false & else \end{cases} $$
The language
To provide an instance with knowledge proof, we can just pick two points in the curve and sum them as the witness. To provide an instance with no proof, we can let one of the points to be outside the curve and that would suffice.
Consider the language
$L_{add}$ from exercise 99. Define an R1CS such that words in$L_{add}$ are in 1:1 correspondance with solutions to this R1CS.
What we need is an R1CS for the following computation:
where the result is denoted as
We define the intermediate variables (which are also witnesses) and the constraints for the two equations above as follows:
With this, we have an R1CS with
Let's work with the matrices now.
Our first matrix
Our second matrix
Our third matrix
Define an R1CS
Consider the circuit $C_{tiny-jj}(\mathbb{F}{13})$ with it's associated language $L{tiny-jj}$. Construct a proof
$\pi$ for the instance$\langle 11, 6 \rangle$ and verify the proof.
The said circuit outputs 0 when the given point coordinates
To be more precise, the circuit calculates the following expression which is just a re-arrangment of the above equation such that one side is equal to 0:
Here is the circuit using MermaidJS:
flowchart TD
%% inputs & constants
x
y
10
12
1
8
%% gates
m1((*))
m2((*))
m3((*))
m4((*))
m5((*))
m6((*))
a1((+))
a2((+))
a3((+))
%% wirings
10 --> m1
m2 --S_3--> m1
x --S_1--> m2
x --S_1--> m2
y --S_2--> m3
y --S_2--> m3
12 --> m4
m3 --S_4--> m4
m2 --S_3--> m5
m3 --S_4--> m5
m1 --> a1
1 --> a1
8 --> m6
m5 --S_5--> m6
a1 --> a2
m6 --> a2
a2 --> a3
m4 --> a3
a3 --S6--> f_tiny-jj
The proof will be to find the correct values for wire labels given the inputs
flowchart TD
%% inputs & constants
x[11]
y[6]
10
12
1
8
%% gates
m1((*))
m2((*))
m3((*))
m4((*))
m5((*))
m6((*))
a1((+))
a2((+))
a3((+))
%% wirings
10 --10--> m1
m2 --"S_3 = 4"--> m1
x --"S_1 = 11"--> m2
x --"S_1 = 11"--> m2
y --"S_2 = 6"--> m3
y --"S_2 = 6"--> m3
12 --12--> m4
m3 --"S_4 = 10"--> m4
m2 --"S_3 = 4"--> m5
m3 --"S_4 = 10"--> m5
m1 --1--> a1
1 --1--> a1
8 --8--> m6
m5 --"S_5 = 1"--> m6
a1 --2--> a2
m6 --8--> a2
a2 --10--> a3
m4 --3--> a3
a3 --"S6 = 0"--> f_tiny-jj
Indeed, we got the output to be 0 and we have a valid set of assignments to prove it! Our proof
Consider the R1CS for points on the TinyJubJub curve. Compute an associated QAP for this R1CS and check your results with Sage.
We can define the qap
function as:
from sage.all import GF
def qap(r1cs, p: int):
"""
Given a R1CS and a prime, returns the QAP (Quadratic Arithmetic Program).
"""
# k := number of constraints
k = len(r1cs[0])
assert k < p
# make sure lengths are alright
cnt = len(r1cs[0][0])
for term in range(3):
# each term must have k constraints
# and each constraint must have same amount of terms
for cons in range(k):
assert cnt == len(r1cs[term][cons])
# polynomial over GF(p)
Fp = GF(p)
Fpx = Fp["x"]
# pick k random elements, unique & invertible
elems = []
for _ in range(k):
rand_elem = Fp.random_element()
if rand_elem not in elems:
elems.append(rand_elem)
# compute the target polynomial
target = Fpx(1)
for e in elems:
target *= Fpx([-e, 1]) # x - e
# compute the lagrange polynomials
polys = ([], [], [])
for term in range(3):
for c in range(cnt):
points = [(elems[cons], r1cs[term][cons][c]) for cons in range(k)]
polys[term].append(Fpx.lagrange_polynomial(points))
return (target, polys)
We give the R1CS along with the prime associated with TinyJubJub to QAP
, and we find the following results:
# prime for finite field of tinyjubjub
p = 13
# R1CS of tiny_jj language (from the book)
r1cs_tiny_jj = (
# [c, I1, I2, W1, W2, W3]
[ # A
[0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0],
[0, 0, 0, 8, 0, 0],
[1, 0, 0, 10, 12, 1],
],
[ # B
[0, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 1, 0],
[1, 0, 0, 0, 0, 1],
],
[ # C
[0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0],
],
)
QAP = qap(r1cs_tiny_jj, p)
print("Target Polynomial")
print(QAP[0])
print("\nPolynomials (A)")
print(QAP[1][0])
print("\nPolynomials (B)")
print(QAP[1][1])
print("\nPolynomials (C)")
print(QAP[1][2])
Target Polynomial
x^4 + 6*x^3 + 7*x^2 + 2*x
Polynomials (A)
[5*x^3 + 3*x^2 + 11*x, 7*x^3 + 11*x^2 + 4*x, 7*x^3 + 9*x^2 + x, 2*x^3 + 2*x^2 + 8*x + 8, 8*x^3 + 10*x^2 + 2*x, 5*x^3 + 3*x^2 + 11*x]
Polynomials (B)
[5*x^3 + 3*x^2 + 11*x, 7*x^3 + 11*x^2 + 4*x, 7*x^3 + 9*x^2 + x, 0, 7*x^3 + 3*x^2 + 10*x + 1, 5*x^3 + 3*x^2 + 11*x]
Polynomials (C)
[0, 0, 0, 7*x^3 + 11*x^2 + 4*x, 7*x^3 + 9*x^2 + x, 7*x^3 + 3*x^2 + 10*x + 1]