diff --git a/packages/lodestar/src/chain/blocks/verifyBlock.ts b/packages/lodestar/src/chain/blocks/verifyBlock.ts index 24f449d465f6..989b8fea7f28 100644 --- a/packages/lodestar/src/chain/blocks/verifyBlock.ts +++ b/packages/lodestar/src/chain/blocks/verifyBlock.ts @@ -1,9 +1,10 @@ import {ssz} from "@chainsafe/lodestar-types"; -import {CachedBeaconState, computeStartSlotAtEpoch, allForks} from "@chainsafe/lodestar-beacon-state-transition"; +import {CachedBeaconState, computeStartSlotAtEpoch, allForks, merge} from "@chainsafe/lodestar-beacon-state-transition"; import {toHexString} from "@chainsafe/ssz"; import {IForkChoice} from "@chainsafe/lodestar-fork-choice"; import {IChainForkConfig} from "@chainsafe/lodestar-config"; import {IMetrics} from "../../metrics"; +import {IExecutionEngine} from "../../executionEngine"; import {BlockError, BlockErrorCode} from "../errors"; import {IBeaconClock} from "../clock"; import {BlockProcessOpts} from "../options"; @@ -13,6 +14,7 @@ import {FullyVerifiedBlock, PartiallyVerifiedBlock} from "./types"; export type VerifyBlockModules = { bls: IBlsVerifier; + executionEngine: IExecutionEngine; regen: IStateRegenerator; clock: IBeaconClock; forkChoice: IForkChoice; @@ -136,6 +138,18 @@ export async function verifyBlockStateTransition( } } + if ( + merge.isMergeStateType(postState) && + merge.isMergeBlockBodyType(block.message.body) && + merge.isExecutionEnabled(postState, block.message.body) + ) { + // TODO: Handle better executePayload() returning error is syncing + const isValid = await chain.executionEngine.executePayload(block.message.body.executionPayload); + if (!isValid) { + throw new BlockError(block, {code: BlockErrorCode.EXECUTION_PAYLOAD_NOT_VALID}); + } + } + // Check state root matches if (!ssz.Root.equals(block.message.stateRoot, postState.tree.root)) { throw new BlockError(block, {code: BlockErrorCode.INVALID_STATE_ROOT, preState, postState}); diff --git a/packages/lodestar/src/chain/chain.ts b/packages/lodestar/src/chain/chain.ts index 278ebcc96da6..c28b5a68fb39 100644 --- a/packages/lodestar/src/chain/chain.ts +++ b/packages/lodestar/src/chain/chain.ts @@ -144,6 +144,7 @@ export class BeaconChain implements IBeaconChain { clock, bls, regen, + executionEngine, eth1, db, forkChoice, diff --git a/packages/lodestar/src/chain/errors/blockError.ts b/packages/lodestar/src/chain/errors/blockError.ts index 2de8cc0b2738..8baeff186721 100644 --- a/packages/lodestar/src/chain/errors/blockError.ts +++ b/packages/lodestar/src/chain/errors/blockError.ts @@ -55,6 +55,8 @@ export enum BlockErrorCode { SAME_PARENT_HASH = "BLOCK_ERROR_SAME_PARENT_HASH", /** Total size of executionPayload.transactions exceed a sane limit to prevent DOS attacks */ TRANSACTIONS_TOO_BIG = "BLOCK_ERROR_TRANSACTIONS_TOO_BIG", + /** Execution engine returned not valid after executePayload() call */ + EXECUTION_PAYLOAD_NOT_VALID = "BLOCK_ERROR_EXECUTION_PAYLOAD_NOT_VALID", } export type BlockErrorType = @@ -86,7 +88,8 @@ export type BlockErrorType = | {code: BlockErrorCode.INCORRECT_TIMESTAMP; timestamp: number; expectedTimestamp: number} | {code: BlockErrorCode.TOO_MUCH_GAS_USED; gasUsed: number; gasLimit: number} | {code: BlockErrorCode.SAME_PARENT_HASH; blockHash: RootHex} - | {code: BlockErrorCode.TRANSACTIONS_TOO_BIG; size: number; max: number}; + | {code: BlockErrorCode.TRANSACTIONS_TOO_BIG; size: number; max: number} + | {code: BlockErrorCode.EXECUTION_PAYLOAD_NOT_VALID}; export class BlockGossipError extends GossipActionError {}