Skip to content

Chain layer - #27

Merged
sbillig merged 20 commits into
feat/block-executionfrom
feat/chain
Nov 16, 2026
Merged

sbillig merged 20 commits into
feat/block-executionfrom
feat/chain

Conversation

@sbillig

@sbillig sbillig commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Adds a chain layer over Block: blocks are imported from their RLP, as a client does.

  • ingots/rlp (fevm_rlp): the Encoder moved out of fevm, and a strict decoder. The decoder reads its input from a MemSpan effect, and list() is a projection, so a sub-list that failed or has items left fails its parent.
  • ingots/chain (fevm_chain):
    • decode_transaction: types 0 to 4, with the sender recovered and the transaction hash.
    • Header: decoding, validation against the parent (base fee, excess blob gas with EIP-7918, gas limit bounds, the post-merge fields, the fields each fork has), and the block's BlockEnv.
    • Schedule: forks by activation timestamp. Config.blob_schedule (target, max, update fraction) replaces max_blobs_per_block.
    • Trie for the transactions, receipts and withdrawals roots, state_root(world), and encode_receipt.
    • Chain::import follows execute_block: EIP-7934's size limit, header validation, execution through Block, then gas used, the four roots, logs bloom, blob gas used, requests hash and access list hash against the header. It gives Valid, Invalid with the first rule broken, or Failed for a host failure. One head, no side branches.
  • The blockchain test driver imports each block's RLP through Chain: nothing decoded comes from the fixture, and every block is judged. The tool checks that a rejection's reason is one the fixture names, and lastblockhash. CI also runs the BPO1, BPO2 and fork-transition fixture sets.

Notes for review:

  • verdict checked Amsterdam transactions in Osaka's order, so a transaction breaking two rules could get the wrong validity code. Each fork now checks in its own order (Rules::FIELDS_FIRST).
  • A legacy transaction wrapped in a byte string is rejected in every fork. Amsterdam's EELS decode_transaction accepts it, which makes block bodies malleable.
  • An invalid block is undone from a copy of the world, and the state root is computed from the whole world. The next PR in the stack replaces both.

A span cannot be a struct field, so the decoder holds only positions and
reads the input from a `MemSpan` effect. `list` is a projection: when the
list cursor's last use passes, a failure in it, or an item left unread,
fails the parent.
`Config.blob_schedule` holds a fork's target and maximum blobs and its blob base fee update fraction, in place of `max_blobs_per_block`. The driver's wire format still carries the maximum.
`decode_transaction` takes a transaction as a block carries it and gives its `TxRequest`, with the sender recovered, and its hash. A gas limit past 64 bits is malformed, where the specification reads it and rejects it as over the cap.
A header with only one of Amsterdam's two fields still decodes, telling them apart by shape, so validation can say which is missing or unexpected.
The trie hashes nodes in place: it reads a node back with `since` and
replaces it with its hash after `truncate`. `raw` puts an item already
encoded, such as a transaction from a block; `words` puts a logs bloom.
`Trie` takes an ordered list's items, keyed by their index's RLP, and
`state_root` the world's accounts and slots under their keccak256 keys.
The root sorts the leaves and hashes sorted ranges recursively, without
storing a trie: one leaf is a leaf node, a prefix all the keys share an
extension, and otherwise the next nibble splits the range into a branch.
Chain::import decodes a block's RLP, checks the header against the head, runs the block through fevm::Block and compares the output and roots with the header. An invalid block or a host failure restores the world from a clone and keeps the head.
The driver takes each test's fork schedule, chain ID, pre-state, genesis and block RLP, checks the genesis state root and imports through Chain. The tool checks each block's validity and that fevm's reason is one the fixture's expectException names, then lastblockhash and postState. Every network fevm supports runs by default; results.json counts them in by_network.
EELS from Amsterdam checks the chain ID first, then the transaction's own fields (nonce limit, initcode size, gas cap, priority fee, blobs, creation, authorizations) and its intrinsic gas before the block's gas. fevm used Osaka's order for both forks, so a legacy transaction with a wrong chain ID and too little gas was named intrinsic_gas, failing test_legacy_chain_id_over_64_bits[case_largest_64_bit_chain_id]. Rules::FIELDS_FIRST places each rule at its fork's position.
import decodes and validates the block and restores or advances the chain; execute runs it; mismatch compares its output and roots with the header. Lines wrap at 120 columns.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T06:25:00.924738Z a5c4613 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.

@sbillig
sbillig added this pull request to stack #29 November 14, 2026 06:23
@sbillig
sbillig merged commit 3df19a3 into main Nov 16, 2026
2 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.

1 participant