Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate header timestamp in engine_forkchoiceUpdated #2278

Merged
merged 2 commits into from
Jun 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions nimbus/beacon/api_handler/api_forkchoice.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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")
tersec marked this conversation as resolved.
Show resolved Hide resolved
# 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,
Expand Down Expand Up @@ -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.
#
Expand Down
Loading