@lodestar/beacon-node 1.46.0 → 1.47.0-dev.ca6d994e0e

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 (53) hide show
  1. package/lib/api/impl/lodestar/index.d.ts.map +1 -1
  2. package/lib/api/impl/lodestar/index.js +11 -12
  3. package/lib/api/impl/lodestar/index.js.map +1 -1
  4. package/lib/chain/blocks/importBlock.js +1 -1
  5. package/lib/chain/blocks/importBlock.js.map +1 -1
  6. package/lib/chain/blocks/importExecutionPayload.js +1 -1
  7. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  8. package/lib/chain/blocks/index.d.ts.map +1 -1
  9. package/lib/chain/blocks/index.js +3 -5
  10. package/lib/chain/blocks/index.js.map +1 -1
  11. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  12. package/lib/chain/blocks/verifyBlock.js +11 -16
  13. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  14. package/lib/chain/chain.d.ts.map +1 -1
  15. package/lib/chain/chain.js +6 -1
  16. package/lib/chain/chain.js.map +1 -1
  17. package/lib/chain/errors/blockError.d.ts +1 -0
  18. package/lib/chain/errors/blockError.d.ts.map +1 -1
  19. package/lib/chain/options.d.ts +0 -2
  20. package/lib/chain/options.d.ts.map +1 -1
  21. package/lib/chain/options.js.map +1 -1
  22. package/lib/chain/prepareNextSlot.js +1 -1
  23. package/lib/chain/prepareNextSlot.js.map +1 -1
  24. package/lib/chain/produceBlock/produceBlockBody.js +2 -2
  25. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  26. package/lib/chain/seenCache/seenBlockProposers.d.ts +5 -1
  27. package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -1
  28. package/lib/chain/seenCache/seenBlockProposers.js +17 -7
  29. package/lib/chain/seenCache/seenBlockProposers.js.map +1 -1
  30. package/lib/chain/validation/block.d.ts.map +1 -1
  31. package/lib/chain/validation/block.js +21 -7
  32. package/lib/chain/validation/block.js.map +1 -1
  33. package/lib/sync/range/batch.js +1 -1
  34. package/lib/sync/range/batch.js.map +1 -1
  35. package/lib/sync/range/utils/hashBlocks.d.ts +16 -4
  36. package/lib/sync/range/utils/hashBlocks.d.ts.map +1 -1
  37. package/lib/sync/range/utils/hashBlocks.js +49 -18
  38. package/lib/sync/range/utils/hashBlocks.js.map +1 -1
  39. package/package.json +16 -16
  40. package/src/api/impl/lodestar/index.ts +11 -12
  41. package/src/chain/blocks/importBlock.ts +1 -1
  42. package/src/chain/blocks/importExecutionPayload.ts +1 -1
  43. package/src/chain/blocks/index.ts +3 -5
  44. package/src/chain/blocks/verifyBlock.ts +21 -25
  45. package/src/chain/chain.ts +6 -1
  46. package/src/chain/errors/blockError.ts +1 -1
  47. package/src/chain/options.ts +0 -2
  48. package/src/chain/prepareNextSlot.ts +1 -1
  49. package/src/chain/produceBlock/produceBlockBody.ts +2 -2
  50. package/src/chain/seenCache/seenBlockProposers.ts +24 -7
  51. package/src/chain/validation/block.ts +21 -7
  52. package/src/sync/range/batch.ts +1 -1
  53. package/src/sync/range/utils/hashBlocks.ts +56 -21
@@ -6,9 +6,9 @@ import {
6
6
  computeEpochAtSlot,
7
7
  signedBlockToSignedHeader,
8
8
  } from "@lodestar/state-transition";
9
- import {IndexedAttestation, Slot, deneb, ssz} from "@lodestar/types";
10
- import {toRootHex} from "@lodestar/utils";
9
+ import {IndexedAttestation, Slot, deneb} from "@lodestar/types";
11
10
  import {getBlobKzgCommitments} from "../../util/dataColumns.js";
11
+ import {callInNextEventLoop} from "../../util/eventLoop.js";
12
12
  import type {BeaconChain} from "../chain.js";
