@lodestar/beacon-node 1.46.0-dev.13423cff6d → 1.46.0-dev.18a1510f34

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 (45) hide show
  1. package/lib/api/impl/validator/index.js +1 -1
  2. package/lib/api/impl/validator/index.js.map +1 -1
  3. package/lib/chain/errors/executionPayloadBid.d.ts +11 -4
  4. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
  5. package/lib/chain/errors/executionPayloadBid.js +1 -0
  6. package/lib/chain/errors/executionPayloadBid.js.map +1 -1
  7. package/lib/chain/prepareNextSlot.js +1 -1
  8. package/lib/chain/prepareNextSlot.js.map +1 -1
  9. package/lib/chain/produceBlock/produceBlockBody.js +3 -3
  10. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  11. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts +6 -5
  12. package/lib/chain/seenCache/seenExecutionPayloadBids.d.ts.map +1 -1
  13. package/lib/chain/seenCache/seenExecutionPayloadBids.js +16 -8
  14. package/lib/chain/seenCache/seenExecutionPayloadBids.js.map +1 -1
  15. package/lib/chain/validation/executionPayloadBid.d.ts +0 -5
  16. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  17. package/lib/chain/validation/executionPayloadBid.js +71 -25
  18. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  19. package/lib/execution/engine/interface.d.ts +1 -1
  20. package/lib/execution/engine/types.js +1 -1
  21. package/lib/execution/engine/types.js.map +1 -1
  22. package/lib/network/gossip/topic.d.ts +3 -3
  23. package/lib/network/processor/index.d.ts.map +1 -1
  24. package/lib/network/processor/index.js +2 -1
  25. package/lib/network/processor/index.js.map +1 -1
  26. package/lib/network/reqresp/handlers/lightClientFinalityUpdate.js +1 -1
  27. package/lib/network/reqresp/handlers/lightClientFinalityUpdate.js.map +1 -1
  28. package/lib/network/reqresp/handlers/lightClientOptimisticUpdate.js +1 -1
  29. package/lib/network/reqresp/handlers/lightClientOptimisticUpdate.js.map +1 -1
  30. package/lib/network/reqresp/handlers/lightClientUpdatesByRange.d.ts.map +1 -1
  31. package/lib/network/reqresp/handlers/lightClientUpdatesByRange.js +6 -2
  32. package/lib/network/reqresp/handlers/lightClientUpdatesByRange.js.map +1 -1
  33. package/package.json +14 -14
  34. package/src/api/impl/validator/index.ts +1 -1
  35. package/src/chain/errors/executionPayloadBid.ts +12 -4
  36. package/src/chain/prepareNextSlot.ts +1 -1
  37. package/src/chain/produceBlock/produceBlockBody.ts +4 -4
  38. package/src/chain/seenCache/seenExecutionPayloadBids.ts +22 -9
  39. package/src/chain/validation/executionPayloadBid.ts +88 -27
  40. package/src/execution/engine/interface.ts +1 -1
  41. package/src/execution/engine/types.ts +1 -1
  42. package/src/network/processor/index.ts +2 -1
  43. package/src/network/reqresp/handlers/lightClientFinalityUpdate.ts +1 -1
  44. package/src/network/reqresp/handlers/lightClientOptimisticUpdate.ts +1 -1
  45. package/src/network/reqresp/handlers/lightClientUpdatesByRange.ts +6 -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.46.0-dev.13423cff6d",
14
+ "version": "1.46.0-dev.18a1510f34",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -126,17 +126,17 @@
126
126
  "@libp2p/peer-id": "^6.0.4",
127
127
  "@libp2p/prometheus-metrics": "^5.0.14",
128
128
  "@libp2p/tcp": "^11.0.13",
129
- "@lodestar/api": "^1.46.0-dev.13423cff6d",
130
- "@lodestar/config": "^1.46.0-dev.13423cff6d",
131
- "@lodestar/db": "^1.46.0-dev.13423cff6d",
132
- "@lodestar/fork-choice": "^1.46.0-dev.13423cff6d",
133
- "@lodestar/logger": "^1.46.0-dev.13423cff6d",
134
- "@lodestar/params": "^1.46.0-dev.13423cff6d",
135
- "@lodestar/reqresp": "^1.46.0-dev.13423cff6d",
136
- "@lodestar/state-transition": "^1.46.0-dev.13423cff6d",
137
- "@lodestar/types": "^1.46.0-dev.13423cff6d",
138
- "@lodestar/utils": "^1.46.0-dev.13423cff6d",
139
- "@lodestar/validator": "^1.46.0-dev.13423cff6d",
129
+ "@lodestar/api": "^1.46.0-dev.18a1510f34",
130
+ "@lodestar/config": "^1.46.0-dev.18a1510f34",
131
+ "@lodestar/db": "^1.46.0-dev.18a1510f34",
132
+ "@lodestar/fork-choice": "^1.46.0-dev.18a1510f34",
133
+ "@lodestar/logger": "^1.46.0-dev.18a1510f34",
134
+ "@lodestar/params": "^1.46.0-dev.18a1510f34",
135
+ "@lodestar/reqresp": "^1.46.0-dev.18a1510f34",
136
+ "@lodestar/state-transition": "^1.46.0-dev.18a1510f34",
137
+ "@lodestar/types": "^1.46.0-dev.18a1510f34",
138
+ "@lodestar/utils": "^1.46.0-dev.18a1510f34",
139
+ "@lodestar/validator": "^1.46.0-dev.18a1510f34",
140
140
  "@multiformats/multiaddr": "^13.0.1",
141
141
  "datastore-core": "^11.0.2",
142
142
  "datastore-level": "^12.0.2",
@@ -158,7 +158,7 @@
158
158
  "@libp2p/interface-internal": "^3.0.13",
159
159
  "@libp2p/logger": "^6.2.2",
160
160
  "@libp2p/utils": "^7.0.13",
161
- "@lodestar/spec-test-util": "^1.46.0-dev.13423cff6d",
161
+ "@lodestar/spec-test-util": "^1.46.0-dev.18a1510f34",
162
162
  "@types/js-yaml": "^4.0.5",
163
163
  "@types/qs": "^6.9.7",
164
164
  "@types/tmp": "^0.2.3",
@@ -175,5 +175,5 @@
175
175
  "beacon",
176
176
  "blockchain"
177
177
  ],
178
- "gitHead": "e205f14b6ecd9eae6565de94c0cca25bb4f0c99b"
178
+ "gitHead": "2d1e5554f3d32442d6d30f3ea5bc6d423242dd4a"
179
179
  }
@@ -1808,7 +1808,7 @@ export function getValidatorApi(
1808
1808
  const filteredRegistrations = registrations.filter((registration) => {
1809
1809
  const {pubkey} = registration.message;
1810
1810
  const validatorIndex = chain.pubkeyCache.getIndex(pubkey);
1811
- if (validatorIndex === null) return false;
1811
+ if (validatorIndex === null || validatorIndex >= headState.validatorCount) return false;
1812
1812
 
1813
1813
  const validator = headState.getValidator(validatorIndex);
1814
1814
  const status = getValidatorStatus(validator, currentEpoch);
@@ -5,6 +5,7 @@ export enum ExecutionPayloadBidErrorCode {
5
5
  BUILDER_NOT_ELIGIBLE = "EXECUTION_PAYLOAD_BID_ERROR_BUILDER_NOT_ELIGIBLE",
6
6
  INVALID_BUILDER_VERSION = "EXECUTION_PAYLOAD_BID_ERROR_INVALID_BUILDER_VERSION",
7
7
  NON_ZERO_EXECUTION_PAYMENT = "EXECUTION_PAYLOAD_BID_ERROR_NON_ZERO_EXECUTION_PAYMENT",
8
+ INCOMPATIBLE_WITH_HEAD = "EXECUTION_PAYLOAD_BID_ERROR_INCOMPATIBLE_WITH_HEAD",
8
9
  BID_ALREADY_KNOWN = "EXECUTION_PAYLOAD_BID_ERROR_BID_ALREADY_KNOWN",
9
10
  BID_TOO_LOW = "EXECUTION_PAYLOAD_BID_ERROR_BID_TOO_LOW",
10
11
  BID_TOO_HIGH = "EXECUTION_PAYLOAD_BID_ERROR_BID_TOO_HIGH",
@@ -31,7 +32,14 @@ export type ExecutionPayloadBidErrorType =
31
32
  | {
32
33
  code: ExecutionPayloadBidErrorCode.NON_ZERO_EXECUTION_PAYMENT;
33
34
  builderIndex: BuilderIndex;
34
- executionPayment: number;
35
+ executionPayment: bigint;
36
+ }
37
+ | {
38
+ code: ExecutionPayloadBidErrorCode.INCOMPATIBLE_WITH_HEAD;
39
+ slot: Slot;
40
+ parentBlockRoot: RootHex;
41
+ parentBlockHash: RootHex;
42
+ headBlockRoot: RootHex;
35
43
  }
36
44
  | {
37
45
  code: ExecutionPayloadBidErrorCode.BID_ALREADY_KNOWN;
@@ -73,9 +81,9 @@ export type ExecutionPayloadBidErrorType =
73
81
  | {
74
82
  code: ExecutionPayloadBidErrorCode.PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH;
75
83
  builderIndex: BuilderIndex;
76
- bidGasLimit: number;
77
- parentGasLimit: number;
78
- targetGasLimit: number;
84
+ bidGasLimit: bigint;
85
+ parentGasLimit: bigint;
86
+ targetGasLimit: bigint;
79
87
  };
80
88
 
81
89
  export class ExecutionPayloadBidError extends GossipActionError<ExecutionPayloadBidErrorType> {}
@@ -173,7 +173,7 @@ export class PrepareNextSlotScheduler {
173
173
  // Apply parent payload once here as it's reused by EL prep and SSE emit below
174
174
  let stateAfterParentPayload: IBeaconStateViewBellatrix = updatedPrepareState;
175
175
  if (isStatePostGloas(updatedPrepareState)) {
176
- // Spec: should_build_on_full(store, head) — see produceBlockBody.ts for context.
176
+ // Spec: should_build_on_full(store, head, slot) - see produceBlockBody.ts for context.
177
177
  if (this.chain.forkChoice.shouldBuildOnFull(updatedHead, prepareSlot)) {
178
178
  parentBlockHash = updatedPrepareState.latestExecutionPayloadBid.blockHash;
179
179
  // Skip applying parent payload unless we're proposing the next slot or have to emit payload_attributes events
@@ -276,7 +276,7 @@ export async function produceBlockBody<T extends BlockType>(
276
276
  let parentExecutionRequests: gloas.ExecutionRequests;
277
277
  // Apply parent payload once here as it's reused by EL prep and voluntary exit filtering below
278
278
  let stateAfterParentPayload: IBeaconStateViewBellatrix = currentState;
279
- // Spec: should_build_on_full(store, head). `parentBlock` is the proposer's head
279
+ // Spec: should_build_on_full(store, head, slot). `parentBlock` is the proposer's head
280
280
  // (set by chain.getProposerHead(slot)). Returns false when the PTC majority signalled
281
281
  // the blob data is not available or the payload was not timely, forcing a build on EMPTY (reorg).
282
282
  const isBuildingOnFull = this.forkChoice.shouldBuildOnFull(parentBlock, blockSlot);
@@ -349,7 +349,7 @@ export async function produceBlockBody<T extends BlockType>(
349
349
  builderIndex: BUILDER_INDEX_SELF_BUILD,
350
350
  slot: blockSlot,
351
351
  value: 0,
352
- executionPayment: 0,
352
+ executionPayment: 0n,
353
353
  blobKzgCommitments: blobsBundle.commitments,
354
354
  executionRequestsRoot: ssz.gloas.ExecutionRequests.hashTreeRoot(executionRequests as gloas.ExecutionRequests),
355
355
  };
@@ -949,7 +949,7 @@ function getProposerTargetGasLimit(
949
949
  prepareSlot: Slot,
950
950
  parentBlockRoot: Root,
951
951
  parentBlockHash: Bytes32
952
- ): number {
952
+ ): bigint {
953
953
  const parentBlockRootHex = toRootHex(parentBlockRoot);
954
954
  const parentBlock = chain.forkChoice.getBlockHexDefaultStatus(parentBlockRootHex);
955
955
  const dependentRootHex = (() => {
@@ -979,7 +979,7 @@ function getProposerTargetGasLimit(
979
979
  `Cannot resolve parent payload gas_limit for proposer targetGasLimit fallback parentBlockRoot=${parentBlockRootHex} parentBlockHash=${toRootHex(parentBlockHash)}`
980
980
  );
981
981
  }
982
- return parentPayloadVariant.executionPayloadGasLimit;
982
+ return BigInt(parentPayloadVariant.executionPayloadGasLimit);
983
983
  }
984
984
 
985
985
  export async function produceCommonBlockBody<T extends BlockType>(
@@ -1,4 +1,4 @@
1
- import {BuilderIndex, Slot} from "@lodestar/types";
1
+ import {BuilderIndex, RootHex, Slot} from "@lodestar/types";
2
2
  import {MapDef} from "@lodestar/utils";
3
3
 
4
4
  /**
@@ -7,29 +7,42 @@ import {MapDef} from "@lodestar/utils";
7
7
  const SLOTS_RETAINED = 2;
8
8
 
9
9
  /**
10
- * Tracks execution payload bids we've already seen per (slot, builder).
10
+ * Tracks execution payload bids we've already seen per
11
+ * (slot, builder, parent block hash, parent block root).
11
12
  */
12
13
  export class SeenExecutionPayloadBids {
13
- private readonly builderIndexesBySlot = new MapDef<Slot, Set<BuilderIndex>>(() => new Set<BuilderIndex>());
14
+ private readonly branchesByBuilderBySlot = new MapDef<Slot, MapDef<BuilderIndex, Set<string>>>(
15
+ () => new MapDef<BuilderIndex, Set<string>>(() => new Set<string>())
16
+ );
14
17
  private lowestPermissibleSlot: Slot = 0;
15
18
 
16
- isKnown(slot: Slot, builderIndex: BuilderIndex): boolean {
17
- return this.builderIndexesBySlot.get(slot)?.has(builderIndex) === true;
19
+ isKnown(slot: Slot, builderIndex: BuilderIndex, parentBlockHash: RootHex, parentBlockRoot: RootHex): boolean {
20
+ return (
21
+ this.branchesByBuilderBySlot.get(slot)?.get(builderIndex)?.has(branchKey(parentBlockHash, parentBlockRoot)) ===
22
+ true
23
+ );
18
24
  }
19
25
 
20
- add(slot: Slot, builderIndex: BuilderIndex): void {
26
+ add(slot: Slot, builderIndex: BuilderIndex, parentBlockHash: RootHex, parentBlockRoot: RootHex): void {
21
27
  if (slot < this.lowestPermissibleSlot) {
22
28
  throw Error(`slot ${slot} < lowestPermissibleSlot ${this.lowestPermissibleSlot}`);
23
29
  }
24
- this.builderIndexesBySlot.getOrDefault(slot).add(builderIndex);
30
+ this.branchesByBuilderBySlot
31
+ .getOrDefault(slot)
32
+ .getOrDefault(builderIndex)
33
+ .add(branchKey(parentBlockHash, parentBlockRoot));
25
34
  }
26
35
 
27
36
  prune(currentSlot: Slot): void {
28
37
  this.lowestPermissibleSlot = Math.max(currentSlot - SLOTS_RETAINED, 0);
29
- for (const slot of this.builderIndexesBySlot.keys()) {
38
+ for (const slot of this.branchesByBuilderBySlot.keys()) {
30
39
  if (slot < this.lowestPermissibleSlot) {
31
- this.builderIndexesBySlot.delete(slot);
40
+ this.branchesByBuilderBySlot.delete(slot);
32
41
  }
33
42
  }
34
43
  }
35
44
  }
45
+
46
+ function branchKey(parentBlockHash: RootHex, parentBlockRoot: RootHex): string {
47
+ return `${parentBlockHash}:${parentBlockRoot}`;
48
+ }
@@ -1,4 +1,5 @@
1
1
  import {PublicKey} from "@chainsafe/blst";
2
+ import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
2
3
  import {PAYLOAD_BUILDER_VERSION} from "@lodestar/params";
3
4
  import {
4
5
  computeEpochAtSlot,
@@ -8,7 +9,7 @@ import {
8
9
  isGasLimitTargetCompatible,
9
10
  isStatePostGloas,
10
11
  } from "@lodestar/state-transition";
11
- import {ValidatorIndex, gloas} from "@lodestar/types";
12
+ import {RootHex, Slot, ValidatorIndex, gloas} from "@lodestar/types";
12
13
  import {byteArrayEquals, toHex, toRootHex} from "@lodestar/utils";
13
14
  import {getShufflingDependentRoot} from "../../util/dependentRoot.js";
14
15
  import {ExecutionPayloadBidError, ExecutionPayloadBidErrorCode, GossipAction} from "../errors/index.js";
@@ -36,12 +37,45 @@ const BID_INCREMENT_CAP_GWEI = 10_000_000;
36
37
  * Return the minimum value a new bid must have to be forwarded given the current highest bid.
37
38
  * Division before multiplication to stay within safe integer range for max gwei values.
38
39
  */
39
- export function getMinBidValue(currentHighestBid: number): number {
40
+ function getMinBidValue(currentHighestBid: number): number {
40
41
  const relativeIncrement = Math.floor(currentHighestBid / 10_000) * BID_INCREMENT_BPS;
41
42
  const increment = Math.min(Math.max(BID_INCREMENT_FLOOR_GWEI, relativeIncrement), BID_INCREMENT_CAP_GWEI);
42
43
  return currentHighestBid + increment;
43
44
  }
44
45
 
46
+ /**
47
+ * Check whether a bid builds on one of the paths compatible with the local head branch.
48
+ *
49
+ * The direct parent path is always allowed for proposer-boost reorgs. Otherwise the bid
50
+ * must build on the local head's full or empty payload variant, as selected for its slot.
51
+ */
52
+ function isBidCompatibleWithHead(
53
+ forkChoice: IForkChoice,
54
+ head: ProtoBlock,
55
+ bidSlot: Slot,
56
+ bidParentBlockRoot: RootHex,
57
+ bidParentBlockHash: RootHex
58
+ ): boolean {
59
+ const buildsOnParentBlock = bidParentBlockRoot === head.parentRoot;
60
+ const buildsOnParentPayload = bidParentBlockHash === head.parentBlockHash;
61
+
62
+ if (buildsOnParentBlock && buildsOnParentPayload) {
63
+ return true;
64
+ }
65
+
66
+ if (bidParentBlockRoot !== head.blockRoot) {
67
+ return false;
68
+ }
69
+
70
+ const buildsOnHeadPayload = bidParentBlockHash === head.executionPayloadBlockHash;
71
+
72
+ if (forkChoice.shouldBuildOnFull(head, bidSlot)) {
73
+ return buildsOnHeadPayload;
74
+ }
75
+
76
+ return buildsOnParentPayload;
77
+ }
78
+
45
79
  export async function validateApiExecutionPayloadBid(
46
80
  chain: IBeaconChain,
47
81
  signedExecutionPayloadBid: gloas.SignedExecutionPayloadBid
@@ -61,8 +95,8 @@ async function validateExecutionPayloadBid(
61
95
  signedExecutionPayloadBid: gloas.SignedExecutionPayloadBid
62
96
  ): Promise<{proposerIndex: ValidatorIndex}> {
63
97
  const bid = signedExecutionPayloadBid.message;
64
- const parentBlockRootHex = toRootHex(bid.parentBlockRoot);
65
- const parentBlockHashHex = toRootHex(bid.parentBlockHash);
98
+ const bidParentBlockRoot = toRootHex(bid.parentBlockRoot);
99
+ const bidParentBlockHash = toRootHex(bid.parentBlockHash);
66
100
 
67
101
  // [IGNORE] `bid.slot` is the current slot, or the next slot (`bid.slot - 1` is current), allowing for `MAXIMUM_GOSSIP_CLOCK_DISPARITY`.
68
102
  if (
@@ -76,14 +110,40 @@ async function validateExecutionPayloadBid(
76
110
  });
77
111
  }
78
112
 
113
+ // [IGNORE] The bid is compatible with the current head branch.
114
+ const head = chain.forkChoice.getHead();
115
+ if (!isBidCompatibleWithHead(chain.forkChoice, head, bid.slot, bidParentBlockRoot, bidParentBlockHash)) {
116
+ throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
117
+ code: ExecutionPayloadBidErrorCode.INCOMPATIBLE_WITH_HEAD,
118
+ slot: bid.slot,
119
+ parentBlockRoot: bidParentBlockRoot,
120
+ parentBlockHash: bidParentBlockHash,
121
+ headBlockRoot: head.blockRoot,
122
+ });
123
+ }
124
+
125
+ // [IGNORE] this is the first signed bid seen with a valid signature from the given builder for
126
+ // the tuple `(bid.slot, bid.parent_block_hash, bid.parent_block_root)`.
127
+ // Entries are only added after signature verification, so known tuples can be dropped before
128
+ // state regeneration and the other expensive validation steps.
129
+ if (chain.seenExecutionPayloadBids.isKnown(bid.slot, bid.builderIndex, bidParentBlockHash, bidParentBlockRoot)) {
130
+ throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
131
+ code: ExecutionPayloadBidErrorCode.BID_ALREADY_KNOWN,
132
+ builderIndex: bid.builderIndex,
133
+ slot: bid.slot,
134
+ parentBlockRoot: bidParentBlockRoot,
135
+ parentBlockHash: bidParentBlockHash,
136
+ });
137
+ }
138
+
79
139
  // [IGNORE] `bid.parent_block_root` is the hash tree root of a known beacon block in fork choice.
80
140
  // Moved earlier than the spec ordering so we can derive the proposer dependent root for the
81
141
  // proposer-preferences lookup below from a known fork-choice block.
82
- const parentBlock = chain.forkChoice.getBlockHexDefaultStatus(parentBlockRootHex);
142
+ const parentBlock = chain.forkChoice.getBlockHexDefaultStatus(bidParentBlockRoot);
83
143
  if (parentBlock === null) {
84
144
  throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
85
145
  code: ExecutionPayloadBidErrorCode.UNKNOWN_BLOCK_ROOT,
86
- parentBlockRoot: parentBlockRootHex,
146
+ parentBlockRoot: bidParentBlockRoot,
87
147
  });
88
148
  }
89
149
 
@@ -122,7 +182,7 @@ async function validateExecutionPayloadBid(
122
182
  throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
123
183
  code: ExecutionPayloadBidErrorCode.NO_MATCHING_PROPOSER_PREFERENCES,
124
184
  slot: bid.slot,
125
- parentBlockRoot: parentBlockRootHex,
185
+ parentBlockRoot: bidParentBlockRoot,
126
186
  dependentRoot: "unknown",
127
187
  });
128
188
  }
@@ -132,7 +192,7 @@ async function validateExecutionPayloadBid(
132
192
  throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
133
193
  code: ExecutionPayloadBidErrorCode.NO_MATCHING_PROPOSER_PREFERENCES,
134
194
  slot: bid.slot,
135
- parentBlockRoot: parentBlockRootHex,
195
+ parentBlockRoot: bidParentBlockRoot,
136
196
  dependentRoot: dependentRootHex,
137
197
  });
138
198
  }
@@ -143,7 +203,7 @@ async function validateExecutionPayloadBid(
143
203
  .catch(() => {
144
204
  throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
145
205
  code: ExecutionPayloadBidErrorCode.UNKNOWN_BLOCK_ROOT,
146
- parentBlockRoot: parentBlockRootHex,
206
+ parentBlockRoot: bidParentBlockRoot,
147
207
  });
148
208
  });
149
209
 
@@ -184,7 +244,7 @@ async function validateExecutionPayloadBid(
184
244
  }
185
245
 
186
246
  // [REJECT] `bid.execution_payment` is zero.
187
- if (bid.executionPayment !== 0) {
247
+ if (bid.executionPayment !== 0n) {
188
248
  throw new ExecutionPayloadBidError(GossipAction.REJECT, {
189
249
  code: ExecutionPayloadBidErrorCode.NON_ZERO_EXECUTION_PAYMENT,
190
250
  builderIndex: bid.builderIndex,
@@ -208,19 +268,19 @@ async function validateExecutionPayloadBid(
208
268
  // payload's hash) and EMPTY parents (EMPTY/PENDING variants carry the inherited parent
209
269
  // payload's hash, since the new block doesn't have its own payload). Variant carries the
210
270
  // executed payload's gas_limit, which we use as `parent_gas_limit` below.
211
- const parentPayloadVariant = chain.forkChoice.getBlockHexAndBlockHash(parentBlockRootHex, parentBlockHashHex);
271
+ const parentPayloadVariant = chain.forkChoice.getBlockHexAndBlockHash(bidParentBlockRoot, bidParentBlockHash);
212
272
  if (parentPayloadVariant === null || parentPayloadVariant.executionPayloadBlockHash === null) {
213
273
  throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
214
274
  code: ExecutionPayloadBidErrorCode.UNKNOWN_PARENT_BLOCK_HASH,
215
- parentBlockHash: parentBlockHashHex,
275
+ parentBlockHash: bidParentBlockHash,
216
276
  });
217
277
  }
218
278
 
219
279
  // [IGNORE] `is_gas_limit_target_compatible(parent_gas_limit, bid.gas_limit, target_gas_limit)`,
220
280
  // where `parent_gas_limit` is the `gas_limit` of the parent execution payload and
221
281
  // `target_gas_limit` is `proposer_preferences.target_gas_limit`.
222
- const bidGasLimit = Number(bid.gasLimit);
223
- const parentGasLimit = parentPayloadVariant.executionPayloadGasLimit;
282
+ const bidGasLimit = bid.gasLimit;
283
+ const parentGasLimit = BigInt(parentPayloadVariant.executionPayloadGasLimit);
224
284
  const targetGasLimit = proposerPreferences.message.targetGasLimit;
225
285
  if (!isGasLimitTargetCompatible(parentGasLimit, bidGasLimit, targetGasLimit)) {
226
286
  throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
@@ -245,23 +305,12 @@ async function validateExecutionPayloadBid(
245
305
  });
246
306
  }
247
307
 
248
- // [IGNORE] this is the first signed bid seen with a valid signature from the given builder for this slot.
249
- if (chain.seenExecutionPayloadBids.isKnown(bid.slot, bid.builderIndex)) {
250
- throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
251
- code: ExecutionPayloadBidErrorCode.BID_ALREADY_KNOWN,
252
- builderIndex: bid.builderIndex,
253
- slot: bid.slot,
254
- parentBlockRoot: parentBlockRootHex,
255
- parentBlockHash: parentBlockHashHex,
256
- });
257
- }
258
-
259
308
  // [IGNORE] this bid is the highest value bid seen for the tuple
260
309
  // `(bid.slot, bid.parent_block_hash, bid.parent_block_root)`.
261
310
  // As a DoS prevention measure, the bid must also exceed the current highest bid by a minimum
262
311
  // increment, see https://github.com/ethereum/consensus-specs/pull/4831. This prevents spam
263
312
  // from builders submitting numerous bids with minimal value increments.
264
- const bestBid = chain.executionPayloadBidPool.getBestBid(bid.slot, parentBlockHashHex, parentBlockRootHex);
313
+ const bestBid = chain.executionPayloadBidPool.getBestBid(bid.slot, bidParentBlockHash, bidParentBlockRoot);
265
314
  if (bestBid !== null && bid.value < getMinBidValue(bestBid.message.value)) {
266
315
  throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
267
316
  code: ExecutionPayloadBidErrorCode.BID_TOO_LOW,
@@ -306,8 +355,20 @@ async function validateExecutionPayloadBid(
306
355
  });
307
356
  }
308
357
 
358
+ // Repeat the seen check after the awaited signature verification to prevent concurrent bids
359
+ // for the same builder and tuple from both passing validation.
360
+ if (chain.seenExecutionPayloadBids.isKnown(bid.slot, bid.builderIndex, bidParentBlockHash, bidParentBlockRoot)) {
361
+ throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
362
+ code: ExecutionPayloadBidErrorCode.BID_ALREADY_KNOWN,
363
+ builderIndex: bid.builderIndex,
364
+ slot: bid.slot,
365
+ parentBlockRoot: bidParentBlockRoot,
366
+ parentBlockHash: bidParentBlockHash,
367
+ });
368
+ }
369
+
309
370
  // Valid
310
- chain.seenExecutionPayloadBids.add(bid.slot, bid.builderIndex);
371
+ chain.seenExecutionPayloadBids.add(bid.slot, bid.builderIndex, bidParentBlockHash, bidParentBlockRoot);
311
372
 
312
373
  return {proposerIndex: proposerPreferences.message.validatorIndex};
313
374
  }
@@ -98,7 +98,7 @@ export type PayloadAttributes = {
98
98
  withdrawals?: capella.Withdrawal[];
99
99
  parentBeaconBlockRoot?: Uint8Array;
100
100
  slotNumber?: number; // EIP-7843
101
- targetGasLimit?: number; // GLOAS (PayloadAttributesV4, execution-apis#796)
101
+ targetGasLimit?: bigint; // GLOAS (PayloadAttributesV4, execution-apis#796)
102
102
  };
103
103
 
104
104
  export type VersionedHashes = Uint8Array[];
@@ -458,7 +458,7 @@ export function deserializePayloadAttributes(data: PayloadAttributesRpc): Payloa
458
458
  withdrawals: data.withdrawals?.map((withdrawal) => deserializeWithdrawal(withdrawal)),
459
459
  parentBeaconBlockRoot: data.parentBeaconBlockRoot ? dataToBytes(data.parentBeaconBlockRoot, 32) : undefined,
460
460
  slotNumber: data.slotNumber !== undefined ? quantityToNum(data.slotNumber) : undefined,
461
- targetGasLimit: data.targetGasLimit !== undefined ? quantityToNum(data.targetGasLimit) : undefined,
461
+ targetGasLimit: data.targetGasLimit !== undefined ? quantityToBigint(data.targetGasLimit) : undefined,
462
462
  };
463
463
  }
