Skip to content

Commit 0a73eae

Browse files
author
Nadim Kobeissi
authored
Merge pull request 0xPolygon#50 from 0xPolygon/empieichO-docs-review
Update - conflicts resolved
2 parents 937ebba + 5d15ed6 commit 0a73eae

File tree

4 files changed

+49
-58
lines changed

4 files changed

+49
-58
lines changed

docs/zkEVM/concepts/generic-state-machine/exec-trace-correct.md

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ In continuing with the previous example of a four-instruction state machine,
2323
The **arithmetic constraints** are therefore defined by the following linear combinations;
2424

2525
$$
26-
\mathtt{A′ = A + setA \cdot \big( inA \cdot A + inB \cdot B + inFREE \cdot FREE + CONST - A \big)} \\
26+
\mathtt{A′ = A + setA \cdot \big( inA \cdot A + inB \cdot B + inFREE \cdot FREE + CONST - A \big)} \\ \tag{Eqn 1a}
27+
$$
2728

28-
\mathtt{B′ = B + setB \cdot \big( inA \cdot A + inB \cdot B + inFREE \cdot FREE + CONST - B \big)} \\ \tag{Eqn 1}
29+
$$
30+
\mathtt{B′ = B + setB \cdot \big( inA \cdot A + inB \cdot B + inFREE \cdot FREE + CONST - B \big)} \\ \tag{Eqn 1b}
2931
$$
3032

3133
The figure below depicts the linear combinations of our state machine as an algebraic processor of sorts.
@@ -43,85 +45,79 @@ We now test if the arithmetic constraints tally with each of the four instructio
4345
The first instruction involves a free input $7$ and this free input is moved into registry $\texttt{A}$, as its the next value. Therefore, by definition of the selectors, $\mathtt{inFREE = 1}$ and $\mathtt{setA = 1}$. Also, the value of the other selectors is $\texttt{0}$. Substituting these values in the above arithmetic constraints yields;
4446

4547
$$
46-
\mathtt{A′ = A + 1 \cdot \big( 0 \cdot A + 0 \cdot B + 1 \cdot 7 + 0 - A \big) = A + (7 - A) = 7}\text{ } \\
48+
\mathtt{A′ = A + 1 \cdot \big( 0 \cdot A + 0 \cdot B + 1 \cdot 7 + 0 - A \big) = A + (7 - A) = 7}\text{ }
49+
$$
4750

51+
$$
4852
\mathtt{B′ = B + 0 \cdot \big( 0 \cdot A + 0 \cdot B + 1 \cdot 7 + 0 - B \big) = B}\qquad\qquad\qquad \\
4953
$$
5054

5155
This illustrates that the value of the free input was moved into $\texttt{A}$, while $\texttt{B}$ remains unaltered. Hence, the first instruction was correctly executed.
5256

5357
2. **The second instruction: "$\mathtt{3 => B}$"**
5458

55-
The second instruction involves the $\mathtt{CONST}$ column, and the constant value $\texttt{3}$ is moved into registry $\texttt{B}$, as its next value. Consequently, $\mathtt{CONST = 3}$ and $\mathtt{setB = 1}$. All other selectors have the value $\texttt{0}$. Again, substituting these values in the arithmetic constraints yields;
59+
The second instruction involves the $\mathtt{CONST}$ column, and the constant value $\texttt{3}$ is moved into registry $\texttt{B}$, as its next value. Consequently, $\mathtt{CONST = 3}$ and $\mathtt{setB = 1}$. All other selectors have the value $\texttt{0}$.
60+
61+
Again, substituting these values in the arithmetic constraints yields;
62+
63+
$$
64+
\mathtt{A′ = A + 0 \cdot \big( 0 \cdot A + 0 \cdot B + 0 \cdot FREE + 3 - A \big) = A}\qquad\qquad\qquad
5665
$$
57-
\mathtt{A′ = A + 0 \cdot \big( 0 \cdot A + 0 \cdot B + 0 \cdot FREE + 3 - A \big) = A}\qquad\qquad\qquad \\
5866

59-
\mathtt{B′ = B + 1 \cdot \big( 0 \cdot A + 0 \cdot B + 0 \cdot FREE + 3 - B \big) = B + (3 - B) = 3} \\
6067
$$
68+
\mathtt{B′ = B + 1 \cdot \big( 0 \cdot A + 0 \cdot B + 0 \cdot FREE + 3 - B \big) = B + (3 - B) = 3}
69+
$$
70+
6171
This shows that the value of $\texttt{A}$ was not changed, but the constant value $\mathtt{3}$ was moved into $\texttt{B}$. And thus, the second instruction was correctly executed.
6272