13
13
  import {BlockError, BlockErrorCode} from "../errors/index.js";
14
14
  import {BlockProcessOpts} from "../options.js";
@@ -193,34 +193,30 @@ export async function verifyBlocksInEpoch(
193
193
  ),
194
194
 
195
195
  // All signatures at once
196
- opts.skipVerifyBlockSignatures !== true
197
- ? verifyBlocksSignatures(
198
- this.config,
199
- this.bls,
200
- this.logger,
201
- this.metrics,
202
- preState0,
203
- blocks,
204
- indexedAttestationsByBlock,
205
- opts
206
- )
207
- : Promise.resolve({verifySignaturesTime: Date.now()}),
196
+ verifyBlocksSignatures(
197
+ this.config,
198
+ this.bls,
199
+ this.logger,
200
+ this.metrics,
201
+ preState0,
202
+ blocks,
203
+ indexedAttestationsByBlock,
204
+ opts
205
+ ),
208
206
 
209
207
  // TODO GLOAS: can verify payload signatures in batch too
210
208
  // maybe chain with the above verifyBlocksSignatures()
211
209
  ]);
212
210
 
213
- if (opts.skipVerifyBlockSignatures !== true) {
214
- for (const block of blocks) {
215
- const {slot, proposerIndex} = block.message;
216
- const signedBlockHeader = signedBlockToSignedHeader(this.config, block);
217
- const blockRoot = toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(signedBlockHeader.message));
218
- this.seenBlockProposers.observeBlockRoot(slot, proposerIndex, blockRoot, signedBlockHeader);
219
- // Only produce a slashing while importing the block. A block that is verified before it is published
220
- // must not be treated as equivocation evidence since it may never be seen by the network
221
- if (opts.verifyOnly !== true && this.seenBlockProposers.isEquivocating(slot, proposerIndex)) {
222
- this.processProposerEquivocation(slot, proposerIndex);
223
- }
211
+ for (const blockInput of blockInputs) {
212
+ const block = blockInput.getBlock();
213
+ const {slot, proposerIndex} = block.message;
214
+ const signedBlockHeader = signedBlockToSignedHeader(this.config, block);
215
+ this.seenBlockProposers.observeBlockRoot(slot, proposerIndex, blockInput.blockRootHex, signedBlockHeader);
216
+ // Only produce a slashing while importing the block. A block that is verified before it is published
217
+ // must not be treated as equivocation evidence since it may never be seen by the network
218
+ if (opts.verifyOnly !== true && this.seenBlockProposers.isEquivocating(slot, proposerIndex)) {
219
+ callInNextEventLoop(() => this.processProposerEquivocation(slot, proposerIndex));
224
220
  }
225
221
  }
226
222
 
@@ -1217,7 +1217,12 @@ export class BeaconChain implements IBeaconChain {
1217
1217
  this.emitter.emit(routes.events.EventType.proposerSlashing, proposerSlashing);
1218
1218
  this.emitter.emit(ChainEvent.publishProposerSlashing, proposerSlashing);
1219
1219
  this.metrics?.opPool.proposerSlashingsProduced.inc();
1220
- this.logger.info("Produced proposer slashing from observed equivocation", {slot: blockSlot, proposerIndex});
1220
+ this.logger.info("Produced proposer slashing from observed equivocation", {
1221
+ slot: blockSlot,
1222
+ proposerIndex,
1223
+ header1Root: toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(header1.message)),
1224
+ header2Root: toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(header2.message)),
1225
+ });
1221
1226
  } finally {
1222
1227
  this.producingProposerSlashing.delete(proposerIndex);
1223
1228
  }
@@ -118,7 +118,7 @@ export type BlockErrorType =
118
118
  | {code: BlockErrorCode.GENESIS_BLOCK}
119
119
  | {code: BlockErrorCode.WOULD_REVERT_FINALIZED_SLOT; blockSlot: Slot; finalizedSlot: Slot}
120
120
  | {code: BlockErrorCode.ALREADY_KNOWN; root: RootHex}
121
- | {code: BlockErrorCode.REPEAT_PROPOSAL; proposerIndex: ValidatorIndex}
121
+ | {code: BlockErrorCode.REPEAT_PROPOSAL; proposerIndex: ValidatorIndex; root: RootHex}
122
122
  | {code: BlockErrorCode.BLOCK_SLOT_LIMIT_REACHED}
123
123
  | {code: BlockErrorCode.INCORRECT_PROPOSER; proposerIndex: ValidatorIndex}
124
124
  | {code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID; blockSlot: Slot}
@@ -86,8 +86,6 @@ export type BlockProcessOpts = {
86
86
  verifyOnly?: boolean;
87
87
  /** Used to specify to skip execution payload validation */
88
88
  skipVerifyExecutionPayload?: boolean;
89
- /** Used to specify to skip block signatures validation */
90
- skipVerifyBlockSignatures?: boolean;
91
89
  };
92
90
 
93
91
  export type PoolOpts = {
@@ -224,7 +224,7 @@ export class PrepareNextSlotScheduler {
224
224
  this.metrics?.blockPayload.payloadAdvancePrepTime.observe(preparationTime);
225
225
 
226
226
  const safeBlockHash = getSafeExecutionBlockHash(this.chain.forkChoice, this.logger);
227
- const finalizedBlockHash = getFinalizedExecutionBlockHash(this.chain.forkChoice, this.logger);
227
+ const finalizedBlockHash = getFinalizedExecutionBlockHash(this.chain.forkChoice);
228
228
 
229
229
  // awaiting here instead of throwing an async call because there is no other task
230
230
  // left for scheduler and this gives nice semantics to catch and log errors in the
@@ -271,7 +271,7 @@ export async function produceBlockBody<T extends BlockType>(
271
271
  // full and blinded no longer makes sense in gloas, it might be a good idea to move
272
272
  // this into a completely separate function and have pre/post gloas more separated
273
273
  const safeBlockHash = getSafeExecutionBlockHash(this.forkChoice, this.logger);
274
- const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice, this.logger);
274
+ const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice);
275
275
  // TODO GLOAS: post-Gloas, proposer feeRecipient is also carried (signed) in
276
276
  // ProposerPreferencesPool. Consider using this unified cache instead
277
277
  // see https://github.com/ChainSafe/lodestar/issues/9379
@@ -417,7 +417,7 @@ export async function produceBlockBody<T extends BlockType>(
417
417
  }
418
418
 
419
419
  const safeBlockHash = getSafeExecutionBlockHash(this.forkChoice, this.logger);
420
- const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice, this.logger);
420
+ const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice);
421
421
  const feeRecipient = requestedFeeRecipient ?? this.beaconProposerCache.getOrDefault(proposerIndex);
422
422
  const feeRecipientType = requestedFeeRecipient
423
423
  ? "requested"
@@ -3,7 +3,7 @@ import {Epoch, RootHex, Slot, ValidatorIndex, phase0} from "@lodestar/types";
3
3
  import {MapDef} from "@lodestar/utils";
4
4
 
5
5
  /** Two distinct block roots signed by the same proposer for the same slot are sufficient to establish an equivocation */
6
- const MAX_BLOCK_ROOTS_PER_PROPOSAL = 2;
6
+ const MIN_EQUIVOCATION_BLOCK_ROOTS_PER_PROPOSAL = 2;
7
7
 
8
8
  /**
9
9
  * Keeps a cache to filter block proposals from the same validator in the same slot.
@@ -19,7 +19,9 @@ const MAX_BLOCK_ROOTS_PER_PROPOSAL = 2;
19
19
  * The cache is pruned on finalization and bounds the number of roots stored per proposer and slot
20
20
  */
21
21
  export class SeenBlockProposers {
22
- private readonly proposerIndexesBySlot = new MapDef<Slot, Set<ValidatorIndex>>(() => new Set<ValidatorIndex>());
22
+ private readonly proposerIndexesBySlot = new MapDef<Slot, Map<ValidatorIndex, RootHex>>(
23
+ () => new Map<ValidatorIndex, RootHex>()
24
+ );
23
25
  private readonly signedBlockHeadersBySlot = new MapDef<
24
26
  Slot,
25
27
  MapDef<ValidatorIndex, Map<RootHex, phase0.SignedBeaconBlockHeader>>
@@ -30,13 +32,22 @@ export class SeenBlockProposers {
30
32
  return this.proposerIndexesBySlot.get(blockSlot)?.has(proposerIndex) === true;
31
33
  }
32
34
 
35
+ /**
36
+ * The block proposer is known at slot with a different root.
37
+ */
38
+ isRepeatProposal(blockSlot: Slot, proposerIndex: ValidatorIndex, blockRoot: RootHex): boolean {
39
+ const knownRoot = this.proposerIndexesBySlot.get(blockSlot)?.get(proposerIndex);
40
+ return knownRoot !== undefined && knownRoot !== blockRoot;
41
+ }
42
+
33
43
  hasBlockRoot(blockSlot: Slot, proposerIndex: ValidatorIndex, blockRoot: RootHex): boolean {
34
44
  return this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.has(blockRoot) === true;
35
45
  }
36
46
 
37
47
  isEquivocating(blockSlot: Slot, proposerIndex: ValidatorIndex): boolean {
38
48
  return (
39
- (this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.size ?? 0) >= MAX_BLOCK_ROOTS_PER_PROPOSAL
49
+ (this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.size ?? 0) >=
50
+ MIN_EQUIVOCATION_BLOCK_ROOTS_PER_PROPOSAL
40
51
  );
41
52
  }
42
53
 
@@ -53,7 +64,10 @@ export class SeenBlockProposers {
53
64
  proposerIndex: ValidatorIndex
54
65
  ): [phase0.SignedBeaconBlockHeader, phase0.SignedBeaconBlockHeader] | null {
55
66
  const signedBlockHeaderByRoot = this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex);
56
- if (signedBlockHeaderByRoot === undefined || signedBlockHeaderByRoot.size < MAX_BLOCK_ROOTS_PER_PROPOSAL) {
67
+ if (
68
+ signedBlockHeaderByRoot === undefined ||
69
+ signedBlockHeaderByRoot.size < MIN_EQUIVOCATION_BLOCK_ROOTS_PER_PROPOSAL
70
+ ) {
57
71
  return null;
58
72
  }
59
73
  const [signedHeader1, signedHeader2] = signedBlockHeaderByRoot.values();
@@ -72,18 +86,21 @@ export class SeenBlockProposers {
72
86
  }
73
87
 
74
88
  const signedBlockHeaderByRoot = this.signedBlockHeadersBySlot.getOrDefault(blockSlot).getOrDefault(proposerIndex);
75
- if (signedBlockHeaderByRoot.size < MAX_BLOCK_ROOTS_PER_PROPOSAL && !signedBlockHeaderByRoot.has(blockRoot)) {
89
+ if (
90
+ signedBlockHeaderByRoot.size < MIN_EQUIVOCATION_BLOCK_ROOTS_PER_PROPOSAL &&
91
+ !signedBlockHeaderByRoot.has(blockRoot)
92
+ ) {
76
93
  signedBlockHeaderByRoot.set(blockRoot, signedBlockHeader);
77
94
  }
78
95
  }
79
96
 
80
97
  /** Mark a block as known from gossip or another block import path */
81
- add(blockSlot: Slot, proposerIndex: ValidatorIndex): void {
98
+ add(blockSlot: Slot, proposerIndex: ValidatorIndex, blockRoot: RootHex): void {
82
99
  if (blockSlot < this.finalizedSlot) {
83
100
  throw Error(`blockSlot ${blockSlot} < finalizedSlot ${this.finalizedSlot}`);
84
101
  }
85
102
 
86
- this.proposerIndexesBySlot.getOrDefault(blockSlot).add(proposerIndex);
103
+ this.proposerIndexesBySlot.getOrDefault(blockSlot).set(proposerIndex, blockRoot);
87
104
  }
88
105
 
89
106
  prune(finalizedSlot: Slot): void {
@@ -89,13 +89,20 @@ export async function validateGossipBlock(
89
89
 
90
90
  // [IGNORE] The block is the first block with valid signature received for the proposer for the slot, signed_beacon_block.message.slot.
91
91
  const proposerIndex = block.proposerIndex;
92
- const hasBlockRoot = chain.seenBlockProposers.hasBlockRoot(blockSlot, proposerIndex, blockRoot);
93
92
  if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
94
- if (!hasBlockRoot && !chain.seenBlockProposers.isEquivocating(blockSlot, proposerIndex)) {
95
- await verifyBlockProposerSignature(chain, signedBlock, blockRoot, {verifyOnMainThread: false});
96
- chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot, signedBlockHeader);
93
+ if (chain.seenBlockProposers.isRepeatProposal(blockSlot, proposerIndex, blockRoot)) {
94
+ const hasBlockRoot = chain.seenBlockProposers.hasBlockRoot(blockSlot, proposerIndex, blockRoot);
95
+ if (!hasBlockRoot && !chain.seenBlockProposers.isEquivocating(blockSlot, proposerIndex)) {
96
+ await verifyBlockProposerSignature(chain, signedBlock, blockRoot, {verifyOnMainThread: false});
97
+ chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot, signedBlockHeader);
98
+ }
99
+ throw new BlockGossipError(GossipAction.IGNORE, {
100
+ code: BlockErrorCode.REPEAT_PROPOSAL,
101
+ proposerIndex,
102
+ root: blockRoot,
103
+ });
97
104
  }
98
- throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.REPEAT_PROPOSAL, proposerIndex});
105
+ throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.ALREADY_KNOWN, root: blockRoot});
99
106
  }