464
464
 
@@ -461,7 +461,8 @@ export class NetworkProcessor {
461
461
  break;
462
462
  }
463
463
  case GossipType.execution_payload_bid: {
464
- // instead of searching for the message root, this searches for the parent root
464
+ // Search for the parent independently of current head compatibility. A bid may arrive
465
+ // before its parent block, so compatibility is checked later during gossip validation.
465
466
  const parentBlockRoot = getParentBlockRootFromSignedExecutionPayloadBidSerialized(message.msg.data);
466
467
  const parentBlockHash = getParentBlockHashFromSignedExecutionPayloadBidSerialized(message.msg.data);
467
468
  if (
@@ -12,7 +12,7 @@ export async function* onLightClientFinalityUpdate(chain: IBeaconChain): AsyncIt
12
12
  throw new ResponseError(RespStatus.RESOURCE_UNAVAILABLE, "No latest finality update available");
13
13
  }
14
14
 
15
- const boundary = chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(update.signatureSlot));
15
+ const boundary = chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(update.attestedHeader.beacon.slot));
16
16
  const type = responseSszTypeByMethod[ReqRespMethod.LightClientFinalityUpdate](boundary.fork, 0);
17
17
  yield {
18
18
  data: type.serialize(update),
@@ -12,7 +12,7 @@ export async function* onLightClientOptimisticUpdate(chain: IBeaconChain): Async
12
12
  throw new ResponseError(RespStatus.RESOURCE_UNAVAILABLE, "No latest optimistic update available");
13
13
  }
