Skip to content

refactor(spec-specs): derive EIP-8037 state gas used from reservoir/spill - #3027

Merged
spencer-tb merged 3 commits into
ethereum:forks/amsterdamfrom
chfast:eips/amsterdam/eip-8037-derive-state-gas-used
Jul 1, 2026
Merged

spencer-tb merged 3 commits into
ethereum:forks/amsterdamfrom
chfast:eips/amsterdam/eip-8037-derive-state-gas-used

Conversation

@chfast

@chfast chfast commented Jun 19, 2026

Copy link
Copy Markdown
Member

🗒️ Description

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.

🔗 Related Issues or PRs

N/A.

✅ Checklist

  • All: Ran fast static checks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:
    just static
  • All: PR title adheres to the repo standard - it will be used as the squash commit message and should start type(scope):.
  • All: Considered updating the online docs in the ./docs/ directory.
  • All: Set appropriate labels for the changes (only maintainers can apply labels).

…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

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.22%. Comparing base (babe45c) to head (935452b).
⚠️ Report is 24 commits behind head on forks/amsterdam.

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     
Flag Coverage Δ
unittests 93.22% <100.00%> (+0.39%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@spencer-tb

Copy link
Copy Markdown
Contributor

I like this more! @kclowes & @SamWilsn wdyt?
It's a refactor for part of #2999

Comment thread src/ethereum/forks/amsterdam/vm/__init__.py
Comment thread src/ethereum/forks/amsterdam/vm/__init__.py
Comment thread src/ethereum/forks/amsterdam/vm/__init__.py Outdated
Comment thread src/ethereum/forks/amsterdam/vm/__init__.py Outdated
Comment thread src/ethereum/forks/amsterdam/vm/gas.py Outdated
@kclowes

kclowes commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

I like this refactor too! Thanks @chfast!

@spencer-tb spencer-tb added A-spec-specs Area: Specification—The Ethereum specification itself (eg. `src/ethereum/*`) C-refactor Category: refactor labels Jul 1, 2026

@spencer-tb spencer-tb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@spencer-tb
spencer-tb merged commit 9920b6e into ethereum:forks/amsterdam Jul 1, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-spec-specs Area: Specification—The Ethereum specification itself (eg. `src/ethereum/*`) C-refactor Category: refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants