Skip to content

Commit 9590d79

Browse files
authored
Update EIP-4762: reworked gas schedule from interop
Merged by EIP-Bot.
1 parent 4a18d8b commit 9590d79

File tree

2 files changed

+84
-76
lines changed

2 files changed

+84
-76
lines changed

EIPS/eip-4762.md

Lines changed: 64 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
eip: 4762
33
title: Statelessness gas cost changes
44
description: Changes the gas schedule to reflect the costs of creating a witness by requiring clients update their database layout to match.
5-
author: Guillaume Ballet (@gballet), Vitalik Buterin (@vbuterin), Dankrad Feist (@dankrad)
5+
author: Guillaume Ballet (@gballet), Vitalik Buterin (@vbuterin), Dankrad Feist (@dankrad), Ignacio Hagopian (@jsign), Tanishq Jasoria (@tanishqjasoria), Gajinder Singh (@g11tech)
66
discussions-to: https://ethereum-magicians.org/t/eip-4762-statelessness-gas-cost-changes/8714
77
status: Draft
88
type: Standards Track
@@ -39,47 +39,42 @@ We define access events as follows. When an access event takes place, the access
3939

4040
#### Access events for account headers
4141

42-
When a non-precompile address is the target of a `CALL`, `CALLCODE`, `DELEGATECALL`, `SELFDESTRUCT`, `EXTCODESIZE`, or `EXTCODECOPY` opcode, or is the target address of a contract creation whose initcode starts execution, process these access events:
42+
When:
4343

44-
```
45-
(address, 0, VERSION_LEAF_KEY)
46-
(address, 0, CODE_SIZE_LEAF_KEY)
47-
```
44+
1. a non-precompile address is the target of a `*CALL`, `SELFDESTRUCT`, `EXTCODESIZE`, or `EXTCODECOPY` opcode,
45+
2. a non-precompile address is the target address of a contract creation whose initcode starts execution,
46+
3. any address is the target of the `BALANCE` opcode
47+
4. a _deployed_ contract calls `CODECOPY`
4848

49-
If a call is value-bearing (ie. it transfers nonzero wei), whether or not the callee is a precompile, process these two access events:
49+
process this access events:
5050

5151
```
52-
(caller_address, 0, BALANCE_LEAF_KEY)
53-
(callee_address, 0, BALANCE_LEAF_KEY)
52+
(address, 0, BASIC_DATA_LEAF_KEY)
5453
```
5554

56-
When a contract is created, process these access events:
57-
58-
```
59-
(contract_address, 0, VERSION_LEAF_KEY)
60-
(contract_address, 0, NONCE_LEAF_KEY)
61-
(contract_address, 0, BALANCE_LEAF_KEY)
62-
(contract_address, 0, CODE_KECCAK_LEAF_KEY)
63-
(contract_address, 0, CODE_SIZE_LEAF_KEY)
64-
```
55+
Note: a non-value-bearing `SELFDESTRUCT` or `*CALL`, targetting a precompile, will not cause the `BASIC_DATA_LEAF_KEY` to be added to the witness.
6556

66-
If the `BALANCE` opcode is called targeting some address, process this access event:
57+
If a `*CALL` or `SELFDESTRUCT` is value-bearing (ie. it transfers nonzero wei), whether or not the callee is a precompile, process this additional access event:
6758

6859
```
69-
(address, 0, BALANCE_LEAF_KEY)
60+
(origin, 0, BASIC_DATA_LEAF_KEY)
7061
```
7162

72-
If the `SELFDESTRUCT` opcode is called by some caller_address targeting some target_address (regardless of whether it’s value-bearing or not), process access events of the form:
63+
Note: when checking for the existence of the callee, the existence check is done by validating that there is an extension-and-suffix tree at the corresponding stem, and does not rely on `CODEHASH_LEAF_KEY`.
64+
65+
When calling `EXTCODEHASH` on a non-precompile target, process the access event:
7366

7467
```
75-
(caller_address, 0, BALANCE_LEAF_KEY)
76-
(target_address, 0, BALANCE_LEAF_KEY)
68+
(address, 0, CODEHASH_LEAF_KEY)
7769
```
7870

79-
If the `EXTCODEHASH` opcode is called targeting some address, process an access event of the form:
71+
Note that precompiles are excluded, as their hashes are known to the client.
72+
73+
When a contract is created, process these access events:
8074

8175
```
82-
(address, 0, CODEHASH_LEAF_KEY)
76+
(contract_address, 0, BASIC_DATA_LEAF_KEY)
77+
(contract_address, 0, CODEHASH_LEAF_KEY)
8378
```
8479

8580
#### Access events for storage
@@ -120,34 +115,29 @@ We define **write events** as follows. Note that when a write takes place, an ac
120115

121116
#### Write events for account headers
122117

123-
When a nonzero-balance-sending `CALL` or `SELFDESTRUCT` with a given sender and recipient takes place, process these write events:
118+
When a nonzero-balance-sending `*CALL` or `SELFDESTRUCT` with a given sender and recipient takes place, process these write events:
124119

125120
```
126-
(sender, 0, BALANCE_LEAF_KEY)
127-
(recipient, 0, BALANCE_LEAF_KEY)
121+
(origin, 0, BASIC_DATA_LEAF_KEY)
122+
(target, 0, BASIC_DATA_LEAF_KEY)
128123
```
129124

130-
When a contract creation is initialized, process these write events:
125+
if no account exists at `callee_address`, also process:
131126

132127
```
133-
(contract_address, 0, VERSION_LEAF_KEY)
134-
(contract_address, 0, NONCE_LEAF_KEY)
128+
(target, 0, CODEHASH_LEAF_KEY)
135129
```
136130

137-
Only if the value sent with the creation is nonzero, also process:
131+
When a contract creation is initialized, process these write events:
138132

139133
```
140-
(contract_address, 0, BALANCE_LEAF_KEY)
134+
(contract_address, 0, BASIC_DATA_LEAF_KEY)
141135
```
142136

143137
When a contract is created, process these write events:
144138

145139
```
146-
(contract_address, 0, VERSION_LEAF_KEY)
147-
(contract_address, 0, NONCE_LEAF_KEY)
148-
(contract_address, 0, BALANCE_LEAF_KEY)
149-
(contract_address, 0, CODE_KECCAK_LEAF_KEY)
150-
(contract_address, 0, CODE_SIZE_LEAF_KEY)
140+
(contract_address, 0, CODEHASH_LEAF_KEY)
151141
```
152142

153143
#### Write events for storage
@@ -174,36 +164,31 @@ When a contract is created, process the write events:
174164

175165
For `i` in `0 ... (len(code)+30)//31`.
176166

167+
Note: since no access list existed for code up until this EIP, note that no warm costs are charged for code accesses.
168+
177169
### Transactions
178170

179171
#### Access events
180172

181173
For a transaction, make these access events:
182174

183175
```
184-
(tx.origin, 0, VERSION_LEAF_KEY)
185-
(tx.origin, 0, BALANCE_LEAF_KEY)
186-
(tx.origin, 0, NONCE_LEAF_KEY)
187-
(tx.origin, 0, CODE_SIZE_LEAF_KEY)
188-
(tx.origin, 0, CODE_KECCAK_LEAF_KEY)
189-
(tx.target, 0, VERSION_LEAF_KEY)
190-
(tx.target, 0, BALANCE_LEAF_KEY)
191-
(tx.target, 0, NONCE_LEAF_KEY)
192-
(tx.target, 0, CODE_SIZE_LEAF_KEY)
193-
(tx.target, 0, CODE_KECCAK_LEAF_KEY)
176+
(tx.origin, 0, BASIC_DATA_LEAF_KEY)
177+
(tx.origin, 0, CODEHASH_LEAF_KEY)
178+
(tx.target, 0, BASIC_DATA_LEAF_KEY)
179+
(tx.target, 0, CODEHASH_LEAF_KEY)
194180
```
195181

196182
#### Write events
197183

198184
```
199-
(tx.origin, 0, NONCE_LEAF_KEY)
185+
(tx.origin, 0, BASIC_DATA_LEAF_KEY)
200186
```
201187

202-
if `value` is non-zero:
188+
If `value` is non-zero:
203189

204190
```
205-
(tx.origin, 0, BALANCE_LEAF_KEY)
206-
(tx.target, 0, BALANCE_LEAF_KEY)
191+
(tx.target, 0, BASIC_DATA_LEAF_KEY)
207192
```
208193

209194
### Witness gas costs
@@ -216,15 +201,15 @@ Remove the following gas costs:
216201

217202
Reduce gas cost:
218203

219-
* `CREATE` to 1000
204+
* `CREATE`/`CREATE2` to 1000
220205

221206
|Constant |Value|
222207
|-|-|
223-
|`WITNESS_BRANCH_COST` |1900|
208+
|`WITNESS_BRANCH_COST`|1900|
224209
|`WITNESS_CHUNK_COST` |200|
225210
|`SUBTREE_EDIT_COST` |3000|
226-
|`CHUNK_EDIT_COST` |500|
227-
|`CHUNK_FILL_COST` |6200|
211+
|`CHUNK_EDIT_COST` |500|
212+
|`CHUNK_FILL_COST` |6200|
228213

229214
When executing a transaction, maintain four sets:
230215

@@ -251,6 +236,13 @@ When a **write** event of `(address, sub_key, leaf_key)` occurs, perform the fol
251236

252237
Note that tree keys can no longer be emptied: only the values `0...2**256-1` can be written to a tree key, and 0 is distinct from `None`. Once a tree key is changed from `None` to not-`None`, it can never go back to `None`.
253238

239+
Note that values should only be added to the witness if there is sufficient gas to cover their associated event costs.
240+
241+
`CREATE*` and `*CALL` reserve 1/64th of the gas before the nested execution. In order to match the behavior of this charge with the pre-fork behavior of access lists:
242+
243+
* this minimum 1/64th gas reservation is checked **AFTER** charging the witness costs when performing a `CALL`, `CODECALL`, `DELEGATECALL` or`STATICCALL`
244+
* this 1/64th of the gas is subtracted **BEFORE** charging the witness costs when performing a `CREATE` or `CREATE2`
245+
254246
### Replacement for access lists
255247

