Skip to content

fix(eip8037): place the system call state-gas margin in the reservoir - #3892

Merged
rakita merged 1 commit into
bluealloy:mainfrom
RealiCZ:cz/fix/eip8037-system-call-reservoir
Sep 3, 2026
Merged

rakita merged 1 commit into
bluealloy:mainfrom
RealiCZ:cz/fix/eip8037-system-call-reservoir

Conversation

@RealiCZ

@RealiCZ RealiCZ commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

EIP-8037 sizes the system call gas limit as 30_000_000 + STATE_BYTES_PER_STORAGE_SET × CPSB × SYSTEM_MAX_SSTORES_PER_CALL and specifies that "the additional STATE_BYTES_PER_STORAGE_SET × CPSB × SYSTEM_MAX_SSTORES_PER_CALL is placed in state_gas_reservoir while the rest of the system call's gas is placed in gas_left" (EIP-8037, "System contracts and system transactions"). execution-specs does the same: the Amsterdam system transaction is built with execution_gas_grant=SYSTEM_TRANSACTION_GAS (30M) and state_gas_reservoir=StateGasCosts.STORAGE_SET * SYSTEM_MAX_SSTORES_PER_CALL (src/ethereum/forks/amsterdam/fork.py, process_system_transaction).

#3672 adopted the new limit but kept building the system call gas through tx_gas with an all-zero InitialAndFloorGas. That path lifts the EIP-7825 cap to u64::MAX for system calls, so the whole 31,566,720 lands in gas_left and the reservoir is 0. The SYSTEM_CALL_GAS_LIMIT doc comment ("the base 30M regular-gas budget plus a state-gas reservoir") already describes the intended split.

Observable differences against the spec today:

  • GAS inside a system contract reports 31,566,718 instead of 29,999,998.
  • Every state-gas charge in a system call spills into regular gas (state_gas_spilled grows), so a revert inside the system call credits it back to gas_left instead of the reservoir.

The four mainnet system contracts (EIP-2935/4788/7002/7251) do not branch on gasleft(), so this does not change their results; it changes what a system contract can observe and how state gas is settled on its failure paths.

Changes

  • SYSTEM_CALL_GAS_LIMIT is now expressed as SYSTEM_CALL_REGULAR_GAS_LIMIT (30M) + SYSTEM_CALL_STATE_GAS_RESERVOIR; both constants are public.
  • New Handler::system_call_gas (default method) builds the system call GasTracker: with EIP-8037 enabled, everything above the regular budget goes to the reservoir; without it the whole limit stays regular gas. run_system_call and inspect_run_system_call use it instead of tx_gas.
  • Test test_system_call_eip8037_state_gas_reservoir: a system contract running GAS PUSH0 SSTORE STOP under SpecId::AMSTERDAM stores 29_999_998 and the fresh-slot SSTORE is accounted as SSTORE_SET_BYTES × CPSB state gas.

No change for configurations without EIP-8037; total_gas_spent of a system call is unchanged (it already subtracts the reservoir).

Verification

  • cargo nextest run -p revm-handler -p revm-inspector: 48 passed
  • cargo nextest run -p revm-ee-tests -E 'test(eip8037) | test(system_call)': 43 passed
  • cargo clippy -p revm-handler -p revm-inspector --all-targets --all-features: clean; cargo fmt --all --check: clean; RUSTDOCFLAGS=-D warnings cargo doc -p revm-handler --no-deps: clean
  • The new test fails on main (6014612) with left: 31566718, right: 29999998 and passes with this change.

EIP-8037 puts the additional SSTORE_SET_BYTES * CPSB * SYSTEM_MAX_SSTORES_PER_CALL
of a system call into state_gas_reservoir and the base 30M into gas_left;
execution-specs builds the Amsterdam system transaction the same way.
run_system_call went through tx_gas with a zero InitialAndFloorGas, which lifts
the EIP-7825 cap and lands the whole 31,566,720 in gas_left with an empty
reservoir, so GAS inside a system contract read 31,566,718 instead of 29,999,998
and every state-gas charge spilled into regular gas.

Split SYSTEM_CALL_GAS_LIMIT into SYSTEM_CALL_REGULAR_GAS_LIMIT and
SYSTEM_CALL_STATE_GAS_RESERVOIR, add Handler::system_call_gas that applies the
split when EIP-8037 is enabled, and use it from both the plain and the
inspected system call paths.
@RealiCZ
RealiCZ force-pushed the cz/fix/eip8037-system-call-reservoir branch from 91a5e35 to 8ee288d Compare September 3, 2026 07:02
@codspeed

codspeed Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 218 untouched benchmarks
⏩ 9 skipped benchmarks1


Comparing RealiCZ:cz/fix/eip8037-system-call-reservoir (8ee288d) with main (6014612)

Open in CodSpeed

Footnotes

  1. 9 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@rakita rakita left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cool, lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants