Skip to content

fix(engine): use caller's gas state on precompile cache hits#23328

Open
decofe wants to merge 1 commit intotip1016from
draganrakita/fix-precompile-cache-tip1016
Open

fix(engine): use caller's gas state on precompile cache hits#23328
decofe wants to merge 1 commit intotip1016from
draganrakita/fix-precompile-cache-tip1016

Conversation

@decofe
Copy link
Copy Markdown
Member

@decofe decofe commented Apr 1, 2026

Cached precompile results stored the full GasTracker from the original
execution, including reservoir and state_gas_spent. On cache hits, returning
that stale tracker overwrote the caller's live gas state — corrupting EIP-8037
reservoir accounting by restoring already-spent reservoir gas and zeroing
state_gas_spent.

Builds a fresh GasTracker from the caller's current gas_limit and
reservoir on cache hits, replaying only the cached regular gas cost.
Also preserves the reverted flag from the cached output.

Same fix applied to the precompile-cache example: caches only output
bytes, gas cost, and reverted flag; uses map_cacheable_precompiles
to skip identity and stateful precompiles.

Prompted by: Dragan

Cached precompile results stored the full GasTracker from the original
execution, including reservoir and state_gas_spent. On cache hits,
returning that stale tracker overwrote the caller's live gas state,
corrupting EIP-8037 reservoir accounting.

Build a fresh GasTracker from the caller's current gas_limit and
reservoir on cache hits, replaying only the cached regular gas cost.
Also preserve the reverted flag from cached output.

Fixes the same bug in the precompile-cache example: store only output
bytes, gas cost, and reverted flag; use map_cacheable_precompiles to
skip identity and stateful precompiles.

Co-Authored-By: rakita <13179220+rakita@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

⚠️ Changelog not found.

A changelog entry is required before merging. We've generated a suggested changelog based on your changes:

Preview
---
reth-engine-tree: patch
example-precompile-cache: patch
---

Fixed precompile cache hits to use the caller's current gas limit and reservoir instead of stale cached values, preventing corruption of EIP-8037 state gas accounting. Updated the example to store only output bytes and gas cost in the cache, reconstructing the `GasTracker` on cache hits from live caller state.

Add changelog to commit this to your branch.

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants