Skip to content

feat(precompile): track spilled state gas in PrecompileOutput - #3820

Merged
rakita merged 1 commit into
mainfrom
feat/precompile-spilled-state-gas
Jul 23, 2026
Merged

rakita merged 1 commit into
mainfrom
feat/precompile-spilled-state-gas

Conversation

@rakita

@rakita rakita commented Jul 23, 2026

Copy link
Copy Markdown
Member

PrecompileOutput carried state_gas_used and reservoir, but not the spilled portion of the state gas (EIP-8037's state_gas_from_gas_left). The reconstructed frame gas therefore always had state_gas_spilled == 0, so:

  • a revert or halt of a precompile frame credited the spilled gas back to the reservoir instead of regular gas, and
  • a successful frame never merged it into the parent (handle_reservoir_remaining_gas).

Changes

  • PrecompileOutput::state_gas_spilled — new field, forwarded into the frame's Gas by precompile_output_to_interpreter_result.
  • PrecompileOutput::{from_gas_tracker, set_gas, to_gas_tracker} — convert between a precompile's gas accounting and a GasTracker.
  • Gas::from_tracker(GasTracker) — lift externally-tracked gas into a frame's gas; pairs with the existing tracker()/tracker_mut().
  • precompile_output_to_interpreter_result simplified on top of those: the status maps to an InstructionResult in one flat match, the overspend check becomes gas_used > gas_limit (exactly when record_regular_cost used to fail), and the gas comes straight from to_gas_tracker. Behavior unchanged.

Breaking

Adding a public field breaks external code that builds PrecompileOutput with struct-literal syntax; the new/halt/revert constructors are unaffected. No in-tree precompile sets state_gas_used yet.

Testing

  • New: precompile_output_propagates_spilled_state_gas, precompile_output_overspend_is_oog, gas_tracker_round_trip, to_gas_tracker_saturates_on_overspend.
  • cargo nextest run --workspace: 393 passed. ./scripts/run-tests.sh: 61,606 passed, 0 failed. fmt + clippy (--all-targets --all-features) clean.

Add `state_gas_spilled` to `PrecompileOutput` and forward it into the
frame's gas tracker, so a revert or halt credits the spilled portion back
to regular gas instead of the reservoir (EIP-8037).

Add `PrecompileOutput::{from_gas_tracker, set_gas, to_gas_tracker}` and
`Gas::from_tracker` to convert between a precompile's gas accounting and a
`GasTracker`, and use them to simplify
`precompile_output_to_interpreter_result`.
@codspeed

codspeed Bot commented Jul 23, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 3.5%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 180 untouched benchmarks
⏩ 1 skipped benchmark1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation blake2/2_rounds 3.2 µs 3.3 µs -3.5%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing feat/precompile-spilled-state-gas (279fc0e) with main (bc8ab33)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩

@rakita
rakita merged commit e4cf8ef into main Jul 23, 2026
32 of 33 checks passed
@rakita
rakita deleted the feat/precompile-spilled-state-gas branch July 23, 2026 12:31
@github-actions github-actions Bot mentioned this pull request Jul 23, 2026
RealiCZ added a commit to megaeth-labs/revm that referenced this pull request Sep 16, 2026
@RealiCZ RealiCZ mentioned this pull request Sep 18, 2026
3 tasks done
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.

1 participant