Skip to content

feat(tests, spec-specs): add full cost per state byte pricing function for EIP-8037#2687

Merged
spencer-tb merged 7 commits intoethereum:eips/amsterdam/eip-8037from
spencer-tb:eips/amsterdam/eip-8037-cpsb
Apr 21, 2026
Merged

feat(tests, spec-specs): add full cost per state byte pricing function for EIP-8037#2687
spencer-tb merged 7 commits intoethereum:eips/amsterdam/eip-8037from
spencer-tb:eips/amsterdam/eip-8037-cpsb

Conversation

@spencer-tb
Copy link
Copy Markdown
Contributor

@spencer-tb spencer-tb commented Apr 15, 2026

🗒️ Description

Summary

  • Un-hardcode the cost_per_state_byte pricing function in both the spec and testing framework to compute the EIP-8037 quantized value from the block gas limit
  • Add BaseFork._env_gas_limit class variable, synced automatically by the fork fixture from Environment.gas_limit (default 120M, or --block-gas-limit)
  • All downstream gas methods (gas_costs(), sstore_state_gas(), etc.) respond to the actual block gas limit — no parameter threading needed
  • Tests that set Environment(gas_limit=X) or use --block-gas-limit get the corresponding cost_per_state_byte automatically
  • Add parametrized tests across 10 block gas limits (1M to 1G) for SSTORE, CREATE, CALL, SELFDESTRUCT, auth, and refunds
  • Add underflow boundary tests at low gas limits where the quantized result falls below the offset, verifying the floor of 1

Gas Limit Flow

  1. Session start, filler plugin reads EnvironmentDefaults.gas_limit (default 120M, or --block-gas-limit) via the env_gas_limit fixture
  2. fork fixture, creates a per-test fork variant via fork.with_env_gas_limit(env_gas_limit) and monkey-patches Environment so any Environment(gas_limit=X) syncs X back to the variant's _env_gas_limit
  3. Test code, calls fork.gas_costs(), fork.sstore_state_gas(), etc. which read cls._env_gas_limit to compute cpsb
  4. Fill pipeline, state.py / blockchain.py set fork._env_gas_limit = env.gas_limit per-block before t8n execution
  5. EELS spec, state_gas_per_byte(gas_limit) receives the block gas limit from the environment and computes cpsb dynamically

Fork Calculator Split

On top of this, Mario's refactor splits the previously combined opcode-gas surface on BaseFork into three separate per-dimension maps:

  • opcode_state_map — state gas cost per opcode (cpsb multiplier or callable)
  • opcode_refund_map — regular gas refund per opcode
  • opcode_state_refund_map — state gas refund per opcode

Tests can now query each dimension independently instead of pulling a mixed regular+state value. Paired with the dynamic cpsb, opcode state-gas/refund calculations scale with the block gas limit automatically.

Remaining Fixes

A separate follow-up commit (feat(tests): remaining fixes) addresses pre-existing tests that assumed the previously-hardcoded cpsb=1174 and broke under the new dynamic computation:

  • test_state_gas_reservoir.py: pin fork._env_gas_limit in four tests so every cpsb-dependent value read matches what the block uses at execution time
  • test_bls12_variable_length_input_contracts.py: apply the default env gas limit variant in the discount-table splitter so collection-time cpsb matches runtime

Ported Static Test Fixes

A separate commit (fix(tests): drop inflated env gas_limit in ported_static) removes the gas_limit=<value> line from Environment(...) calls in 576 ported_static test files. These values were inherited as boilerplate from the original static JSON fillers (ranging from 1M to max-i64) with no functional purpose, under the old hardcoded cpsb=1174 they didn't matter, but under dynamic cpsb they caused:

  • Inflated values (1B-100B, max-i64): cpsb ballooned to tens of thousands, making SSTORE 0 to nonzero OOG with the standard tx budget
  • Deflated values (1M-30M): cpsb dropped to 1–150, shifting gas consumption enough to break Storage / Account.balance assertions

Removing the override lets Environment default to EnvironmentDefaults.gas_limit = 120M, which yields the canonical cpsb=1174 these tests were always implicitly designed against. All 576 files verified to have a single Transaction with tx.gas_limit <= 14M and no references to env.gas_limit in test logic, so the change preserves test semantics.

🔗 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).

@spencer-tb spencer-tb added A-spec-specs Area: Specification—The Ethereum specification itself (eg. `src/ethereum/*`) C-feat Category: an improvement or new feature A-tests Area: Consensus tests. labels Apr 15, 2026
@spencer-tb spencer-tb requested review from kclowes and marioevz April 15, 2026 17:02
Copy link
Copy Markdown
Contributor

@kclowes kclowes left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Member

@marioevz marioevz left a comment

Choose a reason for hiding this comment

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

Just two preliminary comments, which I think we could even apply directly to forks/amsterdam.

Comment thread packages/testing/src/execution_testing/specs/blockchain.py Outdated
@marioevz
Copy link
Copy Markdown
Member

@spencer-tb created #2690 to address the comment I made, it's not a pretty PR but it does the job, and I did an ad-hoc (not in the PR) verification in the specs/state.py file by comparing env.gas_limit to fork._env_gas_limit and it was exactly the same for all tests. PTAL.

@felix314159 felix314159 force-pushed the eips/amsterdam/eip-8037 branch from 9755dba to 3e1d7c4 Compare April 16, 2026 10:34
@spencer-tb spencer-tb force-pushed the eips/amsterdam/eip-8037-cpsb branch from 1c27d22 to 6048561 Compare April 17, 2026 12:37
@spencer-tb spencer-tb force-pushed the eips/amsterdam/eip-8037 branch from 3e1d7c4 to 44b47cc Compare April 17, 2026 16:01
@spencer-tb spencer-tb force-pushed the eips/amsterdam/eip-8037-cpsb branch from 6048561 to 4c80029 Compare April 19, 2026 19:41
@marioevz marioevz force-pushed the eips/amsterdam/eip-8037 branch from cc2cd47 to 44c4c15 Compare April 20, 2026 07:53
@marioevz marioevz force-pushed the eips/amsterdam/eip-8037-cpsb branch from 4c80029 to 0208778 Compare April 20, 2026 07:56
@spencer-tb spencer-tb force-pushed the eips/amsterdam/eip-8037 branch from 44c4c15 to de5bf67 Compare April 20, 2026 15:29
@spencer-tb spencer-tb force-pushed the eips/amsterdam/eip-8037-cpsb branch from 0b39285 to 200cc05 Compare April 20, 2026 16:39
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (eips/amsterdam/eip-8037@f5da8ef). Learn more about missing BASE report.

Additional details and impacted files
@@                    Coverage Diff                     @@
##             eips/amsterdam/eip-8037    #2687   +/-   ##
==========================================================
  Coverage                           ?   86.28%           
==========================================================
  Files                              ?      599           
  Lines                              ?    37164           
  Branches                           ?     3804           
==========================================================
  Hits                               ?    32066           
  Misses                             ?     4530           
  Partials                           ?      568           
Flag Coverage Δ
unittests 86.28% <100.00%> (?)

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

☔ View full report in Codecov by Sentry.
📢 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.

Comment thread packages/testing/src/execution_testing/forks/forks/eips/amsterdam/eip_8037.py Outdated
@spencer-tb spencer-tb force-pushed the eips/amsterdam/eip-8037-cpsb branch from c07a313 to f609e81 Compare April 20, 2026 22:29
@spencer-tb spencer-tb force-pushed the eips/amsterdam/eip-8037-cpsb branch from f609e81 to 7f41819 Compare April 20, 2026 22:47
@spencer-tb spencer-tb force-pushed the eips/amsterdam/eip-8037-cpsb branch 2 times, most recently from ba05246 to a98b09e Compare April 21, 2026 00:10
@spencer-tb spencer-tb force-pushed the eips/amsterdam/eip-8037-cpsb branch from a98b09e to a3cbac3 Compare April 21, 2026 00:13
@spencer-tb
Copy link
Copy Markdown
Contributor Author

@marioevz

Added remaining 8037 test fixes here, with TODOs, feel free to check over: 62719d8

Ported static fixes here (updated in PR desc): a3cbac3

PR desc includes the fork calculator split. We can consolidate in future PR.

Will merge once CI finally passes...

@spencer-tb spencer-tb merged commit de71eca into ethereum:eips/amsterdam/eip-8037 Apr 21, 2026
23 checks passed
spencer-tb added a commit to spencer-tb/execution-specs that referenced this pull request Apr 21, 2026
…n for EIP-8037 (ethereum#2687)

Co-authored-by: marioevz <marioevz@gmail.com>
spencer-tb added a commit that referenced this pull request Apr 21, 2026
…n for EIP-8037 (#2687)

Co-authored-by: marioevz <marioevz@gmail.com>
fselmo pushed a commit that referenced this pull request May 5, 2026
…n for EIP-8037 (#2687)

Co-authored-by: marioevz <marioevz@gmail.com>
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/*`) A-tests Area: Consensus tests. C-feat Category: an improvement or new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants