Validate header timestamp in engine_forkchoiceUpdated (#2278)

* Validate header timestamp in engine_forkchoiceUpdated

* Fix fcUV3 error message
This commit is contained in:
andri lim 2024-06-02 02:14:16 +07:00 committed by GitHub
parent ef864ba167
commit d795a0ecde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 0 deletions

View File

@ -51,6 +51,24 @@ template validateVersion(attr, com, apiVersion) =
raise invalidParams("if timestamp is earlier than Shanghai," & raise invalidParams("if timestamp is earlier than Shanghai," &
" payloadAttributes must be PayloadAttributesV1") " 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 timestamp >= Cancun")
# 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, proc forkchoiceUpdated*(ben: BeaconEngineRef,
apiVersion: Version, apiVersion: Version,
update: ForkchoiceStateV1, update: ForkchoiceStateV1,
@ -100,6 +118,8 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
com.syncReqNewHead(header) com.syncReqNewHead(header)
return simpleFCU(PayloadExecutionStatus.syncing) return simpleFCU(PayloadExecutionStatus.syncing)
validateHeaderTimestamp(header, com, apiVersion)
# Block is known locally, just sanity check that the beacon client does not # Block is known locally, just sanity check that the beacon client does not
# attempt to push us back to before the merge. # attempt to push us back to before the merge.
# #