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.

877 lines
23 KiB

  1. # zkSNARKs from scratch, a technical explanation
  2. <br><br><br>
  3. <div style="float:right; text-align:right;">
  4. <img style="width:80px" src="imgs/arnaucube.png" /> <br>
  5. [arnaucube.com](https://arnaucube.com)
  6. [github.com/arnaucube](https://github.com/arnaucube)
  7. [twitter.com/arnaucube](https://twitter.com/arnaucube)
  8. <br>
  9. <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/"><img src="https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png" /></a>
  10. 2019-08-20
  11. </div>
  12. <img style="width:200px;" src="imgs/iden3.png" /> <br>
  13. [iden3.io](https://iden3.io)
  14. [github.com/iden3](https://github.com/iden3)
  15. [twitter.com/identhree](https://twitter.com/identhree)
  16. ---
  17. ## Warning
  18. <div style="font-size:90%;">
  19. - I'm not a mathematician, this talk is not for mathematicians
  20. - In free time, have been studying zkSNARKS & implementing it in Go
  21. - Talk about a technical explaination from an engineer point of view
  22. - The idea is to try to transmit the learnings from long night study hours during last winter
  23. - Also at the end will briefly overview how we use zkSNARKs in iden3
  24. - This slides will be combined with
  25. - parts of the code from https://github.com/arnaucube/go-snark
  26. - whiteboard draws and writtings
  27. - Don't use your own crypto. But it's fun to implement it (only for learning purposes)
  28. </div>
  29. ---
  30. ## Contents
  31. <div style="font-size: 90%;">
  32. - Introduction
  33. - zkSNARK overview
  34. - zkSNARK flow
  35. - Generating and verifying proofs
  36. - Foundations
  37. - Basics of modular arithmetic
  38. - Groups
  39. - Finite fields
  40. - Elliptic curve operations
  41. - Pairings
  42. - Bilinear Pairings
  43. - BLS signatures
  44. </div>
  45. ---
  46. <div style="font-size: 90%;">
  47. - zkSNARK (Pinocchio)
  48. - Circuit compiler
  49. - R1CS
  50. - QAP
  51. - Lagrange Interpolation
  52. - Trusted Setup
  53. - Proofs generation
  54. - Proofs verification
  55. - Groth16
  56. - How we use zkSNARKs in iden3
  57. - libraries
  58. - Circuit languages
  59. - utilities (Elliptic curve & Hash functions) inside the zkSNARK libraries
  60. - BabyJubJub
  61. - Mimc
  62. - Poseidon
  63. - References
  64. </div>
  65. ---
  66. ## Introduction
  67. - zero knowledge concept
  68. - examples
  69. - some concept explanations
  70. - https://en.wikipedia.org/wiki/Zero-knowledge_proof
  71. - https://hackernoon.com/wtf-is-zero-knowledge-proof-be5b49735f27
  72. ---
  73. ## zkSNARK overview
  74. - protocol to prove the correctness of a computation
  75. - useful for
  76. - scalability
  77. - privacy
  78. - interoperability
  79. - examples:
  80. - Alice can prove to Brenna that knows $x$ such as $f(x) = y$
  81. - Brenna can prove to Alice that knows a certain input which $Hash$ results in a certain known value
  82. - Carol can proof that is a member of an organization without revealing their identity
  83. - etc
  84. ---
  85. ### zkSNARK flow
  86. <div style="text-align:center;">
  87. <img src="imgs/zksnark-concept-flow.png"/>
  88. </div>
  89. ---
  90. ### Generating and verifying proofs
  91. Generating a proof:
  92. <img src="imgs/zksnark-prover.png"/>
  93. <img src="imgs/cat04.jpeg" style="float:right; width:300px;" />
  94. <br><br>
  95. Verifying a proof:
  96. <img src="imgs/zksnark-verifier.png"/>
  97. ---
  98. ## Foundations
  99. - Modular aritmetic
  100. - Groups
  101. - Finite fields
  102. - Elliptic Curve Cryptography
  103. ---
  104. ## Basics of modular arithmetic
  105. - Modulus, `mod`, `%`
  106. - Remainder after division of two numbers
  107. ![clocks](https://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Clock_group.svg/220px-Clock_group.svg.png "clocks")
  108. ```python
  109. 5 mod 12 = 5
  110. 14 mod 12 = 2
  111. 83 mod 10 = 3
  112. ```
  113. ```python
  114. 5 + 3 mod 6 = 8 mod 6 = 2
  115. ```
  116. ---
  117. ## Groups
  118. - a **set** with an **operation**
  119. - **operation** must be *associative*
  120. - neutral element ($identity$): adding the neutral element to any element gives the element
  121. - inverse: $e$ + $e_{inverse}$ = $identity$
  122. - cyclic groups
  123. - finite group with a generator element
  124. - any element must be writable by a multiple of the generator element
  125. - abelian group
  126. - group with *commutative* operation
  127. ---
  128. ## Finite fields
  129. - algebraic structure like Groups, but with **two operations**
  130. - extended fields concept (https://en.wikipedia.org/wiki/Field_extension)
  131. ---
  132. ## Elliptic curve
  133. - point addition
  134. $(x_1, y_1) + (x_2, y_2) =
  135. (\dfrac{
  136. x_1 y_2 + x_2 y_1
  137. }{
  138. 1 + d x_1 x_2 y_1 y_2
  139. },
  140. \dfrac{
  141. y_1 y_2 - x_1 x_2
  142. }{
  143. 1-dx_1 x_2 y_1 y_2
  144. })$
  145. - G1
  146. - G2
  147. *(whiteboard explanation)*
  148. ---
  149. ## Pairings
  150. - 3 typical types used for SNARKS:
  151. - BN (Barreto Naehrig) - used in Ethereum
  152. - BLS (Barreto Lynn Scott) - used in ZCash & Ethereum 2.0
  153. - MNT (Miyaji- Nakabayashi - Takano) - used in CodaProtocol
  154. - $y^2 = x^3 + b$ with embedding degree 12
  155. - function that maps (pairs) two points from sets `S1` and `S2` into another set `S3`
  156. - is a [bilinear](https://en.wikipedia.org/wiki/Bilinear_map) function
  157. - $e(G_1, G_2) -> G_T$
  158. - the groups must be
  159. - cyclic
  160. - same prime order ($r$)
  161. ---
  162. - $F_q$, where $q=$`21888242871839275222246405745257275088696311157297823662689037894645226208583`
  163. - $F_r$, where $r=$`21888242871839275222246405745257275088548364400416034343698204186575808495617`
  164. ---
  165. ## Bilinear Pairings
  166. $e(P_1 + P_2, Q_1) == e(P_1, Q_1) \cdot e(P_2, Q_1)$
  167. $e(P_1, Q_1 + Q_2) == e(P_1, Q_1) \cdot e(P_1, Q_2)$
  168. $e(aP, bQ) == e(P, Q)^{ab} == e(bP, aQ)$
  169. <img src="imgs/cat01.jpeg" style="float:right; width:300px;" />
  170. $e(g_1, g_2)^6 == e(g_1, 6 \cdot g_2)$
  171. $e(g_1, g_2)^6 == e(6 \cdot g_1, g_2)$
  172. $e(g_1, g_2)^6 == e(3 \cdot g_1, 2 g_2)$
  173. $e(g_1, g_2)^6 == e(2 \cdot g_1, 3 g_2)$
  174. ---
  175. ### BLS signatures
  176. *(small overview, is offtopic here, but is interesting)*
  177. - key generation
  178. - random private key $x$ in $[0, r-1]$
  179. - public key $g^x$
  180. - signature
  181. - $h=Hash(m)$ (over G2)
  182. - signature $\sigma=h^x$
  183. - verification
  184. - check that: $e(g, \sigma) == e(g^x, Hash(m))$
  185. $e(g, h^x) == e(g^x, h)$
  186. ---
  187. - aggregate signatures
  188. - $s = s0 + s1 + s2 ...$
  189. - verify aggregated signatures
  190. <div style="font-size:75%">
  191. $e(G,S) == e(P, H(m))$
  192. $e(G, s0+s1+s2...) == e(p0, H(m)) \cdot e(p1, H(m)) \cdot e(p2, H(m)) ...$
  193. </div>
  194. More info: https://crypto.stanford.edu/~dabo/pubs/papers/BLSmultisig.html
  195. ---
  196. ## Circuit compiler
  197. - not a software compiler -> a constraint prover
  198. - what this means
  199. - constraint concept
  200. - `value0` == `value1` `<operation>` `value2`
  201. - want to proof that a certain computation has been done correctly
  202. - graphic of circuit with gates (whiteboard)
  203. - about high level programing languages for zkSNARKS, by *Harry Roberts*: https://www.youtube.com/watch?v=nKrBJo3E3FY
  204. ---
  205. Circuit code example:
  206. $f(x) = x^5 + 2\cdot x + 6$
  207. ```
  208. func exp5(private a):
  209. b = a * a
  210. c = a * b
  211. d = a * c
  212. e = a * d
  213. return e
  214. func main(private s0, public s1):
  215. s2 = exp5(s0)
  216. s3 = s0 * 2
  217. s4 = s3 + s2
  218. s5 = s4 + 6
  219. equals(s1, s5)
  220. out = 1 * 1
  221. ```
  222. ---
  223. ## Inputs and Witness
  224. For a certain circuit, with the inputs that we calculate the Witness for the circuit signals
  225. - private inputs: `[8]`
  226. - in this case the private input is the 'secret' $x$ value that computed into the equation gives the expected $f(x)$
  227. - public inputs: `[32790]`
  228. - in this case the public input is the result of the equation
  229. - signals: `[one s1 s0 b0 c0 d0 s2 s3 s4 s5 out]`
  230. - witness: `[1 32790 8 64 512 4096 32768 16 32784 32790 1]`
  231. ---
  232. ## R1CS
  233. - Rank 1 Constraint System
  234. - way to write down the constraints by 3 linear combinations
  235. - 1 constraint per operation
  236. - $(A, B, C) = A.s \cdot B.s - C.s = 0$
  237. - from flat code constraints we can generate the R1CS
  238. ---
  239. ## R1CS
  240. <div style="font-size:65%">
  241. $(a_{11}s_1 + a_{12}s_2 + ... + a_{1n}s_n) \cdot (b_{11}s_1 + b_{12}s_2 + ... + b_{1n}s_n) - (c_{11}s_1 + c_{12}s_2 + ... + c_{1n}s_n) = 0$
  242. $(a_{21}s_1 + a_{22}s_2 + ... + a_{2n}s_n) \cdot (b_{21}s_1 + b_{22}s_2 + ... + b_{2n}s_n) - (c_{21}s_1 + c_{22}s_2 + ... + c_{2n}s_n) = 0$
  243. $(a_{31}s_1 + a_{32}s_2 + ... + a_{3n}s_n) \cdot (b_{31}s_1 + b_{32}s_2 + ... + b_{3n}s_n) - (c_{31}s_1 + c_{32}s_2 + ... + c_{3n}s_n) = 0$
  244. [...]
  245. $(a_{m1}s_1 + a_{m2}s_2 + ... + a_{mn}s_n) \cdot (b_{m1}s_1 + b_{m2}s_2 + ... + b_{mn}s_n) - (c_{m1}s_1 + c_{m2}s_2 + ... + c_{mn}s_n) = 0$
  246. *where $s$ are the signals of the circuit, and we need to find $a, b, c$ that satisfies the equations
  247. </div>
  248. ---
  249. R1CS constraint example:
  250. - signals: `[one s1 s0 b0 c0 d0 s2 s3 s4 s5 out]`
  251. - witness: `[1 32790 8 64 512 4096 32768 16 32784 32790 1]`
  252. - First constraint flat code: `b0 == s0 * s0`
  253. - R1CS first constraint:
  254. $A_1 = [00100000000]$
  255. $B_1 = [00100000000]$
  256. $C_1 = [00010000000]$
  257. ---
  258. R1CS example:
  259. | $A$| $B$ | $C$: |
  260. |-|-|-|
  261. | $[0 0 1 0 0 0 0 0 0 0 0]$<br>$[0 0 1 0 0 0 0 0 0 0 0]$<br>$[0 0 1 0 0 0 0 0 0 0 0]$<br>$[0 0 1 0 0 0 0 0 0 0 0]$<br>$[0 0 1 0 0 0 0 0 0 0 0]$<br>$[0 0 0 0 0 0 1 1 0 0 0]$<br>$[6 0 0 0 0 0 0 0 1 0 0]$<br>$[0 0 0 0 0 0 0 0 0 1 0]$<br>$[0 1 0 0 0 0 0 0 0 0 0]$<br>$[1 0 0 0 0 0 0 0 0 0 0]$ | $[0 0 1 0 0 0 0 0 0 0 0]$<br>$[0 0 0 1 0 0 0 0 0 0 0]$<br>$[0 0 0 0 1 0 0 0 0 0 0]$<br>$[0 0 0 0 0 1 0 0 0 0 0]$<br>$[2 0 0 0 0 0 0 0 0 0 0]$<br>$[1 0 0 0 0 0 0 0 0 0 0]$<br>$[1 0 0 0 0 0 0 0 0 0 0]$<br>$[1 0 0 0 0 0 0 0 0 0 0]$<br>$[1 0 0 0 0 0 0 0 0 0 0]$<br>$[1 0 0 0 0 0 0 0 0 0 0]$ | $[0 0 0 1 0 0 0 0 0 0 0]$ <br>$[0 0 0 0 1 0 0 0 0 0 0]$<br>$[0 0 0 0 0 1 0 0 0 0 0]$<br>$[0 0 0 0 0 0 1 0 0 0 0]$<br>$[0 0 0 0 0 0 0 1 0 0 0]$<br>$[0 0 0 0 0 0 0 0 1 0 0]$<br>$[0 0 0 0 0 0 0 0 0 1 0]$<br>$[0 1 0 0 0 0 0 0 0 0 0]$<br>$[0 0 0 0 0 0 0 0 0 1 0]$<br>$[0 0 0 0 0 0 0 0 0 0 1]$ |
  262. ---
  263. ## QAP
  264. - Quadratic Arithmetic Programs
  265. - 3 polynomials, linear combinations of R1CS
  266. - very good article about QAP by Vitalik Buterin https://medium.com/@VitalikButerin/quadratic-arithmetic-programs-from-zero-to-hero-f6d558cea649
  267. ---
  268. ![qap](imgs/qap-screenshot.png)
  269. ---
  270. ### Lagrange Interpolation
  271. (Polynomial Interpolation)
  272. - for a group of points, we can find the smallest degree polynomial that goees through all that points
  273. - this polynomial is unique for each group of points
  274. ![](https://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Lagrange_polynomial.svg/440px-Lagrange_polynomial.svg.png)
  275. ---
  276. $L(x) = \sum_{j=0}^{n} y_j l_j(x)$
  277. <br><br>
  278. ![](https://wikimedia.org/api/rest_v1/media/math/render/svg/6e2c3a2ab16a8723c0446de6a30da839198fb04b)
  279. ---
  280. #### Shamir's Secret Sharing
  281. *(small overview, is offtopic here, but is interesting)*
  282. - from a secret to be shared, we generate 5 parts, but we can specify a number of parts that are needed to recover the secret
  283. - so for example, we generate 5 parts, where we will need only 3 of that 5 parts to recover the secret, and the order doesn't matter
  284. - we have the ability to define the thresholds of $M$ parts to be created, and $N$ parts to be able the recover
  285. ---
  286. ##### Shamir's Secret Sharing - Secret generation
  287. - we want that are necessary $n$ parts of $m$ to recover $s$
  288. - where $n<m$
  289. - need to create a polynomial of degree $n-1$
  290. $f(x) = \alpha_0 + \alpha_1 x + \alpha_2 x^2 + \alpha_3 x^3 + ... + + \alpha_{n-1} x^{n-1}$
  291. - where $\alpha_0$ is the secret $s$
  292. - $\alpha_i$ are random values that build the polynomial
  293. *where $\alpha_0$ is the secret to share, and $\alpha_i$ are the random values inside the $Finite Field$
  294. ---
  295. $f(x) = \alpha_0 + \alpha_1 x + \alpha_2 x^2 + \alpha_3 x^3 + ... + + \alpha_{n-1} x^{n-1}$
  296. - the packets that we will generate are $P = (x, f(x))$
  297. - where $x$ is each one of the values between $1$ and $m$
  298. - $P_1=(1, f(1))$
  299. - $P_2=(2, f(2))$
  300. - $P_3=(3, f(3))$
  301. - ...
  302. - $P_m=(m, f(m))$
  303. ---
  304. ##### Shamir's Secret Sharing - Secret recovery
  305. - in order to recover the secret $s$, we will need a minimum of $n$ points of the polynomial
  306. - the order doesn't matter
  307. - with that $n$ parts, we do Lagrange Interpolation/Polynomial Interpolation, recovering the original polynomial
  308. ---
  309. ## QAP
  310. <div style="font-size:50%">
  311. $(\alpha_1(x)s_1 + \alpha_2(x)s_2 + ... + \alpha_n(x)s_n) \cdot (\beta_1(x)s_1 + \beta_2(x)s_2 + ... + \beta_n(x)s_n) - (\gamma_1(x)s_1 + \gamma_2(x)s_2 + ... + \gamma_n(x)s_n) = P(x)$
  312. |----------------------- $A(x)$ -----------------------|------------------------ $B(x)$ -----------------------|------------------------ $C(x)$ ------------------------|
  313. </div>
  314. <div style="font-size:70%">
  315. - $P(x) = A(x)B(x)-C(x)$
  316. - $P(x) = Z(x) h(x)$
  317. - $Z(x)$: divisor polynomial
  318. - $Z(x) = (x - x_1)(x-x_2)...(x-x_m) => ...=> (x_1, 0), (x_2, 0), ..., (x_m, 0)$
  319. - optimizations with FFT
  320. - $h(x) = P(x) / Z(x)$
  321. </div>
  322. ---
  323. *The following explanation is for the [Pinocchio protocol](https://eprint.iacr.org/2013/279.pdf), all the examples will be for this protocol. The [Groth16](https://eprint.iacr.org/2016/260.pdf) is explained also in the end of this slides.*
  324. ---
  325. ## Trusted Setup
  326. - concept
  327. - $\tau$ (Tau)
  328. - "Toxic waste"
  329. - Proving Key
  330. - Verification Key
  331. ---
  332. $g_1 t^0, g_1 t^1, g_1 t^2, g_1 t^3, g_1 t^4, ...$
  333. $g_2 t^0, g_2 t^1, g_2 t^2, g_2 t^3, g_2 t^4, ...$
  334. ---
  335. Proving Key:
  336. $pk = (C, pk_A, pk_A', pk_B, pk_B', pk_C, pk_C', pk_H)$ where:
  337. - $pk_A = \{ A_i(\tau) \rho_A P_1 \}^{m+3}_{i=0}$
  338. - $pk_A' = \{ A_i(\tau) \alpha_A \rho_A P_1 \}^{m+3}_{i=n+1}$
  339. - $pk_B = \{ B_i(\tau) \rho_B P_2 \}^{m+3}_{i=0}$
  340. - $pk_B' = \{ B_i(\tau) \alpha_B \rho_B P_1 \}^{m+3}_{i=0}$
  341. - $pk_C = \{ C_i(\tau) \rho_C P_1 \}^{m+3}_{i=0} = \{C_i(\tau) \rho_A \rho_B P_1\}^{m+3}_{i=0}$
  342. - $pk_C' = \{ C_i(\tau) \alpha_C \rho_C P_1 \}^{m+3}_{i=0} = \{ C_i(\tau) \alpha_C \rho_A \rho_B P_1 \}^{m+3}_{i=0}$
  343. - $pk_K = \{ \beta (A_i(\tau) \rho_A + B_i(\tau) \rho_B C_i(\tau) \rho_A \rho_B) P_1 \} ^{m+3}_{i=0}$
  344. - $pk_H = \{ \tau^i P_1 \}^d_{i=0}$
  345. where:
  346. - $d$: degree of polynomial $Z(x)$
  347. - $m$: number of circuit signals
  348. ---
  349. Verification Key:
  350. $vk = (vk_A, vk_B, vk_C, vk_\gamma, vk^1_{\beta\gamma}, vk^2_{\beta\gamma}, vk_Z, vk_{IC})$
  351. - $vk_A = \alpha_A P_2$, $vk_B = \alpha_B P_1$, $vk_C = \alpha_C P_2$
  352. - $vk_{\beta\gamma} = \gamma P_2$, $vk^1_{\beta\gamma} = \beta\gamma P_1$, $vk^2_{\beta\gamma} = \beta\gamma P_2$
  353. - $vk_Z = Z(\tau) \rho_A \rho_B P_2$, $vk_{IC} = (A_i(\tau) \rho_A P_1)^n_{i=0}$
  354. ---
  355. ```go
  356. type Pk struct { // Proving Key pk:=(pkA, pkB, pkC, pkH)
  357. G1T [][3]*big.Int // t encrypted in G1 curve, G1T == Pk.H
  358. A [][3]*big.Int
  359. B [][3][2]*big.Int
  360. C [][3]*big.Int
  361. Kp [][3]*big.Int
  362. Ap [][3]*big.Int
  363. Bp [][3]*big.Int
  364. Cp [][3]*big.Int
  365. Z []*big.Int
  366. }
  367. type Vk struct {
  368. Vka [3][2]*big.Int
  369. Vkb [3]*big.Int
  370. Vkc [3][2]*big.Int
  371. IC [][3]*big.Int
  372. G1Kbg [3]*big.Int // g1 * Kbeta * Kgamma
  373. G2Kbg [3][2]*big.Int // g2 * Kbeta * Kgamma
  374. G2Kg [3][2]*big.Int // g2 * Kgamma
  375. Vkz [3][2]*big.Int
  376. }
  377. ```
  378. ---
  379. ```go
  380. // Setup is the data structure holding the Trusted Setup data. The Setup.Toxic sub struct must be destroyed after the GenerateTrustedSetup function is completed
  381. type Setup struct {
  382. Toxic struct {
  383. T *big.Int // trusted setup secret
  384. Ka *big.Int
  385. Kb *big.Int
  386. Kc *big.Int
  387. Kbeta *big.Int
  388. Kgamma *big.Int
  389. RhoA *big.Int
  390. RhoB *big.Int
  391. RhoC *big.Int
  392. }
  393. Pk Pk
  394. Vk Vk
  395. }
  396. ```
  397. ---
  398. ## Proofs generation
  399. - $A, B, C, Z$ (from the QAP)
  400. - random $\delta_1, \delta_2, \delta_3$
  401. - $H(z)= \dfrac{A(z)B(z)-C(z)}{Z(z)}$
  402. - $A(z) = A_0(z) + \sum_{i=1}^m s_i A_i(x) + \delta_1 Z(z)$
  403. - $B(z) = B_0(z) + \sum_{i=1}^m s_i B_i(x) + \delta_2 Z(z)$
  404. - $C(z) = C_0(z) + \sum_{i=1}^m s_i B_i(x) + \delta_2 Z(z)$
  405. (where $m$ is the number of public inputs)
  406. ---
  407. - $\pi_A = <c, pk_A>$
  408. - $\pi_A' = <c, pk_A'>$
  409. - $\pi_B = <c, pk_B>$
  410. - example:
  411. ```go
  412. for i := 0; i < circuit.NVars; i++ {
  413. proof.PiB = Utils.Bn.G2.Add(proof.PiB, Utils.Bn.G2.MulScalar(pk.B[i], w[i]))
  414. proof.PiBp = Utils.Bn.G1.Add(proof.PiBp, Utils.Bn.G1.MulScalar(pk.Bp[i], w[i]))
  415. }
  416. ```
  417. ($c=1+witness+\delta_1+\delta_2+\delta_3$
  418. - $\pi_B' = <c, pk_B'>$
  419. - $\pi_C = <c, pk_C>$
  420. - $\pi_C' = <c, pk_C'>$
  421. - $\pi_K = <c, pk_K>$
  422. - $\pi_H = <h, pk_KH>$
  423. - proof: $\pi = (\pi_A, \pi_A', \pi_B, \pi_B', \pi_C, \pi_C', \pi_K, \pi_H$
  424. ---
  425. ## Proofs verification
  426. <img src="imgs/cat03.jpeg" style="float:right; width:300px;" />
  427. - $vk_{kx} = vk_{IC,0} + \sum_{i=1}^n x_i vk_{IC,i}$
  428. Verification:
  429. - $e(\pi_A, vk_a) == e(\pi_{A'}, g_2)$
  430. - $e(vk_b, \pi_B) == e(\pi_{B'}, g_2)$
  431. - $e(\pi_C, vk_c) == e(\pi_{C'}, g_2)$
  432. - $e(vk_{kx}+\pi_A, \pi_B) == e(\pi_H, vk_{kz}) \cdot e(\pi_C, g_2)$
  433. - $e(vk_{kx} + \pi_A + \pi_C, V_{\beta\gamma}^2) \cdot e(vk_{\beta\gamma}^1, \pi_B) == e(\pi_k, vk_{\gamma}^1)$
  434. ---
  435. <div style="font-size:60%">
  436. Example (whiteboard):
  437. <br><br>
  438. $\dfrac{
  439. e(\pi_A, \pi_B)
  440. }{
  441. e(\pi_C, g_2)
  442. }
  443. = e(g_1 h(t), g_2 z(t))
  444. $
  445. <br>
  446. $\dfrac{
  447. e(A_1 + A_2 + ... + A_n, B_1 + B_2 + ... + B_n)
  448. }{
  449. e(C_1 + C_2 + ... + C_n, g_2)
  450. }
  451. = e(g_1 h(t), g_2 z(t))
  452. $
  453. <br>
  454. $\dfrac{
  455. e(g_1 \alpha_1(t) s_1 + g_1 \alpha_2(t) s_2 + ... + g_1 \alpha_n(t) s_n, g_2 \beta_1(t)s_1 + g_2 \beta_2(t) s_2 + ... + g_2 \beta_n(t) s_n)
  456. }{
  457. e(g_1 \gamma_1(t) s_1 + g_1 \gamma_2(t) s_2 + ... + g_1 \gamma_n(t) s_n, g_2)
  458. }
  459. = e(g_1 h(t), g_2 z(t))
  460. $
  461. <br>
  462. $
  463. e(g_1 \alpha_1(t) s_1 + g_1 \alpha_2(t) s_2 + ... + g_1 \alpha_n(t) s_n, g_2 \beta_1(t)s_1 + g_2 \beta_2(t) s_2 + ... + g_2 \beta_n(t) s_n)$
  464. $= e(g_1 h(t), g_2 z(t)) \cdot e(g_1 \gamma_1(t) s_1 + g_1 \gamma_2(t) s_2 + ... + g_1 \gamma_n(t) s_n, g_2)
  465. $
  466. </div>
  467. ---
  468. ## Groth16
  469. <img src="imgs/cat02.jpeg" style="float:right; width:300px;" />
  470. ### Trusted Setup
  471. $\tau = \alpha, \beta, \gamma, \delta, x$
  472. $\sigma_1 =$
  473. - $\alpha, \beta, \delta, \{ x^i\}_{i=0}^{n-1}$
  474. - $\{
  475. \dfrac{
  476. \beta u_i(x) + \alpha v_i(x) + w_i(x)
  477. }{
  478. \gamma
  479. }
  480. \}_{i=0}^l$
  481. - $\{
  482. \dfrac{
  483. \beta u_i(x) + \alpha v_i(x) + w_i(x)
  484. }{
  485. \delta
  486. }
  487. \}_{i=l+1}^m$
  488. - $\{
  489. \dfrac{x^i t(x)}{\delta}
  490. \}_{i=0}^{n-2}$
  491. $\sigma_2 = (\beta, \gamma, \delta, \{ x^i \}_{i=0}^{n-1})$
  492. *(where $u_i(x), v_i(x), w_i(x)$ are the $QAP$)*
  493. ---
  494. ```go
  495. type Pk struct { // Proving Key
  496. BACDelta [][3]*big.Int // {( βui(x)+αvi(x)+wi(x) ) / δ } from l+1 to m
  497. Z []*big.Int
  498. G1 struct {
  499. Alpha [3]*big.Int
  500. Beta [3]*big.Int
  501. Delta [3]*big.Int
  502. At [][3]*big.Int // {a(τ)} from 0 to m
  503. BACGamma [][3]*big.Int // {( βui(x)+αvi(x)+wi(x) ) / γ } from 0 to m
  504. }
  505. G2 struct {
  506. Beta [3][2]*big.Int
  507. Gamma [3][2]*big.Int
  508. Delta [3][2]*big.Int
  509. BACGamma [][3][2]*big.Int // {( βui(x)+αvi(x)+wi(x) ) / γ } from 0 to m
  510. }
  511. PowersTauDelta [][3]*big.Int // powers of τ encrypted in G1 curve, divided by δ
  512. }
  513. ```
  514. ---
  515. ```go
  516. type Vk struct {
  517. IC [][3]*big.Int
  518. G1 struct {
  519. Alpha [3]*big.Int
  520. }
  521. G2 struct {
  522. Beta [3][2]*big.Int
  523. Gamma [3][2]*big.Int
  524. Delta [3][2]*big.Int
  525. }
  526. }
  527. ```
  528. ---
  529. ```go
  530. // Setup is the data structure holding the Trusted Setup data. The Setup.Toxic sub struct must be destroyed after the GenerateTrustedSetup function is completed
  531. type Setup struct {
  532. Toxic struct {
  533. T *big.Int // trusted setup secret
  534. Kalpha *big.Int
  535. Kbeta *big.Int
  536. Kgamma *big.Int
  537. Kdelta *big.Int
  538. }
  539. Pk Pk
  540. Vk Vk
  541. }
  542. ```
  543. ---
  544. #
  545. ## Proofs Generation
  546. $\pi_A=\alpha + \sum_{i=0}^m \alpha_i u_i(x) + r \delta$
  547. $\pi_B=\beta + \sum_{i=0}^m \alpha_i v_i(x) + s \delta$
  548. <div style="font-size:80%;">
  549. $\pi_C = \dfrac{
  550. \sum_{i=l+1}^m a_i(\beta u_i(x) + \alpha v_i(x) + w_i(x)) + h(x)t(x)
  551. }{
  552. \delta
  553. } + \pi_As + \pi_Br -rs\delta$
  554. </div>
  555. $\pi=\pi_A^1, \pi_B^1, \pi_C^2$
  556. ---
  557. ### Proof Verification
  558. <div style="font-size:75%;">
  559. $[\pi_A]_1 \cdot [\pi_B]_2 = [\alpha]_1 \cdot [\beta]_2 +
  560. \sum_{i=0}^l a_i [
  561. \dfrac{
  562. \beta u_i(x) + \alpha v_i(x) + w_i(x)
  563. }{
  564. \gamma
  565. }
  566. ]_1
  567. \cdot [\gamma]_2 + [\pi_C]_1 \cdot [\delta]_2
  568. $
  569. </div>
  570. $e(\pi_A, \pi_B) = e(\alpha, \beta) \cdot e(pub, \gamma) \cdot e(\pi_C, \delta)$
  571. ---
  572. ## How we use zkSNARKs in iden3
  573. - proving a credentials without revealing it's content
  574. - proving that an identity has a claim issued by another identity, without revealing all the data
  575. - proving any property of an identity
  576. - $ITF$ (Identity Transition Function), a way to prove with a zkSNARK that an identity has been updated following the defined protocol
  577. - identities can not cheat when issuing claims
  578. - etc
  579. ## Other ideas for free time side project
  580. - Zendermint (Tendermint + zkSNARKs)
  581. ---
  582. <img src="imgs/cat05.jpeg" style="float:right; width:300px;" />
  583. ## zkSNARK libraries
  584. - [bellman](https://github.com/zkcrypto/bellman) (rust)
  585. - [libsnark](https://github.com/scipr-lab/libsnark) (c++)
  586. - [snarkjs](https://github.com/iden3/snarkjs) (javascript)
  587. - [websnark](https://github.com/iden3/websnark) (wasm)
  588. - [go-snark](https://github.com/arnaucube/go-snark) (golang) <span style="font-size:80%;">[do not use in production]<span>
  589. ## Circuit languages
  590. | language | snark library with which plugs in |
  591. |-----|-----|
  592. | [Zokrates](https://github.com/Zokrates/ZoKrates) | libsnark, bellman |
  593. | [Snarky](https://github.com/o1-labs/snarky) | libsnark |
  594. | [circom](https://github.com/iden3/circom) | snarkjs, websnark, bellman |
  595. | [go-snark-circuit](https://github.com/arnaucube/go-snark) | go-snark |
  596. ---
  597. ## Utilities (Elliptic curve & Hash functions) inside the zkSNARK
  598. - we work over $F_r$, where $r=$`21888242871839275222246405745257275088548364400416034343698204186575808495617`
  599. - BabyJubJub
  600. - Mimc
  601. - Poseidon
  602. ---
  603. ##### *Utilities (Elliptic curve & Hash functions) inside the zkSNARK*
  604. ### BabyJubJub
  605. - explaination: https://medium.com/zokrates/efficient-ecc-in-zksnarks-using-zokrates-bd9ae37b8186
  606. - implementations:
  607. - go: https://github.com/iden3/go-iden3-crypto
  608. - javascript & circom: https://github.com/iden3/circomlib
  609. - rust: https://github.com/arnaucube/babyjubjub-rs
  610. - c++: https://github.com/barryWhiteHat/baby_jubjub_ecc
  611. ---
  612. ##### *Utilities (Elliptic curve & Hash functions) inside the zkSNARK*
  613. ### Mimc7
  614. - explaination: https://eprint.iacr.org/2016/492.pdf
  615. - implementations in:
  616. - go: https://github.com/iden3/go-iden3-crypto
  617. - javascript & circom: https://github.com/iden3/circomlib
  618. - rust: https://github.com/arnaucube/mimc-rs
  619. ---
  620. ##### *Utilities (Elliptic curve & Hash functions) inside the zkSNARK*
  621. ### Poseidon
  622. - explaination: https://eprint.iacr.org/2019/458.pdf
  623. - implementations in:
  624. - go: https://github.com/iden3/go-iden3-crypto
  625. - javascript & circom: https://github.com/iden3/circomlib
  626. ---
  627. # References
  628. - `Succinct Non-Interactive Zero Knowledge for a von Neumann Architecture`, Eli Ben-Sasson, Alessandro Chiesa, Eran Tromer, Madars Virza https://eprint.iacr.org/2013/879.pdf
  629. - `Pinocchio: Nearly practical verifiable computation`, Bryan Parno, Craig Gentry, Jon Howell, Mariana Raykova https://eprint.iacr.org/2013/279.pdf
  630. - `On the Size of Pairing-based Non-interactive Arguments`, Jens Groth https://eprint.iacr.org/2016/260.pdf
  631. - (also all the links through the slides)
  632. ---
  633. <div style="text-align:center;">
  634. Thank you very much
  635. <br>
  636. <img src="imgs/cat00.jpeg" style="width:300px;" />
  637. </div>
  638. <div style="float:right; text-align:right;">
  639. <img style="width:80px" src="imgs/arnaucube.png" /> <br>
  640. [arnaucube.com](https://arnaucube.com)
  641. [github.com/arnaucube](https://github.com/arnaucube)
  642. [twitter.com/arnaucube](https://twitter.com/arnaucube)
  643. <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/"><img src="https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png" /></a>
  644. 2019-08-20
  645. </div>
  646. <img style="width:200px;" src="imgs/iden3.png" /> <br>
  647. [iden3.io](https://iden3.io)
  648. [github.com/iden3](https://github.com/iden3)
  649. [twitter.com/identhree](https://twitter.com/identhree)