@aztec/validator-client 0.0.1-commit.d3ec352c → 0.0.1-commit.e6bd8901

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 (69) hide show
  1. package/README.md +282 -0
  2. package/dest/block_proposal_handler.d.ts +21 -10
  3. package/dest/block_proposal_handler.d.ts.map +1 -1
  4. package/dest/block_proposal_handler.js +335 -80
  5. package/dest/checkpoint_builder.d.ts +67 -0
  6. package/dest/checkpoint_builder.d.ts.map +1 -0
  7. package/dest/checkpoint_builder.js +160 -0
  8. package/dest/config.d.ts +1 -1
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +13 -8
  11. package/dest/duties/validation_service.d.ts +42 -13
  12. package/dest/duties/validation_service.d.ts.map +1 -1
  13. package/dest/duties/validation_service.js +111 -28
  14. package/dest/factory.d.ts +13 -8
  15. package/dest/factory.d.ts.map +1 -1
  16. package/dest/factory.js +2 -2
  17. package/dest/index.d.ts +3 -1
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +2 -0
  20. package/dest/key_store/ha_key_store.d.ts +99 -0
  21. package/dest/key_store/ha_key_store.d.ts.map +1 -0
  22. package/dest/key_store/ha_key_store.js +208 -0
  23. package/dest/key_store/index.d.ts +2 -1
  24. package/dest/key_store/index.d.ts.map +1 -1
  25. package/dest/key_store/index.js +1 -0
  26. package/dest/key_store/interface.d.ts +36 -6
  27. package/dest/key_store/interface.d.ts.map +1 -1
  28. package/dest/key_store/local_key_store.d.ts +10 -5
  29. package/dest/key_store/local_key_store.d.ts.map +1 -1
  30. package/dest/key_store/local_key_store.js +9 -5
  31. package/dest/key_store/node_keystore_adapter.d.ts +18 -5
  32. package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
  33. package/dest/key_store/node_keystore_adapter.js +18 -4
  34. package/dest/key_store/web3signer_key_store.d.ts +10 -5
  35. package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
  36. package/dest/key_store/web3signer_key_store.js +9 -5
  37. package/dest/metrics.d.ts +1 -1
  38. package/dest/metrics.d.ts.map +1 -1
  39. package/dest/metrics.js +8 -33
  40. package/dest/tx_validator/index.d.ts +3 -0
  41. package/dest/tx_validator/index.d.ts.map +1 -0
  42. package/dest/tx_validator/index.js +2 -0
  43. package/dest/tx_validator/nullifier_cache.d.ts +14 -0
  44. package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
  45. package/dest/tx_validator/nullifier_cache.js +24 -0
  46. package/dest/tx_validator/tx_validator_factory.d.ts +18 -0
  47. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
  48. package/dest/tx_validator/tx_validator_factory.js +54 -0
  49. package/dest/validator.d.ts +46 -18
  50. package/dest/validator.d.ts.map +1 -1
  51. package/dest/validator.js +319 -54
  52. package/package.json +19 -11
  53. package/src/block_proposal_handler.ts +254 -44
  54. package/src/checkpoint_builder.ts +284 -0
  55. package/src/config.ts +12 -7
  56. package/src/duties/validation_service.ts +155 -33
  57. package/src/factory.ts +17 -8
  58. package/src/index.ts +2 -0
  59. package/src/key_store/ha_key_store.ts +269 -0
  60. package/src/key_store/index.ts +1 -0
  61. package/src/key_store/interface.ts +44 -5
  62. package/src/key_store/local_key_store.ts +14 -5
  63. package/src/key_store/node_keystore_adapter.ts +28 -5
  64. package/src/key_store/web3signer_key_store.ts +18 -5
  65. package/src/metrics.ts +7 -34
  66. package/src/tx_validator/index.ts +2 -0
  67. package/src/tx_validator/nullifier_cache.ts +30 -0
  68. package/src/tx_validator/tx_validator_factory.ts +135 -0
  69. package/src/validator.ts +440 -79
