@aztec-labs/validator-client 6.0.0-rc.3 → 6.0.0-rc.4

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.
@@ -84,7 +84,11 @@ import { MerkleTreeId } from '@aztec-labs/stdlib/trees';
84
84
  import { InvalidBlockProposalTxsError, ReExFailedTxsError, ReExInitialStateMismatchError, ReExStateMismatchError, ReExTimeoutError, TransactionsNotAvailableError } from '@aztec-labs/stdlib/validators';
85
85
  import { getTelemetryClient } from '@aztec-labs/telemetry-client';
86
86
  import { checkInboxEndpoint } from './checkpoint_endpoint_check.js';
87
+ import { warnCommitteeNotStable } from './committee_not_stable.js';
87
88
  import { checkStreamingBlockProposalMetadata, isRetryableStreamingBlockCheckReason, readStreamingBlockBundle } from './streaming_inbox_checks.js';
89
+ /** Whether a streaming-Inbox block check was rejected for a local-view reason that a forced archiver sync may clear. */ function isRetryableStreamingBlockRejection(result) {
90
+ return !result.accepted && isRetryableStreamingBlockCheckReason(result.reason);
91
+ }
88
92
  /**
89
93
  * Maps an archiver insert rejection to the matching per-block validation reason, or undefined when the error is not
90
94
  * an Inbox prefix rejection and must keep propagating.
@@ -140,6 +144,9 @@ import { checkStreamingBlockProposalMetadata, isRetryableStreamingBlockCheckReas
140
144
  inbox_endpoint_mismatch: 'unvalidated',
141
145
  checkpoint_validation_failed: 'invalid'
142
146
  };
147
+ /** Distinguishes a checkpoint validation stage's failure result from the value it otherwise produces. */ function isCheckpointValidationFailure(result) {
148
+ return 'isValid' in result && result.isValid === false;
149
+ }
143
150
  const MAX_TRACKED_INVALID_PROPOSAL_SLOTS = 1000;
144
151
  /**
145
152
  * How long the live Inbox endpoint gate keeps re-reading L1 before giving up, how short that window may be
@@ -455,8 +462,15 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
455
462
  // which intentionally disables invalid-block slashing then.
456
463
  if (result.reason === 'checkpoint_proposal_equivocation') {
457
464
  this.markProposalEquivocation(slotNumber);
458
- } else if (isSlashableBlockProposalResult(result) && !await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
459
- this.markInvalidProposalSlot(slotNumber);
465
+ } else if (isSlashableBlockProposalResult(result)) {
466
+ const escapeHatch = await this.epochCache.lookupEscapeHatchAtSlot(slotNumber);
467
+ if (escapeHatch.state === 'unstable') {
468
+ warnCommitteeNotStable(this.log, escapeHatch, slotNumber, 'block proposal');
469
+ return false;
470
+ }
471
+ if (!escapeHatch.isEscapeHatchOpen) {
472
+ this.markInvalidProposalSlot(slotNumber);
473
+ }
460
474
  }
461
475
  this.log.warn(`Non-validator block proposal ${blockNumber} at slot ${slotNumber} failed processing with ${result.reason}`, {
462
476
  blockNumber: result.blockNumber,
@@ -494,7 +508,12 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
494
508
  this.log.warn(`Skipping checkpoint proposal validation for slot ${proposal.slotNumber}`, proposalInfo);
495
509
  return undefined;
496
510
  }
497
- if (await this.epochCache.isEscapeHatchOpenAtSlot(proposal.slotNumber)) {
511
+ const escapeHatch = await this.epochCache.lookupEscapeHatchAtSlot(proposal.slotNumber);
512
+ if (escapeHatch.state === 'unstable') {
513
+ warnCommitteeNotStable(this.log, escapeHatch, proposal.slotNumber, 'checkpoint proposal');
514
+ return undefined;
515
+ }
516
+ if (escapeHatch.isEscapeHatchOpen) {
498
517
  this.log.warn(`Escape hatch open for slot ${proposal.slotNumber}, skipping checkpoint proposal validation`, proposalInfo);
499
518
  return undefined;
500
519
  }
@@ -763,23 +782,7 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
763
782
  reason: 'txs_not_available'
764
783
  };
765
784
  }
766
- // Collect the out hashes of all the checkpoints before this one in the same epoch.
767
- // Mirror the proposer-side fallback: under pipelining the immediately-preceding cp may not
768
- // yet be on L1, in which case the helper grafts the locally-known proposed cp's outHash.
769
- const epoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
770
- const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
771
- blockSource: this.blockSource,
772
- epoch,
773
- checkpointNumber,
774
- l1Constants: this.epochCache.getL1Constants(),
775
- pipeliningEnabled: true,
776
- log: this.log
777
- });
778
- const previousInboxRollingHash = await getPreviousCheckpointInboxRollingHash({
779
- blockSource: this.blockSource,
780
- checkpointNumber,
781
- log: this.log
782
- });
785
+ const { previousCheckpointOutHashes, previousInboxRollingHash } = await this.getCheckpointAncestryInputs(slotNumber, checkpointNumber);
783
786
  // Try re-executing the transactions in the proposal if needed
784
787
  let reexecutionResult;
785
788
  try {
@@ -884,6 +887,24 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
884
887
  }
885
888
  }
886
889
  /**
890
+ * Given the first result of a local-view check, keeps re-running the check after forced archiver syncs while its
891
+ * result is a local-view outcome, until it is not or the slot's attestation deadline passes. On a timeout the
892
+ * caller's fallback decides what is reported; every caller builds it from the first result, so the reason it
893
+ * reports is the one it saw before waiting.
894
+ */ async awaitLocalViewCheck(opts) {
895
+ const { first } = opts;
896
+ if (!opts.isRetryable(first)) {
897
+ return first;
898
+ }
899
+ opts.onWait(first);
900
+ const timer = new Timer();
901
+ const resolved = await this.awaitLocalSync(opts.slot, opts.what, async ()=>{
902
+ const result = await opts.check();
903
+ return opts.isRetryable(result) ? undefined : result;
904
+ });
905
+ return resolved ?? opts.onTimeout(first, timer.ms());
906
+ }
907
+ /**
887
908
  * Re-runs `resolve` against this node's local view, forcing an archiver L1 sync before every attempt, until it
888
909
  * yields a value or the slot's attestation deadline passes. Returns `undefined` when the deadline had already
889
910
  * passed on entry (nothing is forced in that case) or when it passes while waiting; anything other than the
@@ -1044,7 +1065,7 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
1044
1065
  const proposalGlobals = proposal.blockHeader.globalVariables;
1045
1066
  const parentGlobals = parentBlock.header.globalVariables;
1046
1067
  // All global variables except blockNumber should match the parent
1047
- // blockNumber naturally increments between blocks
1068
+ // blockNumber naturally increments between blocks, and the caller has already compared the slot
1048
1069
  if (!proposalGlobals.chainId.equals(parentGlobals.chainId)) {
1049
1070
  this.log.warn(`Non-first block in checkpoint has mismatched chainId`, {
1050
1071
  ...proposalInfo,
@@ -1065,16 +1086,6 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
1065
1086
  reason: 'global_variables_mismatch'
1066
1087
  };
1067
1088
  }
1068
- if (proposalGlobals.slotNumber !== parentGlobals.slotNumber) {
1069
- this.log.warn(`Non-first block in checkpoint has mismatched slotNumber`, {
1070
- ...proposalInfo,
1071
- proposalSlotNumber: proposalGlobals.slotNumber,
1072
- parentSlotNumber: parentGlobals.slotNumber
1073
- });
1074
- return {
1075
- reason: 'global_variables_mismatch'
1076
- };
1077
- }
1078
1089
  if (proposalGlobals.timestamp !== parentGlobals.timestamp) {
1079
1090
  this.log.warn(`Non-first block in checkpoint has mismatched timestamp`, {
1080
1091
  ...proposalInfo,
@@ -1195,38 +1206,35 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
1195
1206
  }
1196
1207
  return result;
1197
1208
  };
1198
- const first = await readBundle();
1199
- if (first.accepted || !isRetryableStreamingBlockCheckReason(first.reason)) {
1200
- return first;
1201
- }
1202
1209
  const slotNumber = proposal.slotNumber;
1203
- this.log.info(`Inbox bundle read did not confirm the signed prefix, awaiting archiver sync`, {
1204
- reason: first.reason,
1205
- ...proposalInfo
1206
- });
1207
- const timer = new Timer();
1208
- const resolved = await this.awaitLocalSync(slotNumber, `inbox bundle for block ${blockNumber}`, async ()=>{
1209
- const result = await readBundle();
1210
- return !result.accepted && isRetryableStreamingBlockCheckReason(result.reason) ? undefined : result;
1210
+ return await this.awaitLocalViewCheck({
1211
+ slot: slotNumber,
1212
+ what: `inbox bundle for block ${blockNumber}`,
1213
+ first: await readBundle(),
1214
+ check: readBundle,
1215
+ isRetryable: isRetryableStreamingBlockRejection,
1216
+ onWait: (first)=>this.log.info(`Inbox bundle read did not confirm the signed prefix, awaiting archiver sync`, {
1217
+ reason: first.reason,
1218
+ ...proposalInfo
1219
+ }),
1220
+ onTimeout: (first, waitedMs)=>{
1221
+ this.log.warn(`Timed out reading a consistent Inbox bundle, rejecting proposal`, {
1222
+ reason: 'inbox_prefix_sync_timeout',
1223
+ firstReason: first.reason,
1224
+ // Set only when the message source failed for a reason the checks did not anticipate, rather than sync lag.
1225
+ // The latest such failure, since a later store fault says more about why this node gave up than the first
1226
+ // attempt's lag does.
1227
+ error: latestUnexpectedError,
1228
+ slot: slotNumber,
1229
+ waitedMs,
1230
+ ...proposalInfo
1231
+ });
1232
+ return {
1233
+ ...first,
1234
+ error: latestUnexpectedError
1235
+ };
1236
+ }
1211
1237
  });
1212
- if (resolved === undefined) {
1213
- this.log.warn(`Timed out reading a consistent Inbox bundle, rejecting proposal`, {
1214
- reason: 'inbox_prefix_sync_timeout',
1215
- firstReason: first.reason,
1216
- // Set only when the message source failed for a reason the checks did not anticipate, rather than sync lag.
1217
- // The latest such failure, since a later store fault says more about why this node gave up than the first
1218
- // attempt's lag does.
1219
- error: latestUnexpectedError,
1220
- slot: slotNumber,
1221
- waitedMs: timer.ms(),
1222
- ...proposalInfo
1223
- });
1224
- return {
1225
- ...first,
1226
- error: latestUnexpectedError
1227
- };
1228
- }
1229
- return resolved;
1230
1238
  }
1231
1239
  /**
1232
1240
  * Runs the streaming-Inbox metadata checks, waiting out a local sync lag. The messages the proposer consumed were
@@ -1253,33 +1261,31 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
1253
1261
  reason: first.accepted ? undefined : first.reason
1254
1262
  });
1255
1263
  }
1256
- if (first.accepted || !isRetryableStreamingBlockCheckReason(first.reason)) {
1257
- return first;
1258
- }
1259
1264
  const slotNumber = proposal.slotNumber;
1260
1265
  const inboxRollingHash = proposal.inboxPrefixRef.inboxRollingHash.toString();
1261
- this.log.info(`Referenced Inbox prefix ${inboxRollingHash} unconfirmed locally, awaiting archiver sync`, {
1262
- reason: first.reason,
1263
- inboxRollingHash,
1264
- ...proposalInfo
1265
- });
1266
- const timer = new Timer();
1267
- const resolved = await this.awaitLocalSync(slotNumber, `inbox prefix ${inboxRollingHash}`, async ()=>{
1268
- const result = await this.checkStreamingBlockMetadata(proposal, blockNumber, parentBlock);
1269
- return !result.accepted && isRetryableStreamingBlockCheckReason(result.reason) ? undefined : result;
1266
+ return await this.awaitLocalViewCheck({
1267
+ slot: slotNumber,
1268
+ what: `inbox prefix ${inboxRollingHash}`,
1269
+ first,
1270
+ check: ()=>this.checkStreamingBlockMetadata(proposal, blockNumber, parentBlock),
1271
+ isRetryable: isRetryableStreamingBlockRejection,
1272
+ onWait: (firstRejection)=>this.log.info(`Referenced Inbox prefix ${inboxRollingHash} unconfirmed locally, awaiting archiver sync`, {
1273
+ reason: firstRejection.reason,
1274
+ inboxRollingHash,
1275
+ ...proposalInfo
1276
+ }),
1277
+ onTimeout: (firstRejection, waitedMs)=>{
1278
+ this.log.warn(`Timed out waiting for Inbox prefix ${inboxRollingHash} to sync, rejecting proposal`, {
1279
+ reason: 'inbox_prefix_sync_timeout',
1280
+ firstReason: firstRejection.reason,
1281
+ slot: slotNumber,
1282
+ inboxRollingHash,
1283
+ waitedMs,
1284
+ ...proposalInfo
1285
+ });
1286
+ return firstRejection;
1287
+ }
1270
1288
  });
1271
- if (resolved === undefined) {
1272
- this.log.warn(`Timed out waiting for Inbox prefix ${inboxRollingHash} to sync, rejecting proposal`, {
1273
- reason: 'inbox_prefix_sync_timeout',
1274
- firstReason: first.reason,
1275
- slot: slotNumber,
1276
- inboxRollingHash,
1277
- waitedMs: timer.ms(),
1278
- ...proposalInfo
1279
- });
1280
- return first;
1281
- }
1282
- return resolved;
1283
1289
  }
1284
1290
  /**
1285
1291
  * Runs the streaming-Inbox per-block metadata checks for a block proposal, returning the cumulative message-count
@@ -1337,6 +1343,31 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
1337
1343
  return preBlock === undefined ? undefined : this.blockLeafCount(preBlock);
1338
1344
  }
1339
1345
  /**
1346
+ * The out hashes of the checkpoints before `checkpointNumber` in its epoch, and the Inbox rolling hash the parent
1347
+ * checkpoint ended at, which a checkpoint's rebuild starts from. Mirrors the proposer-side fallback: under
1348
+ * pipelining the immediately-preceding checkpoint may not be on L1 yet, in which case the helpers graft in the
1349
+ * locally-known proposed checkpoint's values.
1350
+ */ async getCheckpointAncestryInputs(slot, checkpointNumber) {
1351
+ const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
1352
+ const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
1353
+ blockSource: this.blockSource,
1354
+ epoch,
1355
+ checkpointNumber,
1356
+ l1Constants: this.epochCache.getL1Constants(),
1357
+ pipeliningEnabled: true,
1358
+ log: this.log
1359
+ });
1360
+ const previousInboxRollingHash = await getPreviousCheckpointInboxRollingHash({
1361
+ blockSource: this.blockSource,
1362
+ checkpointNumber,
1363
+ log: this.log
1364
+ });
1365
+ return {
1366
+ previousCheckpointOutHashes,
1367
+ previousInboxRollingHash
1368
+ };
1369
+ }
1370
+ /**
1340
1371
  * Reads the ordered list of L1-to-L2 messages a checkpoint consumed across its blocks, the compact message-count
1341
1372
  * range between the parent checkpoint's consumed position and the checkpoint's last block, and confirms that the
1342
1373
  * prefix it ends at hashes to the checkpoint header's `inboxRollingHash`. Both are read from one snapshot of the
@@ -1405,31 +1436,29 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
1405
1436
  * deadline passes. Neither outcome is proposer misconduct, so a timeout keeps the nonpunitive reason.
1406
1437
  */ async awaitCheckpointConsumedMessages(slot, checkpointStartTotal, lastBlockTotal, checkpointInboxRollingHash, proposalInfo) {
1407
1438
  const read = ()=>this.readCheckpointConsumedMessages(checkpointStartTotal, lastBlockTotal, checkpointInboxRollingHash);
1408
- const first = await read();
1409
- if (first.accepted) {
1410
- return first;
1411
- }
1412
- this.log.info(`Checkpoint's consumed Inbox prefix unconfirmed locally, awaiting archiver sync`, {
1413
- reason: first.reason,
1414
- checkpointStartTotal,
1415
- lastBlockTotal,
1416
- ...proposalInfo
1417
- });
1418
- const resolved = await this.awaitLocalSync(slot, `inbox prefix for checkpoint at slot ${slot}`, async ()=>{
1419
- const result = await read();
1420
- return result.accepted ? result : undefined;
1439
+ return await this.awaitLocalViewCheck({
1440
+ slot,
1441
+ what: `inbox prefix for checkpoint at slot ${slot}`,
1442
+ first: await read(),
1443
+ check: read,
1444
+ isRetryable: (result)=>!result.accepted,
1445
+ onWait: (first)=>this.log.info(`Checkpoint's consumed Inbox prefix unconfirmed locally, awaiting archiver sync`, {
1446
+ reason: first.reason,
1447
+ checkpointStartTotal,
1448
+ lastBlockTotal,
1449
+ ...proposalInfo
1450
+ }),
1451
+ onTimeout: (first)=>{
1452
+ this.log.warn(`Timed out waiting for the checkpoint's consumed Inbox prefix to sync, refusing to attest`, {
1453
+ reason: 'inbox_prefix_sync_timeout',
1454
+ firstReason: first.reason,
1455
+ checkpointStartTotal,
1456
+ lastBlockTotal,
1457
+ ...proposalInfo
1458
+ });
1459
+ return first;
1460
+ }
1421
1461
  });
1422
- if (resolved === undefined) {
1423
- this.log.warn(`Timed out waiting for the checkpoint's consumed Inbox prefix to sync, refusing to attest`, {
1424
- reason: 'inbox_prefix_sync_timeout',
1425
- firstReason: first.reason,
1426
- checkpointStartTotal,
1427
- lastBlockTotal,
1428
- ...proposalInfo
1429
- });
1430
- return first;
1431
- }
1432
- return resolved;
1433
1462
  }
1434
1463
  async reexecuteTransactions(proposal, blockNumber, checkpointNumber, txs, l1ToL2Messages, previousCheckpointOutHashes, previousInboxRollingHash) {
1435
1464
  const env = {
@@ -1535,11 +1564,12 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
1535
1564
  }
1536
1565
  }
1537
1566
  /**
1538
- * Validates a checkpoint proposal, caches the result, and uploads blobs if configured.
1539
- * Returns a cached result if the same proposal (archive + slot) was already validated.
1567
+ * Validates a checkpoint proposal's content, caches the verdict by signed-payload hash and uploads blobs if
1568
+ * configured, then gates a valid verdict on the live Inbox endpoint and records the outcome on the re-execution
1569
+ * tracker. A cached valid verdict is reused only while the checkpoint's last block is still local.
1540
1570
  * Used by both the all-nodes callback (via register) and the validator client (via delegation).
1541
1571
  * Expects the proposal to have already passed p2p ingress validation (expected proposer and receive-window
1542
- * timeliness); only deterministic properties of the signed payload are checked here.
1572
+ * timeliness), which is not re-applied here.
1543
1573
  */ async handleCheckpointProposal(proposal, proposalInfo) {
1544
1574
  const slot = proposal.slotNumber;
1545
1575
  const payloadHash = proposal.getPayloadHash();
@@ -1570,23 +1600,7 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
1570
1600
  }
1571
1601
  }
1572
1602
  if (result === undefined) {
1573
- const proposer = proposal.getSender();
1574
- if (!proposer) {
1575
- this.log.warn(`Received checkpoint proposal with invalid signature for slot ${proposal.slotNumber}`);
1576
- result = {
1577
- isValid: false,
1578
- reason: 'invalid_signature'
1579
- };
1580
- } else if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
1581
- this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposal.slotNumber}`);
1582
- result = {
1583
- isValid: false,
1584
- reason: 'invalid_fee_asset_price_modifier'
1585
- };
1586
- } else {
1587
- const validation = await this.validateCheckpointProposal(proposal, proposalInfo);
1588
- result = isSlashableCheckpointProposalResult(validation) ? await this.checkLastBlockStillLocal(proposal, validation, proposalInfo) : validation;
1589
- }
1603
+ result = await this.validateCheckpointProposal(proposal, proposalInfo);
1590
1604
  this.lastCheckpointValidationResult = {
1591
1605
  payloadHash,
1592
1606
  result
@@ -1765,9 +1779,34 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
1765
1779
  return this.getReexecutionDeadline(slot);
1766
1780
  }
1767
1781
  /**
1768
- * Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
1769
- * @returns Validation result with isValid flag and reason if invalid.
1782
+ * The verdict on a checkpoint proposal's signed content, before the live Inbox endpoint gate: the signature and fee
1783
+ * modifier checks on the payload, then the checkpoint rebuilt from this node's blocks and compared with it. A
1784
+ * slashable rebuild verdict is demoted when the checkpoint's last block was pruned while it was computed; the two
1785
+ * payload checks do not read the local chain, so their rejections never are.
1770
1786
  */ async validateCheckpointProposal(proposal, proposalInfo) {
1787
+ if (!proposal.getSender()) {
1788
+ this.log.warn(`Received checkpoint proposal with invalid signature for slot ${proposal.slotNumber}`);
1789
+ return {
1790
+ isValid: false,
1791
+ reason: 'invalid_signature'
1792
+ };
1793
+ }
1794
+ if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
1795
+ this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposal.slotNumber}`);
1796
+ return {
1797
+ isValid: false,
1798
+ reason: 'invalid_fee_asset_price_modifier'
1799
+ };
1800
+ }
1801
+ // The rebuild's fork is disposed when it returns, before the demotion reads the local chain again.
1802
+ const content = await this.validateCheckpointContent(proposal, proposalInfo);
1803
+ return isSlashableCheckpointProposalResult(content) ? await this.checkLastBlockStillLocal(proposal, content, proposalInfo) : content;
1804
+ }
1805
+ /**
1806
+ * Validates a checkpoint proposal's content by building the full checkpoint and comparing it with the proposal. The
1807
+ * stages run in order, each on the previous one's output; the fork stays here so its disposal waits for the
1808
+ * comparisons, and so the errors its narrow `try` turns into a verdict stay next to the ones that must escape.
1809
+ */ async validateCheckpointContent(proposal, proposalInfo) {
1771
1810
  const env = {
1772
1811
  stack: [],
1773
1812
  error: void 0,
@@ -1775,177 +1814,22 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
1775
1814
  };
1776
1815
  try {
1777
1816
  const slot = proposal.slotNumber;
1778
- // Block-sync/validation deadline = the single consensus attestation_deadline (target_slot_start + S
1779
- // - 2E): the latest moment the proposer can submit this checkpoint and still have it land on L1 in
1780
- // the target slot. Keeping validation/attestation alive until then lets validators keep attesting
1781
- // right up to the proposer's real publish cutoff.
1782
- const deadline = this.getReexecutionDeadline(slot);
1783
- // Wait for the checkpoint's blocks to sync. One read of the slot's blocks is the snapshot the whole validation
1784
- // runs on: the block carrying the signed archive is the checkpoint's last block, and the slot's blocks before it
1785
- // are the checkpoint's. Reading the last block by archive and the slot's blocks separately would let a local prune
1786
- // between the two reads look like a proposer offense; a slot read without the signed archive, or one that is not
1787
- // a contiguous chain of one checkpoint's blocks starting at its first, is local state in motion and is retried.
1788
- // The deadline is passed to retryUntil as an absolute date so the remaining budget is derived from the date
1789
- // provider; a deadline already in the past times out after a single attempt instead of looping (the
1790
- // immediate-timeout semantics of the deadline overload).
1791
- let snapshot;
1792
- try {
1793
- snapshot = await retryUntil(async ()=>{
1794
- await this.blockSource.syncImmediate();
1795
- return await this.readCheckpointBlocksSnapshot(slot, proposal.archive);
1796
- }, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, {
1797
- deadline,
1798
- dateProvider: this.dateProvider
1799
- }, 0.5);
1800
- } catch (err) {
1801
- if (err instanceof TimeoutError) {
1802
- this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
1803
- return {
1804
- isValid: false,
1805
- reason: 'last_block_not_found'
1806
- };
1807
- }
1808
- this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
1809
- return {
1810
- isValid: false,
1811
- reason: 'block_fetch_error'
1812
- };
1817
+ const located = await this.locateCheckpointBlocks(proposal, proposalInfo);
1818
+ if (isCheckpointValidationFailure(located)) {
1819
+ return located;
1813
1820
  }
1814
- if (!snapshot) {
1815
- this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
1816
- return {
1817
- isValid: false,
1818
- reason: 'last_block_not_found'
1819
- };
1820
- }
1821
- const { blocks, lastBlockIndex } = snapshot;
1822
- const lastBlock = blocks[lastBlockIndex];
1823
- // Refuse to attest if the block's enclosing checkpoint has already been published to L1.
1824
- const existingCheckpoint = await this.blockSource.getCheckpointData({
1825
- number: lastBlock.checkpointNumber
1826
- });
1827
- if (existingCheckpoint) {
1828
- this.log.warn(`Refusing to attest to checkpoint proposal whose checkpoint is already on L1`, {
1829
- ...proposalInfo,
1830
- checkpointNumber: lastBlock.checkpointNumber
1831
- });
1832
- return {
1833
- isValid: false,
1834
- reason: 'checkpoint_already_published',
1835
- checkpointNumber: lastBlock.checkpointNumber
1836
- };
1837
- }
1838
- // The signed archive names a block of the slot that is followed by more of the proposer's blocks for the same
1839
- // slot: the proposal leaves signed blocks of its own slot out, which no local race explains.
1840
- if (lastBlockIndex !== blocks.length - 1) {
1841
- this.log.warn(`Last block archive mismatch for checkpoint proposal`, {
1842
- ...proposalInfo,
1843
- lastBlockNumber: lastBlock.number,
1844
- laterBlockNumbers: blocks.slice(lastBlockIndex + 1).map((b)=>b.number)
1845
- });
1846
- return {
1847
- isValid: false,
1848
- reason: 'last_block_archive_mismatch',
1849
- checkpointNumber: lastBlock.checkpointNumber
1850
- };
1851
- }
1852
- // The checkpoint root circuit caps how many blocks a checkpoint may contain, and L1 cannot check it when the
1853
- // checkpoint is proposed (`ProposedHeader` carries no block count, only `blockHeadersHash`). An over-cap
1854
- // checkpoint would therefore be accepted on L1 and then be unprovable, forcing an epoch reorg, so validators
1855
- // reject it before attesting. An operator-configured limit may only tighten the protocol cap, never relax it.
1856
- const maxBlocksPerCheckpoint = Math.min(this.config.maxBlocksPerCheckpoint ?? MAX_BLOCKS_PER_CHECKPOINT, MAX_BLOCKS_PER_CHECKPOINT);
1857
- if (blocks.length > maxBlocksPerCheckpoint) {
1858
- this.log.warn(`Checkpoint proposal exceeds maxBlocksPerCheckpoint`, {
1859
- ...proposalInfo,
1860
- blocksInProposal: blocks.length,
1861
- maxBlocksPerCheckpoint
1862
- });
1863
- return {
1864
- isValid: false,
1865
- reason: 'too_many_blocks_in_checkpoint',
1866
- checkpointNumber: lastBlock.checkpointNumber
1867
- };
1868
- }
1869
- this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
1870
- ...proposalInfo,
1871
- blockNumbers: blocks.map((b)=>b.number)
1872
- });
1873
- // Get checkpoint constants from first block
1874
- const firstBlock = blocks[0];
1875
- const constants = this.extractCheckpointConstants(firstBlock);
1876
- const checkpointNumber = firstBlock.checkpointNumber;
1877
- // The rebuild derives the header's lastArchiveRoot from the first block's lastArchive (as does the checkpoint
1878
- // circuit), so any other claimed value is an unprovable header; reject it before paying for the rebuild.
1879
- const expectedLastArchiveRoot = firstBlock.header.lastArchive.root;
1880
- if (!proposal.checkpointHeader.lastArchiveRoot.equals(expectedLastArchiveRoot)) {
1881
- this.log.warn(`Checkpoint proposal's last archive root does not match its first block`, {
1882
- ...proposalInfo,
1883
- expectedLastArchiveRoot: expectedLastArchiveRoot.toString(),
1884
- proposalLastArchiveRoot: proposal.checkpointHeader.lastArchiveRoot.toString()
1885
- });
1886
- return {
1887
- isValid: false,
1888
- reason: 'last_archive_root_mismatch',
1889
- checkpointNumber
1890
- };
1821
+ const inputs = await this.awaitCheckpointRebuildInputs(proposal, located, proposalInfo);
1822
+ if (isCheckpointValidationFailure(inputs)) {
1823
+ return inputs;
1891
1824
  }
1892
- // The checkpoint's Inbox consumption starts at the leaf count of the block before its first block. Without that
1893
- // block the consumed bundle cannot be derived; an empty bundle would make a valid proposal fail its rolling-hash
1894
- // recomputation and be classified as a proposer offense, so a missing parent is a local fetch failure instead.
1895
- const checkpointStartTotal = await this.getPreBlockConsumedTotal(firstBlock.number);
1896
- if (checkpointStartTotal === undefined) {
1897
- this.log.warn(`Block before checkpoint proposal's first block ${firstBlock.number} is unavailable locally`, {
1898
- ...proposalInfo,
1899
- checkpointNumber
1900
- });
1901
- return {
1902
- isValid: false,
1903
- reason: 'block_fetch_error',
1904
- checkpointNumber
1905
- };
1906
- }
1907
- // Streaming Inbox: read the checkpoint's consumed L1-to-L2 message list from the count range between the parent
1908
- // checkpoint's consumed position and the last block's, and confirm it ends at the header's rolling hash. The
1909
- // messages are already in the db from per-block validation; this list drives the checkpoint's rolling-hash
1910
- // recomputation in completeCheckpoint. No bucket or L1 endpoint is resolved here: that is the proposer's and
1911
- // L1's publication check.
1912
- const consumed = await this.awaitCheckpointConsumedMessages(slot, checkpointStartTotal, this.blockLeafCount(blocks[blocks.length - 1]), proposal.checkpointHeader.inboxRollingHash, proposalInfo);
1913
- if (!consumed.accepted) {
1914
- this.log.warn(`Streaming Inbox checkpoint content check failed, refusing to attest`, {
1915
- ...proposalInfo,
1916
- reason: consumed.reason,
1917
- checkpointNumber
1918
- });
1919
- return {
1920
- isValid: false,
1921
- reason: consumed.reason,
1922
- checkpointNumber
1923
- };
1924
- }
1925
- const l1ToL2Messages = consumed.messages;
1926
- // Collect the out hashes of all the checkpoints before this one in the same epoch.
1927
- // See note on the analogous block-proposal site: the helper handles pipelining lag.
1928
- const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
1929
- const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
1930
- blockSource: this.blockSource,
1931
- epoch,
1932
- checkpointNumber,
1933
- l1Constants: this.epochCache.getL1Constants(),
1934
- pipeliningEnabled: true,
1935
- log: this.log
1936
- });
1937
- const previousInboxRollingHash = await getPreviousCheckpointInboxRollingHash({
1938
- blockSource: this.blockSource,
1939
- checkpointNumber,
1940
- log: this.log
1941
- });
1825
+ const { checkpointNumber } = inputs;
1942
1826
  // Fork world state at the block before the first block. getFork syncs world state to the parent block
1943
1827
  // first (see its doc): the block source (archiver) can already hold the block while world state still
1944
1828
  // trails it by one, and forking a not-yet-applied block throws a raw tree error that would otherwise
1945
1829
  // escape as an uncaught gossipsub error. We pass the parent's expected block hash so the sync detects a
1946
1830
  // world-state reorg (undefined for the genesis parent, where no block exists to pin). On failure we map
1947
1831
  // to a clean validation result rather than letting it escape.
1948
- const parentBlockNumber = BlockNumber(firstBlock.number - 1);
1832
+ const parentBlockNumber = BlockNumber(inputs.firstBlock.number - 1);
1949
1833
  let forkResult;
1950
1834
  try {
1951
1835
  const parentBlockHash = (await this.blockSource.getBlockData({
@@ -1968,6 +1852,7 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
1968
1852
  // World state must be on the same chain as the archiver blocks being rebuilt; otherwise the rebuild would disagree
1969
1853
  // with an honest proposal. This is a local race (e.g. a reorg between the hash-pinned sync and the fork), never a
1970
1854
  // proposer offense. It mirrors the block-proposal re-execution check.
1855
+ const expectedLastArchiveRoot = inputs.firstBlock.header.lastArchive.root;
1971
1856
  const forkArchiveRoot = new Fr((await fork.getTreeInfo(MerkleTreeId.ARCHIVE)).root);
1972
1857
  if (!forkArchiveRoot.equals(expectedLastArchiveRoot)) {
1973
1858
  this.log.warn(`Fork archive root does not match the checkpoint's first block last archive`, {
@@ -1982,73 +1867,12 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
1982
1867
  };
1983
1868
  }
1984
1869
  // Create checkpoint builder with all existing blocks
1985
- const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, previousInboxRollingHash, fork, blocks, this.log.getBindings());
1870
+ const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, inputs.constants, proposal.feeAssetPriceModifier, inputs.l1ToL2Messages, inputs.previousCheckpointOutHashes, inputs.previousInboxRollingHash, fork, inputs.blocks, this.log.getBindings());
1986
1871
  // Complete the checkpoint to get computed values
1987
1872
  const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
1988
- // Compare checkpoint header with proposal
1989
- if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
1990
- this.log.warn(`Checkpoint header mismatch`, {
1991
- ...proposalInfo,
1992
- computed: computedCheckpoint.header.toInspect(),
1993
- proposal: proposal.checkpointHeader.toInspect()
1994
- });
1995
- return {
1996
- isValid: false,
1997
- reason: 'checkpoint_header_mismatch',
1998
- checkpointNumber
1999
- };
2000
- }
2001
- // Compare archive root with proposal
2002
- if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
2003
- this.log.warn(`Archive root mismatch`, {
2004
- ...proposalInfo,
2005
- computed: computedCheckpoint.archive.root.toString(),
2006
- proposal: proposal.archive.toString()
2007
- });
2008
- return {
2009
- isValid: false,
2010
- reason: 'archive_mismatch',
2011
- checkpointNumber
2012
- };
2013
- }
2014
- // Check that the accumulated epoch out hash matches the value in the proposal.
2015
- // The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
2016
- const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
2017
- const computedEpochOutHash = accumulateCheckpointOutHashes([
2018
- ...previousCheckpointOutHashes,
2019
- checkpointOutHash
2020
- ]);
2021
- const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
2022
- if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
2023
- this.log.warn(`Epoch out hash mismatch`, {
2024
- proposalEpochOutHash: proposalEpochOutHash.toString(),
2025
- computedEpochOutHash: computedEpochOutHash.toString(),
2026
- checkpointOutHash: checkpointOutHash.toString(),
2027
- previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
2028
- ...proposalInfo
2029
- });
2030
- return {
2031
- isValid: false,
2032
- reason: 'out_hash_mismatch',
2033
- checkpointNumber
2034
- };
2035
- }
2036
- // Final round of validations on the checkpoint, just in case.
2037
- try {
2038
- validateCheckpoint(computedCheckpoint, {
2039
- rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
2040
- maxDABlockGas: this.config.validateMaxDABlockGas,
2041
- maxL2BlockGas: this.config.validateMaxL2BlockGas,
2042
- maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
2043
- maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint
2044
- });
2045
- } catch (err) {
2046
- this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
2047
- return {
2048
- isValid: false,
2049
- reason: 'checkpoint_validation_failed',
2050
- checkpointNumber
2051
- };
1873
+ const mismatch = this.compareRebuiltCheckpoint(computedCheckpoint, proposal, inputs, proposalInfo);
1874
+ if (mismatch) {
1875
+ return mismatch;
2052
1876
  }
2053
1877
  this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
2054
1878
  return {
@@ -2063,18 +1887,246 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
2063
1887
  if (result) await result;
2064
1888
  }
2065
1889
  }
2066
- /** Extracts checkpoint global variables from a block. */ extractCheckpointConstants(block) {
2067
- const gv = block.header.globalVariables;
1890
+ /**
1891
+ * Waits for the checkpoint's blocks to sync, forcing archiver syncs until the slot's attestation deadline, then
1892
+ * rejects a checkpoint already on L1, one that leaves later blocks of its own slot out, and one over the block cap.
1893
+ */ async locateCheckpointBlocks(proposal, proposalInfo) {
1894
+ const slot = proposal.slotNumber;
1895
+ // Block-sync/validation deadline = the single consensus attestation_deadline (target_slot_start + S
1896
+ // - 2E): the latest moment the proposer can submit this checkpoint and still have it land on L1 in
1897
+ // the target slot. Keeping validation/attestation alive until then lets validators keep attesting
1898
+ // right up to the proposer's real publish cutoff.
1899
+ const deadline = this.getReexecutionDeadline(slot);
1900
+ // Wait for the checkpoint's blocks to sync. One read of the slot's blocks is the snapshot the whole validation
1901
+ // runs on: the block carrying the signed archive is the checkpoint's last block, and the slot's blocks before it
1902
+ // are the checkpoint's. Reading the last block by archive and the slot's blocks separately would let a local prune
1903
+ // between the two reads look like a proposer offense; a slot read without the signed archive, or one that is not
1904
+ // a contiguous chain of one checkpoint's blocks starting at its first, is local state in motion and is retried.
1905
+ // The deadline is passed to retryUntil as an absolute date so the remaining budget is derived from the date
1906
+ // provider; a deadline already in the past times out after a single attempt instead of looping (the
1907
+ // immediate-timeout semantics of the deadline overload).
1908
+ let snapshot;
1909
+ try {
1910
+ snapshot = await retryUntil(async ()=>{
1911
+ await this.blockSource.syncImmediate();
1912
+ return await this.readCheckpointBlocksSnapshot(slot, proposal.archive);
1913
+ }, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, {
1914
+ deadline,
1915
+ dateProvider: this.dateProvider
1916
+ }, 0.5);
1917
+ } catch (err) {
1918
+ if (err instanceof TimeoutError) {
1919
+ this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
1920
+ return {
1921
+ isValid: false,
1922
+ reason: 'last_block_not_found'
1923
+ };
1924
+ }
1925
+ this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
1926
+ return {
1927
+ isValid: false,
1928
+ reason: 'block_fetch_error'
1929
+ };
1930
+ }
1931
+ const { blocks, lastBlockIndex } = snapshot;
1932
+ const lastBlock = blocks[lastBlockIndex];
1933
+ // Refuse to attest if the block's enclosing checkpoint has already been published to L1.
1934
+ const existingCheckpoint = await this.blockSource.getCheckpointData({
1935
+ number: lastBlock.checkpointNumber
1936
+ });
1937
+ if (existingCheckpoint) {
1938
+ this.log.warn(`Refusing to attest to checkpoint proposal whose checkpoint is already on L1`, {
1939
+ ...proposalInfo,
1940
+ checkpointNumber: lastBlock.checkpointNumber
1941
+ });
1942
+ return {
1943
+ isValid: false,
1944
+ reason: 'checkpoint_already_published',
1945
+ checkpointNumber: lastBlock.checkpointNumber
1946
+ };
1947
+ }
1948
+ // The signed archive names a block of the slot that is followed by more of the proposer's blocks for the same
1949
+ // slot: the proposal leaves signed blocks of its own slot out, which no local race explains.
1950
+ if (lastBlockIndex !== blocks.length - 1) {
1951
+ this.log.warn(`Last block archive mismatch for checkpoint proposal`, {
1952
+ ...proposalInfo,
1953
+ lastBlockNumber: lastBlock.number,
1954
+ laterBlockNumbers: blocks.slice(lastBlockIndex + 1).map((b)=>b.number)
1955
+ });
1956
+ return {
1957
+ isValid: false,
1958
+ reason: 'last_block_archive_mismatch',
1959
+ checkpointNumber: lastBlock.checkpointNumber
1960
+ };
1961
+ }
1962
+ // The checkpoint root circuit caps how many blocks a checkpoint may contain, and L1 cannot check it when the
1963
+ // checkpoint is proposed (`ProposedHeader` carries no block count, only `blockHeadersHash`). An over-cap
1964
+ // checkpoint would therefore be accepted on L1 and then be unprovable, forcing an epoch reorg, so validators
1965
+ // reject it before attesting. An operator-configured limit may only tighten the protocol cap, never relax it.
1966
+ const maxBlocksPerCheckpoint = Math.min(this.config.maxBlocksPerCheckpoint ?? MAX_BLOCKS_PER_CHECKPOINT, MAX_BLOCKS_PER_CHECKPOINT);
1967
+ if (blocks.length > maxBlocksPerCheckpoint) {
1968
+ this.log.warn(`Checkpoint proposal exceeds maxBlocksPerCheckpoint`, {
1969
+ ...proposalInfo,
1970
+ blocksInProposal: blocks.length,
1971
+ maxBlocksPerCheckpoint
1972
+ });
1973
+ return {
1974
+ isValid: false,
1975
+ reason: 'too_many_blocks_in_checkpoint',
1976
+ checkpointNumber: lastBlock.checkpointNumber
1977
+ };
1978
+ }
1979
+ this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
1980
+ ...proposalInfo,
1981
+ blockNumbers: blocks.map((b)=>b.number)
1982
+ });
1983
+ const firstBlock = blocks[0];
1984
+ const checkpointNumber = firstBlock.checkpointNumber;
1985
+ // The rebuild derives the header's lastArchiveRoot from the first block's lastArchive (as does the checkpoint
1986
+ // circuit), so any other claimed value is an unprovable header; reject it before the Inbox waits and the rebuild.
1987
+ const expectedLastArchiveRoot = firstBlock.header.lastArchive.root;
1988
+ if (!proposal.checkpointHeader.lastArchiveRoot.equals(expectedLastArchiveRoot)) {
1989
+ this.log.warn(`Checkpoint proposal's last archive root does not match its first block`, {
1990
+ ...proposalInfo,
1991
+ expectedLastArchiveRoot: expectedLastArchiveRoot.toString(),
1992
+ proposalLastArchiveRoot: proposal.checkpointHeader.lastArchiveRoot.toString()
1993
+ });
1994
+ return {
1995
+ isValid: false,
1996
+ reason: 'last_archive_root_mismatch',
1997
+ checkpointNumber
1998
+ };
1999
+ }
2068
2000
  return {
2069
- chainId: gv.chainId,
2070
- version: gv.version,
2071
- slotNumber: gv.slotNumber,
2072
- timestamp: gv.timestamp,
2073
- coinbase: gv.coinbase,
2074
- feeRecipient: gv.feeRecipient,
2075
- gasFees: gv.gasFees
2001
+ blocks,
2002
+ firstBlock,
2003
+ checkpointNumber
2076
2004
  };
2077
2005
  }
2006
+ /**
2007
+ * Gathers what the checkpoint rebuild consumes besides the fork: the checkpoint constants, the consumed L1-to-L2
2008
+ * messages (waiting out a local sync lag through forced archiver syncs) and the parent checkpoints' out hashes and
2009
+ * Inbox rolling hash. Reads that fail unexpectedly propagate.
2010
+ */ async awaitCheckpointRebuildInputs(proposal, located, proposalInfo) {
2011
+ const slot = proposal.slotNumber;
2012
+ const { blocks, firstBlock, checkpointNumber } = located;
2013
+ // Get checkpoint constants from first block
2014
+ const constants = this.extractCheckpointConstants(firstBlock);
2015
+ // The checkpoint's Inbox consumption starts at the leaf count of the block before its first block. Without that
2016
+ // block the consumed bundle cannot be derived; an empty bundle would make a valid proposal fail its rolling-hash
2017
+ // recomputation and be classified as a proposer offense, so a missing parent is a local fetch failure instead.
2018
+ const checkpointStartTotal = await this.getPreBlockConsumedTotal(firstBlock.number);
2019
+ if (checkpointStartTotal === undefined) {
2020
+ this.log.warn(`Block before checkpoint proposal's first block ${firstBlock.number} is unavailable locally`, {
2021
+ ...proposalInfo,
2022
+ checkpointNumber
2023
+ });
2024
+ return {
2025
+ isValid: false,
2026
+ reason: 'block_fetch_error',
2027
+ checkpointNumber
2028
+ };
2029
+ }
2030
+ // Streaming Inbox: read the checkpoint's consumed L1-to-L2 message list from the count range between the parent
2031
+ // checkpoint's consumed position and the last block's, and confirm it ends at the header's rolling hash. The
2032
+ // messages are already in the db from per-block validation; this list drives the checkpoint's rolling-hash
2033
+ // recomputation in completeCheckpoint. No bucket or L1 endpoint is resolved here: that is the proposer's and
2034
+ // L1's publication check.
2035
+ const consumed = await this.awaitCheckpointConsumedMessages(slot, checkpointStartTotal, this.blockLeafCount(blocks[blocks.length - 1]), proposal.checkpointHeader.inboxRollingHash, proposalInfo);
2036
+ if (!consumed.accepted) {
2037
+ this.log.warn(`Streaming Inbox checkpoint content check failed, refusing to attest`, {
2038
+ ...proposalInfo,
2039
+ reason: consumed.reason,
2040
+ checkpointNumber
2041
+ });
2042
+ return {
2043
+ isValid: false,
2044
+ reason: consumed.reason,
2045
+ checkpointNumber
2046
+ };
2047
+ }
2048
+ return {
2049
+ ...located,
2050
+ constants,
2051
+ l1ToL2Messages: consumed.messages,
2052
+ ...await this.getCheckpointAncestryInputs(slot, checkpointNumber)
2053
+ };
2054
+ }
2055
+ /**
2056
+ * Compares the rebuilt checkpoint with the proposal: header, archive root and epoch out hash, then the checkpoint's
2057
+ * own limits. Returns the first mismatch, or undefined when everything matches.
2058
+ */ compareRebuiltCheckpoint(computedCheckpoint, proposal, inputs, proposalInfo) {
2059
+ const { checkpointNumber, previousCheckpointOutHashes } = inputs;
2060
+ // Compare checkpoint header with proposal
2061
+ if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
2062
+ this.log.warn(`Checkpoint header mismatch`, {
2063
+ ...proposalInfo,
2064
+ computed: computedCheckpoint.header.toInspect(),
2065
+ proposal: proposal.checkpointHeader.toInspect()
2066
+ });
2067
+ return {
2068
+ isValid: false,
2069
+ reason: 'checkpoint_header_mismatch',
2070
+ checkpointNumber
2071
+ };
2072
+ }
2073
+ // Compare archive root with proposal
2074
+ if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
2075
+ this.log.warn(`Archive root mismatch`, {
2076
+ ...proposalInfo,
2077
+ computed: computedCheckpoint.archive.root.toString(),
2078
+ proposal: proposal.archive.toString()
2079
+ });
2080
+ return {
2081
+ isValid: false,
2082
+ reason: 'archive_mismatch',
2083
+ checkpointNumber
2084
+ };
2085
+ }
2086
+ // Check that the accumulated epoch out hash matches the value in the proposal.
2087
+ // The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
2088
+ const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
2089
+ const computedEpochOutHash = accumulateCheckpointOutHashes([
2090
+ ...previousCheckpointOutHashes,
2091
+ checkpointOutHash
2092
+ ]);
2093
+ const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
2094
+ if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
2095
+ this.log.warn(`Epoch out hash mismatch`, {
2096
+ proposalEpochOutHash: proposalEpochOutHash.toString(),
2097
+ computedEpochOutHash: computedEpochOutHash.toString(),
2098
+ checkpointOutHash: checkpointOutHash.toString(),
2099
+ previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
2100
+ ...proposalInfo
2101
+ });
2102
+ return {
2103
+ isValid: false,
2104
+ reason: 'out_hash_mismatch',
2105
+ checkpointNumber
2106
+ };
2107
+ }
2108
+ // Final round of validations on the checkpoint, just in case.
2109
+ try {
2110
+ validateCheckpoint(computedCheckpoint, {
2111
+ rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
2112
+ maxDABlockGas: this.config.validateMaxDABlockGas,
2113
+ maxL2BlockGas: this.config.validateMaxL2BlockGas,
2114
+ maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
2115
+ maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint
2116
+ });
2117
+ } catch (err) {
2118
+ this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
2119
+ return {
2120
+ isValid: false,
2121
+ reason: 'checkpoint_validation_failed',
2122
+ checkpointNumber
2123
+ };
2124
+ }
2125
+ return undefined;
2126
+ }
2127
+ /** Extracts checkpoint global variables from a block. */ extractCheckpointConstants(block) {
2128
+ return pick(block.header.globalVariables, 'chainId', 'version', 'slotNumber', 'timestamp', 'coinbase', 'feeRecipient', 'gasFees');
2129
+ }
2078
2130
  /** Triggers blob upload for a checkpoint if the blob client can upload (fire and forget). */ tryUploadBlobsForCheckpoint(proposal, proposalInfo) {
2079
2131
  if (this.blobClient.canUpload()) {
2080
2132
  void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
@@ -2129,7 +2181,8 @@ const INBOX_ENDPOINT_CHECK_INTERVAL_S = 0.5;
2129
2181
  startBlock: BlockNumber(blockData.header.getBlockNumber() - blockData.indexWithinCheckpoint),
2130
2182
  blockCount: blockData.indexWithinCheckpoint + 1,
2131
2183
  totalManaUsed: proposal.checkpointHeader.totalManaUsed.toBigInt(),
2132
- feeAssetPriceModifier: proposal.feeAssetPriceModifier
2184
+ feeAssetPriceModifier: proposal.feeAssetPriceModifier,
2185
+ signer: proposal.getSender()
2133
2186
  });
2134
2187
  return true;
2135
2188
  }