@aztec/validator-client 0.0.1-commit.b6e433891 → 0.0.1-commit.b9865e97

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.
package/src/validator.ts CHANGED
@@ -1,39 +1,37 @@
1
1
  import type { BlobClientInterface } from '@aztec/blob-client/client';
2
2
  import { type Blob, getBlobsPerL1Block } from '@aztec/blob-lib';
3
3
  import type { EpochCache } from '@aztec/epoch-cache';
4
- import { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
5
- import {
6
- BlockNumber,
7
- CheckpointNumber,
8
- EpochNumber,
9
- IndexWithinCheckpoint,
10
- SlotNumber,
11
- } from '@aztec/foundation/branded-types';
4
+ import { CheckpointNumber, EpochNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
12
5
  import { Fr } from '@aztec/foundation/curves/bn254';
13
- import { TimeoutError } from '@aztec/foundation/error';
14
6
  import type { EthAddress } from '@aztec/foundation/eth-address';
15
7
  import type { Signature } from '@aztec/foundation/eth-signature';
8
+ import { FifoSet } from '@aztec/foundation/fifo-set';
16
9
  import { type LogData, type Logger, createLogger } from '@aztec/foundation/log';
17
- import { retryUntil } from '@aztec/foundation/retry';
18
10
  import { RunningPromise } from '@aztec/foundation/running-promise';
19
11
  import { sleep } from '@aztec/foundation/sleep';
20
12
  import { DateProvider } from '@aztec/foundation/timer';
21
13
  import type { KeystoreManager } from '@aztec/node-keystore';
22
14
  import type { DuplicateAttestationInfo, DuplicateProposalInfo, P2P, PeerId } from '@aztec/p2p';
23
15
  import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
24
- import { OffenseType, WANT_TO_SLASH_EVENT, type Watcher, type WatcherEmitter } from '@aztec/slasher';
16
+ import {
17
+ OffenseType,
18
+ WANT_TO_CLEAR_SLASH_EVENT,
19
+ WANT_TO_SLASH_EVENT,
20
+ type Watcher,
21
+ type WatcherEmitter,
22
+ getOffenseTypeName,
23
+ } from '@aztec/slasher';
25
24
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
26
- import type { CommitteeAttestationsAndSigners, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
27
- import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
28
- import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
25
+ import type { CommitteeAttestationsAndSigners, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
26
+ import type { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
27
+ import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
29
28
  import type {
30
- CreateCheckpointProposalLastBlockData,
31
29
  ITxProvider,
32
30
  Validator,
33
31
  ValidatorClientFullConfig,
34
32
  WorldStateSynchronizer,
35
33
  } from '@aztec/stdlib/interfaces/server';
36
- import { type L1ToL2MessageSource, accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
34
+ import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
37
35
  import {
38
36
  type BlockProposal,
39
37
  type BlockProposalOptions,
@@ -41,9 +39,10 @@ import {
41
39
  CheckpointProposal,
42
40
  type CheckpointProposalCore,
43
41
  type CheckpointProposalOptions,
42
+ type CoordinationSignatureContext,
44
43
  } from '@aztec/stdlib/p2p';
45
44
  import type { CheckpointHeader } from '@aztec/stdlib/rollup';
46
- import type { BlockHeader, CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
45
+ import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
47
46
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
48
47
  import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
49
48
  import {
@@ -57,24 +56,56 @@ import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-
57
56
  import { EventEmitter } from 'events';
58
57
  import type { TypedDataDefinition } from 'viem';
59
58
 
60
- import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
61
59
  import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
62
60
  import { ValidationService } from './duties/validation_service.js';
63
61
  import { HAKeyStore } from './key_store/ha_key_store.js';
64
62
  import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
65
63
  import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
66
64
  import { ValidatorMetrics } from './metrics.js';
65
+ import {
66
+ type BlockProposalValidationFailureReason,
67
+ type CheckpointProposalValidationFailureReason,
68
+ type CheckpointProposalValidationFailureResult,
69
+ ProposalHandler,
70
+ } from './proposal_handler.js';
67
71
 
68
72
  // We maintain a set of proposers who have proposed invalid blocks.
69
73
  // Just cap the set to avoid unbounded growth.
70
74
  const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
75
+ const MAX_TRACKED_INVALID_PROPOSAL_SLOTS = 1000;
76
+ const MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS = 1000;
77
+ const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
71
78
 
72
79
  // What errors from the block proposal handler result in slashing
73
80
  const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT: BlockProposalValidationFailureReason[] = [
74
81
  'state_mismatch',
75
82
  'failed_txs',
83
+ 'global_variables_mismatch',
84
+ 'invalid_proposal',
85
+ 'parent_block_wrong_slot',
86
+ 'in_hash_mismatch',
76
87
  ];
77
88
 
89
+ const SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT: Record<CheckpointProposalValidationFailureReason, boolean> = {
90
+ // enabled
91
+ ['invalid_fee_asset_price_modifier']: true,
92
+ ['checkpoint_header_mismatch']: true,
93
+ // These late mismatches should normally be caught by earlier checks, but if reached after validating the local
94
+ // checkpoint inputs, the proposer-signed payload disagrees with deterministic recomputation.
95
+ ['archive_mismatch']: true,
96
+ ['out_hash_mismatch']: true,
97
+ ['no_blocks_for_slot']: true,
98
+ ['too_many_blocks_in_checkpoint']: true,
99
+ ['checkpoint_validation_failed']: true,
100
+ ['last_block_archive_mismatch']: true,
101
+
102
+ // disabled
103
+ ['invalid_signature']: false,
104
+ ['last_block_not_found']: false,
105
+ ['block_fetch_error']: false,
106
+ ['checkpoint_already_published']: false,
107
+ };
108
+
78
109
  /**
79
110
  * Validator Client
80
111
  */
@@ -97,7 +128,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
97
128
  /** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
98
129
  private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
99
130
 
100
- private proposersOfInvalidBlocks: Set<string> = new Set();
131
+ private proposersOfInvalidBlocks = FifoSet.withLimit<string>(MAX_PROPOSERS_OF_INVALID_BLOCKS);
132
+ private slotsWithInvalidProposals = FifoSet.withLimit<SlotNumber>(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
133
+ private invalidCheckpointProposalOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS);
134
+ private badAttestationOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_BAD_ATTESTATIONS);
135
+ private slotsWithProposalEquivocation = FifoSet.withLimit<SlotNumber>(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
101
136
 
102
137
  /** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
103
138
  private lastAttestedProposal?: CheckpointProposalCore;
@@ -106,7 +141,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
106
141
  private keyStore: ExtendedValidatorKeyStore,
107
142
  private epochCache: EpochCache,
108
143
  private p2pClient: P2P,
109
- private blockProposalHandler: BlockProposalHandler,
144
+ private proposalHandler: ProposalHandler,
110
145
  private blockSource: L2BlockSource,
111
146
  private checkpointsBuilder: FullNodeCheckpointsBuilder,
112
147
  private worldState: WorldStateSynchronizer,
@@ -126,11 +161,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
126
161
  this.tracer = telemetry.getTracer('Validator');
127
162
  this.metrics = new ValidatorMetrics(telemetry);
128
163
 
129
- this.validationService = new ValidationService(keyStore, this.log.createChild('validation-service'));
164
+ this.validationService = new ValidationService(
165
+ keyStore,
166
+ this.getSignatureContext(),
167
+ this.log.createChild('validation-service'),
168
+ );
169
+ this.proposalHandler.setCheckpointProposalValidationFailureCallback((proposal, result, proposalInfo) =>
170
+ this.handleInvalidCheckpointProposal(proposal, result, proposalInfo),
171
+ );
130
172
 
131
173
  // Refresh epoch cache every second to trigger alert if participation in committee changes
132
174
  this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
133
-
134
175
  const myAddresses = this.getValidatorAddresses();
135
176
  this.log.verbose(`Initialized validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
136
177
  }
@@ -199,6 +240,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
199
240
  txProvider: ITxProvider,
200
241
  keyStoreManager: KeystoreManager,
201
242
  blobClient: BlobClientInterface,
243
+ reexecutionTracker: CheckpointReexecutionTracker,
202
244
  dateProvider: DateProvider = new DateProvider(),
203
245
  telemetry: TelemetryClient = getTelemetryClient(),
204
246
  slashingProtectionDb?: SlashingProtectionDatabase,
@@ -207,8 +249,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
207
249
  const blockProposalValidator = new BlockProposalValidator(epochCache, {
208
250
  txsPermitted: !config.disableTransactions,
209
251
  maxTxsPerBlock: config.validateMaxTxsPerBlock,
252
+ maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
253
+ skipSlotValidation: config.skipProposalSlotValidation,
254
+ signatureContext: {
255
+ chainId: config.l1ChainId,
256
+ rollupAddress: config.rollupAddress,
257
+ },
210
258
  });
211
- const blockProposalHandler = new BlockProposalHandler(
259
+ const proposalHandler = new ProposalHandler(
212
260
  checkpointsBuilder,
213
261
  worldState,
214
262
  blockSource,
@@ -217,9 +265,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
217
265
  blockProposalValidator,
218
266
  epochCache,
219
267
  config,
268
+ blobClient,
269
+ reexecutionTracker,
220
270
  metrics,
221
271
  dateProvider,
222
272
  telemetry,
273
+ undefined,
223
274
  );
224
275
 
225
276
  const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
@@ -255,7 +306,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
255
306
  validatorKeyStore,
256
307
  epochCache,
257
308
  p2pClient,
258
- blockProposalHandler,
309
+ proposalHandler,
259
310
  blockSource,
260
311
  checkpointsBuilder,
261
312
  worldState,
@@ -276,14 +327,21 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
276
327
  .filter(addr => !this.config.disabledValidators.some(disabled => disabled.equals(addr)));
277
328
  }
278
329
 
279
- public getBlockProposalHandler() {
280
- return this.blockProposalHandler;
330
+ public getProposalHandler() {
331
+ return this.proposalHandler;
281
332
  }
282
333
 
283
334
  public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
284
335
  return this.keyStore.signTypedDataWithAddress(addr, msg, context);
285
336
  }
286
337
 
338
+ private getSignatureContext(): CoordinationSignatureContext {
339
+ return {
340
+ chainId: this.config.l1ChainId,
341
+ rollupAddress: this.config.rollupAddress,
342
+ };
343
+ }
344
+
287
345
  public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
288
346
  return this.keyStore.getCoinbaseAddress(attestor);
289
347
  }
@@ -296,14 +354,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
296
354
  return this.config;
297
355
  }
298
356
 
357
+ public hasProposalEquivocation(slotNumber: SlotNumber): boolean {
358
+ return this.slotsWithProposalEquivocation.has(slotNumber);
359
+ }
360
+
361
+ public hasInvalidProposals(slotNumber: SlotNumber): boolean {
362
+ return this.slotsWithInvalidProposals.has(slotNumber);
363
+ }
364
+
299
365
  public updateConfig(config: Partial<ValidatorClientFullConfig>) {
300
366
  this.config = { ...this.config, ...config };
367
+ this.proposalHandler.updateConfig(config);
301
368
  }
302
369
 
303
370
  public reloadKeystore(newManager: KeystoreManager): void {
304
371
  const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
305
372
  this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
306
- this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
373
+ this.validationService = new ValidationService(
374
+ this.keyStore,
375
+ this.getSignatureContext(),
376
+ this.log.createChild('validation-service'),
377
+ );
307
378
  }
308
379
 
309
380
  public async start() {
@@ -350,7 +421,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
350
421
  checkpoint: CheckpointProposalCore,
351
422
  proposalSender: PeerId,
352
423
  ): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
353
- this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
424
+ this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
354
425
 
355
426
  // Duplicate proposal handler - triggers slashing for equivocation
356
427
  this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
@@ -362,6 +433,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
362
433
  this.handleDuplicateAttestation(info);
363
434
  });
364
435
 
436
+ this.p2pClient.registerCheckpointAttestationCallback((attestation: CheckpointAttestation) => {
437
+ this.handleCheckpointAttestation(attestation);
438
+ });
439
+
365
440
  const myAddresses = this.getValidatorAddresses();
366
441
  this.p2pClient.registerThisValidatorAddresses(myAddresses);
367
442
 
@@ -408,22 +483,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
408
483
  fishermanMode: this.config.fishermanMode || false,
409
484
  });
410
485
 
411
- // Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
412
- // In fisherman mode, we always reexecute to validate proposals.
413
- const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } =
414
- this.config;
415
- const shouldReexecute =
416
- fishermanMode ||
417
- (slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute) ||
418
- (partOfCommittee && validatorReexecute) ||
419
- alwaysReexecuteBlockProposals ||
420
- this.blobClient.canUpload();
421
-
422
- const validationResult = await this.blockProposalHandler.handleBlockProposal(
423
- proposal,
424
- proposalSender,
425
- !!shouldReexecute && !escapeHatchOpen,
426
- );
486
+ // Reexecute outside the escape hatch so slashing observers can detect invalid proposals even when penalties are 0.
487
+ const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !escapeHatchOpen);
427
488
 
428
489
  if (!validationResult.isValid) {
429
490
  const reason = validationResult.reason || 'unknown';
@@ -446,15 +507,18 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
446
507
  this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
447
508
  }
448
509
 
449
- // Slash invalid block proposals (can happen even when not in committee)
450
510
  if (
451
511
  !escapeHatchOpen &&
452
512
  validationResult.reason &&
453
- SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) &&
454
- slashBroadcastedInvalidBlockPenalty > 0n
513
+ SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
455
514
  ) {
456
- this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
515
+ this.log.info(`Detected invalid block proposal offense`, {
516
+ ...proposalInfo,
517
+ amount: this.config.slashBroadcastedInvalidBlockPenalty,
518
+ offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL),
519
+ });
457
520
  this.slashInvalidBlock(proposal);
521
+ this.markInvalidProposalSlot(proposal.slotNumber);
458
522
  }
459
523
  return false;
460
524
  }
@@ -493,14 +557,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
493
557
  return undefined;
494
558
  }
495
559
 
496
- // Reject proposals with invalid signatures
497
- if (!proposer) {
498
- this.log.warn(`Received checkpoint proposal with invalid signature for proposal slot ${proposalSlotNumber}`);
560
+ // Early-out for equivocation: refuses if we've already attested to a higher slot.
561
+ if (!this.shouldAttestToSlot(proposalSlotNumber)) {
499
562
  return undefined;
500
563
  }
501
564
 
502
565
  // Ignore proposals from ourselves (may happen in HA setups)
503
- if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
566
+ if (proposer && this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
504
567
  this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
505
568
  proposer: proposer.toString(),
506
569
  proposalSlotNumber,
@@ -508,14 +571,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
508
571
  return undefined;
509
572
  }
510
573
 
511
- // Validate fee asset price modifier is within allowed range
512
- if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
513
- this.log.warn(
514
- `Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposalSlotNumber}`,
515
- );
516
- return undefined;
517
- }
518
-
519
574
  // Check that I have any address in the committee where this checkpoint will land before attesting
520
575
  const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
521
576
  const partOfCommittee = inCommittee.length > 0;
@@ -523,27 +578,26 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
523
578
  const proposalInfo = {
524
579
  proposalSlotNumber,
525
580
  archive: proposal.archive.toString(),
526
- proposer: proposer.toString(),
581
+ proposer: proposer?.toString(),
527
582
  };
528
583
  this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
529
584
  ...proposalInfo,
530
585
  fishermanMode: this.config.fishermanMode || false,
531
586
  });
532
587
 
533
- // Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
588
+ // Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
589
+ // Uses the cached result from the all-nodes callback if available (avoids double validation).
590
+ let checkpointNumber: CheckpointNumber;
534
591
  if (this.config.skipCheckpointProposalValidation) {
535
592
  this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
593
+ checkpointNumber = CheckpointNumber(0);
536
594
  } else {
537
- const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
595
+ const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
538
596
  if (!validationResult.isValid) {
539
597
  this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
540
598
  return undefined;
541
599
  }
542
- }
543
-
544
- // Upload blobs to filestore if we can (fire and forget)
545
- if (this.blobClient.canUpload()) {
546
- void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
600
+ checkpointNumber = validationResult.checkpointNumber;
547
601
  }
548
602
 
549
603
  // Check that I have any address in current committee before attesting
@@ -601,7 +655,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
601
655
  return undefined;
602
656
  }
603
657
 
604
- return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
658
+ return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
605
659
  }
606
660
 
607
661
  /**
@@ -628,13 +682,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
628
682
  private async createCheckpointAttestationsFromProposal(
629
683
  proposal: CheckpointProposalCore,
630
684
  attestors: EthAddress[] = [],
685
+ checkpointNumber: CheckpointNumber,
631
686
  ): Promise<CheckpointAttestation[] | undefined> {
632
687
  // Equivocation check: must happen right before signing to minimize the race window
633
688
  if (!this.shouldAttestToSlot(proposal.slotNumber)) {
634
689
  return undefined;
635
690
  }
636
691
 
637
- const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
692
+ const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
638
693
 
639
694
  // Track the proposal we attested to (to prevent equivocation)
640
695
  this.lastAttestedProposal = proposal;
@@ -643,178 +698,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
643
698
  return attestations;
644
699
  }
645
700
 
646
- /**
647
- * Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
648
- * @returns Validation result with isValid flag and reason if invalid.
649
- */
650
- private async validateCheckpointProposal(
651
- proposal: CheckpointProposalCore,
652
- proposalInfo: LogData,
653
- ): Promise<{ isValid: true } | { isValid: false; reason: string }> {
654
- const slot = proposal.slotNumber;
655
-
656
- // Timeout block syncing at the start of the next slot
657
- const config = this.checkpointsBuilder.getConfig();
658
- const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
659
- const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
660
-
661
- // Wait for last block to sync by archive
662
- let lastBlockHeader: BlockHeader | undefined;
663
- try {
664
- lastBlockHeader = await retryUntil(
665
- async () => {
666
- await this.blockSource.syncImmediate();
667
- return this.blockSource.getBlockHeaderByArchive(proposal.archive);
668
- },
669
- `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
670
- timeoutSeconds,
671
- 0.5,
672
- );
673
- } catch (err) {
674
- if (err instanceof TimeoutError) {
675
- this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
676
- return { isValid: false, reason: 'last_block_not_found' };
677
- }
678
- this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
679
- return { isValid: false, reason: 'block_fetch_error' };
680
- }
681
-
682
- if (!lastBlockHeader) {
683
- this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
684
- return { isValid: false, reason: 'last_block_not_found' };
685
- }
686
-
687
- // Get all full blocks for the slot and checkpoint
688
- const blocks = await this.blockSource.getBlocksForSlot(slot);
689
- if (blocks.length === 0) {
690
- this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
691
- return { isValid: false, reason: 'no_blocks_for_slot' };
692
- }
693
-
694
- // Ensure the last block for this slot matches the archive in the checkpoint proposal
695
- if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
696
- this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
697
- return { isValid: false, reason: 'last_block_archive_mismatch' };
698
- }
699
-
700
- this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
701
- ...proposalInfo,
702
- blockNumbers: blocks.map(b => b.number),
703
- });
704
-
705
- // Get checkpoint constants from first block
706
- const firstBlock = blocks[0];
707
- const constants = this.extractCheckpointConstants(firstBlock);
708
- const checkpointNumber = firstBlock.checkpointNumber;
709
-
710
- // Get L1-to-L2 messages for this checkpoint
711
- const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
712
-
713
- // Collect the out hashes of all the checkpoints before this one in the same epoch
714
- const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
715
- const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
716
- .filter(c => c.checkpointNumber < checkpointNumber)
717
- .map(c => c.checkpointOutHash);
718
-
719
- // Fork world state at the block before the first block
720
- const parentBlockNumber = BlockNumber(firstBlock.number - 1);
721
- const fork = await this.worldState.fork(parentBlockNumber);
722
-
723
- try {
724
- // Create checkpoint builder with all existing blocks
725
- const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
726
- checkpointNumber,
727
- constants,
728
- proposal.feeAssetPriceModifier,
729
- l1ToL2Messages,
730
- previousCheckpointOutHashes,
731
- fork,
732
- blocks,
733
- this.log.getBindings(),
734
- );
735
-
736
- // Complete the checkpoint to get computed values
737
- const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
738
-
739
- // Compare checkpoint header with proposal
740
- if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
741
- this.log.warn(`Checkpoint header mismatch`, {
742
- ...proposalInfo,
743
- computed: computedCheckpoint.header.toInspect(),
744
- proposal: proposal.checkpointHeader.toInspect(),
745
- });
746
- return { isValid: false, reason: 'checkpoint_header_mismatch' };
747
- }
748
-
749
- // Compare archive root with proposal
750
- if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
751
- this.log.warn(`Archive root mismatch`, {
752
- ...proposalInfo,
753
- computed: computedCheckpoint.archive.root.toString(),
754
- proposal: proposal.archive.toString(),
755
- });
756
- return { isValid: false, reason: 'archive_mismatch' };
757
- }
758
-
759
- // Check that the accumulated epoch out hash matches the value in the proposal.
760
- // The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
761
- const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
762
- const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
763
- const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
764
- if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
765
- this.log.warn(`Epoch out hash mismatch`, {
766
- proposalEpochOutHash: proposalEpochOutHash.toString(),
767
- computedEpochOutHash: computedEpochOutHash.toString(),
768
- checkpointOutHash: checkpointOutHash.toString(),
769
- previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
770
- ...proposalInfo,
771
- });
772
- return { isValid: false, reason: 'out_hash_mismatch' };
773
- }
774
-
775
- // Final round of validations on the checkpoint, just in case.
776
- try {
777
- validateCheckpoint(computedCheckpoint, {
778
- rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
779
- maxDABlockGas: this.config.validateMaxDABlockGas,
780
- maxL2BlockGas: this.config.validateMaxL2BlockGas,
781
- maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
782
- maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint,
783
- });
784
- } catch (err) {
785
- this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
786
- return { isValid: false, reason: 'checkpoint_validation_failed' };
787
- }
788
-
789
- this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
790
- return { isValid: true };
791
- } finally {
792
- await fork.close();
793
- }
794
- }
795
-
796
- /**
797
- * Extract checkpoint global variables from a block.
798
- */
799
- private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
800
- const gv = block.header.globalVariables;
801
- return {
802
- chainId: gv.chainId,
803
- version: gv.version,
804
- slotNumber: gv.slotNumber,
805
- timestamp: gv.timestamp,
806
- coinbase: gv.coinbase,
807
- feeRecipient: gv.feeRecipient,
808
- gasFees: gv.gasFees,
809
- };
810
- }
811
-
812
701
  /**
813
702
  * Uploads blobs for a checkpoint to the filestore (fire and forget).
814
703
  */
815
704
  protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
816
705
  try {
817
- const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
706
+ const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
818
707
  if (!lastBlockHeader) {
819
708
  this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
820
709
  return;
@@ -847,12 +736,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
847
736
  return;
848
737
  }
849
738
 
850
- // Trim the set if it's too big.
851
- if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
852
- // remove oldest proposer. `values` is guaranteed to be in insertion order.
853
- this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value!);
854
- }
855
-
856
739
  this.proposersOfInvalidBlocks.add(proposer.toString());
857
740
 
858
741
  this.emit(WANT_TO_SLASH_EVENT, [
@@ -865,20 +748,115 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
865
748
  ]);
866
749
  }
867
750
 
751
+ private handleInvalidCheckpointProposal(
752
+ proposal: CheckpointProposalCore,
753
+ result: CheckpointProposalValidationFailureResult,
754
+ proposalInfo: LogData,
755
+ ): void {
756
+ if (!SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
757
+ return;
758
+ }
759
+
760
+ this.markInvalidProposalSlot(proposal.slotNumber);
761
+
762
+ if (this.slashInvalidCheckpointProposal(proposal)) {
763
+ this.log.info(`Detected invalid checkpoint proposal offense`, {
764
+ ...proposalInfo,
765
+ reason: result.reason,
766
+ amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
767
+ offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL),
768
+ });
769
+ }
770
+ }
771
+
772
+ private slashInvalidCheckpointProposal(proposal: CheckpointProposalCore): boolean {
773
+ const proposer = proposal.getSender();
774
+ if (!proposer) {
775
+ this.log.warn(`Cannot slash checkpoint proposal with invalid signature`, {
776
+ slotNumber: proposal.slotNumber,
777
+ archive: proposal.archive.toString(),
778
+ });
779
+ return false;
780
+ }
781
+
782
+ const offenseType = OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL;
783
+ const offenseKey = `${proposer.toString()}:${offenseType}:${proposal.slotNumber}`;
784
+ if (!this.invalidCheckpointProposalOffenseKeys.addIfAbsent(offenseKey)) {
785
+ return false;
786
+ }
787
+
788
+ this.emit(WANT_TO_SLASH_EVENT, [
789
+ {
790
+ validator: proposer,
791
+ amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
792
+ offenseType,
793
+ epochOrSlot: BigInt(proposal.slotNumber),
794
+ },
795
+ ]);
796
+ return true;
797
+ }
798
+
799
+ private markInvalidProposalSlot(slotNumber: SlotNumber): void {
800
+ this.slotsWithInvalidProposals.add(slotNumber);
801
+ }
802
+
803
+ private handleCheckpointAttestation(attestation: CheckpointAttestation): void {
804
+ const slotNumber = attestation.slotNumber;
805
+ if (!this.slotsWithInvalidProposals.has(slotNumber) || this.slotsWithProposalEquivocation.has(slotNumber)) {
806
+ return;
807
+ }
808
+
809
+ const attester = attestation.getSender();
810
+ if (!attester) {
811
+ this.log.warn(`Cannot slash checkpoint attestation with invalid signature`, {
812
+ slotNumber,
813
+ archive: attestation.archive.toString(),
814
+ });
815
+ return;
816
+ }
817
+
818
+ this.slashAttestedToInvalidCheckpointProposal(slotNumber, attester);
819
+ }
820
+
821
+ private slashAttestedToInvalidCheckpointProposal(slotNumber: SlotNumber, attester: EthAddress): void {
822
+ const offenseKey = `${attester.toString()}:${OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL}:${slotNumber}`;
823
+ if (!this.badAttestationOffenseKeys.addIfAbsent(offenseKey)) {
824
+ return;
825
+ }
826
+
827
+ this.log.info(`Detected attestation to invalid checkpoint proposal offense`, {
828
+ attester: attester.toString(),
829
+ slotNumber,
830
+ amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
831
+ offenseType: getOffenseTypeName(OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL),
832
+ });
833
+
834
+ this.emit(WANT_TO_SLASH_EVENT, [
835
+ {
836
+ validator: attester,
837
+ amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
838
+ offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
839
+ epochOrSlot: BigInt(slotNumber),
840
+ },
841
+ ]);
842
+ }
843
+
868
844
  /**
869
845
  * Handle detection of a duplicate proposal (equivocation).
870
846
  * Emits a slash event when a proposer sends multiple proposals for the same position.
871
847
  */
872
848
  private handleDuplicateProposal(info: DuplicateProposalInfo): void {
873
849
  const { slot, proposer, type } = info;
850
+ this.slotsWithProposalEquivocation.add(slot);
874
851
 
875
- this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
852
+ this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
876
853
  proposer: proposer.toString(),
877
854
  slot,
878
855
  type,
856
+ amount: this.config.slashDuplicateProposalPenalty,
857
+ offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL),
879
858
  });
880
859
 
881
- // Emit slash event
882
860
  this.emit(WANT_TO_SLASH_EVENT, [
883
861
  {
884
862
  validator: proposer,
@@ -887,6 +865,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
887
865
  epochOrSlot: BigInt(slot),
888
866
  },
889
867
  ]);
868
+
869
+ this.emit(WANT_TO_CLEAR_SLASH_EVENT, [
870
+ {
871
+ offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
872
+ epochOrSlot: BigInt(slot),
873
+ },
874
+ ]);
890
875
  }
891
876
 
892
877
  /**
@@ -896,9 +881,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
896
881
  private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
897
882
  const { slot, attester } = info;
898
883
 
899
- this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
884
+ this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
900
885
  attester: attester.toString(),
901
886
  slot,
887
+ amount: this.config.slashDuplicateAttestationPenalty,
888
+ offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION),
902
889
  });
903
890
 
904
891
  this.emit(WANT_TO_SLASH_EVENT, [
@@ -913,6 +900,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
913
900
 
914
901
  async createBlockProposal(
915
902
  blockHeader: BlockHeader,
903
+ checkpointNumber: CheckpointNumber,
916
904
  indexWithinCheckpoint: IndexWithinCheckpoint,
917
905
  inHash: Fr,
918
906
  archive: Fr,
@@ -939,6 +927,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
939
927
  );
940
928
  const newProposal = await this.validationService.createBlockProposal(
941
929
  blockHeader,
930
+ checkpointNumber,
942
931
  indexWithinCheckpoint,
943
932
  inHash,
944
933
  archive,
@@ -946,7 +935,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
946
935
  proposerAddress,
947
936
  {
948
937
  ...options,
949
- broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
938
+ broadcastInvalidBlockProposal:
939
+ options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal,
950
940
  },
951
941
  );
952
942
  this.lastProposedBlock = newProposal;
@@ -956,8 +946,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
956
946
  async createCheckpointProposal(
957
947
  checkpointHeader: CheckpointHeader,
958
948
  archive: Fr,
949
+ checkpointNumber: CheckpointNumber,
959
950
  feeAssetPriceModifier: bigint,
960
- lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
951
+ lastBlockProposal: BlockProposal | undefined,
961
952
  proposerAddress: EthAddress | undefined,
962
953
  options: CheckpointProposalOptions = {},
963
954
  ): Promise<CheckpointProposal> {
@@ -978,12 +969,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
978
969
  const newProposal = await this.validationService.createCheckpointProposal(
979
970
  checkpointHeader,
980
971
  archive,
972
+ checkpointNumber,
981
973
  feeAssetPriceModifier,
982
- lastBlockInfo,
974
+ lastBlockProposal,
983
975
  proposerAddress,
984
976
  options,
985
977
  );
986
978
  this.lastProposedCheckpoint = newProposal;
979
+ // Self-record this slot's outcome on the re-execution tracker. Proposers don't run their
980
+ // own proposals through `handleCheckpointProposal`, so without this call the proposer's
981
+ // sentinel would see no outcome for slots it proposed and would mis-attribute itself as
982
+ // inactive. We pass the locally-computed `archive` (not `newProposal.archive`, which may
983
+ // be intentionally corrupted under test-only flags); from the proposer's local-view
984
+ // perspective the work it just completed is valid by definition.
985
+ this.proposalHandler.recordOwnCheckpointProposalAsValid(checkpointHeader.slotNumber, archive, checkpointNumber);
987
986
  return newProposal;
988
987
  }
989
988
 
@@ -995,16 +994,24 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
995
994
  attestationsAndSigners: CommitteeAttestationsAndSigners,
996
995
  proposer: EthAddress,
997
996
  slot: SlotNumber,
998
- blockNumber: BlockNumber | CheckpointNumber,
997
+ checkpointNumber: CheckpointNumber,
999
998
  ): Promise<Signature> {
1000
- return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
999
+ return await this.validationService.signAttestationsAndSigners(
1000
+ attestationsAndSigners,
1001
+ proposer,
1002
+ slot,
1003
+ checkpointNumber,
1004
+ );
1001
1005
  }
1002
1006
 
1003
- async collectOwnAttestations(proposal: CheckpointProposal): Promise<CheckpointAttestation[]> {
1007
+ async collectOwnAttestations(
1008
+ proposal: CheckpointProposal,
1009
+ checkpointNumber: CheckpointNumber,
1010
+ ): Promise<CheckpointAttestation[]> {
1004
1011
  const slot = proposal.slotNumber;
1005
1012
  const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
1006
1013
  this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
1007
- const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
1014
+ const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
1008
1015
 
1009
1016
  if (!attestations) {
1010
1017
  return [];
@@ -1023,6 +1030,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
1023
1030
  proposal: CheckpointProposal,
1024
1031
  required: number,
1025
1032
  deadline: Date,
1033
+ checkpointNumber: CheckpointNumber,
1026
1034
  ): Promise<CheckpointAttestation[]> {
1027
1035
  // Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
1028
1036
  const slot = proposal.slotNumber;
@@ -1035,33 +1043,23 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
1035
1043
  throw new AttestationTimeoutError(0, required, slot);
1036
1044
  }
1037
1045
 
1038
- await this.collectOwnAttestations(proposal);
1046
+ await this.collectOwnAttestations(proposal, checkpointNumber);
1039
1047
 
1040
- const proposalId = proposal.archive.toString();
1048
+ const proposalPayloadHash = proposal.getPayloadHash();
1041
1049
  const myAddresses = this.getValidatorAddresses();
1042
1050
 
1043
1051
  let attestations: CheckpointAttestation[] = [];
1044
1052
  while (true) {
1045
- // Filter out attestations with a mismatching archive. This should NOT happen since we have verified
1046
- // the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
1047
- const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter(
1048
- attestation => {
1049
- if (!attestation.archive.equals(proposal.archive)) {
1050
- this.log.warn(
1051
- `Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`,
1052
- { attestationArchive: attestation.archive.toString(), proposalArchive: proposal.archive.toString() },
1053
- );
1054
- return false;
1055
- }
1056
- return true;
1057
- },
1058
- );
1053
+ // The pool already filters by proposal payload hash; if any attestation slips through with a
1054
+ // mismatched payload hash, drop it defensively. Equivocations are emitted as separate slash
1055
+ // events from libp2p_service.
1056
+ const collectedAttestations = await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
1059
1057
 
1060
1058
  // Log new attestations we collected
1061
1059
  const oldSenders = attestations.map(attestation => attestation.getSender());
1062
1060
  for (const collected of collectedAttestations) {
1063
1061
  const collectedSender = collected.getSender();
1064
- // Skip attestations with invalid signatures
1062
+ // Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
1065
1063
  if (!collectedSender) {
1066
1064
  this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
1067
1065
  continue;