100
107
 
101
108
  // [REJECT] The current finalized_checkpoint is an ancestor of block -- i.e.
@@ -301,10 +308,17 @@ export async function validateGossipBlock(
301
308
 
302
309
  // Check again after all async validation and the early-block delay so concurrent proposals cannot both pass
303
310
  if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
304
- throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.REPEAT_PROPOSAL, proposerIndex});
311
+ if (chain.seenBlockProposers.isRepeatProposal(blockSlot, proposerIndex, blockRoot)) {
312
+ throw new BlockGossipError(GossipAction.IGNORE, {
313
+ code: BlockErrorCode.REPEAT_PROPOSAL,
314
+ proposerIndex,
315
+ root: blockRoot,
316
+ });
317
+ }
318
+ throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.ALREADY_KNOWN, root: blockRoot});
305
319
  }
306
320
 
307
- chain.seenBlockProposers.add(blockSlot, proposerIndex);
321
+ chain.seenBlockProposers.add(blockSlot, proposerIndex, blockRoot);
308
322
 
309
323
  return {skippedSlots};
310
324
  }
@@ -593,7 +593,7 @@ export class Batch {
593
593
  if (allComplete) {
594
594
  const attempt: Attempt = {
595
595
  peers: this.getSuccessfulPeers(),
596
- hash: hashBlocks(blocks, this.config),
596
+ hash: hashBlocks(blocks, payloadEnvelopes),
597
597
  };
598
598
  this.state = {status: BatchStatus.AwaitingProcessing, blocks, payloadEnvelopes: newPayloadEnvelopes, attempt};
599
599
  } else {
@@ -1,27 +1,62 @@
1
- import {ChainForkConfig} from "@lodestar/config";
2
- import {RootHex, SignedBeaconBlock} from "@lodestar/types";
3
- import {toRootHex} from "@lodestar/utils";
1
+ import {digest} from "@chainsafe/as-sha256";
2
+ import {RootHex, Slot, ssz} from "@lodestar/types";
3
+ import {fromHex, toRootHex} from "@lodestar/utils";
4
4
  import {IBlockInput} from "../../../chain/blocks/blockInput/types.js";
5
+ import {PayloadEnvelopeInput} from "../../../chain/blocks/payloadEnvelopeInput/payloadEnvelopeInput.js";
6
+
7
+ const ROOT_SIZE = 32;
8
+ const SIGNATURE_SIZE = 96;
9
+ /** Every block and every payload envelope contributes a fixed-size (root, signature) entry */
10
+ const ENTRY_SIZE = ROOT_SIZE + SIGNATURE_SIZE;
11
+ /** uint32 LE counts of block and envelope entries, so the variable-length sections are self-describing */
12
+ const COUNT_SIZE = 4;
13
+ const HEADER_SIZE = COUNT_SIZE * 2;
5
14
 
6
15
  /**
7
- * String to uniquely identify block segments. Used for peer scoring and to compare if batches are equivalent.
16
+ * Root uniquely identifying a batch attempt (its blocks AND payloads). Used for peer scoring and to
17
+ * compare if two attempts are equivalent.
18
+ *
19
+ * Signatures are part of the id for BOTH blocks and payload envelopes, not just their message roots:
20
+ * a peer serving a correct message with a garbage signature would otherwise produce the same id as
21
+ * the honest attempt and escape scoring in `SyncChain.advanceChain`. Signatures are not verified at
22
+ * download time, only during processChainSegment (block signatures in verifyBlocksSignatures,
23
+ * envelope signatures in importExecutionPayload).
24
+ *
25
+ * Entries are written as raw bytes into a single exactly-sized buffer and digested once, so an
26
+ * `Attempt` retains 32 bytes rather than the ~16 KB a full 32-slot gloas batch would need if the
27
+ * roots and signatures were concatenated as hex. sha256 (not a 64-bit hash) because a peer that
28
+ * could force a collision with the winning attempt would escape peer scoring.
8
29
  */
9
- export function hashBlocks(blocks: IBlockInput[], config: ChainForkConfig): RootHex {
10
- switch (blocks.length) {
11
- case 0:
12
- return "0x";
13
- case 1: {
14
- const block0 = blocks[0].getBlock();
15
- return toRootHex(config.getForkTypes(block0.message.slot).SignedBeaconBlock.hashTreeRoot(block0));
16
- }
17
- default: {
18
- const block0 = blocks[0].getBlock();
19
- const blockN = blocks.at(-1)?.getBlock() as SignedBeaconBlock;
20
- return (
21
- // TODO(fulu): should we be doing checks for presence to make sure these do not blow up?
22
- toRootHex(config.getForkTypes(block0.message.slot).SignedBeaconBlock.hashTreeRoot(block0)) +
23
- toRootHex(config.getForkTypes(blockN.message.slot).SignedBeaconBlock.hashTreeRoot(blockN))
24
- );
25
- }
30
+ export function hashBlocks(blocks: IBlockInput[], payloadEnvelopes: Map<Slot, PayloadEnvelopeInput> | null): RootHex {
31
+ // Envelopes without a payload carry no attributable data, so they are skipped entirely. A `null`
32
+ // map and a map whose entries all lack a payload are therefore equivalent, which is intended.
33
+ const envelopes =
34
+ payloadEnvelopes && payloadEnvelopes.size > 0
35
+ ? Array.from(payloadEnvelopes.entries())
36
+ .filter(([, envelope]) => envelope.hasPayloadEnvelope())
37
+ .sort(([slotA], [slotB]) => slotA - slotB)
38
+ : [];
39
+
40
+ const buf = Buffer.allocUnsafe(HEADER_SIZE + (blocks.length + envelopes.length) * ENTRY_SIZE);
41
+ buf.writeUInt32LE(blocks.length, 0);
42
+ buf.writeUInt32LE(envelopes.length, COUNT_SIZE);
43
+ let offset = HEADER_SIZE;
44
+
45
+ for (const block of blocks) {
46
+ buf.set(fromHex(block.blockRootHex), offset);
47
+ offset += ROOT_SIZE;
48
+ buf.set(block.getBlock().signature, offset);
49
+ offset += SIGNATURE_SIZE;
26
50
  }
51
+
52
+ for (const [, envelope] of envelopes) {
53
+ const signedEnvelope = envelope.getPayloadEnvelope();
54
+ // envelope's root is cached thanks to cachePermanentRootStruct, so this avoids re-hashing
55
+ buf.set(ssz.gloas.ExecutionPayloadEnvelope.hashTreeRoot(signedEnvelope.message), offset);
56
+ offset += ROOT_SIZE;
57
+ buf.set(signedEnvelope.signature, offset);
58
+ offset += SIGNATURE_SIZE;
59
+ }
60
+
61
+ return toRootHex(digest(buf));
27
62
  }