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
- Misc cleanup
- Recategorized and *reordered* instructions
- Updated instruction expressions to match context structure in
high-level spec
- Removed opcode numbers from section titles as it makes links ugly
- Removed opcode numbers from images so they don't need to be
regenerated for now
- `in-tag` -> `inTag`, same with `dstTag`
- Intro Instruction Set section with some relevant notes
- Removed misc `*ROOT` opcodes in favor of `BLOCKHEADERBYNUM` opcode
- Cleanup in high-level avm spec
-[**Execution context**](#execution-context), outlining the AVM's environment and state
25
-
-[**Execution**](#execution), outlining control flow, gas tracking, halting, and reverting
25
+
-[**Execution**](#execution), outlining control flow, gas tracking, normal halting, and exceptional halting
26
26
-[**Initial contract calls**](#initial-contract-calls), outlining the initiation of a contract call from a public execution request
27
27
-[**Nested contract calls**](#nested-contract-calls), outlining the initiation of a contract call from an instruction as well as the processing of nested execution results, gas refunds, and state reverts
28
28
@@ -69,14 +69,13 @@ ExecutionEnvironment {
69
69
address: AztecAddress,
70
70
storageAddress: AztecAddress,
71
71
origin: AztecAddress,
72
-
l1GasPrice: field,
73
-
l2GasPrice: field,
74
-
daGasPrice: field,
75
72
sender: AztecAddress,
76
73
portal: AztecAddress,
77
-
blockHeader: BlockHeader,
78
-
globalVariables: PublicGlobalVariables,
74
+
feePerL1Gas: field,
75
+
feePerL2Gas: field,
76
+
feePerDaGas: field,
79
77
contractCallDepth: field,
78
+
globals: PublicGlobalVariables,
80
79
isStaticCall: boolean,
81
80
isDelegateCall: boolean,
82
81
calldata: [field; <calldata-length>],
@@ -95,7 +94,7 @@ MachineState {
95
94
daGasLeft: field,
96
95
pc: field = 0,
97
96
internalCallStack: Vector<field> = [], // initialized as empty
98
-
memory: [field; 32768] = [0, ..., 0], // all 32768 (2^32) entries are initialized to zero
97
+
memory: [field; 2^32] = [0, ..., 0], // all 2^32 entries are initialized to zero
99
98
}
100
99
```
101
100
@@ -121,7 +120,7 @@ WorldState {
121
120
contracts: AztecAddress => {bytecode, portalAddress}, // read-only from within AVM
122
121
blockHeaders: Vector<BlockHeader>, // read-only from within AVM
l1ToL2Messages: (AztecAddress, field) => message, // read-only from within AVM
123
+
l1ToL2Messages: field => message, // read-only from within AVM
125
124
l2ToL1Messages: Vector<[field; <msg-length>]>, // append-only (no reads) from within AVM
126
125
noteHashes: Vector<field>, // append-only (no reads) from within AVM
127
126
nullifiers: Vector<field>, // append-only (no reads) from within AVM
@@ -217,7 +216,7 @@ machineState.daGasLeft = 0
217
216
218
217
An instruction's gas cost is meant to reflect the computational cost of generating a proof of its correct execution. For some instructions, this computational cost changes based on inputs. Here are some examples and important notes:
219
218
-[`JUMP`](./instruction-set/#isa-section-jump) is an example of an instruction with constant gas cost. Regardless of its inputs, the instruction always incurs the same `l1GasCost`, `l2GasCost`, and `daGasCost`.
220
-
- The [`SET`](./instruction-set/#isa-section-set) instruction operates on a different sized constant (based on its `dst-type`). Therefore, this instruction's gas cost increases with the size of its input.
219
+
- The [`SET`](./instruction-set/#isa-section-set) instruction operates on a different sized constant (based on its `dstTag`). Therefore, this instruction's gas cost increases with the size of its input.
221
220
- Instructions that operate on a data range of a specified "size" scale in cost with that size. An example of this is the [`CALLDATACOPY`](./instruction-set/#isa-section-calldatacopy) argument which copies `copySize` words from `environment.calldata` to `machineState.memory`.
222
221
- The [`CALL`](./instruction-set/#isa-section-call)/[`STATICCALL`](./instruction-set/#isa-section-call)/`DELEGATECALL` instruction's gas cost is determined by its `*Gas` arguments, but any gas unused by the nested contract call's execution is refunded after its completion ([more on this later](#updating-the-calling-context-after-nested-call-halts)).
223
222
- An instruction with "offset" arguments (like [`ADD`](./instruction-set/#isa-section-add) and many others), has increased cost for each offset argument that is flagged as "indirect".
@@ -226,11 +225,11 @@ An instruction's gas cost is meant to reflect the computational cost of generati
226
225
227
226
> An instruction's gas cost takes into account the costs of associated downstream computations. An instruction that triggers accesses to the public data tree (`SLOAD`/`SSTORE`) incurs a cost that accounts for state access validation in later circuits (public kernel or rollup). A contract call instruction (`CALL`/`STATICCALL`/`DELEGATECALL`) incurs a cost accounting for the nested call's complete execution as well as any work required by the public kernel circuit for this additional call.
228
227
229
-
## Halting
228
+
###Halting
230
229
231
230
A context's execution can end with a **normal halt** or **exceptional halt**. A halt ends execution within the current context and returns control flow to the calling context.
232
231
233
-
### Normal halting
232
+
####Normal halting
234
233
235
234
A normal halt occurs when the VM encounters an explicit halting instruction ([`RETURN`](./instruction-set#isa-section-return) or [`REVERT`](./instruction-set#isa-section-revert)). Such instructions consume gas normally and optionally initialize some output data before finally halting the current context's execution.
> `results.output` is only relevant when the caller is a contract call itself. In other words, it is only relevant for [nested contract calls](#nested-contract-calls). When an [initial contract call](#initial-contract-calls) (initiated by a public execution request) halts normally, its `results.output` is ignored.
248
247
249
-
### Exceptional halting
248
+
####Exceptional halting
250
249
251
250
An exceptional halt is not explicitly triggered by an instruction but instead occurs when an exceptional condition is met.
memory = [0, ..., 0], // all 32768 (2^32) entries are initialized to zero
465
+
memory = [0, ..., 0], // all 2^32 entries are initialized to zero
469
466
}
470
467
```
471
468
> The nested context's machine state's `*GasLeft` is initialized based on the call instruction's `gasOffset` argument. The caller allocates some amount of L1, L2, and DA gas to the nested call. It does so using the instruction's `gasOffset` argument. In particular, prior to the contract call instruction, the caller populates `M[gasOffset]` with the nested context's initial `l1GasLeft`. Likewise it populates `M[gasOffset+1]` with `l2GasLeft` and `M[gasOffset+2]` with `daGasLeft`.
0 commit comments