6373
3. **The third instruction, "$\mathtt{:ADD }$"**
6474

65-
This instruction involves the registries $\texttt{A}$ and $\texttt{B}$, and the result is moved into registry $\texttt{A}$, as its the next value. This means, the values of the corresponding selectors are as follows; $\mathtt{inA = 1}$, $\mathtt{inB = 1}$ and $\mathtt{setA = 1}$. The arithmetic constraints become;
75+
This instruction involves the registries $\texttt{A}$ and $\texttt{B}$, and the result is moved into registry $\texttt{A}$, as its the next value. This means, the values of the corresponding selectors are as follows; $\mathtt{inA = 1}$, $\mathtt{inB = 1}$ and $\mathtt{setA = 1}$.
76+
77+
The arithmetic constraints become;
6678

6779
$$
68-
\mathtt{A′ = A + 1 \cdot \big( 1 \cdot A + 1 \cdot B + 0 \cdot FREE + 0 - A \big) = A + (A + B - A) = A + B}\text{ } \\
80+
\mathtt{A′ = A + 1 \cdot \big( 1 \cdot A + 1 \cdot B + 0 \cdot FREE + 0 - A \big) = A + (A + B - A) = A + B}\text{ }
81+
$$
6982

70-
\mathtt{B′ = B + 0 \cdot \big( 1 \cdot A + 1 \cdot B + 0 \cdot FREE + 0 - B \big) = B}\qquad\qquad\qquad\qquad\quad \\
83+
$$
84+
\mathtt{B′ = B + 0 \cdot \big( 1 \cdot A + 1 \cdot B + 0 \cdot FREE + 0 - B \big) = B}\qquad\qquad\qquad\qquad\quad
7185
$$
7286

7387
The sum of the registry values in $\mathtt{A}$ and $\mathtt{B}$ was moved into $\texttt{A}$, while $\texttt{B}$ remains unmodified, proving that the third instruction was correctly executed.
7488

7589
4. **The fourth instruction, "$\mathtt{:END }$"**
7690

77-
The fourth instruction moves the initial registry values (i.e., $\mathtt{A = 0}$ and $\mathtt{B_0 = 0}$) into registries $\texttt{A}$ and $\texttt{B}$, as their next values, respectively. As a result, values of the corresponding selectors are; $\mathtt{setA = 1}$ and $\mathtt{setB = 1}$. Substitutions into the arithmetic constraints give us the following;
91+
The fourth instruction moves the initial registry values (i.e., $\mathtt{A = 0}$ and $\mathtt{B_0 = 0}$) into registries $\texttt{A}$ and $\texttt{B}$, as their next values, respectively. As a result, values of the corresponding selectors are; $\mathtt{setA = 1}$ and $\mathtt{setB = 1}$.
92+
93+
Substitutions into the arithmetic constraints give us the following;
7894

7995
$$
80-
\mathtt{A′ = A + 1 \cdot \big( 0 \cdot A + 0 \cdot B + 0 \cdot FREE + 0 - A \big) = A - A = 0} \\
96+
\mathtt{A′ = A + 1 \cdot \big( 0 \cdot A + 0 \cdot B + 0 \cdot FREE + 0 - A \big) = A - A = 0}
97+
$$
8198

82-
\mathtt{B′ = B + 1 \cdot \big( 0 \cdot A + 0 \cdot B + 0 \cdot FREE + 0 - B \big) = B - B = 0} \\
99+
$$
100+
\mathtt{B′ = B + 1 \cdot \big( 0 \cdot A + 0 \cdot B + 0 \cdot FREE + 0 - B \big) = B - B = 0}
83101
$$
84102

85103
Clearly, the next registry values of both $\mathtt{A}$ and $\mathtt{B}$ are reset to zeros as per the fourth instruction.
86104

87105
The execution trace can now be updated to reflect the selector columns, as shown below.
88106