14
14
 
15
- const boundary = chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(update.signatureSlot));
15
+ const boundary = chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(update.attestedHeader.beacon.slot));
16
16
  const type = responseSszTypeByMethod[ReqRespMethod.LightClientOptimisticUpdate](boundary.fork, 0);
17
17
  yield {
18
18
  data: type.serialize(update),
@@ -19,11 +19,15 @@ export async function* onLightClientUpdatesByRange(
19
19
  assertLightClientServer(chain.lightClientServer);
20
20
 
21
21
  const count = Math.min(MAX_REQUEST_LIGHT_CLIENT_UPDATES, requestBody.count);
22
+ if (!Number.isSafeInteger(requestBody.startPeriod)) {
23
+ throw new ResponseError(RespStatus.INVALID_REQUEST, "startPeriod out of range");
24
+ }
22
25
  let started = false;
23
- for (let period = requestBody.startPeriod; period < requestBody.startPeriod + count; period++) {
26
+ for (let i = 0; i < count; i++) {
27
+ const period = requestBody.startPeriod + i;
24
28
  try {
25
29
  const update = await chain.lightClientServer.getUpdate(period);
26
- const boundary = chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(update.signatureSlot));
30
+ const boundary = chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(update.attestedHeader.beacon.slot));
27
31
  const type = responseSszTypeByMethod[ReqRespMethod.LightClientUpdatesByRange](boundary.fork, 0);
28
32
 
29
33
  yield {