@@ -1,19 +1,25 @@
1
1
  import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
2
- import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type { EpochCache } from '@aztec/epoch-cache';
3
+ import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
4
+ import { chunkBy } from '@aztec/foundation/collection';
5
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
6
  import { TimeoutError } from '@aztec/foundation/error';
4
- import { Fr } from '@aztec/foundation/fields';
5
7
  import { createLogger } from '@aztec/foundation/log';
6
8
  import { retryUntil } from '@aztec/foundation/retry';
7
9
  import { DateProvider, Timer } from '@aztec/foundation/timer';
8
10
  import type { P2P, PeerId } from '@aztec/p2p';
9
11
  import { TxProvider } from '@aztec/p2p';
10
12
  import { BlockProposalValidator } from '@aztec/p2p/msg_validators';
11
- import type { L2Block, L2BlockSource } from '@aztec/stdlib/block';
12
- import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
13
- import type { IFullNodeBlockBuilder, ValidatorClientFullConfig } from '@aztec/stdlib/interfaces/server';
14
- import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
15
- import { type BlockProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
16
- import { BlockHeader, type FailedTx, GlobalVariables, type Tx } from '@aztec/stdlib/tx';
13
+ import type { L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
14
+ import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
15
+ import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
16
+ import {
17
+ type L1ToL2MessageSource,
18
+ computeCheckpointOutHash,
19
+ computeInHashFromL1ToL2Messages,
20
+ } from '@aztec/stdlib/messaging';
21
+ import type { BlockProposal } from '@aztec/stdlib/p2p';
22
+ import { BlockHeader, type CheckpointGlobalVariables, type FailedTx, type Tx } from '@aztec/stdlib/tx';
17
23
  import {
18
24
  ReExFailedTxsError,
19
25
  ReExStateMismatchError,
@@ -22,6 +28,7 @@ import {
22
28
  } from '@aztec/stdlib/validators';
23
29
  import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
24
30
 
31
+ import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
25
32
  import type { ValidatorMetrics } from './metrics.js';
26
33
 
27
34
  export type BlockProposalValidationFailureReason =
@@ -29,6 +36,7 @@ export type BlockProposalValidationFailureReason =
29
36
  | 'parent_block_not_found'
30
37
  | 'parent_block_wrong_slot'
31
38
  | 'in_hash_mismatch'
39
+ | 'global_variables_mismatch'
32
40
  | 'block_number_already_exists'
33
41
  | 'txs_not_available'
34
42
  | 'state_mismatch'
@@ -58,15 +66,21 @@ export type BlockProposalValidationFailureResult = {
58
66
 
59
67
  export type BlockProposalValidationResult = BlockProposalValidationSuccessResult | BlockProposalValidationFailureResult;
60
68
 
69
+ type CheckpointComputationResult =
70
+ | { checkpointNumber: CheckpointNumber; reason?: undefined }
71
+ | { checkpointNumber?: undefined; reason: 'invalid_proposal' | 'global_variables_mismatch' };
72
+
61
73
  export class BlockProposalHandler {
62
74
  public readonly tracer: Tracer;
63
75
 
64
76
  constructor(
65
- private blockBuilder: IFullNodeBlockBuilder,
66
- private blockSource: L2BlockSource,
77
+ private checkpointsBuilder: FullNodeCheckpointsBuilder,
78
+ private worldState: WorldStateSynchronizer,
79
+ private blockSource: L2BlockSource & L2BlockSink,
67
80
  private l1ToL2MessageSource: L1ToL2MessageSource,
68
81
  private txProvider: TxProvider,
69
82
  private blockProposalValidator: BlockProposalValidator,
83
+ private epochCache: EpochCache,
70
84
  private config: ValidatorClientFullConfig,
71
85
  private metrics?: ValidatorMetrics,
72
86
  private dateProvider: DateProvider = new DateProvider(),
@@ -80,7 +94,9 @@ export class BlockProposalHandler {
80
94
  }
81
95
 
82
96
  registerForReexecution(p2pClient: P2P): BlockProposalHandler {
83
- const handler = async (proposal: BlockProposal, proposalSender: PeerId) => {
97
+ // Non-validator handler that re-executes for monitoring but does not attest.
98
+ // Returns boolean indicating whether the proposal was valid.
99
+ const handler = async (proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> => {
84
100
  try {
85
101
  const result = await this.handleBlockProposal(proposal, proposalSender, true);
86
102
  if (result.isValid) {
@@ -90,16 +106,18 @@ export class BlockProposalHandler {
90
106
  totalManaUsed: result.reexecutionResult?.totalManaUsed,
91
107
  numTxs: result.reexecutionResult?.block?.body?.txEffects?.length ?? 0,
92
108
  });
109
+ return true;
93
110
  } else {
94
111
  this.log.warn(`Non-validator reexecution failed for slot ${proposal.slotNumber}`, {
95
112
  blockNumber: result.blockNumber,
96
113
  reason: result.reason,
97
114
  });
115
+ return false;
98
116
  }
99
117
  } catch (error) {
100
118
  this.log.error('Error processing block proposal in non-validator handler', error);
119
+ return false;
101
120
  }
102
- return undefined; // Non-validator nodes don't return attestations
103
121
  };
104
122
 
105
123
  p2pClient.registerBlockProposalHandler(handler);
@@ -113,7 +131,7 @@ export class BlockProposalHandler {
113
131
  ): Promise<BlockProposalValidationResult> {
114
132
  const slotNumber = proposal.slotNumber;
115
133
  const proposer = proposal.getSender();
116
- const config = this.blockBuilder.getConfig();
134
+ const config = this.checkpointsBuilder.getConfig();
117
135
 
118
136
  // Reject proposals with invalid signatures
119
137
  if (!proposer) {
@@ -129,8 +147,8 @@ export class BlockProposalHandler {
129
147
 
130
148
  // Check that the proposal is from the current proposer, or the next proposer
131
149
  // This should have been handled by the p2p layer, but we double check here out of caution
132
- const invalidProposal = await this.blockProposalValidator.validate(proposal);
133
- if (invalidProposal) {
150
+ const validationResult = await this.blockProposalValidator.validate(proposal);
151
+ if (validationResult.result !== 'accept') {
134
152
  this.log.warn(`Proposal is not valid, skipping processing`, proposalInfo);
135
153
  return { isValid: false, reason: 'invalid_proposal' };
136
154
  }
@@ -172,10 +190,17 @@ export class BlockProposalHandler {
172
190
  deadline: this.getReexecutionDeadline(slotNumber, config),
173
191
  });
174
192
 
193
+ // Compute the checkpoint number for this block and validate checkpoint consistency
194
+ const checkpointResult = await this.computeCheckpointNumber(proposal, parentBlockHeader, proposalInfo);
195
+ if (checkpointResult.reason) {
196
+ return { isValid: false, blockNumber, reason: checkpointResult.reason };
197
+ }
198
+ const checkpointNumber = checkpointResult.checkpointNumber;
199
+
175
200
  // Check that I have the same set of l1ToL2Messages as the proposal
176
- const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(blockNumber);
201
+ const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
177
202
  const computedInHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
178
- const proposalInHash = proposal.payload.header.contentCommitment.inHash;
203
+ const proposalInHash = proposal.inHash;
179
204
  if (!computedInHash.equals(proposalInHash)) {
180
205
  this.log.warn(`L1 to L2 messages in hash mismatch, skipping processing`, {
181
206
  proposalInHash: proposalInHash.toString(),
@@ -194,9 +219,28 @@ export class BlockProposalHandler {
194
219
  // Try re-executing the transactions in the proposal if needed
195
220
  let reexecutionResult;
196
221
  if (shouldReexecute) {
222
+ // Compute the previous checkpoint out hashes for the epoch.
223
+ // TODO(leila/mbps): There can be a more efficient way to get the previous checkpoint out
224
+ // hashes without having to fetch all the blocks.
225
+ const epoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
226
+ const checkpointedBlocks = (await this.blockSource.getCheckpointedBlocksForEpoch(epoch))
227
+ .filter(b => b.block.number < blockNumber)
228
+ .sort((a, b) => a.block.number - b.block.number);
229
+ const blocksByCheckpoint = chunkBy(checkpointedBlocks, b => b.checkpointNumber);
230
+ const previousCheckpointOutHashes = blocksByCheckpoint.map(checkpointBlocks =>
231
+ computeCheckpointOutHash(checkpointBlocks.map(b => b.block.body.txEffects.map(tx => tx.l2ToL1Msgs))),
232
+ );
233
+
197
234
  try {
198
235
  this.log.verbose(`Re-executing transactions in the proposal`, proposalInfo);
199
- reexecutionResult = await this.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
236
+ reexecutionResult = await this.reexecuteTransactions(
237
+ proposal,
238
+ blockNumber,
239
+ checkpointNumber,
240
+ txs,
241
+ l1ToL2Messages,
242
+ previousCheckpointOutHashes,
243
+ );
200
244
  } catch (error) {
201
245
  this.log.error(`Error reexecuting txs while processing block proposal`, error, proposalInfo);
202
246
  const reason = this.getReexecuteFailureReason(error);
@@ -204,14 +248,23 @@ export class BlockProposalHandler {
204
248
  }
205
249
  }
206
250
 
207
- this.log.info(`Successfully processed proposal for slot ${slotNumber}`, proposalInfo);
251
+ // If we succeeded, push this block into the archiver (unless disabled)
252
+ if (reexecutionResult?.block && this.config.skipPushProposedBlocksToArchiver === false) {
253
+ await this.blockSource.addBlock(reexecutionResult?.block);
254
+ }
255
+
256
+ this.log.info(
257
+ `Successfully processed block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`,
258
+ proposalInfo,
259
+ );
260
+
208
261
  return { isValid: true, blockNumber, reexecutionResult };
209
262
  }
210
263
 
211
264
  private async getParentBlock(proposal: BlockProposal): Promise<'genesis' | BlockHeader | undefined> {
212
- const parentArchive = proposal.payload.header.lastArchiveRoot;
265
+ const parentArchive = proposal.blockHeader.lastArchive.root;
213
266
  const slot = proposal.slotNumber;
214
- const config = this.blockBuilder.getConfig();
267
+ const config = this.checkpointsBuilder.getConfig();
215
268
  const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
216
269
 
217
270
  if (parentArchive.equals(genesisArchiveRoot)) {
@@ -245,10 +298,142 @@ export class BlockProposalHandler {
245
298
  }
246
299
  }
247
300
 
301
+ private async computeCheckpointNumber(
302
+ proposal: BlockProposal,
303
+ parentBlockHeader: 'genesis' | BlockHeader,
304
+ proposalInfo: object,
305
+ ): Promise<CheckpointComputationResult> {
306
+ if (parentBlockHeader === 'genesis') {
307
+ // First block is in checkpoint 1
308
+ if (proposal.indexWithinCheckpoint !== 0) {
309
+ this.log.warn(`First block proposal has non-zero indexWithinCheckpoint`, proposalInfo);
310
+ return { reason: 'invalid_proposal' };
311
+ }
312
+ return { checkpointNumber: CheckpointNumber.INITIAL };
313
+ }
314
+
315
+ // Get the parent block to find its checkpoint number
316
+ // TODO(palla/mbps): The block header should include the checkpoint number to avoid this lookup,
317
+ // or at least the L2BlockSource should return a different struct that includes it.
318
+ const parentBlockNumber = parentBlockHeader.getBlockNumber();
319
+ const parentBlock = await this.blockSource.getL2Block(parentBlockNumber);
320
+ if (!parentBlock) {
321
+ this.log.warn(`Parent block ${parentBlockNumber} not found in archiver`, proposalInfo);
322
+ return { reason: 'invalid_proposal' };
323
+ }
324
+
325
+ if (proposal.indexWithinCheckpoint === 0) {
326
+ // If this is the first block in a new checkpoint, increment the checkpoint number
327
+ if (!(proposal.blockHeader.getSlot() > parentBlockHeader.getSlot())) {
328
+ this.log.warn(`Slot should be greater than parent block slot for first block in checkpoint`, proposalInfo);
329
+ return { reason: 'invalid_proposal' };
330
+ }
331
+ return { checkpointNumber: CheckpointNumber(parentBlock.checkpointNumber + 1) };
332
+ }
333
+
334
+ // Otherwise it should follow the previous block in the same checkpoint
335
+ if (proposal.indexWithinCheckpoint !== parentBlock.indexWithinCheckpoint + 1) {
336
+ this.log.warn(`Non-sequential indexWithinCheckpoint`, proposalInfo);
337
+ return { reason: 'invalid_proposal' };
338
+ }
339
+ if (proposal.blockHeader.getSlot() !== parentBlockHeader.getSlot()) {
340
+ this.log.warn(`Slot should be equal to parent block slot for non-first block in checkpoint`, proposalInfo);
341
+ return { reason: 'invalid_proposal' };
342
+ }
343
+
344
+ // For non-first blocks in a checkpoint, validate global variables match parent (except blockNumber)
345
+ const validationResult = this.validateNonFirstBlockInCheckpoint(proposal, parentBlock, proposalInfo);
346
+ if (validationResult) {
347
+ return validationResult;
348
+ }
349
+
350
+ return { checkpointNumber: parentBlock.checkpointNumber };
351
+ }
352
+
353
+ /**
354
+ * Validates that a non-first block in a checkpoint has consistent global variables with its parent.
355
+ * For blocks with indexWithinCheckpoint > 0, all global variables except blockNumber must match the parent.
356
+ * @returns A failure result if validation fails, undefined if validation passes
357
+ */
358
+ private validateNonFirstBlockInCheckpoint(
359
+ proposal: BlockProposal,
360
+ parentBlock: L2Block,
361
+ proposalInfo: object,
362
+ ): CheckpointComputationResult | undefined {
363
+ const proposalGlobals = proposal.blockHeader.globalVariables;
364
+ const parentGlobals = parentBlock.header.globalVariables;
365
+
366
+ // All global variables except blockNumber should match the parent
367
+ // blockNumber naturally increments between blocks
368
+ if (!proposalGlobals.chainId.equals(parentGlobals.chainId)) {
369
+ this.log.warn(`Non-first block in checkpoint has mismatched chainId`, {
370
+ ...proposalInfo,
371
+ proposalChainId: proposalGlobals.chainId.toString(),
372
+ parentChainId: parentGlobals.chainId.toString(),
373
+ });
374
+ return { reason: 'global_variables_mismatch' };
375
+ }
376
+
377
+ if (!proposalGlobals.version.equals(parentGlobals.version)) {
378
+ this.log.warn(`Non-first block in checkpoint has mismatched version`, {
379
+ ...proposalInfo,
380
+ proposalVersion: proposalGlobals.version.toString(),
381
+ parentVersion: parentGlobals.version.toString(),
382
+ });
383
+ return { reason: 'global_variables_mismatch' };
384
+ }
385
+
386
+ if (proposalGlobals.slotNumber !== parentGlobals.slotNumber) {
387
+ this.log.warn(`Non-first block in checkpoint has mismatched slotNumber`, {
388
+ ...proposalInfo,
389
+ proposalSlotNumber: proposalGlobals.slotNumber,
390
+ parentSlotNumber: parentGlobals.slotNumber,
391
+ });
392
+ return { reason: 'global_variables_mismatch' };
393
+ }
394
+
395
+ if (proposalGlobals.timestamp !== parentGlobals.timestamp) {
396
+ this.log.warn(`Non-first block in checkpoint has mismatched timestamp`, {
397
+ ...proposalInfo,
398
+ proposalTimestamp: proposalGlobals.timestamp.toString(),
399
+ parentTimestamp: parentGlobals.timestamp.toString(),
400
+ });
401
+ return { reason: 'global_variables_mismatch' };
402
+ }
403
+
404
+ if (!proposalGlobals.coinbase.equals(parentGlobals.coinbase)) {
405
+ this.log.warn(`Non-first block in checkpoint has mismatched coinbase`, {
406
+ ...proposalInfo,
407
+ proposalCoinbase: proposalGlobals.coinbase.toString(),
408
+ parentCoinbase: parentGlobals.coinbase.toString(),
409
+ });
410
+ return { reason: 'global_variables_mismatch' };
411
+ }
412
+
413
+ if (!proposalGlobals.feeRecipient.equals(parentGlobals.feeRecipient)) {
414
+ this.log.warn(`Non-first block in checkpoint has mismatched feeRecipient`, {
415
+ ...proposalInfo,
416
+ proposalFeeRecipient: proposalGlobals.feeRecipient.toString(),
417
+ parentFeeRecipient: parentGlobals.feeRecipient.toString(),
418
+ });
419
+ return { reason: 'global_variables_mismatch' };
420
+ }
421
+
422
+ if (!proposalGlobals.gasFees.equals(parentGlobals.gasFees)) {
423
+ this.log.warn(`Non-first block in checkpoint has mismatched gasFees`, {
424
+ ...proposalInfo,
425
+ proposalGasFees: proposalGlobals.gasFees.toInspect(),
426
+ parentGasFees: parentGlobals.gasFees.toInspect(),
427
+ });
428
+ return { reason: 'global_variables_mismatch' };
429
+ }
430
+
431
+ return undefined;
432
+ }
433
+
248
434
  private getReexecutionDeadline(slot: SlotNumber, config: { l1GenesisTime: bigint; slotDuration: number }): Date {
249
435
  const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
250
- const msNeededForPropagationAndPublishing = this.config.validatorReexecuteDeadlineMs;
251
- return new Date(nextSlotTimestampSeconds * 1000 - msNeededForPropagationAndPublishing);
436
+ return new Date(nextSlotTimestampSeconds * 1000);
252
437
  }
253
438
 
254
439
  private getReexecuteFailureReason(err: any) {
@@ -266,11 +451,12 @@ export class BlockProposalHandler {
266
451
  async reexecuteTransactions(
267
452
  proposal: BlockProposal,
268
453
  blockNumber: BlockNumber,
454
+ checkpointNumber: CheckpointNumber,
269
455
  txs: Tx[],
270
456
  l1ToL2Messages: Fr[],
457
+ previousCheckpointOutHashes: Fr[],
271
458
  ): Promise<ReexecuteTransactionsResult> {
272
- const { header } = proposal.payload;
273
- const { txHashes } = proposal;
459
+ const { blockHeader, txHashes } = proposal;
274
460
 
275
461
  // If we do not have all of the transactions, then we should fail
276
462
  if (txs.length !== txHashes.length) {
@@ -279,28 +465,48 @@ export class BlockProposalHandler {
279
465
  throw new TransactionsNotAvailableError(missingTxHashes);
280
466
  }
281
467
 
282
- // Use the sequencer's block building logic to re-execute the transactions
283
468
  const timer = new Timer();
284
- const config = this.blockBuilder.getConfig();
285
-
286
- // We source most global variables from the proposal
287
- const globalVariables = GlobalVariables.from({
288
- slotNumber: proposal.payload.header.slotNumber, // checked in the block proposal validator
289
- coinbase: proposal.payload.header.coinbase, // set arbitrarily by the proposer
290
- feeRecipient: proposal.payload.header.feeRecipient, // set arbitrarily by the proposer
291
- gasFees: proposal.payload.header.gasFees, // validated by the rollup contract
292
- blockNumber, // computed from the parent block and checked it does not exist in archiver
293
- timestamp: header.timestamp, // checked in the rollup contract against the slot number
469
+ const slot = proposal.slotNumber;
470
+ const config = this.checkpointsBuilder.getConfig();
471
+
472
+ // Get prior blocks in this checkpoint (same slot before current block)
473
+ const allBlocksInSlot = await this.blockSource.getBlocksForSlot(slot);
474
+ const priorBlocks = allBlocksInSlot.filter(b => b.number < blockNumber && b.header.getSlot() === slot);
475
+
476
+ // Fork before the block to be built
477
+ const parentBlockNumber = BlockNumber(blockNumber - 1);
478
+ using fork = await this.worldState.fork(parentBlockNumber);
479
+
480
+ // Build checkpoint constants from proposal (excludes blockNumber and timestamp which are per-block)
481
+ const constants: CheckpointGlobalVariables = {
294
482
  chainId: new Fr(config.l1ChainId),
295
483
  version: new Fr(config.rollupVersion),
296
- });
484
+ slotNumber: slot,
485
+ coinbase: blockHeader.globalVariables.coinbase,
486
+ feeRecipient: blockHeader.globalVariables.feeRecipient,
487
+ gasFees: blockHeader.globalVariables.gasFees,
488
+ };
297
489
 
298
- const { block, failedTxs } = await this.blockBuilder.buildBlock(txs, l1ToL2Messages, globalVariables, {
299
- deadline: this.getReexecutionDeadline(proposal.payload.header.slotNumber, config),
490
+ // Create checkpoint builder with prior blocks
491
+ const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
492
+ checkpointNumber,
493
+ constants,
494
+ l1ToL2Messages,
495
+ previousCheckpointOutHashes,
496
+ fork,
497
+ priorBlocks,
498
+ );
499
+
500
+ // Build the new block
501
+ const deadline = this.getReexecutionDeadline(slot, config);
502
+ const result = await checkpointBuilder.buildBlock(txs, blockNumber, blockHeader.globalVariables.timestamp, {
503
+ deadline,
504
+ expectedEndState: blockHeader.state,
300
505
  });
301
506
 
507
+ const { block, failedTxs } = result;
302
508
  const numFailedTxs = failedTxs.length;
303
- const slot = proposal.slotNumber;
509
+
304
510
  this.log.verbose(`Transaction re-execution complete for slot ${slot}`, {
305
511
  numFailedTxs,
306
512
  numProposalTxs: txHashes.length,
@@ -319,11 +525,15 @@ export class BlockProposalHandler {
319
525
  }
320
526
 
321
527
  // Throw a ReExStateMismatchError error if state updates do not match
322
- const blockPayload = ConsensusPayload.fromBlock(block);
323
- if (!blockPayload.equals(proposal.payload)) {
528
+ // Compare the full block structure (archive and header) from the built block with the proposal
529
+ const archiveMatches = proposal.archive.equals(block.archive.root);
530
+ const headerMatches = proposal.blockHeader.equals(block.header);
531
+ if (!archiveMatches || !headerMatches) {
324
532
  this.log.warn(`Re-execution state mismatch for slot ${slot}`, {
325
- expected: blockPayload.toInspect(),
326
- actual: proposal.payload.toInspect(),
533
+ expectedArchive: block.archive.root.toString(),
534
+ actualArchive: proposal.archive.toString(),
535
+ expectedHeader: block.header.toInspect(),
536
+ actualHeader: proposal.blockHeader.toInspect(),
327
537
  });
328
538
  this.metrics?.recordFailedReexecution(proposal);
329
539
  throw new ReExStateMismatchError(proposal.archive, block.archive.root);