Repository navigation
feat(p2p): refuse execution payloads whose block hash is not their header's - #770
MegaRedHand wants to merge 24 commits into
Conversation
…ader's Rebuild the execution block header from a payload's own fields and reject the message when keccak256(rlp(header)) differs from the claimed block_hash. Runs on pre-gloas beacon_block gossip (bellatrix to fulu), on gloas execution_payload gossip, and on every envelope fetched by root or range. Since engine_newPayloadV2 the Engine API answers a block-hash mismatch with INVALID and a null latestValidHash, indistinguishable from an executed-invalid payload whose last valid ancestor is unknown. Catching the structural case on the consensus side keeps such payloads from being applied to fork choice ahead of the execution client's answer. The header is encoded in ethlambda-p2p rather than through ethrex's BlockHeader, which holds base_fee_per_gas as a u64 where the payload has 256 bits. Each fork is tested against a real block or envelope (Sepolia, Hoodi, mainnet, Plataberget) plus a one-field-changed refusal. This is stricter than the consensus specs' gossip rules, documented in docs/spec_deviations.md and docs/beacon_wire.md.
…ader's (#770) Rebuild the execution block header from a payload's own fields and reject the message when keccak256(rlp(header)) differs from the claimed block_hash. Runs on pre-gloas beacon_block gossip (bellatrix to fulu), on gloas execution_payload gossip, and on every envelope fetched by root or range. Since engine_newPayloadV2 the Engine API answers a block-hash mismatch with INVALID and a null latestValidHash, indistinguishable from an executed-invalid payload whose last valid ancestor is unknown. Catching the structural case on the consensus side keeps such payloads from being applied to fork choice ahead of the execution client's answer. The header is encoded in ethlambda-p2p rather than through ethrex's BlockHeader, which holds base_fee_per_gas as a u64 where the payload has 256 bits. Each fork is tested against a real block or envelope (Sepolia, Hoodi, mainnet, Plataberget) plus a one-field-changed refusal. This is stricter than the consensus specs' gossip rules, documented in docs/spec_deviations.md and docs/beacon_wire.md. Cherry-picked from feat/gossip-payload-block-hash at 686b481. Claude-Session: https://claude.ai/code/session_011vghNmndKPkZinHRkVTwVB
🤖 Codex Code Review
The fork-specific header reconstruction otherwise looks consistent on inspection. Tests could not run because Rustup attempted to write to its read-only installation directory. Automated review by OpenAI Codex · gpt-6.1-sol · custom prompt |
🤖 Claude Code ReviewReview: execution payload block-hash check in p2p (PR 770)The approach is sound. Rebuilding the header from the payload and comparing it to Correctness / consensus safety
Performance
Readability
Tests
Automated review by Claude · claude-opus-5-5 · custom prompt |
🤖 Gemini Code ReviewSolid PR — the header reconstruction across all forks (Bellatrix through Gloas/Amsterdam) is clean, well-documented, and well-tested against real chain vectors. A few suggestions:
Automated review by Gemini · gemini-4-argon · custom prompt |
🤖 Grok Code ReviewI'll inspect the hash check against the surrounding gossip path and the header-encoding details that real vectors might not cover. Automated review by Grok (xAI) · grok-4.7 · custom prompt |
🤖 Kimi Code ReviewFindings
The fork-specific header construction and real-chain test coverage otherwise look solid. Automated review by Kimi (Moonshot AI) · kimi-k3.1-pro · custom prompt |
🤖 DeepSeek Code ReviewThe PR is well-structured and the real-chain SSZ vectors give strong evidence the header reconstruction is correct. A few issues worth addressing:
No other correctness issues found; the RLP field ordering and trie-root construction match the included real-chain vectors. Automated review by DeepSeek · deepseek-v4-pro · custom prompt |
pablodeymo
left a comment
There was a problem hiding this comment.
Reviewed at a01c0f6. The header reconstruction looks right to me: field order and the post-merge constants are correct, the transaction trie uses the same keys and routine as ethrex's own compute_transactions_root, and the requests list is the one newPayloadV4 already sends. My concerns are about where the check runs and what it answers.
Before merge
-
REJECTpenalizes honest peers (handler.rs:329). The spec has no such gossip rule, so other clients forward a validly signed block whoseblock_hashis wrong. Gossipsub then counts an invalid delivery for the sender and for every peer that already forwarded it. With our parameters (scoring.rs:487) one such block costs each of those peers 107.5 × count², and the count decays over 50 epochs. By my arithmetic (not a simulation), a proposer set with about 1.6% of slots that publishes such blocks keeps every relaying peer below the gossip threshold, and about 3.4% keeps them below the graylist, where we disconnect them. It costs the attacker those proposals, but it isolates only us.IGNOREkeeps "don't import, don't forward" without the scoring effect. Theexecution_payloadtopic has no score parameters today, so this is aboutbeacon_block. -
The check runs on the P2P actor, before the signature check (
handler.rs:329,:538). Any peer can make the actor build a transaction trie for an unsigned message of up to the gossip size limit, on top of the decode and root it already pays. It is also outsideguarded(), so a panic in the trie code would stop the actor, where the stateful half would answerIgnore(Internal). I read ethrex's insert path and found no panic reachable from these inputs, so that part is defense in depth.Suggestion for 1 and 2 together: run the check in the stateful half, after the proposer (or builder) signature verifies, and answer
IGNORE. An unsigned message is then rejected by the signature rule as it is today, and only a proposer can reach thewarn!. A message forwarded underOverloadedwould skip the check, which is fine given point 3. -
The rationale in
spec_deviations.mdoverclaims. "Applying payloads to fork choice before the execution client answers is only safe if the structural case cannot get that far" does not hold as written. Blocks fetched by range or root are not checked. #773 has its own path for a mismatch (it reverts the applied payload) and describes this PR as a complement that makes that path rare. And the Engine API requires the execution client to validateblockHashin all cases, even while syncing (paris.md), so today, with the import waiting fornewPayload, this catches nothing the execution client does not. I'd describe the rule as what it is: it saves #773 a revert for gossip blocks. -
Two encodings have no real-chain vector (
payload_hash/tests.rs). The electra and fulu vectors both carry emptyexecution_requests, and the largest block vector has 116 transactions, below the 128 where the trie key becomes two bytes. I expect both paths to be right, since they go through ethrex's routines, but a false mismatch on gossip would penalize honest peers on every such block. A mainnet block with 128 or more transactions and at least one request would pin it, with an assertion for both inthe_vectors_exercise_what_each_fork_adds. Has this run on a live node?lean_beacon_payload_block_hash_mismatch_totalstaying at zero on mainnet for a few days would be good evidence.
Should fix
-
Gloas has no fallback. Envelopes are checked on gossip and on fetch, so if the Amsterdam header changes on a later devnet, the node refuses every payload and cannot follow the chain. A pre-gloas block refused in error still comes back by root. Consider counting and logging without refusing for gloas until the header is final, or a flag that turns the rule off.
-
Bellatrix pre-merge skip (
payload_hash.rs:180). It tests two zero hashes; the spec's predicate is the whole payload being the default.*payload == Default::default()states that exactly, anda_pre_merge_bellatrix_payload_has_nothing_to_checkshould use a default payload too. -
Cost. "One trie over the transactions" has no number. Could you time
verify_blockon the fulu vector and on a block at the size limit?
Nits
- The deneb/electra/fulu arm matches on
blockthree times with twounreachable!()arms. One inner match returning(parent_root, payload, requests)removes them. ethrex_crypto_keccakreads as a crate name;keccak256is clearer.
The pre-merge skip tested two zero hashes, where the specification's is_execution_enabled asks whether the whole payload is the default ExecutionPayload(). bellatrix::ExecutionPayload now implements Default (the all-zero value BeaconBlockBody::empty already built by hand), and verify_block compares against it. A payload with zero hashes over real fields is now checked, and the pre-merge test uses a default payload.
The deneb/electra/fulu arm of verify_block matched on the block three times, two of them with unreachable!() arms. Deneb and electra/fulu are now their own arms of the one match, sharing a Fields::deneb helper for the payload container they have in common, so nothing is unreachable. ethrex_crypto_keccak read like a crate name; it is keccak256 now.
…E it The rule ran in triage on the P2P actor, before the signature check and outside guarded(), and answered REJECT. Any peer could make the actor build a transaction trie for an unsigned message, and since other clients have no such rule and relay a validly signed block whatever its block_hash, a REJECT scored every honest peer that forwarded one. It now runs at the end of the stateful half, on the blocking thread inside guarded(), and only on a message the topic's rules accepted, so the proposer's (or builder's) signature has verified. A pre-gloas block whose hash does not match is IGNOREd (new IgnoreReason PayloadBlockHashMismatch, replacing the RejectReason): not imported, not relayed, nobody scored. A Queue or Overloaded block is not hashed. Gloas envelopes, from gossip and from fetches, are hashed the same way once accepted but only counted and logged, never refused: the Amsterdam header may still change between devnets, and a wrong encoding would otherwise refuse every payload and stop the node following the chain. The test helpers that sealed envelopes for the old rule are gone again.
No real-chain vector reached a transactions trie key of two bytes (index 128 and up) or carried any execution request: the electra and fulu blocks had empty requests and the largest had 116 transactions. The fulu vector is now mainnet slot 15684701 (finalized, canonical; the same SSZ bytes from an ethlambda node's Beacon API and from lodestar-mainnet.chainsafe.io): 238 transactions, one withdrawal request and two consolidation requests, and its hash matches. the_vectors_exercise_what_each_fork_adds asserts more than 128 transactions, rlp(128) being 0x81 0x80, and requests of two types; a changed field inside one of its consolidation requests must be refused. The "one more request" mutation pushes a withdrawal request now, since the consolidation list (two at most) is already full in this block. The old fulu vector (slot 15576000, 116 transactions, no requests) covered nothing this one does not, so it is dropped.
An ignored test that prints how long verify_block takes, copies
included: on the real fulu vector, and on that block refilled to the
10 MiB gossip limit three ways (the most transactions the list allows,
transactions of the vector's mean size, and one transaction). Run with
cargo test -p ethlambda-p2p --profile release-fast --lib \
payload_hash::tests::verify_block_cost -- --ignored --nocapture --test-threads=1
spec_deviations.md said applying payloads to fork choice early "is only safe if the structural case cannot get that far", which does not hold: blocks fetched by range or root are not checked, the early import has its own revert path, and the Engine API already requires the execution client to validate blockHash on every newPayload, even while syncing. The section now says that, and that the rule saves the early import a revert for gossip blocks. It also covers where the rule now runs (after the signature, IGNORE, gloas counted only), what is not covered, and the measured cost. beacon_wire.md (both passages and the metric row) and the reason list in metrics.md follow.
|
Thanks. Going through it in order.
Nits: both in f24dde2. I split deneb and electra/fulu into their own arms sharing a The description is rewritten to match: its What/Why were about REJECT in triage. |
|
/review |
🤖 Claude Code ReviewReview: PR 770, payload block-hash check on gossipThe PR is well-scoped and well-documented. Gating the check on Correctness / consensus
Performance
Maintainability
TestsThe fork-by-fork mutation tests, the The Automated review by Claude · claude-opus-5-5 · custom prompt |
🤖 Codex Code ReviewNo actionable findings. The fork-specific header reconstruction, signature-gated hashing, and IGNORE handling look correct. Real-chain vectors and mutation tests provide good coverage. Tests could not run: rustup attempted to update the pinned toolchain in a read-only directory. Automated review by OpenAI Codex · gpt-6.1-sol · custom prompt |
🤖 Gemini Code ReviewThis PR is well-structured, thoroughly documented, and well-tested with real chain vectors across all execution-enabled forks (Bellatrix through Gloas). Gating the trie computation behind A couple of minor suggestions:
Automated review by Gemini · gemini-4-argon · custom prompt |
🤖 Grok Code ReviewI'll inspect the hash-check call sites and the header-encoding assumptions against the surrounding validation path. Automated review by Grok (xAI) · grok-4.7 · custom prompt |
🤖 Kimi Code ReviewNo blocking correctness or security issues found in the diff. The header field ordering and post-merge constants look correct, the check is appropriately gated on One non-blocking performance concern:
The uncovered paths ( Automated review by Kimi (Moonshot AI) · kimi-k3.1-pro · custom prompt |
🤖 DeepSeek Code ReviewOverall this is a well-reasoned, well-tested change. Running only after A few issues/concerns:
No production-blocking bug found in the payload hash computation or verdict integration itself. Automated review by DeepSeek · deepseek-v4-pro · custom prompt |
🤖 Codex Code ReviewNo actionable findings. Header reconstruction, fork-specific fields, signature gating, and mismatch verdict handling look correct. Real-chain vectors provide useful coverage across forks. Tests could not run because rustup attempted to write to a read-only directory while resolving the pinned toolchain. Automated review by OpenAI Codex · gpt-6.1-sol · custom prompt |
🤖 Kimi Code ReviewNo correctness issues found in the header reconstruction or verdict handling. The fork-specific field ordering, little-endian One non-blocking concern:
A smaller performance consideration: Otherwise, the change is well documented, appropriately signature-gated, and careful about consensus and peer-scoring compatibility. Automated review by Kimi (Moonshot AI) · kimi-k3.1-pro · custom prompt |
🤖 DeepSeek Code ReviewOverall this is a thorough, well-tested PR. The use of real-chain SSZ vectors per fork and the tests around seen-cache handling for mismatches are especially good. A few issues worth addressing:
Automated review by DeepSeek · deepseek-v4-pro · custom prompt |
🤖 Grok Code ReviewThe header rebuild is carefully pinned to real blocks and the IGNORE-vs-REJECT choice is right. A few gaps are still worth fixing before this is treated as protection for early fork-choice import.
The per-fork vectors (especially mainnet fulu with >128 txs and two request types) are the right way to pin RLP order, tx-trie keys, withdrawals root, and EIP-7685 requests hash. Keeping gloas count-only until the Amsterdam header is frozen is the correct call. I would not refuse on that path until a vector from a frozen devnet is required for the release. Automated review by Grok (xAI) · grok-4.7 · custom prompt |
settle() recorded a block ignored for its payload hash but dropped record_seen's answer, so a second such block for a slot and proposer already recorded (two checked at once) was still reported as payload_block_hash_mismatch. It is now AlreadySeen, the same as a second Accept, and a_payload_hash_mismatch_marks_its_slot_and_proposer_seen covers it.
verify_block, verify_envelope and HashMismatch were pub, though only the p2p crate's own verdict code calls them.
The seen cache stops another block for a slot and proposer once the first verdict reaches the p2p actor, not while blocks are still being checked. A proposer publishing several signed equivocations at once has each one hashed until then, up to the 128 validation permits. The cost bullet now says so, and that the signature check has the same window.
|
Round five (the automated review of adc00e2). Fixed in d38e786, a726ddd and e1f1b2c. Fixed
Not changed
Gemini and Codex had no findings (Codex's tests did not run). |
|
/review |
🤖 Claude Code ReviewReview: payload block hash check (PR 770)This is a careful, well-scoped change. The rule only fires after the signature verifies. It answers IGNORE, not REJECT. Gloas is count-only. The encoding is pinned per fork by real-chain vectors, including the two-byte trie key case and multi-type requests. The Operational risk
Code quality
Minor
Overall this looks good to merge. I'd prioritize item 1 (a kill switch for the enforcing path) and item 2 (fetch-path log volume). Automated review by Claude · claude-opus-5-5 · custom prompt |
🤖 Gemini Code ReviewThe implementation looks solid and well-tested against real chain vectors across all forks (Bellatrix through Gloas). Deferring the hash computation until One minor optional suggestion:
Automated review by Gemini · gemini-4-argon · custom prompt |
🤖 Codex Code Review
The header encoding and fork-specific handling otherwise look sound. Tests could not run because rustup attempted to write to a read-only directory. Automated review by OpenAI Codex · gpt-6.1-sol · custom prompt |
🤖 Grok Code ReviewThe header reconstruction is in good shape: real-chain vectors pin bellatrix through fulu, IGNORE-not-REJECT is the right gossip scoring choice, and hashing only after
Smaller notes:
Automated review by Grok (xAI) · grok-4.7 · custom prompt |
🤖 Kimi Code Review
Otherwise, the implementation looks careful: header field ordering and optional-field handling are consistent across forks, the real-chain vectors provide strong encoding coverage, and converting only an accepted gossip block to Automated review by Kimi (Moonshot AI) · kimi-k3.1-pro · custom prompt |
🤖 DeepSeek Code ReviewAutomated review by DeepSeek |
envelope_verdict warned on every mismatch, fetched envelopes included, so if the Amsterdam header moved, range sync would warn once per envelope of every batch. It now takes the envelope's source: a gossip envelope still warns and a fetched one logs at debug, and the counter counts both as before. A block's mismatch warning also names its proposer, the one party a signed mismatch is attributable to. A comment at the gloas header fields says what pins their order (a real Platåberget envelope) and that it needs re-checking against the final EIPs before a mismatch is refused.
The cost bullet gave the 128 gossip_validation_permits as the bound on concurrent hashing without saying what else draws from them. It is data columns and envelopes only; the attestation, sync committee and builder topics have pools of their own. The bullet also says what each log line names, and that fetched envelopes log at debug.
|
Round six (the automated review of e1f1b2c). Fixed in 8e0d90d and 17b4e41. Fixed
Not changed
DeepSeek's review failed (empty content). |
|
/review |
🤖 Gemini Code ReviewThis PR looks great. The execution header reconstruction across Bellatrix through Gloas is clean, well-isolated in A few highlights:
LGTM! Automated review by Gemini · gemini-4-argon · custom prompt |
🤖 Claude Code ReviewReview: PR 770, payload block-hash check on gossipThe design is sound: the check is opt-in, gated on a verified signature, and returns IGNORE rather than REJECT. Wiring Correctness / consensus
Performance / DoS
Rust idioms / maintainability
TestsThe mutation tests per field and per fork are good. Two additions would strengthen them:
Overall this looks good to merge once Item 1 (circuit breaker or at least a documented guard) and Item 5 (a cost cap) are considered. Automated review by Claude · claude-opus-5-5 · custom prompt |
🤖 Codex Code Review
The fork-specific header encoding otherwise looks consistent. Tests could not run because rustup attempted to write to a read-only directory. Automated review by OpenAI Codex · gpt-6.1-sol · custom prompt |
🤖 Kimi Code Review
Otherwise, the production logic looks careful: post- Automated review by Kimi (Moonshot AI) · kimi-k3.1-pro · custom prompt |
🤖 Grok Code ReviewThe header reconstruction is in good shape. Real-chain vectors for every fork, the IGNORE-vs-REJECT choice, and recording a hash mismatch as the first valid signature are the right calls. A few gaps are worth fixing before this is the thing standing in front of early fork-choice import.
Smaller notes, not blockers. Automated review by Grok (xAI) · grok-4.7 · custom prompt |
🤖 DeepSeek Code ReviewAutomated review by DeepSeek |
|
Round seven (the automated review of 17b4e41). No changes. Not changed
Gemini said LGTM, and DeepSeek's review failed (empty content). |
|
The review loop for this PR stops here: the last round raised nothing left to address. It only re-raised points settled in earlier rounds, plus a compile claim that does not hold. Follow-ups still open from this PR's rounds:
|
What
Beacon p2p rebuilds the execution block header from a payload's own fields and compares
keccak256(rlp(header))with the payload'sblock_hash:beacon_blockgossip (bellatrix to fulu), at the end of the stateful checks andonly when they answered
Accept, so the proposer signature has verified. A mismatch isIGNOREd (
IgnoreReason::PayloadBlockHashMismatch,payload_block_hash_mismatch): notimported from gossip, not relayed, no peer scored.
the builder signature). A mismatch is only counted and logged until the Amsterdam header
is final.
Not checked: blocks fetched by range or root, and gossip blocks answered
Queueor forwardedunder
Overloaded. Counterlean_beacon_payload_block_hash_mismatch_total{kind}and awarn!with slot and root. Code incrates/net/p2p/src/beacon/payload_hash.rs(
verify_block,verify_envelope,block_verdict,envelope_verdict), in p2p rather thanstate_transition::gossip::*so the spec gossip fixtures (arbitrary payload hashes) areunaffected. Header encoding with
ethrex-rlp'sEncoder(ethrex'sBlockHeaderholdsbase_fee_per_gasasu64); trie roots fromethrex-commonandethrex-trie(v25.0.0,already in the lockfile).
bellatrix::ExecutionPayloadgains aDefaultimpl for thepre-merge skip.
Why
The Engine API already requires the execution client to validate
blockHashon everynewPayload, even while syncing (paris.md), so while an import waits for that answer thiscatches nothing the EL would not. It exists for the early fork-choice import in #773, which
applies a payload before the EL answers and reverts it on INVALID: a gossip block caught here
saves that path a revert.
Deviation
Stricter than the consensus-specs gossip rules; IGNORE rather than REJECT because other
clients relay such blocks. Documented in
docs/spec_deviations.md("A payload's block hashmust be its header's") and
docs/beacon_wire.md.Header per fork
bellatrix: London fields; capella:
withdrawals_root; deneb:blob_gas_used,excess_blob_gas,parent_beacon_block_root(the block'sparent_root); electra/fulu:requests_hash(from the Engine API request list); gloas:block_access_list_hash(keccak of the payload's BAL bytes, EIP-7928) andslot_number(EIP-7843), parent root from the envelope. A bellatrix block with the empty default payload (pre-merge) is skipped.Real-chain vectors (SSZ,
crates/net/p2p/src/beacon/testdata/payload_hash/)Each vector must match, and per fork a changed field must be refused. Also checked locally
(not committed): 200 consecutive finalized mainnet blocks (15684600-15684799), all match.
Cost
payload_hash::tests::verify_block_cost(ignored): ~0.24 ms on the fulu vector; at the10 MiB gossip limit 11 ms (one tx), 19 ms (~15k mainnet-sized txs), 0.6 s (1,048,576
five-byte txs, worst case). M3 Pro, release-fast, shared machine at load ~20.
Testing
cargo fmt --all,cargo clippy --workspace --all-targets -- -D warnings,cargo test --profile release-fast -p ethlambda-p2p -p ethlambda-types -p ethlambda-state-transition.No leanSpec or consensus-spec fixtures were run.