You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

270 lines
14 KiB

  1. \documentclass{article}
  2. \usepackage[utf8]{inputenc}
  3. \usepackage{amsfonts}
  4. \usepackage{amsthm}
  5. \usepackage{amsmath}
  6. \usepackage{mathtools}
  7. \usepackage{enumerate}
  8. \usepackage{hyperref}
  9. \usepackage{xcolor}
  10. \usepackage{pgf-umlsd} % diagrams
  11. \usepackage{centernot}
  12. % prevent warnings of underfull \hbox:
  13. \usepackage{etoolbox}
  14. \apptocmd{\sloppy}{\hbadness 4000\relax}{}{}
  15. \theoremstyle{definition}
  16. \newtheorem{definition}{Def}[section]
  17. \newtheorem{theorem}[definition]{Thm}
  18. % custom lemma environment to set custom numbers
  19. \newtheorem{innerlemma}{Lemma}
  20. \newenvironment{lemma}[1]
  21. {\renewcommand\theinnerlemma{#1}\innerlemma}
  22. {\endinnerlemma}
  23. \title{Notes on Spartan}
  24. \author{arnaucube}
  25. \date{April 2023}
  26. \begin{document}
  27. \maketitle
  28. \begin{abstract}
  29. Notes taken while reading about Spartan \cite{cryptoeprint:2019/550}.
  30. Usually while reading papers I take handwritten notes, this document contains some of them re-written to $LaTeX$.
  31. The notes are not complete, don't include all the steps neither all the proofs.
  32. \end{abstract}
  33. \tableofcontents
  34. \section{R1CS into Sum-Check protocol}
  35. \begin{definition}{R1CS}
  36. $\exists w \in \mathbb{F}^{m - |io| - 1}$ such that $(A \cdot z) \circ (B \cdot z) = (C \cdot z)$, where $z=(io, 1, w)$.
  37. \end{definition}
  38. \textbf{Thm 4.1} $\forall$ R1CS instance $x = (\mathbb{F}, A, B, C, io, m, n)$, $\exists$ a degree-3 log m-variate polynomial $G$ such that $\sum_{x \in \{0,1\}^{log m}} G(x) = 0$ iff $\exists$ a witness $w$ such that $Sat_{R1CS}(x, w)=1$.
  39. % \begin{theorem}{4.1} // TODO use theorem gadget
  40. % $\forall$
  41. % \begin{end}
  42. \vspace{0.5cm}
  43. % For a RCS instance $x$, let $s = \lceil \log m \rceil$.
  44. We can view matrices $A, B, C \in \mathbb{F}^{m \times m}$ as functions $\{0,1\}^s \times \{0,1\}^s \rightarrow \mathbb{F}$ ($s= \lceil \log m \rceil$).
  45. For a given witness $w$ to $x$, let $z=(io, 1, w)$.
  46. View $z$ as a function $\{0,1\}^s \rightarrow \mathbb{F}$, so any entry in $z$ can be accessed with a $s$-bit identifier.
  47. \begin{small}
  48. $$
  49. F_{io}(x)=\left( \sum_{y \in \{0,1\}^s} A(x, y) \cdot Z(y) \right) \cdot \left( \sum_{y \in \{0,1\}^s} B(x, y) \cdot Z(y) \right) - \sum_{y \in \{0,1\}^s} C(x, y) \cdot Z(y)
  50. $$
  51. \end{small}
  52. \begin{lemma}{4.1}
  53. $\forall x \in \{0,1\}^s,~ F_{io}(x)=0$ iff $Sat_{R1CS}(x,w)=1$.
  54. \end{lemma}
  55. $F_{io}(\cdot)$ is a function, not a polynomial, so it can not be used in the Sum-check protocol.
  56. $F_{io}(x)$ function is converted to a polynomial by using its polynomial extension $\widetilde{F}_{io}(x): \mathbb{F}^s \rightarrow \mathbb{F}$,
  57. \begin{small}
  58. $$
  59. \widetilde{F}_{io}(x)=\left( \sum_{y \in \{0,1\}^s} \widetilde{A}(x, y) \cdot \widetilde{Z}(y) \right) \cdot \left( \sum_{y \in \{0,1\}^s} \widetilde{B}(x, y) \cdot \widetilde{Z}(y) \right) - \sum_{y \in \{0,1\}^s} \widetilde{C}(x, y) \cdot \widetilde{Z}(y)
  60. $$
  61. \end{small}
  62. \begin{lemma}{4.2}
  63. $\forall x \in \{0,1\}^s,~ \widetilde{F}_{io}(x)=0$ iff $Sat_{R1CS}(x, w)=1$.
  64. \end{lemma}
  65. (proof: $\forall x \in \{0,1\}^s,~ \widetilde{F}_{io}(x)=F_{io}(x)$, so, result follows from Lemma 4.1.) % TODO link to lemma
  66. \vspace{0.5cm}
  67. So, for this, V will need to check that $\widetilde{F}_{io}$ vanishes over the boolean hypercube ($\widetilde{F}_{io}(x)=0 ~\forall x \in \{0,1\}^s$).
  68. Recall that $\widetilde{F}_{io}(\cdot)$ is a low-degree multivariate polynomial over $\mathbb{F}$ in $s$ variables.
  69. Thus, checking that $\widetilde{F}_{io}$ vanishes over the boolean hypercube is equivalent to checking that $\widetilde{F}_io=0$.
  70. Thus, V can check $\sum_{x \in \{0,1\}^s} \widetilde{F}_{io}(x)=0$ using the Sum-check protocol (through SZ lemma, V can check if for a random value it equals to 0, and be convinced that applies to all the points whp.).
  71. But: as $\widetilde{F}_{io}(x)$ is not multilinear, so $\sum_{x\in \{0,1\}^s} \widetilde{F}_{io}(x)=0 \centernot\Longleftrightarrow F_{io}(x)=0 ~\forall x \in \{0,1\}^s$.
  72. Bcs: the $2^s$ terms in the sum might cancel each other even when the individual terms are not zero.
  73. Solution: combine $\widetilde{F}_{io}(x)$ with $\widetilde{eq}(t, x)$ to get $Q_{io}(t, x)$ which will be the unique multilinear polynomial, and then check that it is a zero-polynomial
  74. $$Q_{io}(t)= \sum_{x \in \{0,1\}^s} \widetilde{F}_{io}(x) \cdot \widetilde{eq}(t, x)$$
  75. where $\widetilde{eq}(t, x) = \prod_{i=1}^s (t_i \cdot x_i + (1- t_i) \cdot (1- x_i))$, which is the MLE of $eq(x,e)= \{ 1 ~\text{if}~ x=e,~ 0 ~\text{otherwise} \}$.
  76. Basically $Q_{io}(\cdot)$ is a multivariate (the unique multilinear) polynomial such that
  77. $$Q_{io}(t) = \widetilde{F}_{io}(t) ~\forall t \in \{0,1\}^s$$
  78. thus, $Q_{io}(\cdot)$ is a zero-polynomial iff $\widetilde{F}_{io}(x)=0 ~\forall x\in \{0,1\}^s$.
  79. $\Longleftrightarrow$ iff $\widetilde{F}_{io}(\cdot)$ encodes a witness $w$ such that $Sat_{R1CS}(x, w)=1$.
  80. $\widetilde{F}_{io}(x)$ has degree 2 in each variable, and $\widetilde{eq}(t, x)$ has degree 1 in each variable, so $Q_{io}(t)$ has degree 3 in each variable.
  81. To check that $Q_{io}(\cdot)$ is a zero-polynomial: check $Q_{io}(\tau)=0,~ \tau \in^R \mathbb{F}^s$ (Schwartz-Zippel-DeMillo–Lipton lemma) through the sum-check protocol.
  82. This would mean that the R1CS instance is satisfied.
  83. \paragraph{Recap}
  84. \begin{itemize}
  85. \item[] We have that $Sat_{R1CS}(x,w)=1$ iff $F_{io}(x)=0$.
  86. \item[] To be able to use sum-check, we use its polynomial extension $\widetilde{F}_{io}(x)$, using sum-check to prove that $\widetilde{F}_{io}(x) =0 ~\forall x \in \{0, 1\}^s$, which means that $Sat_{R1CS}(x,~w)=1$.
  87. \item[] To prevent potential canceling terms, we combine $\widetilde{F}_{io}(x)$ with $\widetilde{eq}(t, x)$, obtaining $G_{io, \tau}(x)= \widetilde{F}_{io}(x) \cdot \widetilde{eq}(t, x)$.
  88. \item[] Thus $Q_{io}(t)= \sum_{x \in \{0,1\}^s} \widetilde{F}_{io}(x) \cdot \widetilde{eq}(t, x)$, and then we prove that $Q_{io}(\tau)=0$, for $\tau \in^R \mathbb{F}^s$.
  89. \end{itemize}
  90. \section{NIZKs with succinct proofs for R1CS}
  91. From Thm 4.1: to check R1CS instance $(\mathbb{F}, A, B, C, io, m, n)$ V can check if
  92. $\sum_{x \in \{0,1\}^s} G_{io, \tau} (x) = 0$, which through sum-check protocol can be reduced to $e_x = G_{io, \tau} (r_x)$, where $r_x \in \mathbb{F}^s$.
  93. Recall: $G_{io, \tau}(x) = \widetilde{F}_{io}(x) \cdot \widetilde{eq}(\tau, x)$.
  94. Evaluating $\widetilde{eq}(\tau, r_x)$ takes $O(log~m)$, but to evaluate $\widetilde{F}_{io}(r_x)$, V needs to evaluate
  95. $$\widetilde{A}(r_x, y), \widetilde{B}(r_x, y), \widetilde{C}(r_x, y), \widetilde{Z}(y),~ \forall y \in \{0,1\}^s$$
  96. which requires 3 sum-check instances (\begin{scriptsize}
  97. $\left( \sum_{y \in \{0,1\}^s} \widetilde{A}(x, y) \cdot \widetilde{Z}(y) \right)$,\\ $\left( \sum_{y \in \{0,1\}^s} \widetilde{B}(x, y) \cdot \widetilde{Z}(y) \right)$, $\left( \sum_{y \in \{0,1\}^s} \widetilde{C}(x, y) \cdot \widetilde{Z}(y) \right)$
  98. \end{scriptsize}), one for each summation in\\ $\widetilde{F}_{io}(x)$.
  99. But note that evaluations of $\widetilde{Z}(y) ~\forall y \in \{0,1\}^s$ are already known as $(io, 1, w)$.
  100. Solution: combination of 3 protocols:
  101. \begin{itemize}
  102. \item Sum-check protocol
  103. \item randomized mini protocol
  104. \item polynomial commitment scheme
  105. \end{itemize}
  106. Basically to do a random linear combination of the 3 summations to end up doing just a single sum-check.
  107. Observation: let $\widetilde{F}_{io}(r_x) = \overline{A}(r_x) \cdot \overline{B}(r_x) - \overline{C}(r_x)$, where
  108. $$\overline{A}(r_x) = \sum_{y \in \{0,1\}} \widetilde{A}(r_x, y) \cdot \widetilde{Z}(y),~~\overline{B}(r_x) = \sum_{y \in \{0,1\}} \widetilde{B}(r_x, y) \cdot \widetilde{Z}(y)$$
  109. $$\overline{C}(r_x) = \sum_{y \in \{0,1\}} \widetilde{C}(r_x, y) \cdot \widetilde{Z}(y)$$
  110. Prover makes 3 separate claims: $\overline{A}(r_x)=v_A,~ \overline{B}(r_x)=v_B,~ \overline{C}(r_x)=v_C$,
  111. then V evaluates:
  112. $$G_{io, \tau}(r_x) = (v_A \cdot v_B - v_C) \cdot \widetilde{eq}(r_x, \tau)$$
  113. \begin{footnotesize}
  114. which equals to
  115. $$=\left(\overline{A}(r_x) \cdot \overline{B}(r_x) - \overline{C}(r_x)\right) \cdot \widetilde{eq}(r_x, \tau)=$$
  116. $$\left(\left(\sum_{y \in \{0,1\}} \widetilde{A}(r_x, y) \cdot \widetilde{Z}(y)\right) \cdot \left(\sum_{y \in \{0,1\}} \widetilde{B}(r_x, y) \cdot \widetilde{Z}(y)\right) - \sum_{y \in \{0,1\}} \widetilde{C}(r_x, y) \cdot \widetilde{Z}(y)\right) \cdot \widetilde{eq}(r_x, \tau)$$
  117. \end{footnotesize}
  118. \vspace{0.5cm}
  119. This would be 3 sum-check protocol instances (3 claims: $\overline{A}(r_x)=v_A$, $\overline{B}(r_x)=v_B$, $\overline{C}(r_x)=v_C$).
  120. Instead, combine 3 claims into a single claim:
  121. \begin{itemize}
  122. \item V samples $r_A, r_B, r_C \in^R \mathbb{F}$, and computes $c= r_A v_A + r_B v_B + r_C v_C$.
  123. \item V, P use sum-check protocol to check:
  124. $$r_A \cdot \overline{A}(r_x) + r_B \cdot \overline{B}(r_x) + r_C \cdot \overline{C}(r_x) == c$$
  125. % Let $L(r_x) = r_A \cdot \overline{A}(r_x) +r_B \cdot \overline{B}(r_x) +r_C \cdot \overline{C}(r_x)$,
  126. Let
  127. \begin{small}
  128. \begin{align*}
  129. &L(r_x) = r_A \cdot \overline{A}(r_x) +r_B \cdot \overline{B}(r_x) +r_C \cdot \overline{C}(r_x)\\
  130. &= \sum_{y \in \{0,1\}^s}
  131. \left( r_A \cdot \widetilde{A}(r_x, y) \cdot \widetilde{Z}(y)
  132. + r_B \cdot \widetilde{B}(r_x, y) \cdot \widetilde{Z}(y)
  133. + r_C \cdot \widetilde{C}(r_x, y) \cdot \widetilde{Z}(y) \right)\\
  134. &= \sum_{y \in \{0,1\}^s} M_{r_x}(y)
  135. \end{align*}
  136. \end{small}
  137. $M_{r_x}(y)$ is a s-variate polynomial with deg $\leq 2$ in each variable ($\Longleftrightarrow \mu = s,~ l=2,~ T=c$).
  138. \end{itemize}
  139. \begin{align*}
  140. M_{r_x}(r_y) &=
  141. r_A \cdot \widetilde{A}(r_x, r_y) \cdot \widetilde{Z}(r_y)
  142. + r_B \cdot \widetilde{B}(r_x, r_y) \cdot \widetilde{Z}(r_y)
  143. + r_C \cdot \widetilde{C}(r_x, r_y) \cdot \widetilde{Z}(r_y)\\
  144. &=
  145. (r_A \cdot \widetilde{A}(r_x, r_y)
  146. + r_B \cdot \widetilde{B}(r_x, r_y)
  147. + r_C \cdot \widetilde{C}(r_x, r_y)) \cdot \widetilde{Z}(r_y)\\
  148. \end{align*}
  149. only one term in $M_{r_x}(r_y)$ depends on prover's witness: $\widetilde{Z}(r_y)$, the other terms can be computed locally by V in $O(n)$ time (Section 6 of the paper for sub-linear in $n$).
  150. Instead of evaluating $\widetilde{Z}(r_y)$ in $O(|w|)$ communications, P sends a commitment to $\widetilde{w}(\cdot)$ (= MLE of the witness $w$) to V before the first instance of the sum-check protocol.
  151. \paragraph{Recap}
  152. \begin{itemize}
  153. \item[] To check the R1CS instance, V can check $\sum_{x \in \{0,1\}^s} G_{io, \tau} (x) = 0$, which through the sum-check is reduced to $e_x = G_{io, \tau} (r_x)$, for $r_x \in \mathbb{F}^s$.
  154. \item[] Evaluating $G_{io, \tau}(x)$ ($G_{io, \tau}(x) = \widetilde{F}_{io}(x) \cdot \widetilde{eq}(\tau, x)$) is not cheap. Evaluating $\widetilde{eq}(\tau, r_x)$ takes $O(log~m)$, but to evaluate $\widetilde{F}_{io}(r_x)$, V needs to evaluate $\widetilde{A}, \widetilde{B}, \widetilde{C}, \widetilde{Z},~ \forall y \in \{0,1\}^s$
  155. % \item[] Solution: combine 3 protocols: sum-check protocol, randomized mini protocol, polynomial commitment scheme.
  156. \item[] P makes 3 separate claims: $\overline{A}(r_x)=v_A,~ \overline{B}(r_x)=v_B,~ \overline{C}(r_x)=v_C$, so V can evaluate $G_{io, \tau}(r_x) = (v_A \cdot v_B - v_C) \cdot \widetilde{eq}(r_x, \tau)$
  157. \item[] The previous claims are combined into a single claim (random linear combination) to use only a single sum-check protocol:
  158. \begin{itemize}
  159. \item[] P: $c= r_A v_A + r_B v_B + r_C v_C$, for $r_A, r_B, r_C \in^R \mathbb{F}$
  160. \item[] V, P: sum-check $r_A \cdot \overline{A}(r_x) + r_B \cdot \overline{B}(r_x) + r_C \cdot \overline{C}(r_x) == c$
  161. \end{itemize}
  162. \item[] $c=L(r_x)=\sum_{y \in \{0,1\}^s} M_{r_x}(y)$, where $M_{r_x}(y)$ is a s-variate polynomial with deg $\leq 2$ in each variable ($\Longleftrightarrow \mu = s,~ l=2,~ T=c$). Only $\widetilde{Z}(r_y)$ depends on P's witness, the other terms can be computed locally by V.
  163. \item[] Instead of evaluating $\widetilde{Z}(r_y)$ in $O(|w|)$ communications, P uses a commitment to $\widetilde{w}(\cdot)$ (= MLE of the witness $w$).
  164. \end{itemize}
  165. \subsection{Full protocol}
  166. \begin{footnotesize}
  167. (Recall: Sum-Check params: $\mu$: n vars, n rounds, $l$: degree in each variable upper bound, $T$: claimed result.)
  168. \end{footnotesize}
  169. \begin{itemize}
  170. \item $pp \leftarrow Setup(1^{\lambda})$: invoke $pp \leftarrow PC.Setup(1^{\lambda}, log m)$; output $pp$
  171. \item $b \leftarrow <P(w), V(r)>(\mathbb{F}, A,B,C, io, m, n)$:
  172. \begin{enumerate}
  173. \item P: $(C, S) \leftarrow PC.Commit(pp, \widetilde{w})$ and send $C$ to V
  174. \item V: send $\tau \in^R \mathbb{F}^{log~m}$ to P
  175. \item let $T_1=0,~ \mu_1=log~m,~ l_1=3$
  176. \item V: set $r_x \in^R \mathbb{F}^{\mu_1}$
  177. \item Sum-check 1. $e_x \leftarrow <P_{SC}(G_{io,\tau}), V_{SC}(r_x)>(\mu_1, l_1, T_1)$
  178. \item P: compute $v_A=\overline{A}(r_x),~ v_B=\overline{B}(r_x),~ v_C=\overline{C}(r_x)$, send $(v_A, v_B, v_C)$ to V
  179. \item V: abort with $b=0$ if $e_x \neq (v_A \cdot v_B - v_C)\cdot \widetilde{eq}(r_x, \tau)$
  180. \item V: send $r_A, r_B, r_C \in^R \mathbb{F}$ to P
  181. \item let $T_2 = r_A \cdot v_A + r_B \cdot v_B + r_C \cdot v_C,~ \mu_2=log~m,~ l_2=2$
  182. \item V: set $r_y \in^R \mathbb{F}^{\mu_2}$
  183. \item Sum-check 2. $e_y \leftarrow <P_{SC}(M_{r_x}), V_{SC}(r_y)>(\mu_2, l_2, T_2)$
  184. \item P: $v \leftarrow \widetilde{w}(r_y[1..])$, send $v$ to V
  185. \item $b_e \leftarrow <P_{PC.Eval}(\widetilde{w}, S), V_{PC.Eval}(r)>(pp, C, r_y, v, \mu_2)$
  186. \item V: abort with $b=0$ if $b_e==0$
  187. \item V: $v_z \leftarrow (1 - r_y[0]) \cdot \widetilde{w}(r_y [1..]) + r_y[0] \widetilde{(io, 1)} (r_y[1..])$
  188. \item V: $v_1 \leftarrow \widetilde{A}(r_x, r_y),~ v_2 \leftarrow \widetilde{B}(r_x, r_y),~ v_3 \leftarrow \widetilde{C}(r_x, r_y)$
  189. \item V: abort with $b=0$ if $e_y \neq (r_A v_1 + r_B v_2 + r_C v_3) \cdot v_z$
  190. \item V: output $b=1$
  191. \end{enumerate}
  192. \end{itemize}
  193. Section 6 of the paper, describes how in step 16, instead of evaluating $\widetilde{A},~\widetilde{B},~\widetilde{C}$ at $r_x,~r_y$ with $O(n)$ costs, P commits to $\widetilde{A},~\widetilde{B},~\widetilde{C}$ and later provides proofs of openings.
  194. In a practical implementation those commits to $\widetilde{A},~\widetilde{B},~\widetilde{C}$ could be done in a preprocessing step.
  195. \vspace{1cm}
  196. \framebox{WIP: covered until sec.6}
  197. \bibliography{paper-notes.bib}
  198. \bibliographystyle{unsrt}
  199. \end{document}