From ffaba9d3d8f2455d28d7914a49e710a53726d381 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Thu, 15 Aug 2024 00:55:04 +0200 Subject: [PATCH 1/2] Synchronously check all `transactions` to have non-zero length Reject blocks with zero length transactions early when no EL connected. - https://github.com/ethereum/consensus-specs/pull/3885 --- .../gossip_processing/block_processor.nim | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/beacon_chain/gossip_processing/block_processor.nim b/beacon_chain/gossip_processing/block_processor.nim index f6e845b668..d30db4be73 100644 --- a/beacon_chain/gossip_processing/block_processor.nim +++ b/beacon_chain/gossip_processing/block_processor.nim @@ -13,7 +13,7 @@ import ../sszdump from std/deques import Deque, addLast, contains, initDeque, items, len, shrink -from std/sequtils import mapIt +from std/sequtils import anyIt, mapIt from ../consensus_object_pools/consensus_manager import ConsensusManager, checkNextProposer, optimisticExecutionBlockHash, runProposalForkchoiceUpdated, shouldSyncOptimistically, updateHead, @@ -541,31 +541,32 @@ proc storeBlock( if NewPayloadStatus.noResponse == payloadStatus: # When the execution layer is not available to verify the payload, we do the - # required check on the CL side instead and proceed as if the EL was syncing - - # TODO run https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/deneb/beacon-chain.md#blob-kzg-commitments - # https://github.com/ethereum/execution-apis/blob/main/src/engine/experimental/blob-extension.md#specification - # "This validation MUST be instantly run in all cases even during active - # sync process." - # - # Client software MUST validate `blockHash` value as being equivalent to - # `Keccak256(RLP(ExecutionBlockHeader))` - # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/paris.md#specification - # - # This should simulate an unsynced EL, which still must perform these - # checks. This means it must be able to do so without context, beyond - # whatever data the block itself contains. + # required checks on the CL instead and proceed as if the EL was syncing + # https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.4/specs/bellatrix/beacon-chain.md#verify_and_notify_new_payload + # https://github.com/ethereum/consensus-specs/blob/1.5.0-alpha.4/specs/deneb/beacon-chain.md#modified-verify_and_notify_new_payload when typeof(signedBlock).kind >= ConsensusFork.Bellatrix: - template payload(): auto = signedBlock.message.body.execution_payload - if signedBlock.message.is_execution_block and - payload.block_hash != + if signedBlock.message.is_execution_block: + template payload(): auto = signedBlock.message.body.execution_payload + + template returnWithError(msg: string): untyped = + debug msg, executionPayload = shortLog(payload) + self[].dumpInvalidBlock(signedBlock) + doAssert strictVerification notin dag.updateFlags + self.consensusManager.quarantine[].addUnviable(signedBlock.root) + return err((VerifierError.Invalid, ProcessingStatus.completed)) + + if payload.transactions.anyIt(it.len == 0): + returnWithError "Execution block contains zero length transactions" + + if payload.block_hash != signedBlock.message.compute_execution_block_hash(): - debug "Execution block hash validation failed", - execution_payload = shortLog(payload) - self[].dumpInvalidBlock(signedBlock) - doAssert strictVerification notin dag.updateFlags - self.consensusManager.quarantine[].addUnviable(signedBlock.root) - return err((VerifierError.Invalid, ProcessingStatus.completed)) + returnWithError "Execution block hash validation failed" + + # [New in Deneb:EIP4844] + # TODO run https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/deneb/beacon-chain.md#blob-kzg-commitments + # https://github.com/ethereum/execution-apis/blob/main/src/engine/experimental/blob-extension.md#specification + # "This validation MUST be instantly run in all cases even during active + # sync process." let newPayloadTick = Moment.now() From 67b4abc897c616b07c9b498a88fe860494c170b1 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Fri, 16 Aug 2024 20:01:49 +0200 Subject: [PATCH 2/2] Update beacon_chain/gossip_processing/block_processor.nim --- beacon_chain/gossip_processing/block_processor.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beacon_chain/gossip_processing/block_processor.nim b/beacon_chain/gossip_processing/block_processor.nim index d30db4be73..262011f184 100644 --- a/beacon_chain/gossip_processing/block_processor.nim +++ b/beacon_chain/gossip_processing/block_processor.nim @@ -543,7 +543,7 @@ proc storeBlock( # When the execution layer is not available to verify the payload, we do the # required checks on the CL instead and proceed as if the EL was syncing # https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.4/specs/bellatrix/beacon-chain.md#verify_and_notify_new_payload - # https://github.com/ethereum/consensus-specs/blob/1.5.0-alpha.4/specs/deneb/beacon-chain.md#modified-verify_and_notify_new_payload + # https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.4/specs/deneb/beacon-chain.md#modified-verify_and_notify_new_payload when typeof(signedBlock).kind >= ConsensusFork.Bellatrix: if signedBlock.message.is_execution_block: template payload(): auto = signedBlock.message.body.execution_payload