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: yellow-paper/docs/public-vm/avm.md
+84-2
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@ A contract's public bytecode is a series of execution instructions for the AVM.
38
38
Many terms and definitions here are borrowed from the [Ethereum Yellow Paper](https://ethereum.github.io/yellowpaper/paper.pdf).
39
39
:::
40
40
41
-
An "Execution Context" includes the information necessary to trigger AVM execution along with the state maintained by the AVM throughout execution:
41
+
An "Execution Context" includes the information necessary to initiate AVM execution along with the state maintained by the AVM throughout execution:
42
42
```
43
43
AVMContext {
44
44
environment: ExecutionEnvironment,
@@ -51,12 +51,13 @@ AVMContext {
51
51
52
52
The first two entries, "Execution Environment" and "Machine State", share the same lifecycle. They contain information pertaining to a single message call and are initialized prior to the start of a call's execution.
53
53
54
-
> When a nested message call is made, a new environment and machine state are initialized by the caller. In other words, a nested message call has its own environment and machine state, although their initialization will be partially derived from the caller's context.
54
+
> When a nested message call is made, a new environment and machine state are initialized by the caller. In other words, a nested message call has its own environment and machine state which are _partially_ derived from the caller's context.
55
55
56
56
The "Execution Environment" is fully specified by a message call's execution agent and remains constant throughout a call's execution.
57
57
```
58
58
ExecutionEnvironment {
59
59
address,
60
+
storageAddress,
60
61
origin,
61
62
l1GasPrice,
62
63
l2GasPrice,
@@ -68,6 +69,7 @@ ExecutionEnvironment {
68
69
globalVariables: PublicGlobalVariables,
69
70
messageCallDepth,
70
71
isStaticCall,
72
+
isDelegateCall,
71
73
}
72
74
```
73
75
@@ -77,6 +79,86 @@ MachineState {
77
79
l1GasLeft,
78
80
l2GasLeft,
79
81
pc,
82
+
memory: offset => value, // uninitialized at start
83
+
}
84
+
```
85
+
86
+
"World State" contains persistable VM state. If a message call succeeds, its world state updates are applied to the calling context (whether that be a parent call's context or the transaction context). If a message call fails, its world state updates are rejected by its caller. When a _transaction_ succeeds, its world state updates persist into future transactions.
noteHashes: (address, index) => noteHash, // read & append only
91
+
nullifiers: (address, index) => nullifier, // read & append only
92
+
l1l2messageHashes: (address, key) => messageHash, // read only
93
+
contracts: (address) => bytecode, // read only
94
+
}
95
+
```
96
+
97
+
> Note: the notation `key => value` describes a mapping from `key` to `value`.
98
+
99
+
> Note: each member of the world state is implemented as an independent merkle tree with different properties.
100
+
101
+
The "Accrued Substate", as coined in the [Ethereum Yellow Paper](https://ethereum.github.io/yellowpaper/paper), contains information that is accrued throughout transaction execution to be "acted upon immediately following the transaction." These are append-only arrays containing state that is not relevant to other calls or transactions. Similar to world state, if a message call succeeds, its substate is appended to its calling context, but if it fails its substate is dropped by its caller.
102
+
```
103
+
AccruedSubstate {
104
+
logs: [], // append-only
105
+
l2toL1Messages: [], // append-only
106
+
}
107
+
```
108
+
109
+
Finally, when a message call halts, it sets the context's "Message Call Results" to communicate results to the caller.
110
+
```
111
+
MessageCallResults {
112
+
reverted: boolean,
113
+
output: [] | undefined,
114
+
}
115
+
```
116
+
117
+
### Context initialization for initial call
118
+
This section outlines AVM context initialization specifically for a **public execution request's initial message call** (_i.e._ not a nested message call). Context initialization for nested message calls will be explained in a later section.
119
+
120
+
When AVM execution is initiated for a public execution request, the AVM context is initialized as follows:
121
+
```
122
+
context = AVMContext {
123
+
environment: INITIAL_EXECUTION_ENVIRONMENT,
124
+
machineState: INITIAL_MACHINE_STATE,
125
+
accruedSubstate: empty,
126
+
worldState: <latest world state>,
127
+
results: INITIAL_MESSAGE_CALL_RESULTS,
128
+
}
129
+
```
130
+
> Note: Since world state persists between transactions, the latest state is injected into a new AVM context.
131
+
132
+
Given a `PublicCallRequest` and its parent `TxRequest`, these above-listed "`INITIAL_*`" entries are defined as follows:
> Note: unlike memory in the Ethereum Virtual Machine, uninitialized memory in the AVM is not readable! A memory cell must be written (and therefore [type-tagged](./state-model#types-and-tagged-memory)) before it can be read.
0 commit comments