Skip to content

Commit

Permalink
Verify executePayload in verifyBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Sep 27, 2021
1 parent dc5538f commit ea294a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
16 changes: 15 additions & 1 deletion packages/lodestar/src/chain/blocks/verifyBlock.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -13,6 +14,7 @@ import {FullyVerifiedBlock, PartiallyVerifiedBlock} from "./types";

export type VerifyBlockModules = {
bls: IBlsVerifier;
executionEngine: IExecutionEngine;
regen: IStateRegenerator;
clock: IBeaconClock;
forkChoice: IForkChoice;
Expand Down Expand Up @@ -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});
Expand Down
1 change: 1 addition & 0 deletions packages/lodestar/src/chain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class BeaconChain implements IBeaconChain {
clock,
bls,
regen,
executionEngine,
eth1,
db,
forkChoice,
Expand Down
5 changes: 4 additions & 1 deletion packages/lodestar/src/chain/errors/blockError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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<BlockErrorType> {}

Expand Down

0 comments on commit ea294a8

Please sign in to comment.