Skip to content

refactor(message): carry bytecode in Message; rename regular gas to execution gas - #329

Closed
rakita wants to merge 1 commit into
mainfrom
execute-message-refactor
Closed

rakita wants to merge 1 commit into
mainfrom
execute-message-refactor

Conversation

@rakita

@rakita rakita commented Jul 29, 2026

Copy link
Copy Markdown
Member

Stacked on #315 (base: glam-devnet-7). Moves the execute_message/Message refactors and the gas-dimension rename out of the devnet-7 PR — they are not devnet-7 spec changes. The final tree is byte-identical to what glam-devnet-7 contained before the split.

Commits

  • refactor(message): carry bytecode in Message; EIP-8037 create depth check — the message producer resolves the bytecode a frame executes (delegate code for EIP-7702 calls, initcode for creates) into Message.code, so execute_message and the interpreter no longer thread a separate bytecode argument; the EIP-2780 first-frame runtime charges move out of frame entry into prepare_initial_frame on the handler side. Also checks the call-depth limit alongside the EIP-8037 endowment/nonce pre-checks before reading the destination in CREATE/CREATE2 — a too-deep create previously read (and charged) the destination, leaking it into the EIP-7928 block access list and warm set. Mirrored in the JIT builtin; regression test asserts the read is skipped.
  • refactor(create): build the create Message at its execute_message call site — replaces MessageExt::derive_destination/init_code_hash_slow with a standalone derive_create_destination so the created address can be derived before the message exists; the interpreter create opcode and the JIT create builtin construct the fully-populated Message right before execute_message, dropping the placeholder fields and the mutate-after-build dance.
  • refactor(gas): rename the regular gas dimension to execution gas — across GasTracker, the transaction handlers, block gas accounting, and docs (TxResult::regular_gas_spent → execution_gas_spent). No functional change.

Testing

  • Head tree is identical to the pre-split glam-devnet-7 head (git diff is empty), which passed the full devnet v7.2.0 suites.
  • Each intermediate commit builds, passes cargo fmt --check, and the unit/ee-test suite.

@rakita
rakita requested review from DaniPopes and onbjerg as code owners July 29, 2026 12:51
@rakita
rakita marked this pull request as draft July 29, 2026 13:03
rakita added a commit that referenced this pull request Jul 30, 2026
)

Aligns Amsterdam to the **glamsterdam devnet-7** spec and the
`[email protected]` fixtures. All Amsterdam `state_tests`
and `blockchain_tests` pass (interpreter + JIT + AOT); no regressions in
earlier-fork state suites or the unit/ee-test suite.

Ports bluealloy/revm#3795 to evm2's architecture.

## EIP-2780 runtime gas phase (ethereum/EIPs#11844)

State-dependent transaction charges move from the intrinsic phase to a
runtime phase applied as the first frame is entered. Running out of gas
there is an **included out-of-gas halt** consuming all regular gas, not
a transaction rejection.

- **Create transactions**: account-creation state gas is charged at the
create frame's entry (`execute_create_message`), conditional on the
destination not already existing. The intrinsic `create_state_gas` and
its refund path are removed.
- **EIP-7702**: the intrinsic per-auth charge drops to the
state-independent `REGULAR_PER_AUTH_BASE_COST` (7,816); `ACCOUNT_WRITE`,
new-account, and delegation-bytes state gas are charged per authority at
runtime on a transaction-level `GasTracker` (the `RuntimeAuthCharges`
accounting), stopping at the first unaffordable charge. A runtime
out-of-gas reverts the applied delegations and includes the tx as an OOG
halt.
- **Delegated recipient (depth 0)**: resolution is deferred into the
frame (`apply_eip2780_call_charges`) and the target load is gated on gas
(`skip_cold_load`, as nested calls do), so a cold, unafforded target
stays out of the EIP-7928 block access list.
`MessageResult::runtime_gas_oog` signals a recipient-charge OOG back to
the 7702 handler so it drops the delegations too.

The CALL/CREATE runtime charges live in the shared
`execute_call_message` / `execute_create_message` (gated on `depth == 0`
+ feature, not tx type), so **all transaction types** get them; only the
authorization-specific charges are in the 7702 handler.

## Devnet-7 spec alignment

