Commit 2119b38
authored
refactor(spec-specs): organize gas logic in amsterdam EIP-8037/8038/2780 (#3159)
* refactor(spec-specs, tools): bundle amsterdam frame gas into GasMeter
Gather the flat gas fields on Evm into a GasMeter dataclass in
vm/gas.py and replace the scattered hand-rolled gas arithmetic with
named operations:
- State-gas rollback becomes self-contained on the meter: a
state_gas_baseline field records the reservoir level a rollback
refills to (the frame's grant at entry), commit_state_gas folds
everything consumed since the baseline into state_gas_committed and
moves the baseline down (zeroing the spill, so post-commit refunds
route to the reservoir), restore_state_gas refills to the baseline
on revert or halt, and restore_state_gas_to_entry undoes the commit
when the transaction rollback also reverts the applied delegations.
Message.state_gas_reservoir is never mutated after construction.
- Frame lifecycle helpers (refill/commit and credit_state_gas_refund)
move from vm/__init__.py into vm/gas.py; incorporate_child_on_*
stay as thin wrappers over the new absorb_child_gas_on_* meter
operations.
- Inline arithmetic in interpreter.py (burn-all-gas), system.py
(reservoir handoffs) and fork.py (EIP-8037 split, refund + floor
settlement) becomes forfeit_remaining_gas, withhold_create_gas,
drain_state_gas_reservoir, restore_child_gas, allocate_execution_gas
and settle_transaction_gas; tx_state_gas_used measures the top
frame's net state gas at settlement.
- t8n tracer protocols gain gas-layout accessors so both the flat and
gas-meter Evm shapes trace through one code path.
The meter carries no per-frame regular-gas counter: since #3005 the
block's regular-gas dimension is derived from transaction totals
(tx.gas - gas_left - state_gas_left, floor-bound), so a frame-level
counter would only ever be charged, discounted across sub-calls, and
forfeited on halts without being read.
The identifiers avoid "frame" (restore_child_gas, tx_state_gas_used,
withhold_create_gas) ahead of EIP-8141, which will give the term a
protocol meaning.
Behavior-preserving: verified with ruff, mypy, ethereum-spec-lint,
vulture, spec-tools, json_loader tracing on Amsterdam and Osaka, and
the EIP-8037/2780/7778 fill battery.
* refactor(spec-specs): name the gas stages in amsterdam opcodes
Give the two-dimensional gas choreography named stages so structurally
corresponding code sits in structurally corresponding places:
- CALL*/CREATE* wrappers price the opcode in labeled sections --
GAS (STATE-INDEPENDENT) computes and affordability-checks everything
that needs no state access, STATE ACCESS (STATE-DEPENDENT GAS)
performs the accesses and completes the pricing, STATE GAS holds the
account-creation charge, and CHILD GRANT withholds the child's
regular share and drains the reservoir in one block.
- generic_call and generic_create reduce to the child-frame lifecycle
(PREFLIGHT, DESTINATION ACCESS, DISPATCH, OUTCOME): grant
withholding and all charging move to the wrappers, and the balance
preflight folds into generic_call via
GenericCall.insufficient_balance, unifying the abort-without-spawn
paths.
- The same stage labels apply to sstore and selfdestruct, the two
other opcodes with state-gas stages; single-stage opcodes keep the
bare GAS marker.
- Frame-settlement comments on the process_message handlers state the
postcondition the parent-side absorb relies on.
Behavior-preserving: statement order of every charge, check, and
trace event is unchanged; verified with the EIP-8037/2780/7778 fill
battery and the full static suite.
* refactor(spec-specs): unify amsterdam child-frame incorporation
Discard a failed frame's refunds in restore_state_gas, alongside the
state gas rollback, instead of ignoring them at the absorption sites.
Every settled meter now states exactly what the frame gives back, so
a single incorporate_child replaces the on-success/on-error pair (and
the absorb_child_gas_on_* helpers): gas is absorbed unconditionally,
while logs, self-destructs, and warmed access sets survive only on
success. The top frame's refund read in process_message_call becomes
unconditional for the same reason.
* chore(tooling): document gas handling rules in implement-eip skill
Capture the two-dimensional gas philosophy from the Amsterdam gas
refactors so future sessions do not re-derive it: gas movements are
named GasMeter helpers in vm/gas.py, opcodes price in labeled stages
with all charging before the operation, generic_call/generic_create
run only the child-frame lifecycle, and gas changes are verified by
preserving charge/check/trace order against the fill tests.
* fix static test fails1 parent a45205c commit 2119b38
11 files changed
Lines changed: 872 additions & 394 deletions
File tree
- .claude/commands
- src
- ethereum_spec_tools/evm_tools/t8n/evm_trace
- ethereum/forks/amsterdam
- vm
- instructions
- tests/amsterdam/eip8037_state_creation_gas_cost_increase
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
35 | 47 | | |
36 | 48 | | |
37 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
| 111 | + | |
110 | 112 | | |
111 | 113 | | |
112 | 114 | | |
| |||
1032 | 1034 | | |
1033 | 1035 | | |
1034 | 1036 | | |
1035 | | - | |
1036 | | - | |
1037 | 1037 | | |
1038 | 1038 | | |
1039 | 1039 | | |
| |||
1055 | 1055 | | |
1056 | 1056 | | |
1057 | 1057 | | |
1058 | | - | |
1059 | | - | |
1060 | | - | |
1061 | | - | |
1062 | | - | |
1063 | | - | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
1064 | 1061 | | |
1065 | 1062 | | |
1066 | 1063 | | |
| |||
1087 | 1084 | | |
1088 | 1085 | | |
1089 | 1086 | | |
1090 | | - | |
1091 | | - | |
| 1087 | + | |
| 1088 | + | |
1092 | 1089 | | |
1093 | 1090 | | |
1094 | 1091 | | |
| |||
1102 | 1099 | | |
1103 | 1100 | | |
1104 | 1101 | | |
1105 | | - | |
1106 | | - | |
1107 | | - | |
1108 | | - | |
1109 | | - | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
1110 | 1109 | | |
1111 | | - | |
1112 | 1110 | | |
1113 | | - | |
1114 | | - | |
1115 | | - | |
1116 | | - | |
1117 | | - | |
1118 | | - | |
| 1111 | + | |
1119 | 1112 | | |
1120 | 1113 | | |
1121 | 1114 | | |
1122 | | - | |
| 1115 | + | |
1123 | 1116 | | |
1124 | 1117 | | |
1125 | 1118 | | |
1126 | 1119 | | |
1127 | 1120 | | |
1128 | 1121 | | |
1129 | 1122 | | |
1130 | | - | |
1131 | | - | |
1132 | | - | |
1133 | | - | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
1138 | | - | |
| 1123 | + | |
| 1124 | + | |
1139 | 1125 | | |
1140 | 1126 | | |
1141 | | - | |
| 1127 | + | |
1142 | 1128 | | |
1143 | 1129 | | |
1144 | 1130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
173 | | - | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
178 | 177 | | |
179 | 178 | | |
180 | 179 | | |
| |||
183 | 182 | | |
184 | 183 | | |
185 | 184 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | 185 | | |
196 | 186 | | |
197 | | - | |
| 187 | + | |
198 | 188 | | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
223 | 200 | | |
224 | 201 | | |
225 | 202 | | |
| |||
228 | 205 | | |
229 | 206 | | |
230 | 207 | | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
| 208 | + | |
337 | 209 | | |
338 | 210 | | |
339 | | - | |
340 | | - | |
341 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
342 | 236 | | |
343 | 237 | | |
344 | 238 | | |
| |||
0 commit comments