You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/zkEVM/architecture/zkprover/main-state-machine/index.md
+44-44Lines changed: 44 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,31 +1,31 @@
1
-
Main State Machine is a component of the zkProver that can be instantiated with various computations pertaining to transactions submitted by users to the Polygon zkEVM network.
1
+
Main state machine is a component of the zkProver that can be instantiated with various computations pertaining to transactions submitted by users to the Polygon zkEVM network.
2
2
3
-
In addition to carrying out these computations, the Main SM also generates fixed-length, easy-to-verify cryptographic proofs of Computational Integrity (CI). These proofs can be verified by spending only a minimal amount of computational resources.
3
+
In addition to carrying out these computations, the main SM also generates fixed-length, easy-to-verify cryptographic proofs of Computational Integrity (CI). These proofs can be verified by spending only a minimal amount of computational resources.
4
4
5
5
It achieves this by using cutting-edge zero-knowledge technology. In particular, these proofs are STARK proofs that are recursively aggregated into one STARK proof, which is in turn proved with a SNARK proof. This last SNARK proof is published as the validity proof. You can read a summary of the STARK proofs recursion [here](index.md), and its complete documentation [here](../stark-recursion/index.md).
The ROM is a program written in zero-knowledge Assembly (zkASM) and contains all the instructions the Main SM must execute. It is to the Polygon zkEVM what the EVM Interpreter is to Ethereum. Since the ROM is in fact analogous to computer memory, it is named with a well-known acronym that stands for **Read-Only Memory**.
11
+
The ROM is a program written in zero-knowledge Assembly (zkASM) and contains all the instructions the main SM must execute. It is to the Polygon zkEVM what the EVM Interpreter is to Ethereum. Since the ROM is in fact analogous to computer memory, it is named with a well-known acronym that stands for **Read-Only Memory**.
12
12
13
-
The Main SM can be viewed as a processor capable of interpreting a set of instructions, and the ROM as the memory containing the firmware. The term firmware here refers to a piece of low-level software that is infrequently subjected to changes.
13
+
The main SM can be viewed as a processor capable of interpreting a set of instructions, and the ROM as the memory containing the firmware. The term firmware here refers to a piece of low-level software that is infrequently subjected to changes.
14
14
15
15
It is a piece of software, composed of a set of instructions, which implements a special EVM interpreter for Polygon zkEVM's L2 architecture.
16
16
17
-
All EVM opcodes are interpreted in the ROM, as well as interpretation of batches and the execution logic of transactions. The ROM is therefore the interpreter of all opcodes to the Polygon zkEVM, allowing the Main SM to execute Polygon zkEVM's L2 state transitions with Computational Integrity (CI).
17
+
All EVM opcodes are interpreted in the ROM, as well as interpretation of batches and the execution logic of transactions. The ROM is therefore the interpreter of all opcodes to the Polygon zkEVM, allowing the main SM to execute Polygon zkEVM's L2 state transitions with Computational Integrity (CI).
18
18
19
19
!!!info
20
20
In order to avoid any misunderstandings in the future, it is helpful to distinguish between the set of ROM instructions and EVM opcodes:
21
21
22
-
**ROM Instructions** → Set of instructions created and developed by Polygon to target a ”special” zero-knowledge virtual machine (Main SM) that can execute computations with probable Computational Integrity (CI).
22
+
**ROM Instructions** → Set of instructions created and developed by Polygon to target a ”special” zero-knowledge virtual machine (main SM) that can execute computations with probable Computational Integrity (CI).
23
23
24
24
**EVM opcodes** → Set of instructions designed to target the EVM, used to define smart contract’s computations.
25
25
26
26
Although zkASM instructions and EVM opcodes are different types of instructions, the Polygon zkEVM's ROM contains a piece of code written in zkASM instructions to implement each EVM opcode.
27
27
28
-
## Public Parameters
28
+
## Public parameters
29
29
30
30
Polygon zkEVM's proofs of Computational Integrity (CI) are zero-knowledge proofs. That is, the proofs do not reveal any information about the executed computations to effect the state transition.
31
31
@@ -59,11 +59,11 @@ Here is a complete list of the public parameters;
59
59
60
60
-`forkID`: the fork ID is a unique identifier of the version of the ROM that is currently being used. It ensures that computations can only be proved and verified for a specific version of the ROM code.
61
61
62
-
## State Trie
62
+
## State trie
63
63
64
64
The state of a Blockchain is typically recorded in the form of a Merkle Tree. Both the EVM and the Polygon zkEVM store their states in their respective especially modified Merkle Trees.
65
65
66
-
### EVM State Trie
66
+
### EVM state trie
67
67
68
68
An Ethereum state is stored in the form of a **Modified Patricia Merkle Tree**.
69
69
@@ -89,7 +89,7 @@ Here is how the tree in the EVM looks like:
89
89
90
90

91
91
92
-
### zkEVM State Trie
92
+
### zkEVM state trie
93
93
94
94
There are some differences between the zkEVM Merkle tree and EVM Merkle tree.
95
95
@@ -113,49 +113,49 @@ The figure below depicts the 5 leaf-types together with the corresponding keys:
113
113
114
114

115
115
116
-
## Memory Regions
116
+
## Memory regions
117
117
118
118
Memory is a volatile Read-Write data storage that exists only during the execution of a ROM instruction.
119
119
120
-
In Ethereum, whenever a call is made, a new **Context** together with its new Stack and new Memory is created. Each created **Context** is referred to as volatile because it is temporarily available for the call being executed.
120
+
In Ethereum, whenever a call is made, a new **context** together with its new stack and new Memory is created. Each created **context** is referred to as volatile because it is temporarily available for the call being executed.
121
121
122
-
### zkEVM Memory map
122
+
### zkEVM memory map
123
123
124
-
The Polygon zkEVM uses Context-based Memory. And, by **Context** we refer to an environment of every Ethereum call.
124
+
The Polygon zkEVM uses context-based Memory. And, by **context** we refer to an environment of every Ethereum call.
125
125
126
-
As in Ethereum, when a transactions begins, a new Context is created for that transaction:
126
+
As in Ethereum, when a transactions begins, a new context is created for that transaction:
The `Stack` and `Memory` are each filled with relevant values in accordance with the call that has been made. Similar to how the EVM uses the Stack, zkEVM operations can be performed by pushing and popping values on and off the Stack.
132
+
The `Stack` and `Memory` are each filled with relevant values in accordance with the call that has been made. Similar to how the EVM uses the stack, zkEVM operations can be performed by pushing and popping values on and off the stack.
133
133
134
-
`Memory` is divided into different Contexts of $\mathtt{0x40000}$ words.
134
+
`Memory` is divided into different contexts of $\mathtt{0x40000}$ words.
135
135
136
-
Each word is $256$ bits in length, so each Context is $8$ Megabytes (MB) in size.
136
+
Each word is $256$ bits in length, so each context is $8$ Megabytes (MB) in size.
137
137
138
-
#### Contexts in Memory
138
+
#### Contexts in memory
139
139
140
-
There can be several Contexts within one transaction. Specific registers are used to handle any necessary switching between Contexts as pertaining to the made call.
140
+
There can be several contexts within one transaction. Specific registers are used to handle any necessary switching between contexts as pertaining to the made call.
141
141
142
-
As depicted in the figure below, each Context is divided into three word-blocks. And these are:
142
+
As depicted in the figure below, each context is divided into three word-blocks. And these are:
143
143
144
-
-`VARS`: contains the local Context's variables which are pre-defined in the language.
144
+
-`VARS`: contains the local context's variables which are pre-defined in the language.
145
145
146
-
It has a relative offset of `0x00000` and a height of `0x10000` words (taking $2$ MB of the $8$ MB allocated for a Context).
146
+
It has a relative offset of `0x00000` and a height of `0x10000` words (taking $2$ MB of the $8$ MB allocated for a context).
147
147
148
-
The list of all Context variables can be found in the [`vars.zkasm`](https://github.com/0xPolygonHermez/zkevm-rom/blob/main/main/vars.zkasm) file.
148
+
The list of all context variables can be found in the [`vars.zkasm`](https://github.com/0xPolygonHermez/zkevm-rom/blob/main/main/vars.zkasm) file.
149
149
150
-
-`STACK`: contains the stack of the EVM. So, a `STACK` is defined per Context.
150
+
-`STACK`: contains the stack of the EVM. So, a `STACK` is defined per context.
151
151
152
-
It has a relative offset of `0x10000`, a height of `0x10000` words and takes $2$MB of the $8$MB allocated for a Context.
152
+
It has a relative offset of `0x10000`, a height of `0x10000` words and takes $2$MB of the $8$MB allocated for a context.
153
153
154
154
-`MEM`: contains the free memory that can be freely used.
155
155
156
-
It has a relative offset of `0x20000`, a height of `0x20000` words and takes $4$ MB of the $8$ MB allocated for a Context.
156
+
It has a relative offset of `0x20000`, a height of `0x20000` words and takes $4$ MB of the $8$ MB allocated for a context.
157
157
158
-
`MEM`, like `STACK`, is also defined per Context.
158
+
`MEM`, like `STACK`, is also defined per context.
159
159
160
160

161
161
@@ -167,46 +167,46 @@ $$
167
167
168
168
where,
169
169
170
-
-`CTX`: an integer variable indicating to the Context being accessed in the EVM’s memory.
171
-
-`isStack`: a Boolean value indicating whether the Memory operation being performed is related to the EVM’s Stack or not.
172
-
-`SP`: a variable referring to the current position of the Stack Pointer in the EVM’s stack. The Stack Pointer keeps track of the top of the Stack.
170
+
-`CTX`: an integer variable indicating to the context being accessed in the EVM’s memory.
171
+
-`isStack`: a Boolean value indicating whether the Memory operation being performed is related to the EVM’s stack or not.
172
+
-`SP`: a variable referring to the current position of the stack Pointer in the EVM’s stack. The stack Pointer keeps track of the top of the stack.
173
173
-`isMem`: a Boolean value indicating whether the Memory operation being performed is related to the EVM’s memory. Observe that `isStack` and `isMem` cannot be $1$ at the same time.
174
-
-`offset`: a set `addr` in Memory to which the `zkPC` jumps to within the currently accessed Context.
174
+
-`offset`: a set `addr` in Memory to which the `zkPC` jumps to within the currently accessed context.
175
175
176
-
### Memory Alignment
176
+
### Memory alignment
177
177
178
178
There is a major difference between the EVM Memory and the zkEVM Memory.
179
179
180
180
That difference is the EVM Memory is created in the form of slots where each slot has $8$-bit capacity, while each Memory slot in the zkEVM can store $256$ bits of data.
181
181
182
182
It was therefore necessary to align the EVM's $8$-bit slots with the zkEVM's $256$-bit slots.
183
183
184
-
A mapping to synchronize the two Memories comes in the form a special state machine called the [**Mem-Align State Machine**](../mem-align-sm.md). It is a specialized SM solely dealing with the alignment of the EVM Memory with the zkEVM Memory.
184
+
A mapping to synchronize the two Memories comes in the form a special state machine called the [**Mem-Align state machine**](../mem-align-sm.md). It is a specialized SM solely dealing with the alignment of the EVM Memory with the zkEVM Memory.
185
185
186
186

187
187
188
-
### zkEVM Stack
188
+
### zkEVM stack
189
189
190
-
The zkEVM Stack is exactly the same as the EVM Stack except for the number of steps. It has $65536$ steps instead of $1024$.
190
+
The zkEVM stack is exactly the same as the EVM stack except for the number of steps. It has $65536$ steps instead of $1024$.
191
191
192
-
Note that the EVM works with $256$-bit words, and thus the elements of the EVM Stack are also $256$-bit.
192
+
Note that the EVM works with $256$-bit words, and thus the elements of the EVM stack are also $256$-bit.
193
193
194
-
The zkEVM Stack therefore, with its $8 \times 32$-bits representation of values, naturally mimics the $256$-bit architecture of the EVM Stack.
194
+
The zkEVM stack therefore, with its $8 \times 32$-bits representation of values, naturally mimics the $256$-bit architecture of the EVM stack.
195
195
196
-
But since there are more steps in the zkEVM Stack than the $1024$ slots of the EVM Stack, only the first $1024$ slots of the zkEVM Stack are used for the EVM Stack.
196
+
But since there are more steps in the zkEVM stack than the $1024$ slots of the EVM stack, only the first $1024$ slots of the zkEVM stack are used for the EVM stack.
197
197
198
-
The rest of the zkEVM Stack slots are used to store `CALLDATA` and its interpretation.
198
+
The rest of the zkEVM stack slots are used to store `CALLDATA` and its interpretation.
199
199
200
-
The figure below displays a schematic representation of the zkEVM Stack and the EVM Stack:
200
+
The figure below displays a schematic representation of the zkEVM stack and the EVM stack:
201
201
202
-

202
+

203
203
204
204
## TLDR
205
205
206
206
→ The ROM is a program written in zkASM. It contains the instructions that the zkProver must execute in order to produce verifiable Computational Integrity proofs. The ROM contains the rules and logic that form the firmware of the zkProver. Its code can be found [here](https://github.com/0xPolygonHermez/zkevm-rom) in the GitHub repository.
207
207
208
208
→ The zkEVM uses SMT with five different leaf types.
209
209
210
-
→ Memory alignment between the EVM and the zkEVM is handled by a specialist state machine, the [**Mem-Align State Machine**](../mem-align-sm.md).
210
+
→ Memory alignment between the EVM and the zkEVM is handled by a specialist state machine, the [**Mem-Align state machine**](../mem-align-sm.md).
211
211
212
-
→ The two Stacks are exactly the same except that the zkEVM has many more slots compared to the EVM.
212
+
→ The two stacks are exactly the same except that the zkEVM has many more slots compared to the EVM.
0 commit comments