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.

233 lines
14 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta name="description" content="In the following notes I've tried to summarize the KZG Commitment scheme with the concepts that helped me to follow the reasoning." />
  5. <meta charset="utf-8">
  6. <title> Notes on KZG polynomial commitments - arnaucube - blog</title>
  7. <meta name="title" content=" Notes on KZG polynomial commitments - arnaucube - blog">
  8. <meta name="description" content="In the following notes I've tried to summarize the KZG Commitment scheme with the concepts that helped me to follow the reasoning.">
  9. <meta property="og:title" content=" Notes on KZG polynomial commitments - arnaucube - blog" />
  10. <meta property="og:description" content="In the following notes I've tried to summarize the KZG Commitment scheme with the concepts that helped me to follow the reasoning." />
  11. <meta property="og:url" content="https://arnaucube.com/blog/kzg-commitments.html" />
  12. <meta property="og:type" content="article" />
  13. <meta property="og:image" content="https://arnaucube.com/blog/" />
  14. <meta name="twitter:title" content=" Notes on KZG polynomial commitments - arnaucube - blog">
  15. <meta name="twitter:description" content="In the following notes I've tried to summarize the KZG Commitment scheme with the concepts that helped me to follow the reasoning.">
  16. <meta name="twitter:image" content="https://arnaucube.com/blog/">
  17. <meta name="twitter:card" content="summary_large_image">
  18. <meta name="author" content="arnaucube">
  19. <meta name="viewport" content="width=device-width, initial-scale=1">
  20. <link href="css/bootstrap.min.css" rel="stylesheet">
  21. <link rel="stylesheet" href="css/style.css">
  22. <!-- highlightjs -->
  23. <!-- <link rel="stylesheet" href="js/highlightjs/atom-one-dark.css"> -->
  24. <link rel="stylesheet" href="js/highlightjs/gruvbox-dark.css">
  25. <script src="js/highlightjs/highlight.pack.js"></script>
  26. <!-- katex -->
  27. <link rel="stylesheet" href="js/katex/katex.min.css">
  28. </head>
  29. <body>
  30. <!-- o_gradient_background" -->
  31. <nav id="mainNav" class="navbar navbar-default navbar-fixed-top"
  32. style="height:50px;font-size:130%;">
  33. <div class="container">
  34. <a href="/blog" style="color:#000;">Blog index</a>
  35. <div style="float:right;">
  36. <a href="/" style="color:#000;display:inline-block;">arnaucube.com</a>
  37. <div class="onoffswitch" style="margin:10px;display:inline-block;" title="change theme">
  38. <input onclick="switchTheme()" type="checkbox" name="onoffswitch" class="onoffswitch-checkbox"
  39. id="themeSwitcher">
  40. <label class="onoffswitch-label" for="themeSwitcher"></label>
  41. </div>
  42. </div>
  43. </div>
  44. <img style="height:5px; width:100%; margin-top:8px;" src="img/gradient-line.jpg" />
  45. </nav>
  46. <div class="container" style="margin-top:40px;max-width:800px;">
  47. <h2>Notes on KZG polynomial commitments</h2>
  48. <p><em>2021-08-05</em></p>
  49. <blockquote>
  50. <p><strong>Warning</strong>: I want to state clearly that I&rsquo;m not a mathematician, I&rsquo;m just an amateur on math studying in my free time, and this article is just an attempt to try to sort the notes that I took while reading about the KZG Commitments.</p>
  51. </blockquote>
  52. <p>Few weeks ago I started reading about <a href="https://www.iacr.org/archive/asiacrypt2010/6477178/6477178.pdf">KZG Commitments</a> from the articles written by <a href="https://dankradfeist.de/ethereum/2020/06/16/kate-polynomial-commitments.html">Dankrad Feist</a>, by <a href="https://hackmd.io/@tompocock/Hk2A7BD6U">Tom Walton-Pocock</a> and by <a href="https://alinush.github.io/2020/05/06/kzg-polynomial-commitments.html">Alin Tomescu</a>. I want to thank them, because their articles helped me to understand a bit the concepts. I recommend spending the time reading their articles instead of this current notes.</p>
  53. <div class="row">
  54. <div class="col-md-7">
  55. <br>
  56. In the following notes I've tried to summarize the KZG Commitments scheme with the concepts that helped me to follow the reasoning.
  57. </div>
  58. <div class="col-md-5" style="font-size:90%; padding:10px;border:1px solid #cfcfcf;">
  59. <b>Notation:</b><br>
  60. $[x]_1 = x G \in \mathbb{G}_1\newline
  61. [x]_2 = x H \in \mathbb{G}_2$
  62. <br>Where $\mathbb{G}_1 = \langle G \rangle$ and $\mathbb{G}_2 = \langle H \rangle$.
  63. <br>In other words: $G$ is the generator of $\mathbb{G}_1$, and $H$ is the generator of $\mathbb{G}_2$
  64. </div>
  65. </div>
  66. <h4>Trusted setup</h4>
  67. <p>First of all, we need to generate a <em>Trusted Setup</em> that will be used later in the rest of steps. Here, the concept of <em>Trusted Setup</em> is quite similar to what we are familiar when dealing with other zk protocols such zkSNARKs, but with the advantage that for the <em>KZG Commitments</em> the nature of its <em>Trusted Setup</em> allows to have some kind of &lsquo;global&rsquo; <em>Trusted Setup</em> that can be used for different polynomials.</p>
  68. <p>It should be computed in a <em>Multi-Party Computation</em> (<em>MPC</em>) fashion, and ensuring that at least one of the participants is honest, in order to ensure that the original parameter <span class="math inline">\(\tau\)</span> can not be restored.</p>
  69. <p>The parameters of the <em>Trusted Setup</em> are generated by generating a random <span class="math inline">\(\tau \in \mathbb{F}_p\)</span>, and from this parameter we can compute <span class="math inline">\([\tau^i]_1\)</span> and <span class="math inline">\([\tau^i]_2\)</span> for <span class="math inline">\(i=0,...,n-1\)</span>:</p>
  70. <p><span class="math display">\[
  71. [\tau^i]_1 = ([\tau^0]_1, [\tau^1]_1, [\tau^2]_1, ..., [\tau^{n-1}]_1)\newline
  72. [\tau^i]_2 = ([\tau^0]_2, [\tau^1]_2, [\tau^2]_2, ..., [\tau^{n-1}]_2)
  73. \]</span></p><p>Which in additive representation is:</p>
  74. <p><span class="math display">\[
  75. (G, \tau G, \tau^2 G, ..., \tau^{n-1} G) \in \mathbb{G}_1\newline
  76. (H, \tau H, \tau^2 H, ..., \tau^{n-1} H) \in \mathbb{G}_2
  77. \]</span></p><p>The &lsquo;intuition&rsquo; about the <em>Trusted Setup</em> is that is like encrypting a secret value (<span class="math inline">\(\tau\)</span>) that later will be used in the &lsquo;encrypted&rsquo; form to evaluate the polynomials.</p>
  78. <h4>Commitments</h4>
  79. <p>A commitment to a polynomial <span class="math inline">\(p(x) = \sum^n_{i=0} p_i x^i\)</span> is done by computing</p>
  80. <p><span class="math display">\[c=[p(\tau)]_1\]</span></p><p>which is computed by <span class="math inline">\(c = \sum^{deg(p(x))}_{i=0} [\tau^i] \cdot p_i\)</span>.</p>
  81. <p>The prover would send the commitment to the polynomial <span class="math inline">\(c\)</span>, and then the verifier would choose a value <span class="math inline">\(z \in \mathbb{F}_p\)</span>, where <span class="math inline">\(\mathbb{F}_p\)</span> is the finite field of the polynomial.</p>
  82. <h4>Evalutaion proofs</h4>
  83. <p>To prove an evaluation of the polynomial at the choosen value <span class="math inline">\(z\)</span> such that <span class="math inline">\(p(z)=y\)</span>, a quotient polynomial is computed: <span class="math inline">\(q(x) = \frac{p(x)-y}{x-z}\)</span>. This polynomial is the proof that <span class="math inline">\(p(z)=y\)</span>, as if <span class="math inline">\(q\)</span> exists it means that <span class="math inline">\(p(x)-y\)</span> is divisible by <span class="math inline">\(x-z\)</span>, which means that it has a root at <span class="math inline">\(z\)</span>, being <span class="math inline">\(p(z)-y=0\)</span>.</p>
  84. <p>Then, the evaluation proof is</p>
  85. <p><span class="math display">\[\pi = [q(\tau)]_1\]</span></p><p>which, as when computing <span class="math inline">\(c\)</span>, is computed by <span class="math inline">\(\pi=\sum^{deg(q(x))}_{i=0} [\tau^i] \cdot q_i\)</span>.</p>
  86. <p>Once computed, the prover would send this evaluation proof <span class="math inline">\(\pi\)</span> to the verifier.</p>
  87. <h4>Verifying an evaluation proof</h4>
  88. <p>In order to verify an evaluation proof, the verifier has the commitment <span class="math inline">\(c=[p(\tau)]_1\)</span>, the evaluation <span class="math inline">\(y=p(z)\)</span>, and the proof <span class="math inline">\(\pi=[q(\tau)]_1\)</span>.</p>
  89. <p>So, the verifier can check the <a href="https://en.wikipedia.org/wiki/Pairing-based_cryptography">pairing</a> evaluation:
  90. $<span class="math inline">\(\hat{e}(\pi, [\tau]_2 - [z]_2) == \hat{e}(c - [y]_1, H)\)</span>$</p>
  91. <p>Where <span class="math inline">\([\tau]_2\)</span> comes from the Trusted Setup, <span class="math inline">\([z]_2\)</span> is point at which the polynomial is evaluated, and <span class="math inline">\([y]_1\)</span> is the claimed value p(z). And <span class="math inline">\(\pi\)</span> and <span class="math inline">\(c\)</span> are given by the prover.</p>
  92. <p>We can unroll that last equivalence, and see that:</p>
  93. <p><span class="math display">\[
  94. \hat{e}(\pi, [\tau]_2 - [z]_2) == \hat{e}(c - [y]_1, H)\newline
  95. \Rightarrow \hat{e}([q(\tau)]_1, [\tau-z]_2) == \hat{e}([p(\tau)]_1 - [y]_1, H)\newline
  96. \Rightarrow [q(\tau) \cdot (\tau-z)]_T == [p(\tau) - y]_T
  97. \]</span></p><p>We can see that is the equation <span class="math inline">\(q(x)(x-z)=p(x)-y\)</span>, which can be expressed as <span class="math inline">\(q(x) = \frac{p(x) - y}{x-z}\)</span>, evaluated at <span class="math inline">\(\tau\)</span> from the <em>trusted setup</em>, which is not known: <span class="math inline">\(q(\tau) = \frac{p(\tau) - y}{\tau-z}\)</span>.</p>
  98. <h3>Conclusions</h3>
  99. <p>The content covered in this notes is just a quick overview, but allows us to see the potential of the scheme. One next iteration from what we&rsquo;ve seen is the approach to do batch proofs, which allows us to evaluate at multiple points with a single evaluation proof. This scheme can be used as a <em>vector commitment</em>, using a polynomial where the <span class="math inline">\(p(i) = x_i\)</span> for all values of <span class="math inline">\(x_i\)</span> of the vector, which can be obtained from the <span class="math inline">\(x_i\)</span> values and computing the <a href="https://en.wikipedia.org/wiki/Lagrange_polynomial">Lagrange interpolation</a>. This is quite useful combined with the mentioned batch proofs. The <em>batch proofs</em> logic can be found at the <a href="https://arnaucube.com/blog/kzg-batch-proof.html">blog/kzg-batch-proof</a> notes (kind of the continuation of the current notes).</p>
  100. <p>As a final note, in order to try to digest the notes, I&rsquo;ve did a <em>toy implementation</em> of this scheme at <a href="https://github.com/arnaucube/kzg-commitments-study">https://github.com/arnaucube/kzg-commitments-study</a>. It&rsquo;s quite simple, but contains the logic overviewed in this notes.</p>
  101. <p><br>
  102. - <a href="https://arnaucube.com/blog/kzg-batch-proof.html">Part 2: Batch proof in KZG Commitments</a></p>
  103. </div>
  104. <footer style="text-align:center; margin-top:100px;margin-bottom:50px;">
  105. <div class="container">
  106. <div class="row">
  107. <ul class="list-inline">
  108. <li><a href="https://twitter.com/arnaucube"
  109. style="color:gray;text-decoration:none;"
  110. target="_blank">twitter.com/arnaucube</a>
  111. </li>
  112. <li><a href="https://github.com/arnaucube"
  113. style="color:gray;text-decoration:none;"
  114. target="_blank">github.com/arnaucube</a>
  115. </li>
  116. </ul>
  117. </div>
  118. <div class="row" style="display:inline-block;">
  119. Blog made with <a href="http://github.com/arnaucube/blogo/"
  120. target="_blank" style="color: gray;text-decoration:none;">Blogo</a>
  121. </div>
  122. </div>
  123. </footer>
  124. <script>
  125. </script>
  126. <script src="js/external-links.js"></script>
  127. <script>hljs.initHighlightingOnLoad();</script>
  128. <script defer src="js/katex/katex.min.js"></script>
  129. <script defer src="js/katex/auto-render.min.js"></script>
  130. <script>
  131. document.addEventListener("DOMContentLoaded", function() {
  132. renderMathInElement(document.body, {
  133. displayMode: false,
  134. // customised options
  135. // • auto-render specific keys, e.g.:
  136. delimiters: [
  137. {left: '$$', right: '$$', display: true},
  138. {left: '$', right: '$', display: false},
  139. {left: "\\[", right: "\\]", display: true},
  140. {left: "\\(", right: "\\)", display: false},
  141. ],
  142. // • rendering keys, e.g.:
  143. throwOnError : true
  144. });
  145. });
  146. ///
  147. let theme = localStorage.getItem("theme");
  148. if ((theme === "light-theme")||(theme==null)) {
  149. theme = "light-theme";
  150. document.getElementById("themeSwitcher").checked = false;
  151. } else if (theme === "dark-theme") {
  152. theme = "dark-theme";
  153. document.getElementById("themeSwitcher").checked = true;
  154. }
  155. document.body.className = theme;
  156. localStorage.setItem("theme", theme);
  157. function switchTheme() {
  158. theme = localStorage.getItem("theme");
  159. if (theme === "light-theme") {
  160. theme = "dark-theme";
  161. document.getElementById("themeSwitcher").checked = true;
  162. } else {
  163. theme = "light-theme";
  164. document.getElementById("themeSwitcher").checked = false;
  165. }
  166. document.body.className = theme;
  167. localStorage.setItem("theme", theme);
  168. console.log(theme);
  169. }
  170. </script>
  171. <script>
  172. function tagLinks(tagName) {
  173. var tags = document.getElementsByTagName(tagName);
  174. for (var i=0, hElem; hElem = tags[i]; i++) {
  175. if (hElem.parentNode.className=="row postThumb") {
  176. continue;
  177. }
  178. hElem.id = hElem.innerHTML.toLowerCase().replace(" ", "-");
  179. hElem.innerHTML = "<a style='text-decoration:none;color:black;' href='#"+hElem.id+"'>"+hElem.innerHTML+"</a>";
  180. }
  181. }
  182. tagLinks("h2");
  183. tagLinks("h3");
  184. tagLinks("h4");
  185. tagLinks("h5");
  186. </script>
  187. <script src="js/mermaid.min.js"></script>
  188. </body>
  189. </html>