refactor(spec-specs): derive EIP-8037 state gas used from reservoir/spill - #3027
Merged
spencer-tb merged 3 commits intoJul 1, 2026
Conversation
…pill
The EIP-8037 reservoir model tracked three running per-frame quantities:
the reservoir (`state_gas_left`), the amount spilled into `gas_left`
(`state_gas_spilled`), and the net consumed (`state_gas_used`). The
third is redundant: at every point a frame's net state gas equals
(reservoir_at_entry - state_gas_left) + state_gas_spilled
This invariant is preserved by every charge, refund, and child
incorporation, so `state_gas_used` no longer needs to be maintained.
Drop the `state_gas_used` field and compute it on demand:
- `charge_state_gas`, `credit_state_gas_refund`, and
`incorporate_child_on_success` no longer update the counter.
- `refill_frame_state_gas` resets the reservoir to its frame-entry value
`message.state_gas_reservoir` (the LIFO inverse of the frame's charges)
instead of folding `state_gas_used` back in.
- New helper `frame_state_gas_used` derives the value at frame end; it is
read only when building the `MessageCallOutput`.
Behavior is unchanged. Verified by filling the full Amsterdam suite
(6686 passed, 0 failed), producing fixtures identical to the
three-counter model.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## forks/amsterdam #3027 +/- ##
===================================================
+ Coverage 92.82% 93.22% +0.39%
===================================================
Files 620 624 +4
Lines 36719 36936 +217
Branches 3342 3377 +35
===================================================
+ Hits 34086 34433 +347
+ Misses 1773 1709 -64
+ Partials 860 794 -66
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
10 tasks
chfast
commented
Jun 19, 2026
SamWilsn
reviewed
Jun 19, 2026
28 tasks
Contributor
|
I like this refactor too! Thanks @chfast! |
This was referenced Jun 24, 2026
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🗒️ Description
The EIP-8037 reservoir model tracked three running per-frame quantities: the reservoir (
state_gas_left), the amount spilled intogas_left(state_gas_spilled), and the net consumed (state_gas_used). The third is redundant: at every point a frame's net state gas equalsThis invariant is preserved by every charge, refund, and child incorporation, so
state_gas_usedno longer needs to be maintained.Drop the
state_gas_usedfield and compute it on demand:charge_state_gas,credit_state_gas_refund, andincorporate_child_on_successno longer update the counter.refill_frame_state_gasresets the reservoir to its frame-entry valuemessage.state_gas_reservoir(the LIFO inverse of the frame's charges) instead of foldingstate_gas_usedback in.frame_state_gas_usedderives the value at frame end; it is read only when building theMessageCallOutput.Behavior is unchanged. Verified by filling the full Amsterdam suite (6686 passed, 0 failed), producing fixtures identical to the three-counter model.
🔗 Related Issues or PRs
N/A.
✅ Checklist
just statictype(scope):.