arnaucube
arnaucube/arnaucube.comPublic Self-hosted repository
arnaucube.com/public/kzg-commitments.html
public/kzg-commitments.htmlRaw
  1<!DOCTYPE html>
  2<html lang="en">
  3
  4  <head>
  5    <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." />
  6    <meta charset="utf-8">
  7    <title> Notes on KZG polynomial commitments - arnaucube</title>
  8    <meta name="title" content=" Notes on KZG polynomial commitments - arnaucube">
  9    <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.">
 10
 11    <meta property="og:title" content=" Notes on KZG polynomial commitments - arnaucube" />
 12    <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." />
 13    <meta property="og:url" content="https://arnaucube.com/blog/kzg-commitments.html" />
 14    <meta property="og:type" content="article" />
 15    <meta property="og:image" content="https://arnaucube.com/blog/" />
 16    <meta name="twitter:title" content=" Notes on KZG polynomial commitments - arnaucube">
 17    <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.">
 18    <meta name="twitter:image" content="https://arnaucube.com/blog/">
 19    <meta name="twitter:card" content="summary_large_image">
 20    <meta name="author" content="arnaucube">
 21
 22    <meta name="viewport" content="width=device-width, initial-scale=1">
 23
 24    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
 25    <link rel="stylesheet" href="css/style.css">
 26
 27    <!-- highlightjs -->
 28    <!-- <link rel="stylesheet" href="js/highlightjs/atom-one-dark.css"> -->
 29    <link rel="stylesheet" href="js/highlightjs/gruvbox-dark.css">
 30    <script src="js/highlightjs/highlight.pack.js"></script>
 31
 32    <!-- katex -->
 33    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/katex.min.css" integrity="sha384-Um5gpz1odJg5Z4HAmzPtgZKdTBHZdw8S29IecapCSB31ligYPhHQZMIlWLYQGVoc" crossorigin="anonymous">
 34  </head>
 35
 36  <body>
 37
 38    <!-- o_gradient_background" -->
 39    <nav id="mainNav" class="navbar navbar-default navbar-fixed-top"
 40                      style="height:50px;font-size:130%;">
 41      <div class="container">
 42        <a href="/blog" style="color:#000;">Blog index</a>
 43        <a href="/" style="color:#000;float:right;">arnaucube.com</a>
 44      </div>
 45      <img style="height:5px; width:100%; margin-top:8px;" src="img/gradient-line.jpg" />
 46    </nav>
 47
 48
 49
 50    <div class="container" style="margin-top:40px;max-width:800px;">
 51      <h2>Notes on KZG polynomial commitments</h2>
 52
 53<p><em>2021-08-05</em></p>
 54
 55<blockquote>
 56<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>
 57</blockquote>
 58
 59<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>
 60
 61<div class="row">
 62    <div class="col-md-7">
 63	<br>
 64	In the following notes I've tried to summarize the KZG Commitments scheme with the concepts that helped me to follow the reasoning.
 65    </div>
 66    <div class="col-md-5" style="font-size:90%; padding:10px;border:1px solid #cfcfcf;">
 67	<b>Notation:</b><br>
 68	$[x]_1 = x G \in \mathbb{G}_1\newline
 69	[x]_2 = x H \in \mathbb{G}_2$
 70	<br>Where $\mathbb{G}_1 = \langle G \rangle$ and $\mathbb{G}_2 = \langle H \rangle$.
 71	<br>In other words: $G$ is the generator of $\mathbb{G}_1$, and $H$ is the generator of $\mathbb{G}_2$
 72    </div>
 73</div>
 74
 75<h4>Trusted setup</h4>
 76
 77<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>
 78
 79<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 $\tau$ can not be restored.</p>
 80
 81<p>The parameters of the <em>Trusted Setup</em> are generated by generating a random $\tau \in \mathbb{F}_p$, and from this parameter we can compute $[\tau^i]_1$ and $[\tau^i]_2$ for $i=0,&hellip;,n-1$:</p>
 82
 83<p>$$
 84[\tau^i]_1 = ([\tau^0]_1, [\tau^1]_1, [\tau^2]_1, &hellip;, [\tau^{n-1}]_1)\newline
 85[\tau^i]_2 = ([\tau^0]_2, [\tau^1]_2, [\tau^2]_2, &hellip;, [\tau^{n-1}]_2)
 86$$</p>
 87
 88<p>Which in additive representation is:
 89$$
 90(G, \tau G, \tau^2 G, &hellip;, \tau^{n-1} G) \in \mathbb{G}_1\newline
 91(H, \tau H, \tau^2 H, &hellip;, \tau^{n-1} H) \in \mathbb{G}_2
 92$$</p>
 93
 94<p>The &lsquo;intuition&rsquo; about the <em>Trusted Setup</em> is that is like encrypting a secret value ($\tau$) that later will be used in the &lsquo;encrypted&rsquo; form to evaluate the polynomials.</p>
 95
 96<h4>Commitments</h4>
 97
 98<p>A commitment to a polynomial $p(x) = \sum^n_{i=0} p_i x^i$ is done by computing</p>
 99
100<p>$$c=[p(\tau)]_1$$</p>
101
102<p>which is computed by $c = \sum^{deg(p(x))}_{i=0} [\tau^i] \cdot p_i$.</p>
103
104<p>The prover would send the commitment to the polynomial $c$, and then the verifier would choose a value $z \in \mathbb{F}_p$, where $\mathbb{F}_p$ is the finite field of the polynomial.</p>
105
106<h4>Evalutaion proofs</h4>
107
108<p>To prove an evaluation of the polynomial at the choosen value $z$ such that $p(z)=y$, a quotient polynomial is computed: $q(x) = \frac{p(x)-y}{x-z}$. This polynomial is the proof that $p(z)=y$, as if $q$ exists it means that $p(x)-y$ is divisible by $x-z$, which means that it has a root at $z$, being $p(z)-y=0$.</p>
109
110<p>Then, the evaluation proof is</p>
111
112<p>$$\pi = [q(\tau)]_1$$</p>
113
114<p>which, as when computing $c$, is computed by $\pi=\sum^{deg(q(x))}_{i=0} [\tau^i] \cdot q_i$.</p>
115
116<p>Once computed, the prover would send this evaluation proof $\pi$ to the verifier.</p>
117
118<h4>Verifying an evaluation proof</h4>
119
120<p>In order to verify an evaluation proof, the verifier has the commitment $c=[p(\tau)]_1$, the evaluation $y=p(z)$, and the proof $\pi=[q(\tau)]_1$.</p>
121
122<p>So, the verifier can check the <a href="https://en.wikipedia.org/wiki/Pairing-based_cryptography">pairing</a> evaluation:
123$$\hat{e}(\pi, [\tau]_2 - [z]_2) == \hat{e}(c - [y]_1, H)$$</p>
124
125<p>Where $[\tau]_2$ comes from the Trusted Setup, $[z]_2$ is point at which the polynomial is evaluated, and $[y]_1$ is the claimed value p(z). And $\pi$ and $c$ are given by the prover.</p>
126
127<p>We can unroll that last equivalence, and see that:</p>
128
129<p>$$
130\hat{e}(\pi, [\tau]_2 - [z]_2) == \hat{e}(c - [y]_1, H)\newline
131\Rightarrow \hat{e}([q(\tau)]_1, [\tau-z]_2) == \hat{e}([p(\tau)]_1 - [y]_1, H)\newline
132\Rightarrow [q(\tau) \cdot (\tau-z)]_T == [p(\tau) - y]_T
133$$</p>
134
135<p>We can see that is the equation $q(x)(x-z)=p(x)-y$, which can be expressed as $q(x) = \frac{p(x) - y}{x-z}$, evaluated at $\tau$ from the <em>trusted setup</em>, which is not known: $q(\tau) = \frac{p(\tau) - y}{\tau-z}$.</p>
136
137<h3>Conclusions</h3>
138
139<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 $p(i) = x_i$ for all values of $x_i$ of the vector, which can be obtained from the $x_i$ 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.</p>
140
141<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>
142
143    </div>
144
145    <footer style="text-align:center; margin-top:100px;margin-bottom:50px;">
146      <div class="container">
147        <div class="row">
148          <ul class="list-inline">
149            <li><a href="https://twitter.com/arnaucube"
150                   style="color:gray;text-decoration:none;"
151                   target="_blank">twitter.com/arnaucube</a>
152            </li>
153            <li><a href="https://github.com/arnaucube"
154                   style="color:gray;text-decoration:none;"
155                   target="_blank">github.com/arnaucube</a>
156            </li>
157          </ul>
158        </div>
159        <div class="row" style="display:inline-block;">
160          Blog made with <a href="http://github.com/arnaucube/blogo/"
161                            target="_blank" style="color: gray;text-decoration:none;">Blogo</a>
162        </div>
163      </div>
164    </footer>
165
166    <script>
167    </script>
168    <script src="js/external-links.js"></script>
169    <script>hljs.initHighlightingOnLoad();</script>
170    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/katex.min.js" integrity="sha384-YNHdsYkH6gMx9y3mRkmcJ2mFUjTd0qNQQvY9VYZgQd7DcN7env35GzlmFaZ23JGp" crossorigin="anonymous"></script>
171    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/contrib/auto-render.min.js" integrity="sha384-vZTG03m+2yp6N6BNi5iM4rW4oIwk5DfcNdFfxkk9ZWpDriOkXX8voJBFrAO7MpVl" crossorigin="anonymous"></script>
172    <script>
173      document.addEventListener("DOMContentLoaded", function() {
174        renderMathInElement(document.body, {
175          displayMode: false,
176          // customised options
177          // • auto-render specific keys, e.g.:
178          delimiters: [
179            {left: '$$', right: '$$', display: true},
180            {left: '$', right: '$', display: false},
181          ],
182          // • rendering keys, e.g.:
183          throwOnError : true
184        });
185      });
186    </script>
187    <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
188
189
190  </body>
191</html>
192