From 49fb07c1bc0017b74d572e7f6ac919a0e560d695 Mon Sep 17 00:00:00 2001 From: Cayman Date: Tue, 17 May 2022 10:11:33 -0500 Subject: [PATCH] Ensure light client update is in a single period --- packages/lodestar/src/chain/lightClient/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/lodestar/src/chain/lightClient/index.ts b/packages/lodestar/src/chain/lightClient/index.ts index 1747671e9b83..353b7fc9b9ab 100644 --- a/packages/lodestar/src/chain/lightClient/index.ts +++ b/packages/lodestar/src/chain/lightClient/index.ts @@ -428,6 +428,8 @@ export class LightClientServer { * ``` * * 3. On new blocks use `block.body.sync_aggregate`, `block.parent_root` and `block.slot - 1` + * + * @param syncPeriod The sync period of the sync aggregate and signed block root */ private async onSyncAggregate( syncPeriod: SyncPeriod, @@ -445,6 +447,11 @@ export class LightClientServer { } } + const attestedPeriod = computeSyncPeriodAtSlot(attestedData.attestedHeader.slot); + if (syncPeriod !== attestedPeriod) { + throw new Error("attested data period different than signature period"); + } + const headerUpdate: routes.lightclient.LightclientHeaderUpdate = { attestedHeader: attestedData.attestedHeader, syncAggregate, @@ -506,7 +513,7 @@ export class LightClientServer { // Only checkpoint candidates are stored, and not all headers are guaranteed to be available const finalizedCheckpointRoot = attestedData.finalizedCheckpoint.root as Uint8Array; const finalizedHeader = await this.getFinalizedHeader(finalizedCheckpointRoot); - if (finalizedHeader) { + if (finalizedHeader && computeSyncPeriodAtSlot(finalizedHeader.slot) == syncPeriod) { // If finalizedHeader is available (should be most times) create a finalized update newPartialUpdate = {...attestedData, finalizedHeader, syncAggregate}; } else {