89107
$$
108+
\small
90109
\begin{aligned}
91-
92-
\begin{array}{|l|c|}
93-
\hline
94-
\texttt{ }\texttt{ }\texttt{ }\texttt{ }\texttt{ }\texttt{ } \bf{Instructions }\\ \hline
95-
\texttt{ } \mathtt{\$\{getAFreeInput()\} => A} \\\hline
96-
\texttt{ } \mathtt{3 => B} \qquad\qquad\qquad\qquad\quad\\\hline
97-
\texttt{ } \mathtt{:ADD } \qquad\qquad\qquad\quad\quad\quad\text{ }\text{ }\\\hline
98-
\texttt{ } \mathtt{:END } \qquad\qquad\qquad\quad\qquad\text{}\text{ }\text{ }\\\hline
99-
\end{array}
100-
\hspace{0.1cm}
101-
102-
\begin{array}{|l|c|c|c|c|c|c|c|}\hline
103-
\texttt{FREE} & \texttt{CONST}& \texttt{setB}& \mathtt{setA}& \texttt{inFREE}& \mathtt{inB} & \mathtt{inA} \\ \hline
104-
\texttt{7} & \texttt{0} & \texttt{0} & \texttt{1} & \texttt{1} & \texttt{0} & \texttt{0} \\ \hline
105-
106-
\texttt{0} & \texttt{3} & \texttt{1} & \texttt{0} & \texttt{0} & \texttt{0} & \texttt{0} \\ \hline
107-
108-
\texttt{0} & \texttt{0} & \texttt{0} & \texttt{1} & \texttt{0} & \texttt{1} & \texttt{1} \\ \hline
109-
110-
\texttt{0} & \texttt{0} & \texttt{1} & \texttt{1} & \texttt{0} & \texttt{0} & \texttt{0} \\ \hline
111-
112-
\end{array}
113-
\hspace{0.1cm}
114-
115110
\begin{array}{|l|c|c|c|c|c|c|c|}\hline
116-
\mathtt{A} & \mathtt{A'} & \mathtt{B} & \mathtt{B'}\\\hline
117-
\mathtt{0} & \mathtt{7} & \mathtt{0} & \mathtt{0}\\\hline
118-
\mathtt{7} & \mathtt{7} & \mathtt{0} & \mathtt{3}\\\hline
119-
\mathtt{7} & \mathtt{10} & \mathtt{3} & \mathtt{3}\\\hline
120-
\mathtt{10} & \mathtt{0} & \mathtt{3} & \mathtt{0}\\\hline
111+
\texttt{ }\texttt{ }\texttt{ }\texttt{ }\texttt{ }\texttt{ } \bf{Instructions } & \texttt{FREE} & \texttt{CONST}& \texttt{setB}& \mathtt{setA}& \texttt{inFREE}& \mathtt{inB} & \mathtt{inA} & \mathtt{A} & \mathtt{A'} & \mathtt{B} & \mathtt{B'} \\ \hline
112+
\texttt{ } \mathtt{\$\{getAFreeInput()\} => A} & \texttt{7} & \texttt{0} & \texttt{0} & \texttt{1} & \texttt{1} & \texttt{0} & \texttt{0} & \mathtt{0} & \mathtt{7} & \mathtt{0} & \mathtt{0} \\ \hline
113+
\texttt{ } \mathtt{3 => B} \qquad\qquad\qquad\qquad\quad & \texttt{0} & \texttt{3} & \texttt{1} & \texttt{0} & \texttt{0} & \texttt{0} & \texttt{0} & \mathtt{7} & \mathtt{7} & \mathtt{0} & \mathtt{3} \\ \hline
114+
\texttt{ } \mathtt{:ADD } \qquad\qquad\qquad\quad\quad\quad\text{ }\text{ } & \texttt{0} & \texttt{0} & \texttt{0} & \texttt{1} & \texttt{0} & \texttt{1} & \texttt{1} & \mathtt{7} & \mathtt{10} & \mathtt{3} & \mathtt{3} \\ \hline
115+
\texttt{ } \mathtt{:END } \qquad\qquad\qquad\quad\qquad\text{}\text{ }\text{ } & \texttt{0} & \texttt{0} & \texttt{1} & \texttt{1} & \texttt{0} & \texttt{0} & \texttt{0} & \mathtt{10} & \mathtt{0} & \mathtt{3} & \mathtt{0} \\ \hline
121116
\end{array}
122117
\end{aligned}
123118
$$
124119

120+
125121
## Remarks
126122

