Repository navigation
Amsterdam and fork selection - #22
Merged
Merged
Conversation
`Config.fork` selects a fork, and `Rules` gives its rules as constants. `transact`, `simulate`, `validate` and `Vm::run` match the fork once and run code generic over its `Rules` type, so each fork compiles to its own interpreter and opcodes never check the fork. Handlers carry the type in `Cursor<F>`. Osaka is the only fork; the cold account access cost is its first rule.
Add `Fork::Amsterdam` with `Config::amsterdam()` (EIP-7954's code size limits) and `BlockEnv.slot_number` (EIP-7843). The serve protocol's configure request takes a fork byte and set block a slot number, as the Rust client does. The state-test case format, version 5, carries the fork and slot number. The conformance runner runs each fixture post of every fork fevm runs, or those `--fork` names, tallies them by fork, and checks the receipt's gas used and status that fixtures since v21.0.2 give. Amsterdam still runs Osaka's rules.
Amsterdam's SLOTNUM (EIP-7843) pushes the block's slot number, and DUPN, SWAPN and EXCHANGE (EIP-8024) reach words past the sixteenth through an immediate byte. They are handlers; earlier forks dispatch them to the invalid opcode path. An immediate in the gap that keeps it from reading as a JUMPDEST or PUSH halts with the new `ERR_INVALID_IMMEDIATE`.
From Amsterdam, moving ether between two accounts logs a Transfer from 0xff..fe (EIP-7708): a call or creation with value, the transaction's own, and a SELFDESTRUCT to another account. The log belongs to the frame that receives the ether, so its failure drops it. A SELFDESTRUCT no longer burns ether (EIP-8246): settlement clears a self-destructed account's code, nonce and storage but keeps its balance.
EIP-8037: gas past the execution cap (EIP-7825's 2^24) is the top frame's state gas reservoir, and a transaction may have up to 2^32 - 1. New accounts, storage set from zero, new delegations and deposited code cost state gas, which the reservoir pays first and execution gas after. A child takes the whole reservoir. A failed frame refills it to the level it started at and returns the execution gas state charges took, and the refills of storage reset to zero and of accounts a failed call or creation charged for go back the way they were charged. Settlement returns the reservoir left with the gas. EIP-8038 reprices cold accounts, CALL value, CREATE, code reads, SSTORE and SELFDESTRUCT. EIP-2780, EIP-7976 and EIP-7981 reprice intrinsic gas and the calldata floor; authorizations pay for their state at the top frame, whose failure before the message starts undoes them.
Describe the fork type and `Config::amsterdam()` in the README and the conformance runner's forks and receipt checks, and run CI's state tests on tests@v21.0.2. The session client tests SLOTNUM and a transfer log under Amsterdam.
`fevm_tools bench --rules Amsterdam` runs FeVM and evmone by Amsterdam's rules at mainnet's gas cap, past which gas is the state gas reservoir. The evmone runner takes the revision from the case's fork byte; revm 33.1 has no EIP-8037 and sits out.
`LogBuffer::record` was out of line, so LOG passed it the topics by value: LOG0 of nothing took 24% more instructions than before `append_word`. Inlined, it takes 1% fewer.
Preparing the top frame built its `Vm` up front, and Osaka took a checkpoint for it, so a transaction that runs no code paid for both: 12% more instructions for a plain transfer. EIP-8037's meter is now `StateGas`, a value the preparation charges with the frame's gas and a `Vm` takes when code runs. Osaka authorizes without a checkpoint, as before Amsterdam.
`transact` matched the fork and called `apply` for it, which copied the world, request and buffers once more on the way: three more `memcpy`s a transaction. `apply` now builds the `Transaction` and then matches, calling `apply_in` with everything in place. The receipt takes the logs without an `Option`, whose `unwrap_or` had stopped inlining. A plain transfer runs 22 fewer instructions than before Amsterdam.
From Amsterdam a block counts a transaction's gas before refunds (EIP-7778) and its state gas apart (EIP-8037), which a host building blocks cannot work out from the gas used. Receipts carry both, as `execution_gas_used` and `state_gas_used`, through `fevm serve` and the Rust client; before Amsterdam they are the gas used and zero. `StateGas` keeps the spill the top frame commits for authorizations, which counts as state gas used.
`fevm --fork amsterdam <hex-bytecode>` runs the code by Amsterdam's rules; without `--fork` it runs Osaka's, as before.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds Amsterdam (Glamsterdam's execution layer, EIP-7773) and lets a host choose the fork.
The fork is a type.
Rulesgives a fork's rules as constants, each defined once from the fork it begins in (Self::FORK.since(Fork::Amsterdam)), so a fork is one line.transact,simulate,validateandVm::runmatchConfig.forkonce and run code generic over itsRulestype, as they are over the tracer. Each fork compiles to its own interpreter with its rules folded in: Osaka's dispatch sends the new opcodes to the invalid opcode path, and its code has no state gas in it. The world andBuffersare the same for every fork, so a host can switch between transactions.Amsterdam:
StateGasmeters it per frame.ERR_INVALID_IMMEDIATEfor an immediate in the gap) and EIP-7843 SLOTNUM (BlockEnv.slot_number).Config::amsterdam().execution_gas_used,state_gas_used: EIP-7778 and EIP-8037). The block-level EIPs (7928's access list, 7997, 8282) are for block execution, later.Hosts and tools:
fevm serve's configure request takes a fork byte and set block a slot number, as the Rust client does;fevm --fork amsterdamruns the CLI by Amsterdam's rules. The state-test runner runs each fixture's posts for every fork (or those--forknames) and checks the receipt's gas used and status that fixtures since v21.0.2 give; CI moves totests@v21.0.2.fevm_tools bench --rules Amsterdamruns FeVM against evmone by Amsterdam's rules.