256248
We replace [EIP-2930](./eip-2930.md) access lists with an SSZ structure of the form:
@@ -268,6 +260,22 @@ class AccessSubtree(Container):
268260
elements: BitVector[256]
269261
```
270262

263+
### Block-level operations
264+
265+
None of:
266+
267+
* Precompile accounts, system contract accounts and slots of a system contract that are accessed during a system call,
268+
* The coinbase account
269+
* Withdrawal accounts
270+
271+
are warm at the start of a transaction.
272+
273+
Note: When (and only when) calling a system contract _via a system call_, the code chunks and account should not appear in the witness.
274+
275+
### Account abstraction
276+
277+
TODO : still waiting on a final decision between 7702 and 3074
278+
271279
## Rationale
272280

273281
### Gas reform

EIPS/eip-6800.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
eip: 6800
33
title: Ethereum state using a unified verkle tree
44
description: This introduces a new Verkle state tree alongside the existing MPT.
5-
author: Vitalik Buterin (@vbuterin), Dankrad Feist (@dankrad), Kevaundray Wedderburn (@kevaundray), Guillaume Ballet (@gballet), Piper Merriam (@pipermerriam), Gottfried Herold (@GottfriedHerold)
5+
author: Vitalik Buterin (@vbuterin), Dankrad Feist (@dankrad), Kevaundray Wedderburn (@kevaundray), Guillaume Ballet (@gballet), Piper Merriam (@pipermerriam), Gottfried Herold (@GottfriedHerold), Ignacio Hagopian (@jsign), Tanishq Jasoria (@tanishqjasoria), Gajinder Singh (@g11tech), Danno Ferrin (@shemnon)
66
discussions-to: https://ethereum-magicians.org/t/proposed-verkle-tree-scheme-for-ethereum-state/5805
77
status: Draft
88
type: Standards Track
@@ -115,11 +115,8 @@ Instead of a two-layer structure as in the Patricia tree, in the Verkle tree we
115115

116116
| Parameter | Value |
117117
| --------------------- | ------- |
118-
| VERSION_LEAF_KEY | 0 |
119-
| BALANCE_LEAF_KEY | 1 |
120-
| NONCE_LEAF_KEY | 2 |
121-
| CODE_KECCAK_LEAF_KEY | 3 |
122-
| CODE_SIZE_LEAF_KEY | 4 |
118+
| BASIC_DATA_LEAF_KEY | 0 |
119+
| CODE_KECCAK_LEAF_KEY | 1 |
123120
| HEADER_STORAGE_OFFSET | 64 |
124121
| CODE_OFFSET | 128 |
125122
| VERKLE_NODE_WIDTH | 256 |
@@ -157,25 +154,28 @@ def get_tree_key(address: Address32, tree_index: int, sub_index: int):
157154
bytes([sub_index])
158155
)
159156
160-
def get_tree_key_for_version(address: Address32):
161-
return get_tree_key(address, 0, VERSION_LEAF_KEY)
162-
163-
def get_tree_key_for_balance(address: Address32):
164-
return get_tree_key(address, 0, BALANCE_LEAF_KEY)
165-
166-
def get_tree_key_for_nonce(address: Address32):
167-
return get_tree_key(address, 0, NONCE_LEAF_KEY)
157+
def get_tree_key_for_basic_data(address: Address32):
158+
return get_tree_key(address, 0, BASIC_DATA_LEAF_KEY)
168159
169160
# Backwards compatibility for EXTCODEHASH
170161
def get_tree_key_for_code_keccak(address: Address32):
171162
return get_tree_key(address, 0, CODE_KECCAK_LEAF_KEY)
172-
173-
# Backwards compatibility for EXTCODESIZE
174-
def get_tree_key_for_code_size(address: Address32):
175-
return get_tree_key(address, 0, CODE_SIZE_LEAF_KEY)
176163
```
177164

178-
When any account header field is set, the `version` is also set to zero. The `code_keccak` and `code_size` fields are set upon contract creation.
165+
An account's `version`, `balance`, `nonce` and `code_size` fields are packed in the value found at `BASIC_DATA_LEAF_KEY`:
166+
167+
| Name | Offset | Size |
168+
| ----------- | ------ | ---- |
169+
| `version` | 0 | 1 |
170+
| `code_size` | 5 | 3 |
171+
| `nonce` | 8 | 8 |
172+
| `balance` | 16 | 16 |
173+
174+
Bytes `1..4` are reserved for future use.
175+
176+
Note: the code size is stored on 3 bytes. To allow for an extension to 4 bytes without changing the account version is possible, reserved byte #4 should be allocated last.
177+
178+
When any account header field is set, the `version` field is also set to zero. The `code_keccak` and `code_size` fields are set upon contract or EoA creation.
179179

180180
#### Code
181181

@@ -239,7 +239,7 @@ Note that storage slots in the same size `VERKLE_NODE_WIDTH` range (ie. a range
239239

240240
#### Fork
241241

242-
TODO - see specific EIP
242+
Described in [EIP-7612](./eip-7612.md).
243243

244244
#### Access events
245245

0 commit comments

Comments
 (0)