127123
1. The $\texttt{CONST}$ column stores the constants of the computation. It should however, not be mistaken for a constant polynomial. The term 'constant' refers to the fact that the column contains constants of the computations.
@@ -173,31 +169,24 @@ That is, according to the execution trace in Table 3 above, these polynomials ar
173169
$$
174170
\begin{aligned}
175171
\mathtt{ A = [0,7,7,10]}\text{ }\text{ } \iff\text{ } \ \mathtt{ A(x) = A(\omega^i) = A[i]} \qquad\qquad\qquad\qquad\quad\text{ }\text{ }\text{ } \\
176-
177172
\mathtt{ B = [0,0,3,3] } \text{ }\text{ } \iff\text{ } \ \mathtt{ B(x) = B(\omega^i) = B[i] }\qquad\qquad\qquad\qquad\qquad\text{}\text{ } \\
178-
179-
\mathtt{ inA = [0,0,1,1]\text{ }\text{ } \iff\text{ } \ \mathtt{ inA(x) = inA(\omega^i) = inA[i]} }\qquad\qquad\quad\quad\text{}\text{ } \\
180-
173+
\mathtt{ inA = [0,0,1,1]\text{ }\text{ } \iff\text{ } \ \mathtt{ inA(x) = inA(\omega^i) = inA[i]} }\qquad\qquad\quad\text{}\text{ } \\
181174
\mathtt{ inB = [0,0,1,0] } \text{ }\text{ } \iff\text{ } \ \mathtt{inB(x) = inB(\omega^i) = inB[i]} \quad\text{}\text{}\qquad\qquad\text{ }\text{ }\text{}\text{ }\text{ }\text{ } \\
182-
183-
\mathtt{ setA = [1,0,1,1] \text{ }\text{ } \iff\text{ } \ \mathtt{ setA(x) = setA(\omega^i) = setA[i] } }\qquad\quad\text{ }\text{ }\text{ }\text{ } \\
184-
175+
\mathtt{ setA = [1,0,1,1] \text{ }\text{ } \iff\text{ } \ \mathtt{ setA(x) = setA(\omega^i) = setA[i] } }\qquad\text{ }\text{ }\text{ }\text{ } \\
185176
\mathtt{ setB = [0,1,0,1] } \text{ }\text{ } \iff\text{ } \ \mathtt{setB(x) = setB(\omega^i) = setB[i]} \qquad\qquad\text{}\\
186-
187177
\mathtt{ FREE = [7,0,0,0] }\text{ }\text{ } \iff\text{ } \ \mathtt{FREE(x) = FREE(\omega^i) = FREE[i]}\qquad\qquad\text{} \\
188-
189178
\mathtt{ CONST = [1,0,0,0] }\text{ }\text{ } \iff\text{ } \ \mathtt{CONST(x) = CONST(\omega^i) = CONST[i]}\qquad\text{} \\
190-
191179
\text{ }\mathtt{ inFREE = [1,0,0,0] } \text{ }\text{ } \iff\text{ } \ \mathtt{inFREE(x) = inFREE(\omega^i) = inFREE[i]} \\
192180
\end{aligned}
193181
$$
194182

195183
The arithmetic constraints seen above as $\bf{Eqn\ 1}$, are easily written as polynomial identities, as follows,
196184

197185
$$
186+
\begin{aligned}
198187
\mathtt{A(x\omega) - \big(A(x) + setA(x) \cdot \big( op(x) - A(x) \big) \big) = 0} \\
199-
200-
\mathtt{B(x\omega) - \big( B(x) + setB(x) \cdot \big( op(x) - B(x) \big) \big) = 0} \\
188+
\mathtt{B(x\omega) - \big( B(x) + setB(x) \cdot \big( op(x) - B(x) \big) \big) = 0}
189+
\end{aligned}
201190
$$
202191

203192
where $\mathtt{op(x) = inA(x) \cdot A(x) + inB(x) \cdot B(x) + inFREE(x) \cdot FREE(x) + CONST(x)}$.
@@ -213,7 +202,8 @@ As far as **boundary constraints** are concerned, we can, for instance,
213202
\mathtt{L1(x) \cdot \big(FREE(\omega^0) - input\big) = 0} \\
214203
\mathtt{L2(x) \cdot \big(A(\omega^{3}) - output\big) = 0}\quad \\
215204
$$
216-
where $\mathtt{L1(x)}$ and $\mathtt{L2(x)}$ are precomputed constant polynomials. In fact, $\mathtt{L1(x) = [1,0,0,0]}$ and $\mathtt{L2(x) = [0,0,0,1]}$.
205+
where $\mathtt{L1(x)}$ and $\mathtt{L2(x)}$ are precomputed constant polynomials.
206+
In fact, $\mathtt{L1(x) = [1,0,0,0]}$ and $\mathtt{L2(x) = [0,0,0,1]}$.
217207

