From 439d976a53f8e26c89407aef1ca774c8660eae6d Mon Sep 17 00:00:00 2001 From: jangko Date: Sat, 1 Jun 2024 20:33:23 +0700 Subject: [PATCH] Validate header timestamp in engine_forkchoiceUpdated --- nimbus/beacon/api_handler/api_forkchoice.nim | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/nimbus/beacon/api_handler/api_forkchoice.nim b/nimbus/beacon/api_handler/api_forkchoice.nim index cf61b60501..505aebc7d1 100644 --- a/nimbus/beacon/api_handler/api_forkchoice.nim +++ b/nimbus/beacon/api_handler/api_forkchoice.nim @@ -51,6 +51,24 @@ template validateVersion(attr, com, apiVersion) = raise invalidParams("if timestamp is earlier than Shanghai," & " payloadAttributes must be PayloadAttributesV1") +template validateHeaderTimestamp(header, com, apiVersion) = + # See fCUV3 specification No.2 bullet iii + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/cancun.md#specification-1 + if com.isCancunOrLater(header.timestamp): + if apiVersion != Version.V3: + raise invalidAttr("forkChoiceUpdated" & $apiVersion & + " doesn't support head block with Cancun timestamp") + # See fCUV2 specification No.2 bullet 1 + # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/shanghai.md#specification-1 + elif com.isShanghaiOrLater(header.timestamp): + if apiVersion != Version.V2: + raise invalidAttr("forkChoiceUpdated" & $apiVersion & + " doesn't support head block with Shanghai timestamp") + else: + if apiVersion != Version.V1: + raise invalidAttr("forkChoiceUpdated" & $apiVersion & + " doesn't support head block with timestamp earlier than Shanghai") + proc forkchoiceUpdated*(ben: BeaconEngineRef, apiVersion: Version, update: ForkchoiceStateV1, @@ -100,6 +118,8 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef, com.syncReqNewHead(header) return simpleFCU(PayloadExecutionStatus.syncing) + validateHeaderTimestamp(header, com, apiVersion) + # Block is known locally, just sanity check that the beacon client does not # attempt to push us back to before the merge. #