- **ethereum/EIPs#11836**: calldata floor anchored on the decomposed
intrinsic base instead of flat `TX_BASE`.
- **ethereum/EIPs#11891**: 7702 `ACCOUNT_WRITE` charged once per
authority, skipped when already paid (sender / value-recipient / a
preceding valid authorization).
- **ethereum/EIPs#11858**: `CREATE`/`CREATE2` account-creation state gas
charged conditionally at access (endowment/nonce pre-check + a single
destination read), refilled on failure. Mirrored in the JIT builtin.
- **ethereum/EIPs#11854**: `SSTORE` covers the slot's access cost before
the implicit read; an unaffordable cold access skips the read
(`Evm::sstore` now honors `skip_cold_load`).
- **EIP-8282**: builder deposit/exit system-contract addresses updated.
- **EIP-7623** floor binds the block regular-gas component
(`TxResult::regular_gas_spent = max(total - state, floor)`).

## Cleanups

- Remove the superseded devnet-6 create accounting
(`create_initial_state_gas`, `refund_create_state_gas`,
`MessageResult::created_target_was_alive`, `settle_gas`'s `is_create`
path).
- Remove `rollback_failed_execution`: failed execution is already rolled
back to the message's own checkpoint (and halt gas zeroed) inside
`execute_message`, so it was redundant.

## Follow-up refactors

- **Message construction**: `Message` now carries its `destination` —
the CREATE/CREATE2 address is derived when the message is constructed
(`Message::derive_destination`) instead of being re-derived at frame
entry.
- **EIP-7702 authorization unification**: both gas regimes share one
`apply_auth_list` loop (validate → account → apply) driven by an
`AuthAccounting` strategy — `RuntimeAuthCharges` (EIP-2780 runtime
metering, abortable mid-list) and `AuthRefunds` (pre-Amsterdam
pessimistic-intrinsic refunds, owning the EIP-8037 gating). The handler
tail funnels every exit through a single `settle` closure (`settle_oog`
for the runtime OOG halts), and `initial_gas_and_reservoir` loses its
always-zero `state_refund` parameter — the pre-Amsterdam state refund is
credited straight to the reservoir at the call site, matching
execution-specs `set_delegation`. Crate constants are now `pub`.

The `Message`-carries-bytecode refactor (with the EIP-8037 create depth
check) and the regular→execution gas rename are split out into the
stacked PR #329.

## Fixtures / harness

- Bump devnet fixtures to v7.2.0 (setup script, CI, `AGENTS.md`).
- eest: honor an explicit per-transaction `chainId` (v7 fixtures test
type-0 `INVALID_CHAINID`).

## Testing

- Amsterdam `state_tests`: 406/406; `blockchain_tests`: 657/657.
- JIT + AOT Amsterdam state suites pass on v7.2.0.
- Unit + ee-tests: 2829/2829; Prague/Osaka/Cancun/Berlin/London/Shanghai
state suites unchanged.

Two revm changes were no-ops in evm2: EIP-7708 (already implemented) and
`JournalEntry::CodeChange` recording prior code (evm2's `AccountChange`
already snapshots the full prior `AccountInfo`).
Base automatically changed from glam-devnet-7 to main July 30, 2026 09:36
@rakita
rakita marked this pull request as ready for review July 30, 2026 12:10
@DaniPopes

Copy link
Copy Markdown
Member

Superseded by #352 (bytecode in Message) and stacked #353 (execution-gas rename). Credit to @rakita is preserved in both replacement PRs.

@DaniPopes DaniPopes closed this Aug 10, 2026
@DaniPopes
DaniPopes deleted the execute-message-refactor branch August 10, 2026 20:36
DaniPopes pushed a commit that referenced this pull request Aug 10, 2026
Split the execution-gas portion out of #329. Original implementation by @rakita.
DaniPopes pushed a commit that referenced this pull request Aug 10, 2026
Split the execution-gas portion out of #329. Original implementation by @rakita.
DaniPopes added a commit that referenced this pull request Aug 10, 2026
This is the bytecode-carrying portion of #329, split out for review.
Each `Message` now carries the bytecode it executes, including top-level
and test messages.

The test cleanup standardizes `Message { ..., code: ... }` construction.
Credit to @rakita for the original implementation in #329.

---------

Co-authored-by: rakita <[email protected]>
DaniPopes pushed a commit that referenced this pull request Aug 10, 2026
Split the execution-gas portion out of #329. Original implementation by @rakita.
onbjerg added a commit that referenced this pull request Aug 11, 2026
This is the remaining portion of #329, stacked on #352. It keeps the
transaction handler and runtime-gas changes out of the bytecode-only PR,
including the regular-gas to execution-gas rename. Credit to @rakita for
the original implementation in #329.

Co-authored-by: rakita <[email protected]>

This branch was previously deployed

1 inactive deployment
codspeed — 86c59003 Deployed Aug 3, 2026 by rakita via codspeed #541
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