arnaucube
arnaucube/mathPublic Self-hosted repository
math/pinocchio-groth16.tex
pinocchio-groth16.texRaw
  1\documentclass{article}
  2\usepackage[utf8]{inputenc}
  3\usepackage{amsfonts}
  4\usepackage{amsthm}
  5\usepackage{amsmath}
  6\usepackage{enumerate}
  7\usepackage{hyperref}
  8\usepackage{amssymb}
  9\usepackage{tikz} % diagram
 10
 11\begin{filecontents}[overwrite]{pinocchio-groth16.bib}
 12@misc{cryptoeprint:2013/279,
 13  author = {Bryan Parno and Craig Gentry and Jon Howell and Mariana Raykova},
 14  title = {Pinocchio: Nearly Practical Verifiable Computation},
 15  howpublished = {Cryptology {ePrint} Archive, Paper 2013/279},
 16  year = {2013},
 17  url = {https://eprint.iacr.org/2013/279}
 18}
 19@misc{cryptoeprint:2016/260,
 20  author = {Jens Groth},
 21  title = {On the Size of Pairing-based Non-interactive Arguments},
 22  howpublished = {Cryptology {ePrint} Archive, Paper 2016/260},
 23  year = {2016},
 24  url = {https://eprint.iacr.org/2016/260}
 25}
 26
 27@misc{pairings,
 28  note = {\url{https://github.com/arnaucube/math/blob/master/weil-pairing.pdf}},
 29  url = {https://github.com/arnaucube/math/blob/master/weil-pairing.pdf}
 30}
 31\end{filecontents}
 32\nocite{*} % TODO review
 33
 34
 35\newtheorem{thm}{Theorem}[section]
 36\newtheorem{lemma}[thm]{Lemma}
 37\newtheorem{prop}[thm]{Proposition}
 38\newtheorem{cor}[thm]{Corollary}
 39\newtheorem{defn}[thm]{Definition}
 40
 41
 42\title{Pinocchio and Groth16 notes}
 43\author{arnaucube}
 44\date{2026}
 45
 46\begin{document}
 47
 48\maketitle
 49
 50\begin{abstract}
 51    Notes taken while studying the schemes Pinocchio (\cite{2013/279}) and Groth16 (\cite{2016/260}).
 52
 53    Usually while reading books and papers I take handwritten notes in a notebook, this document contains some of them re-written to $LaTeX$.
 54
 55    The proofs may slightly differ from the ones from the books or papers, since I try to extend them for a deeper understanding.
 56\end{abstract}
 57
 58\tableofcontents
 59\newpage
 60
 61
 62\section{Introduction}
 63
 64% TODO.
 65% what we want to prove, how it connects with R1CS & QAP
 66
 67
 68\section{R1CS}
 69% TODO Add R_{R1CS} relation definition.
 70
 71Rank-One Constraint System (R1CS) is the representation of the constraints of the circuit by 3 linear combinations, where there is one constraint per operation.
 72
 73$$
 74\begin{aligned}
 75(a_{11}w_1 + a_{12}w_2 + ... + a_{1n}w_n) \cdot (b_{11}w_1 + b_{12}w_2 + ... + b_{1n}w_n)\\- (c_{11}w_1 + c_{12}w_2 + ... + c_{1n}w_n) = 0
 76\\
 77(a_{21}w_1 + a_{22}w_2 + ... + a_{2n}w_n) \cdot (b_{21}w_1 + b_{22}w_2 + ... + b_{2n}w_n)\\- (c_{21}w_1 + c_{22}w_2 + ... + c_{2n}w_n) = 0
 78\\
 79(a_{31}w_1 + a_{32}w_2 + ... + a_{3n}w_n) \cdot (b_{31}w_1 + b_{32}w_2 + ... + b_{3n}w_n)\\- (c_{31}w_1 + c_{32}w_2 + ... + c_{3n}w_n) = 0
 80\\
 81\ldots
 82\\
 83(a_{m1}w_1 + a_{m2}w_2 + ... + a_{mn}w_n) \cdot (b_{m1}w_1 + b_{m2}w_2 + ... + b_{mn}w_n)\\- (c_{m1}w_1 + c_{m2}w_2 + ... + c_{mn}w_n) = 0
 84\end{aligned}
 85$$
 86
 87Where the R1CS linear combinations can be represented by three matrices $A$, $B$ and $C$:
 88$$
 89\begin{aligned}
 90A =
 91\begin{pmatrix}
 92a_{11} & a_{12} & ... & a_{1n}\\
 93a_{21} & a_{22} & ... & a_{2n}\\
 94a_{31} & a_{32} & ... & a_{3n}\\
 95...\\
 96a_{m1} & a_{m2} & ... & a_{mn}
 97\end{pmatrix}
 98B =
 99\begin{pmatrix}
100b_{11} & b_{12} & ... & b_{1n}\\
101b_{21} & b_{22} & ... & b_{2n}\\
102b_{31} & b_{32} & ... & b_{3n}\\
103...\\
104b_{m1} & b_{m2} & ... & b_{mn}
105\end{pmatrix}
106\\
107C =
108\begin{pmatrix}
109c_{11} & c_{12} & ... & c_{1n}\\
110c_{21} & c_{22} & ... & c_{2n}\\
111c_{31} & c_{32} & ... & c_{3n}\\
112...\\
113c_{m1} & c_{m2} & ... & c_{mn}
114\end{pmatrix}
115\end{aligned}
116$$
117
118Where
119$(A, B, C) = A w \circ B w - C w = 0$
120
121The process that converts the \emph{flat constraints} into \emph{R1CS} is the following:
122
123Lets assume that we have a constraint $5 w_3 = w_1 \cdot 2 w_2$ (being $w_1$, $w_2$ and $w_3$ the signals 1, 2 and 3 respectively)). We can represent this constraint in the matrices form by:
124
125$$
126\begin{aligned}
127A =
128\begin{pmatrix}
1291 & 0 & 0 & ... & 0\\
130\end{pmatrix}
131\\
132B =
133\begin{pmatrix}
1340 & 2 & 0 & ... & 0\\
135\end{pmatrix}
136\\
137C =
138\begin{pmatrix}
1390 & 0 & 5 & ... & 0\\
140\end{pmatrix}
141\end{aligned}
142$$
143
144
145Which in the R1CS equation form would look as:
146$$
147\begin{aligned}
148(1 \cdot w_1 + 0 \cdot w_2 + 0 \cdot w_3 + ... + 0 \cdot w_n) \cdot
149(0 \cdot w_1 + 2 \cdot w_2 + 0 \cdot w_3 + ... + 0 \cdot w_n) -\\
150(0 \cdot w_1 + 0 \cdot w_2 + 5 \cdot w_3 + ... + 0 \cdot w_n) = 0
151\end{aligned}
152$$
153
154If we simplify the previous liniar combination we get:
155$$
156\begin{aligned}
157(1 \cdot w_1) \cdot (2 \cdot w_2) - (5 \cdot w_3) = 0
158\\
159w_1 \cdot 2w_1 - 5 w_3 = 0
160\\
1615 w_3 = w_1 \cdot 2w_1
162\end{aligned}
163$$
164Where $5 w_3 = w_1 \cdot 2w_1$ is the constraint that we wanted to represent in the R1CS format.
165
166The nice thing from R1CS is that allows us to standarize the constraints in an equation fashion, where all the signals are involved and we 'activate' these ones that are used in each constraint.
167Since we have now the constraints in a polynomial format, we can do work with it in the polynomial way.
168
169
170\section{QAP (Quadratic Arithmetic Programs)} \label{qap}
171
172Once we have the constraints of a circuit represented in \emph{R1CS}, we can do one more iteration and represent it in \emph{Quadratic Arithmetic Programs (QAP)}.
173%% TODO %%
174\emph{QAP} is a representation of the XXX in a linear combination of the \emph{R1CS}, represented by 3 polynomials $a(X)$, $b(X)$ and $c(X)$.
175The \emph{QAP} consists of the 3 polynomials $a(X)$, $b(X)$ and $c(X)$, plus a divisor polynomial $h(X) \in \mathbb{F}[X]^{<d}$.
176
177The main idea behind the \emph{QAP} is that they 'contain' all the constraints of the circuit, meaning that these polynomials need to be able to generate all the constraints.
178
179In order to 'collapse' the \emph{R1CS} polynomials into the 3 polynomials of the \emph{QAP}, we make use of \emph{polynomial interpolation}, also named \emph{Lagrange interpolation}. \emph{Lagrange interpolation} allows for a group of points, to find the smallest degree and unique polynomial that goes through all those points. It can be calculated by computing:
180
181$$L(X) = \sum_{j=0}^{n} y_j l_j(X)$$
182
183where $l_j(X)$ is:
184$$
185l_j(X) = \prod_{0\leq m \leq k ; m\neq j}
186\frac{X-x_m}{x_j - x_m}
187...
188\frac{(X-x_{j-1})}{(x_j - x_{j-1})}
189\frac{(X-x_{j+1})}{(x_j - x_{j+1})}
190...
191\frac{X-x_k}{x_j - x_k}
192$$
193
194The intuition behind the \emph{Lagrange interpolation} is quite simple. If we have two points (on a 2 dimensional plane) we can find a line that goes through both points (this can be done with a pen and a ruler on a paper), if we have 3 points we can find a curved line that goes through all the three points, if we do this through math trying to get the lowest degree curve we obtain a  2nd degree polynomial. This can be generalized using the *Lagrange interpolation*, allowing us for a group of $n$ points to find a $n-1$ degree polynomial that goes through all of them.
195
196In our case, \emph{Lagrange interpolation} is used to go from the \emph{R1CS} polynomials into the \emph{QAP} polynomials, which are defined by:
197
198$$
199\begin{aligned}
200    a(X) = (\alpha_1(X)w_1 + \alpha_2(X)w_2 + ... + \alpha_n(X)w_n) = \sum_{i=1}^n \alpha_i(X) w_i\\
201    b(X) = (\beta_1(X)w_1 + \beta_2(X)w_2 + ... + \beta_n(X)w_n) = \sum_{i=1}^n \beta_i(X) w_i\\
202    c(X) = (\gamma_1(X)w_1 + \gamma_2(X)w_2 + ... + \gamma_n(X)w_n) = \sum_{i=1}^n \gamma_i(X) w_i
203\end{aligned}
204$$
205
206The polynomials $a(X), b(X), c(X)$ are the QAP, such that
207$$a(X) \cdot b(X) = c(X)$$
208so that
209$$p(X) = a(X) \cdot b(X) - c(X) = 0$$
210
211that is,
212$$
213\begin{aligned}
214p(X) = (\alpha_1(X)w_1 + \alpha_2(X)w_2 + ... + \alpha_n(X)w_n)
215\\ \cdot (\beta_1(X)w_1 + \beta_2(X)w_2 + ... + \beta_n(X)w_n)
216\\ - (\gamma_1(X)w_1 + \gamma_2(X)w_2 + ... + \gamma_n(X)w_n)
217\\
218= (\sum_{i=1}^n \alpha_i(X) w_i) \cdot (\sum_{i=1}^n \beta_i(X) w_i) - (\sum_{i=1}^n \gamma_i(X) w_i)
219\end{aligned}
220$$
221
222The main idea, is that $p(X)$ defines the constraints of our circuit, so that for a valid witness evaluated at $p(X)$, it will be equal to zero.
223
224
225
226\bibliographystyle{unsrt}
227\bibliography{pinocchio-groth16.bib}
228
229\end{document}