@lodestar/beacon-node 1.52.0-dev.4996a91d93 → 1.52.0-dev.50261a81cb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/lib/api/impl/validator/index.d.ts.map +1 -1
  2. package/lib/api/impl/validator/index.js +12 -3
  3. package/lib/api/impl/validator/index.js.map +1 -1
  4. package/lib/chain/errors/attestationError.d.ts +15 -1
  5. package/lib/chain/errors/attestationError.d.ts.map +1 -1
  6. package/lib/chain/errors/attestationError.js +8 -0
  7. package/lib/chain/errors/attestationError.js.map +1 -1
  8. package/lib/chain/validation/aggregateAndProof.d.ts.map +1 -1
  9. package/lib/chain/validation/aggregateAndProof.js +24 -7
  10. package/lib/chain/validation/aggregateAndProof.js.map +1 -1
  11. package/lib/chain/validation/attestation.d.ts.map +1 -1
  12. package/lib/chain/validation/attestation.js +32 -16
  13. package/lib/chain/validation/attestation.js.map +1 -1
  14. package/lib/chain/validation/block.d.ts.map +1 -1
  15. package/lib/chain/validation/block.js +9 -1
  16. package/lib/chain/validation/block.js.map +1 -1
  17. package/lib/sync/unknownBlock.d.ts +3 -2
  18. package/lib/sync/unknownBlock.d.ts.map +1 -1
  19. package/lib/sync/unknownBlock.js +19 -3
  20. package/lib/sync/unknownBlock.js.map +1 -1
  21. package/lib/sync/utils/downloadByRoot.d.ts +24 -2
  22. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  23. package/lib/sync/utils/downloadByRoot.js +41 -1
  24. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  25. package/package.json +16 -16
  26. package/src/api/impl/validator/index.ts +14 -3
  27. package/src/chain/errors/attestationError.ts +11 -1
  28. package/src/chain/validation/aggregateAndProof.ts +24 -9
  29. package/src/chain/validation/attestation.ts +31 -20
  30. package/src/chain/validation/block.ts +9 -1
  31. package/src/sync/unknownBlock.ts +24 -3
  32. package/src/sync/utils/downloadByRoot.ts +66 -2
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ChainSafe/lodestar/issues"
13
13
  },
14
- "version": "1.52.0-dev.4996a91d93",
14
+ "version": "1.52.0-dev.50261a81cb",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -126,18 +126,18 @@
126
126
  "@libp2p/prometheus-metrics": "^5.0.31",
127
127
  "@libp2p/tcp": "^11.0.30",
128
128
  "@libp2p/utils": "^7.4.3",
129
- "@lodestar/api": "^1.52.0-dev.4996a91d93",
130
- "@lodestar/config": "^1.52.0-dev.4996a91d93",
131
- "@lodestar/db": "^1.52.0-dev.4996a91d93",
132
- "@lodestar/fork-choice": "^1.52.0-dev.4996a91d93",
133
- "@lodestar/logger": "^1.52.0-dev.4996a91d93",
134
- "@lodestar/native": "^1.52.0-dev.4996a91d93",
135
- "@lodestar/params": "^1.52.0-dev.4996a91d93",
136
- "@lodestar/reqresp": "^1.52.0-dev.4996a91d93",
137
- "@lodestar/state-transition": "^1.52.0-dev.4996a91d93",
138
- "@lodestar/types": "^1.52.0-dev.4996a91d93",
139
- "@lodestar/utils": "^1.52.0-dev.4996a91d93",
140
- "@lodestar/validator": "^1.52.0-dev.4996a91d93",
129
+ "@lodestar/api": "^1.52.0-dev.50261a81cb",
130
+ "@lodestar/config": "^1.52.0-dev.50261a81cb",
131
+ "@lodestar/db": "^1.52.0-dev.50261a81cb",
132
+ "@lodestar/fork-choice": "^1.52.0-dev.50261a81cb",
133
+ "@lodestar/logger": "^1.52.0-dev.50261a81cb",
134
+ "@lodestar/native": "^1.52.0-dev.50261a81cb",
135
+ "@lodestar/params": "^1.52.0-dev.50261a81cb",
136
+ "@lodestar/reqresp": "^1.52.0-dev.50261a81cb",
137
+ "@lodestar/state-transition": "^1.52.0-dev.50261a81cb",
138
+ "@lodestar/types": "^1.52.0-dev.50261a81cb",
139
+ "@lodestar/utils": "^1.52.0-dev.50261a81cb",
140
+ "@lodestar/validator": "^1.52.0-dev.50261a81cb",
141
141
  "@multiformats/multiaddr": "^13.0.1",
142
142
  "datastore-core": "^12.0.1",
143
143
  "datastore-level": "^13.0.1",
@@ -159,8 +159,8 @@
159
159
  "@ethereumjs/rlp": "^4.0.1",
160
160
  "@libp2p/interface-internal": "^3.2.0",
161
161
  "@libp2p/logger": "^6.2.15",
162
- "@lodestar/spec-test-util": "^1.52.0-dev.4996a91d93",
163
- "@lodestar/test-utils": "^1.52.0-dev.4996a91d93",
162
+ "@lodestar/spec-test-util": "^1.52.0-dev.50261a81cb",
163
+ "@lodestar/test-utils": "^1.52.0-dev.50261a81cb",
164
164
  "@types/js-yaml": "^4.0.5",
165
165
  "@types/qs": "^6.9.7",
166
166
  "@types/tmp": "^0.2.3",
@@ -174,5 +174,5 @@
174
174
  "beacon",
175
175
  "blockchain"
176
176
  ],
177
- "gitHead": "676718df6a2f613e16064dbf990063dff45281b6"
177
+ "gitHead": "e57ee2553cc4fa7b114fddc5e83a1b6a0ebff815"
178
178
  }
@@ -409,7 +409,7 @@ export function getValidatorApi(
409
409
  * Both the above scenarios could be problematic and hence validator shouldn't participate
410
410
  * or weigh its vote on a head till it resolves to a Valid execution status.
411
411
  * Following activities should be skipped on an Optimistic head (with Syncing status):
412
- * 1. Attestation if targetRoot is optimistic
412
+ * 1. Attestation if the head block voted for (post-gloas the variant voted for) or the targetRoot is optimistic
413
413
  * 2. SyncCommitteeContribution if if the root for which to produce contribution is Optimistic.
414
414
  * 3. ProduceBlock if the parentRoot (chain's current head) is optimistic. Must be checked
415
415
  * explicitly as only local payload production consults the EL, blinded blocks from an
@@ -1397,10 +1397,18 @@ export function getValidatorApi(
1397
1397
  // After Gloas, attestation.data.index signals payload status in fork-choice:
1398
1398
  // - 0 = EMPTY / not present, 1 = FULL / present
1399
1399
  // - same-slot attestations must always use index = 0
1400
+ // Validator shouldn't vote on an optimistic head, post-gloas that is the variant voted for
1400
1401
  if (canonicalBlock.slot !== slot) {
1401
1402
  index = canonicalBlock.payloadStatus === PayloadStatus.FULL ? 1 : 0;
1403
+ if (isOptimisticBlock(canonicalBlock)) {
1404
+ throw new NodeIsSyncing(
1405
+ `Head block's execution payload not yet validated, executionPayloadBlockHash=${canonicalBlock.executionPayloadBlockHash}`
1406
+ );
1407
+ }
1402
1408
  } else {
1403
1409
  index = 0;
1410
+ // Same-slot votes support the PENDING variant, which does not depend on the block's own payload
1411
+ notOnOptimisticBlockRoot(beaconBlockRoot);
1404
1412
  }
1405
1413
  } else if (isForkPostElectra(fork)) {
1406
1414
  index = 0;
@@ -1418,8 +1426,11 @@ export function getValidatorApi(
1418
1426
  headBlockRoot
1419
1427
  : headState.getBlockRootAtSlot(targetSlot);
1420
1428
 
1421
- // Check the execution status as validator shouldn't vote on an optimistic head
1422
- // Check on target is sufficient as a valid target would imply a valid source
1429
+ // Check the execution status as validator shouldn't vote on an optimistic head, post-gloas the
1430
+ // variant voted for is checked above. Check on target is sufficient for a valid source
1431
+ if (!isForkPostGloas(fork)) {
1432
+ notOnOptimisticBlockRoot(beaconBlockRoot);
1433
+ }
1423
1434
  notOnOptimisticBlockRoot(targetRoot);
1424
1435
  notOnOutOfRangeData(targetRoot);
1425
1436
 
@@ -151,6 +151,14 @@ export enum AttestationErrorCode {
151
151
  * Gloas: index-1 attestation but the execution payload has not been seen yet
152
152
  */
153
153
  EXECUTION_PAYLOAD_NOT_SEEN = "ATTESTATION_ERROR_EXECUTION_PAYLOAD_NOT_SEEN",
154
+ /**
155
+ * Gloas: index-1 attestation to a block whose execution payload is not yet validated by the execution engine
156
+ */
157
+ EXECUTION_PAYLOAD_OPTIMISTIC = "ATTESTATION_ERROR_EXECUTION_PAYLOAD_OPTIMISTIC",
158
+ /**
159
+ * Gloas: index-1 attestation to a block whose execution payload was invalidated
160
+ */
161
+ EXECUTION_PAYLOAD_INVALID = "ATTESTATION_ERROR_EXECUTION_PAYLOAD_INVALID",
154
162
  }
155
163
 
156
164
  export type AttestationErrorType =
@@ -190,7 +198,9 @@ export type AttestationErrorType =
190
198
  | {code: AttestationErrorCode.ATTESTER_NOT_IN_COMMITTEE}
191
199
  | {code: AttestationErrorCode.INVALID_PAYLOAD_STATUS_VALUE; attDataIndex: number}
192
200
  | {code: AttestationErrorCode.PREMATURELY_INDICATED_PAYLOAD_PRESENT}
193
- | {code: AttestationErrorCode.EXECUTION_PAYLOAD_NOT_SEEN; beaconBlockRoot: RootHex};
201
+ | {code: AttestationErrorCode.EXECUTION_PAYLOAD_NOT_SEEN; beaconBlockRoot: RootHex}
202
+ | {code: AttestationErrorCode.EXECUTION_PAYLOAD_OPTIMISTIC; beaconBlockRoot: RootHex}
203
+ | {code: AttestationErrorCode.EXECUTION_PAYLOAD_INVALID; beaconBlockRoot: RootHex};
194
204
 
195
205
  export class AttestationError extends GossipActionError<AttestationErrorType> {
196
206
  getMetadata(): Record<string, string | number | null> {
@@ -1,3 +1,4 @@
1
+ import {ExecutionStatus, PayloadStatus} from "@lodestar/fork-choice";
1
2
  import {ForkName, ForkSeq} from "@lodestar/params";
2
3
  import {
3
4
  ISignatureSet,
@@ -100,15 +101,29 @@ async function validateAggregateAndProof(
100
101
  // (a client MAY queue attestations for processing until the payload is imported and SHOULD
101
102
  // request the payload envelope via `ExecutionPayloadEnvelopesByRoot` using
102
103
  // `aggregate.data.beacon_block_root`).
103
- if (
104
- block !== null &&
105
- attData.index === 1 &&
106
- !chain.forkChoice.hasPayloadHexUnsafe(toRootHex(attData.beaconBlockRoot))
107
- ) {
108
- throw new AttestationError(GossipAction.IGNORE, {
109
- code: AttestationErrorCode.EXECUTION_PAYLOAD_NOT_SEEN,
110
- beaconBlockRoot: toRootHex(attData.beaconBlockRoot),
111
- });
104
+ if (block !== null && attData.index === 1) {
105
+ const beaconBlockRoot = toRootHex(attData.beaconBlockRoot);
106
+ const fullBlock = chain.forkChoice.getBlockHex(beaconBlockRoot, PayloadStatus.FULL);
107
+ if (fullBlock === null) {
108
+ throw new AttestationError(GossipAction.IGNORE, {
109
+ code: AttestationErrorCode.EXECUTION_PAYLOAD_NOT_SEEN,
110
+ beaconBlockRoot,
111
+ });
112
+ }
113
+ // [IGNORE] The attested execution payload is optimistic
114
+ if (fullBlock.executionStatus === ExecutionStatus.Syncing) {
115
+ throw new AttestationError(GossipAction.IGNORE, {
116
+ code: AttestationErrorCode.EXECUTION_PAYLOAD_OPTIMISTIC,
117
+ beaconBlockRoot,
118
+ });
119
+ }
120
+ // [REJECT] The attested execution payload is processed and invalid
121
+ if (fullBlock.executionStatus === ExecutionStatus.Invalid) {
122
+ throw new AttestationError(GossipAction.REJECT, {
123
+ code: AttestationErrorCode.EXECUTION_PAYLOAD_INVALID,
124
+ beaconBlockRoot,
125
+ });
126
+ }
112
127
  }
113
128
 
114
129
  // [REJECT] len(committee_indices) == 1, where committee_indices = get_committee_indices(aggregate)
@@ -1,6 +1,6 @@
1
1
  import {BitArray} from "@chainsafe/ssz";
2
2
  import {BeaconConfig} from "@lodestar/config";
3
- import {ProtoBlock} from "@lodestar/fork-choice";
3
+ import {ExecutionStatus, PayloadStatus, ProtoBlock} from "@lodestar/fork-choice";
4
4
  import {
5
5
  ATTESTATION_SUBNET_COUNT,
6
6
  DOMAIN_BEACON_ATTESTER,
@@ -309,25 +309,6 @@ async function validateAttestationNoSignatureCheck(
309
309
  code: AttestationErrorCode.PREMATURELY_INDICATED_PAYLOAD_PRESENT,
310
310
  });
311
311
  }
312
-
313
- // [REJECT] If `attestation.data.index == 1` (payload present for a past block),
314
- // the execution payload for `block` passes validation.
315
- // [IGNORE] When `attestation.data.index == 1` (payload present for a past block),
316
- // the execution payload for `block` has been fully imported, including its data -- i.e.
317
- // `is_payload_verified(store, attestation.data.beacon_block_root)` returns `True`
318
- // (a client MAY queue attestations for processing until the payload is imported and
319
- // SHOULD request the payload envelope via `ExecutionPayloadEnvelopesByRoot` using
320
- // `attestation.data.beacon_block_root`).
321
- if (
322
- block !== null &&
323
- attData.index === 1 &&
324
- !chain.forkChoice.hasPayloadHexUnsafe(toRootHex(attData.beaconBlockRoot))
325
- ) {
326
- throw new AttestationError(GossipAction.IGNORE, {
327
- code: AttestationErrorCode.EXECUTION_PAYLOAD_NOT_SEEN,
328
- beaconBlockRoot: toRootHex(attData.beaconBlockRoot),
329
- });
330
- }
331
312
  } else {
332
313
  // [REJECT] attestation.data.index == 0
333
314
  if (attData.index !== 0) {
@@ -343,6 +324,36 @@ async function validateAttestationNoSignatureCheck(
343
324
  committeeIndex = attestationOrCache.cache.committeeIndex;
344
325
  }
345
326
 
327
+ // The payload status can change after the attestation data was cached, so this runs for cached data too
328
+ if (isForkPostGloas(fork) && attData.index === 1) {
329
+ const beaconBlockRoot = toRootHex(attData.beaconBlockRoot);
330
+ const fullBlock = chain.forkChoice.getBlockHex(beaconBlockRoot, PayloadStatus.FULL);
331
+ // [IGNORE] The corresponding execution payload envelope has been seen and verified
332
+ // (a client MAY queue attestations for processing until the payload is imported and
333
+ // SHOULD request the payload envelope via `ExecutionPayloadEnvelopesByRoot`).
334
+ // An unknown block is handled by `verifyHeadBlockAndTargetRoot`
335
+ if (fullBlock === null) {
336
+ if (chain.forkChoice.hasBlockHexUnsafe(beaconBlockRoot)) {
337
+ throw new AttestationError(GossipAction.IGNORE, {
338
+ code: AttestationErrorCode.EXECUTION_PAYLOAD_NOT_SEEN,
339
+ beaconBlockRoot,
340
+ });
341
+ }
342
+ } else if (fullBlock.executionStatus === ExecutionStatus.Syncing) {
343
+ // [IGNORE] The attested execution payload is optimistic
344
+ throw new AttestationError(GossipAction.IGNORE, {
345
+ code: AttestationErrorCode.EXECUTION_PAYLOAD_OPTIMISTIC,
346
+ beaconBlockRoot,
347
+ });
348
+ } else if (fullBlock.executionStatus === ExecutionStatus.Invalid) {
349
+ // [REJECT] The attested execution payload is processed and invalid
350
+ throw new AttestationError(GossipAction.REJECT, {
351
+ code: AttestationErrorCode.EXECUTION_PAYLOAD_INVALID,
352
+ beaconBlockRoot,
353
+ });
354
+ }
355
+ }
356
+
346
357
  chain.metrics?.gossipAttestation.attestationSlotToClockSlot.observe(
347
358
  {caller: RegenCaller.validateGossipAttestation},
348
359
  chain.clock.currentSlot - attSlot
@@ -121,13 +121,21 @@ export async function validateGossipBlock(
121
121
  // (via gossip or non-gossip sources) (a client MAY queue blocks for processing once the parent payload is retrieved).
122
122
  if (isGloasBeaconBlock(block)) {
123
123
  const parentBlockHashHex = toRootHex(block.body.signedExecutionPayloadBid.message.parentBlockHash);
124
- if (chain.forkChoice.getBlockHexAndBlockHash(parentRoot, parentBlockHashHex) === null) {
124
+ const parentPayloadBlock = chain.forkChoice.getBlockHexAndBlockHash(parentRoot, parentBlockHashHex);
125
+ if (parentPayloadBlock === null) {
125
126
  throw new BlockGossipError(GossipAction.IGNORE, {
126
127
  code: BlockErrorCode.PARENT_PAYLOAD_UNKNOWN,
127
128
  parentRoot,
128
129
  parentBlockHash: parentBlockHashHex,
129
130
  });
130
131
  }
132
+ // [IGNORE] The block's parent passed validation but the payload it builds on is invalid
133
+ if (parentPayloadBlock.executionStatus === ExecutionStatus.Invalid) {
134
+ throw new BlockGossipError(GossipAction.IGNORE, {
135
+ code: BlockErrorCode.PARENT_EXECUTION_INVALID,
136
+ parentRoot,
137
+ });
138
+ }
131
139
  }
132
140
 
133
141
  // [REJECT] The block is from a higher slot than its parent.
@@ -52,7 +52,7 @@ import {
52
52
  isPendingPayloadEnvelope,
53
53
  isPendingPayloadInput,
54
54
  } from "./types.js";
55
- import {DownloadByRootError, downloadByRoot} from "./utils/downloadByRoot.js";
55
+ import {DownloadByRootError, DownloadByRootErrorCode, downloadByRoot} from "./utils/downloadByRoot.js";
56
56
  import {getAllDescendantBlocks, getUnknownAndAncestorBlocks} from "./utils/pendingBlocksTree.js";
57
57
  import {getRateLimitedUntilMs} from "./utils/rateLimit.js";
58
58
 
@@ -549,8 +549,9 @@ export class BlockInputSync {
549
549
  /**
550
550
  * Limit pending blocks to prevent DOS attacks that cause OOM. Any gossip message with an unknown root adds a root-only
551
551
  * entry before validation, so those nothing waits on are evicted before a block or a root a pending block waits on.
552
- * A downloaded block is only checked against its root, so this only applies while blocks and the roots they wait on
553
- * fill at most half the cap, otherwise they could pin it and evict every new root on insertion.
552
+ * A downloaded block is only checked against its root and proposer signature, not that the proposer is due at its
553
+ * slot, so this only applies while blocks and the roots they wait on fill at most half the cap, otherwise they could
554
+ * pin it and evict every new root on insertion.
554
555
  */
555
556
  private prunePendingBlocks(): void {
556
557
  if (this.pendingBlocks.size <= this.maxPendingBlocks) {
@@ -1291,6 +1292,15 @@ export class BlockInputSync {
1291
1292
  return;
1292
1293
  }
1293
1294
 
1295
+ if (
1296
+ res.err instanceof DownloadByRootError &&
1297
+ res.err.type.code === DownloadByRootErrorCode.BELOW_FINALIZED_SLOT
1298
+ ) {
1299
+ this.logger.debug("Downloaded block is before finalized slot", logCtx, res.err);
1300
+ this.removeAllDescendants(block, DroppedItemReason.belowFinalized);
1301
+ return;
1302
+ }
1303
+
1294
1304
  this.metrics?.blockInputSync.downloadedBlocksError.inc();
1295
1305
  this.logger.debug("Failed to download unknown block root, retained for retry", logCtx, res.err);
1296
1306
  const pendingBlock = this.pendingBlocks.get(rootHex);
@@ -2060,6 +2070,17 @@ export class BlockInputSync {
2060
2070
  if (e instanceof DownloadByRootError) {
2061
2071
  const errorCode = e.type.code;
2062
2072
  downloadByRootMetrics?.error.inc({code: errorCode, client: peerClient});
2073
+ if (errorCode === DownloadByRootErrorCode.BELOW_FINALIZED_SLOT) {
2074
+ throw e;
2075
+ }
2076
+ // Low as in range sync, not Fatal as peers may serve unverified copies of a root with a bad signature
2077
+ if (
2078
+ errorCode === DownloadByRootErrorCode.MISMATCH_BLOCK_ROOT ||
2079
+ errorCode === DownloadByRootErrorCode.PROPOSAL_SIGNATURE_INVALID ||
2080
+ errorCode === DownloadByRootErrorCode.UNKNOWN_PROPOSER
2081
+ ) {
2082
+ this.network.reportPeer(peerId, PeerAction.LowToleranceError, errorCode);
2083
+ }
2063
2084
  excludedPeers.add(peerId);
2064
2085
  } else if (e instanceof RequestError) {
2065
2086
  // should look into req_resp metrics in this case
@@ -1,7 +1,8 @@
1
1
  import {routes} from "@lodestar/api";
2
2
  import {ChainForkConfig} from "@lodestar/config";
3
3
  import {ForkPostFulu, ForkPostGloas, isForkPostFulu, isForkPostGloas} from "@lodestar/params";
4
- import {ColumnIndex, SignedBeaconBlock, Slot, fulu} from "@lodestar/types";
4
+ import {getBlockProposerSignatureSet} from "@lodestar/state-transition";
5
+ import {ColumnIndex, SignedBeaconBlock, Slot, ValidatorIndex, fulu} from "@lodestar/types";
5
6
  import {LodestarError, byteArrayEquals, fromHex, prettyPrintIndices, toHex, toRootHex} from "@lodestar/utils";
6
7
  import {isBlockInputColumns} from "../../chain/blocks/blockInput/blockInput.js";
7
8
  import {BlockInputSource, IBlockInput} from "../../chain/blocks/blockInput/types.js";
@@ -30,10 +31,12 @@ export type FetchByRootCoreProps = {
30
31
  peerMeta: PeerSyncMeta;
31
32
  };
32
33
  export type FetchByRootProps = FetchByRootCoreProps & {
34
+ chain: IBeaconChain;
33
35
  cacheItem: BlockInputSyncCacheItem;
34
36
  blockRoot: Uint8Array;
35
37
  };
36
38
  export type FetchByRootAndValidateBlockProps = Omit<FetchByRootCoreProps, "peerMeta"> & {
39
+ chain: IBeaconChain;
37
40
  peerIdStr: PeerIdStr;
38
41
  blockRoot: Uint8Array;
39
42
  };
@@ -190,6 +193,7 @@ export async function fetchByRoot({
190
193
  } else {
191
194
  block = await fetchAndValidateBlock({
192
195
  config,
196
+ chain,
193
197
  network,
194
198
  peerIdStr,
195
199
  blockRoot,
@@ -212,6 +216,7 @@ export async function fetchByRoot({
212
216
  } else {
213
217
  block = await fetchAndValidateBlock({
214
218
  config,
219
+ chain,
215
220
  network,
216
221
  peerIdStr,
217
222
  blockRoot,
@@ -245,10 +250,11 @@ export async function fetchByRoot({
245
250
 
246
251
  export async function fetchAndValidateBlock({
247
252
  config,
253
+ chain,
248
254
  network,
249
255
  peerIdStr,
250
256
  blockRoot,
251
- }: Omit<FetchByRootAndValidateBlockProps, "chain">): Promise<SignedBeaconBlock> {
257
+ }: FetchByRootAndValidateBlockProps): Promise<SignedBeaconBlock> {
252
258
  const response = await network.sendBeaconBlocksByRoot(peerIdStr, [blockRoot]);
253
259
  const block = response.at(0);
254
260
  if (!block) {
@@ -270,6 +276,41 @@ export async function fetchAndValidateBlock({
270
276
  "block does not match requested root"
271
277
  );
272
278
  }
279
+
280
+ const blockRootHex = toRootHex(blockRoot);
281
+ const {slot, proposerIndex} = block.message;
282
+ // Before the signature check, honest peers serve the genesis block unsigned
283
+ const finalizedSlot = chain.forkChoice.getFinalizedBlock().slot;
284
+ if (slot < finalizedSlot) {
285
+ throw new DownloadByRootError({
286
+ code: DownloadByRootErrorCode.BELOW_FINALIZED_SLOT,
287
+ peer: prettyPrintPeerIdStr(peerIdStr),
288
+ slot,
289
+ finalizedSlot,
290
+ blockRoot: blockRootHex,
291
+ });
292
+ }
293
+ if (proposerIndex >= chain.pubkeyCache.size) {
294
+ throw new DownloadByRootError({
295
+ code: DownloadByRootErrorCode.UNKNOWN_PROPOSER,
296
+ peer: prettyPrintPeerIdStr(peerIdStr),
297
+ slot,
298
+ blockRoot: blockRootHex,
299
+ proposerIndex,
300
+ });
301
+ }
302
+ // Not marked as verified, the block has not passed proposer or ancestry checks yet
303
+ if (!chain.seenBlockInputCache.isVerifiedProposerSignature(slot, blockRootHex, block.signature)) {
304
+ const signatureSet = getBlockProposerSignatureSet(chain.config, block);
305
+ if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: false}))) {
306
+ throw new DownloadByRootError({
307
+ code: DownloadByRootErrorCode.PROPOSAL_SIGNATURE_INVALID,
308
+ peer: prettyPrintPeerIdStr(peerIdStr),
309
+ slot,
310
+ blockRoot: blockRootHex,
311
+ });
312
+ }
313
+ }
273
314
  return block;
274
315
  }
275
316
 
@@ -376,6 +417,9 @@ export enum DownloadByRootErrorCode {
376
417
  INVALID_KZG_PROOF = "DOWNLOAD_BY_ROOT_ERROR_INVALID_KZG_PROOF",
377
418
  MISSING_BLOCK_RESPONSE = "DOWNLOAD_BY_ROOT_ERROR_MISSING_BLOCK_RESPONSE",
378
419
  MISSING_COLUMN_RESPONSE = "DOWNLOAD_BY_ROOT_ERROR_MISSING_COLUMN_RESPONSE",
420
+ BELOW_FINALIZED_SLOT = "DOWNLOAD_BY_ROOT_ERROR_BELOW_FINALIZED_SLOT",
421
+ UNKNOWN_PROPOSER = "DOWNLOAD_BY_ROOT_ERROR_UNKNOWN_PROPOSER",
422
+ PROPOSAL_SIGNATURE_INVALID = "DOWNLOAD_BY_ROOT_ERROR_PROPOSAL_SIGNATURE_INVALID",
379
423
  Z = "DOWNLOAD_BY_ROOT_ERROR_Z",
380
424
  }
381
425
  export type DownloadByRootErrorType =
@@ -425,6 +469,26 @@ export type DownloadByRootErrorType =
425
469
  code: DownloadByRootErrorCode.MISSING_COLUMN_RESPONSE;
426
470
  peer: string;
427
471
  blockRoot: string;
472
+ }
473
+ | {
474
+ code: DownloadByRootErrorCode.BELOW_FINALIZED_SLOT;
475
+ peer: string;
476
+ slot: Slot;
477
+ finalizedSlot: Slot;
478
+ blockRoot: string;
479
+ }
480
+ | {
481
+ code: DownloadByRootErrorCode.UNKNOWN_PROPOSER;
482
+ peer: string;
483
+ slot: Slot;
484
+ blockRoot: string;
485
+ proposerIndex: ValidatorIndex;
486
+ }
487
+ | {
488
+ code: DownloadByRootErrorCode.PROPOSAL_SIGNATURE_INVALID;
489
+ peer: string;
490
+ slot: Slot;
491
+ blockRoot: string;
428
492
  };
429
493
 
430
494
  export class DownloadByRootError extends LodestarError<DownloadByRootErrorType> {}