Skip to content

chore: cherry-pick precompile cache memory limit fix from paradigmxyz/reth v1.11.4#188

Merged
constwz merged 1 commit into
developfrom
cherry/precompile-cache-relax-limits
May 14, 2026
Merged

chore: cherry-pick precompile cache memory limit fix from paradigmxyz/reth v1.11.4#188
constwz merged 1 commit into
developfrom
cherry/precompile-cache-relax-limits

Conversation

@constwz
Copy link
Copy Markdown
Contributor

@constwz constwz commented May 14, 2026

Summary

Cherry-picks upstream commit 2ac58a2 (tagged as v1.11.4 in paradigmxyz/reth) which bounds the precompile cache by actual byte usage instead of entry count.

Motivation

Before this change, PrecompileCache was configured with MAX_CACHE_SIZE = 10_000 interpreted by moka as a max entry count (default weigher = 1 per entry). Because the cache stores precompile inputs/outputs whose sizes are attacker-controllable (e.g. IDENTITY, MODEXP), an adversary could fill the cache with large entries and balloon node memory well into the hundreds of MB range with only 10,000 cached results.

Change

crates/engine/tree/src/tree/precompile_cache.rs:

  • Add .weigher(|key, value| (key.len() + value.output.bytes.len()) as u32) so each entry's weight equals the bytes it actually holds.
  • Raise the capacity constant to 1024 * 1024, which under the new weigher means ≈1 MiB total bytes instead of 10,000 entries.

Net effect: precompile cache memory is now hard-bounded at ~1 MiB regardless of per-entry size, eliminating the unbounded-growth surface.

Test plan

  • cargo check -p reth-engine-tree passes
  • CI green
  • Optional targeted test run: cargo test -p reth-engine-tree precompile_cache

Upstream reference

🤖 Generated with Claude Code

@constwz constwz requested a review from joey0612 as a code owner May 14, 2026 09:00
@constwz constwz merged commit 3c86476 into develop May 14, 2026
42 of 49 checks passed
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.

4 participants