218208
In the big scheme of things, these are Lagrange polynomials emanating from interpolation. Verification relies on the fact that: these polynomial identities, including the boundary constraints, hold true *if, and only if* the execution trace is correct and faithful to the instructions in the zkASM program.
219209

docs/zkEVM/concepts/generic-state-machine/plookup.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This subsection is part of the Generic SM and its goal is to define Plookup befo
66

77
Plookup was described by the original authors in [GW20](https://eprint.iacr.org/2020/315.pdf) as a protocol for checking whether values of a committed polynomial, over a multiplicative subgroup $\text{H}$ of a finite field $\mathbb{F}$, are contained in a vector $\mathbf{t} \in \mathbb{F}^d$ that represents values of a table $\mathcal{T}$. More precisely, Plookup is used to check if certain evaluations of some committed polynomial are part of some row $\mathbf{t}$ of a lookup table $\mathcal{T}$.
88

9-
One particular use case of this primitive is: checking whether all evaluations of a polynomial $f(x)$, restricted to values of a multiplicative subgroup $\text{H} \sub \mathbb{F}$, fall in a given range $\{ 0 , 1 , \dots , M \}$. i.e., proving that, for every $z \in \text{H}$, we have $\mathbf{f(z) \in \{ 0 , 1 , \dots , M \}}$.
9+
One particular use case of this primitive is: checking whether all evaluations of a polynomial $f(x)$, restricted to values of a multiplicative subgroup $\text{H} \subset \mathbb{F}$, fall in a given range $\{ 0 , 1 , \dots , M \}$. i.e., proving that, for every $z \in \text{H}$, we have $\mathbf{f(z) \in \{ 0 , 1 , \dots , M \}}$.
1010

1111
Plookup's strategy for soundness depends on a few basic mathematical concepts described below.
1212

@@ -114,9 +114,10 @@ In the case of a non-interactive proof/verification system, **the Trusted Party
114114
The polynomials $F$ and $G$ in the polynomial identities $\{F \equiv G\}$ are bi-variate polynomials in $\beta$ and $\gamma$, related to randomized sets of differences associated with $\{f\}$ and $\{t\}$. They are defined in terms of grand product expressions seen here,
115115

116116
$$
117+
\begin{aligned}
117118
F(\beta, \gamma) := (1+\beta)^n \cdot \prod_{i \in [n]} (\gamma + f_i) \prod_{i \in [d-1]} (\gamma (1+\beta) + t_i + \beta t_{i+1}) \\
118-
119119
G(\beta, \gamma) := \prod_{i\in[n+d-1]}(\gamma(1+\beta) + s_i + \beta s_{i+1})
120+
\end{aligned}
120121
$$
121122

122123
where $\beta$ and $\gamma$ are the randomly selected field elements.

docs/zkEVM/get-started/quick-start/connect-wallet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Navigate to `Add network` in your wallet, and enter the respective network detai
1414
Here is a video tutorial on **how to add Polygon zkEVM Testnet to MetaMask and deploy smart contracts**:
1515

1616
<video loop width="100%" height="100%" controls="true" >
17-
<source type="video/mp4" src="../../../img/zkEVM/tutorial.mp4"></source>
17+
<source type="video/mp4" src="../../../../img/zkEVM/tutorial.mp4"></source>
1818
<p>Your browser does not support the video element.</p>
1919
</video>
2020

docs/zkEVM/how-to/verify-contract.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ After successfully compiling a smart contract, follow the next steps to verify y
2828

2929
In order to flatten the contract code with Remix, one needs to only right-click on the contract name and select **Flatten** option from the drop-down menu that appears. See the below figure for reference.
3030

31-
![Selecting the flatten code option](../img/zkEVM/flatten-code-remix.png)
31+
![Selecting the flatten code option](../../img/zkEVM/flatten-code-remix.png)
3232

3333
After selecting **Flatten**, a new `.sol` file with the suffix `_flatten.sol` is automatically created. Copy the contents of the new `<Original-Name>_flatten.sol` file and paste into the `Enter the Solidity Contract` field in the explorer.
3434

0 commit comments

Comments
 (0)