Skip to content

chore: cherry-pick upstream fixes #3735 #3752 #3746 #3802 #3864 - #54

Merged
RealiCZ merged 5 commits into
mainfrom
cz/chore/upstream-fixes-batch
Sep 18, 2026
Merged

RealiCZ merged 5 commits into
mainfrom
cz/chore/upstream-fixes-batch

Conversation

@RealiCZ

@RealiCZ RealiCZ commented Sep 17, 2026

Copy link
Copy Markdown

Summary

Five independent soundness/correctness fixes merged upstream after v112, outside the earlier gas-core sweep (fork #45). Each commit is git cherry-pick -x of the upstream squash-merge, kept under the upstream subject. All five applied cleanly; no conflict resolution.

git diff origin/main..HEAD has the same stable patch-id as the concatenation of the five upstream diffs. No public-API signature change.

Commits

1. fix(interpreter): use IntoAddress in pop_address to avoid const-eval panic (#3735)

  • Upstream: 939b879a0eb5104a71076ab07a9fb9ef796c2381
  • Fork: d976ab1ba8e13cda5da83cf8716d5b91776cb4b3
  • Fixes: StackTr::pop_address used Address::from(value.to_be_bytes()), which infers ruint's Uint::<256,4>::to_be_bytes::<20>(). That const-generic has a const { assert BYTES == 32 } that some build profiles actually evaluate (coverage, release codegen) and then fail with E0080. Switch to the crate's IntoAddress (value.into_address()), which converts through a 32-byte word.
  • Fork paths: crates/interpreter/src/interpreter_types.rs
  • Fork hook next to the change? No. Amsterdam table activation lives in crates/interpreter/src/instructions.rs (enable_amsterdam_opcodes) / instructions/stack.rs (dupn_enabled / swapn_enabled / exchange_enabled). This is a default method on StackTr, a different file.

2. fix(bytecode): avoid out-of-bounds pointer in analyze_legacy (#3752)

  • Upstream: 59a5aea8dfbb42360d4814b10490e9747c82e4f9
  • Fork: f1c6b25af79a495877df4a29e8efa50679342189
  • Fixes: A trailing PUSH in analyze_legacy formed a pointer up to 33 bytes past the allocation via ptr::add (UB; Kani/Miri). wrapping_add keeps the offset defined; the existing < end guard still prevents an OOB read. Named zkVM backends as the risk; the fork's rule 5 is zkVM/no_std riscv.
  • Fork paths: crates/bytecode/src/legacy/analysis.rs
  • Fork hook next to the change? No. No pricing / history-gas / Amsterdam-table hook in the bytecode crate.

3. fix(state): re-baseline storage original_value only across tx boundaries (#3746)

  • Upstream: 84fe60ca382aa903180d6e49ecd156d2aa6a1957
  • Fork: 238801a313344d0b5740caebcc6747055775c857
  • Fixes: EvmStorageSlot::mark_warm_with_transaction_id re-baselined EIP-2200 original_value whenever is_cold_transaction_id was true. That predicate is also true for a slot flagged cold inside the same tx (reverted StorageWarmed / mark_cold). Key the re-baseline on transaction-id mismatch only, matching geth's GetCommittedState vs access-list split. Latent: standard execution already keeps original_value across an in-tx cold re-warm because a modification requires a prior warm, and a reverted checkpoint reverts both; the new keying is the spec-correct one.
  • Fork paths: crates/state/src/lib.rs
  • Fork hook next to the change? No. The pricing hook that reads original_value for SSTORE state-gas is in crates/interpreter/src/instructions/host.rs (state_gas_charge) and the Host defaults in crates/context/interface/src/host.rs. This commit only changes how the slot records the baseline.

4. fix(context): keep is_empty on EIP-7702 account in load_account_delegated (#3802)

  • Upstream: 41e8b33652ef61e3b09a90b814eb97ec58012ae1
  • Fork: 805bbc2ee5dd8c84dc806a8bb0e4b1e494be69ea
  • Fixes: The Host::load_account_delegated default overwrote AccountLoad::is_empty with the delegate account's flag. A value CALL to a delegated EOA whose delegate is empty would then be charged new-account gas (regular + 8037 state gas). Empty/creation-cost checks must reflect the callee, matching JournalInner::load_account_delegated (which already kept the callee's is_empty).
  • Fork paths: crates/context/interface/src/host.rs (one-line deletion in the default method + a 171-line regression test)
  • Fork hook next to the change? Same file, not the same method. The pricing hook (Host::state_gas_price / state_gas_charge) sits in the Config section of this trait, ~90 lines above. The deleted line is in the Journal section. History gas is in gas.rs / frame.rs. Amsterdam table activation is in instructions/stack.rs. None of those three hooks were edited.
  • CALL path: revm's own CALL path is unaffected. crates/interpreter/src/instructions/contract/call_helpers.rs is a free function load_account_delegated that:
    1. loads the callee via Host::load_account_info_skip_cold_load (not Host::load_account_delegated);
    2. checks account.is_empty before loading the delegate and returns early on a new-account charge;
    3. is unchanged in origin/main..HEAD.
      No in-tree caller except the new unit test and examples/cheatcode_inspector (the latter forwards to JournalTr::load_account_delegated, already correct). This bites a consumer that calls the Host default itself (mega-evm's revm-27 engine overrides and delegates to inner.load_account_delegated).

5. fix(interpreter): return MemoryOOG when memory resize fails (#3864)

  • Upstream: 3660eeb0d1f5d586cc49e1bd93a7533a95ddbb4c
  • Fork: 901101d5119e858049d457a5a0b0e46f8bdbc338
  • Fixes: resize_memory_cold ignored MemoryTr::resize's bool. SharedMemory::resize always returns true, so no observable change on the default memory; a custom MemoryTr (zkVM memory) that returns false would otherwise proceed and later access out of bounds. Now returns InstructionResult::MemoryOOG.
  • Fork paths: crates/interpreter/src/interpreter/shared_memory.rs
  • Fork hook next to the change? No. The function still charges via gas.record_regular_cost (regular gas). History gas lives on Gas / GasTracker in crates/interpreter/src/gas.rs and is merged in crates/handler/src/frame.rs. This hunk does not touch history gas.

Semver

Touched crates from scripts/mega/crates.txt: revm-bytecode, revm-context-interface, revm-interpreter, revm-state. No signature change; expect api:superset (no api:exception).

Out of scope

The gas-core follow-ups (upstream bluealloy#3893, and the system-call reservoir margin that upstream bluealloy#3892 introduced and bluealloy#3903 reverted) land in separate pull requests.

Labels checklist

mega:cherry-pick, api:superset.

pjdurden and others added 5 commits September 17, 2026 20:46
…panic (bluealloy#3735)

* fix(interpreter): use IntoAddress in pop_address to avoid const-eval panic

`StackTr::pop_address` converted the popped word with
`Address::from(value.to_be_bytes())`. Since `Address: From<[u8; 20]>`, type
inference forces ruint's const-generic `Uint::<256, 4>::to_be_bytes::<20>()`,
whose `const { Self::assert_bytes(BYTES) }` requires `BYTES == Self::BYTES`
(32 for U256). That unreachable const block is only sometimes dead-code
eliminated; build profiles that actually evaluate it (cargo-fuzz coverage,
release codegen) hit `error[E0080]: BYTES must be equal to Self::BYTES`,
breaking downstream builds (bluealloy#3728).

Use the crate's existing `IntoAddress` converter (`value.into_address()`),
which does `Address::from_word(B256::from(value.to_be_bytes()))`. Its
`to_be_bytes()` infers the correct `[u8; 32]` size, so there is no fragile
const-generic instantiation, and `pop_address` now reuses the canonical
U256->Address conversion instead of inlining its own.

Add a regression test asserting `pop_address` truncates a full 32-byte word to
its low 20 bytes and returns `None` on an empty stack.

Closes bluealloy#3728

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* test(interpreter): drop pop_address regression test per review

Remove `pop_address_truncates_to_low_20_bytes` as requested in review on
bluealloy#3735 — the truncation behaviour is covered by the shared `IntoAddress`
conversion path and the dedicated test is not needed.

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
(cherry picked from commit 939b879)
…ies (bluealloy#3746)

`EvmStorageSlot::mark_warm_with_transaction_id` resets `original_value` to
`present_value` whenever the slot is cold. But `is_cold_transaction_id` is true
both on a genuine transaction-id mismatch AND when the `is_cold` flag is set
within the same transaction (e.g. a reverted `StorageWarmed` entry, or an
explicit `mark_cold`).

The EIP-2200 "original"/committed value is transaction-scoped and independent of
the EIP-2929 access list, so it should only be re-baselined when the slot
genuinely belongs to a previous transaction. Key the re-baseline on the
transaction-id mismatch instead of `is_cold`.

This matches go-ethereum, where the EIP-2200 original (`GetCommittedState`,
backed by pending/origin storage) is fully decoupled from the access list
(`SlotInAccessList`). No observable change for standard execution — all state
tests and ~97k blockchain tests pass identically — but it removes a latent
coupling that would corrupt `original_value` for any caller that marks a slot
cold mid-transaction.

(cherry picked from commit 84fe60c)
…ated (bluealloy#3802)

Do not overwrite AccountLoad::is_empty with the delegate account's flag.
Empty-account / creation-cost checks must reflect the caller account,
matching JournalInner::load_account_delegated.

(cherry picked from commit 41e8b33)
…y#3864)

MemoryTr::resize can fail for custom memory implementations; ignore that result and later accesses can go out of bounds.
(cherry picked from commit 3660eeb)
@RealiCZ RealiCZ added mega:cherry-pick Upstream commits brought in unchanged apart from recorded conflicts api:superset Public API stays a superset of the baseline labels Sep 17, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-17T14:24:57.014617Z 901101d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@mega-maxwell

mega-maxwell Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Claude review status

Living comment — rewritten in place. The review workflow keeps this single comment up to date instead of posting a new one each round, so it always describes the latest reviewed commit and the earlier text is intentionally gone. No reply is needed here; reply to a finding in its own review thread, and answer an open question in a reply on this PR. The next review round reconciles your answer.

🛠️ Review did not finish

Attempted head 901101d5 · updated 2026-09-17T14:22:43+00:00

This round did not publish: MODEL_ACTION_FAILED in phase review_retry. Anything listed below is from the last round that did. Re-run the workflow or push a new commit to try again.

@RealiCZ
RealiCZ merged commit a65435f into main Sep 18, 2026
37 of 43 checks passed
@RealiCZ
RealiCZ deleted the cz/chore/upstream-fixes-batch branch September 18, 2026 01:50
RealiCZ added a commit that referenced this pull request Sep 18, 2026
…backend (#66)

## Summary

Two rules for upstream picks, learned from the first batches (#54, #57)
and from how alloy-rs/evm2 backports revm precompile work:

- picks are batched by crate or subsystem, one pull request per batch,
so one reviewer can read a whole batch;
- a pick that touches a precompile is tested under mutually exclusive
feature sets (the `std`-only fallback run, the default set,
`--all-features`, and the single backend feature it changes), because
`--all-features` selects only the preferred backend in each `cfg_if!`
block.

`REVIEW.md`'s `mega:cherry-pick` row names both.

## API exceptions

None (documentation only).

## Test plan

The mutually exclusive feature sets were run on `main` at 43485bf for
the perf picks in #57: `--no-default-features --features std` (every
fallback) 57/57, `std,blst` 57/57, `std,c-kzg` 57/57, the default set
57/57, `--all-features` 57/57.

## Labels checklist

`mega:ci`, `api:superset`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api:superset Public API stays a superset of the baseline mega:cherry-pick Upstream commits brought in unchanged apart from recorded conflicts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants