@aztec/validator-client 0.0.1-commit.7b86788 → 0.0.1-commit.7cbc774

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +51 -11
  2. package/dest/checkpoint_builder.d.ts +14 -4
  3. package/dest/checkpoint_builder.d.ts.map +1 -1
  4. package/dest/checkpoint_builder.js +101 -30
  5. package/dest/config.d.ts +1 -1
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +33 -7
  8. package/dest/duties/validation_service.d.ts +12 -13
  9. package/dest/duties/validation_service.d.ts.map +1 -1
  10. package/dest/duties/validation_service.js +33 -45
  11. package/dest/factory.d.ts +10 -4
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +11 -5
  14. package/dest/index.d.ts +2 -2
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +1 -1
  17. package/dest/key_store/ha_key_store.js +1 -1
  18. package/dest/metrics.d.ts +14 -2
  19. package/dest/metrics.d.ts.map +1 -1
  20. package/dest/metrics.js +24 -0
  21. package/dest/proposal_handler.d.ts +135 -0
  22. package/dest/proposal_handler.d.ts.map +1 -0
  23. package/dest/proposal_handler.js +1111 -0
  24. package/dest/validator.d.ts +31 -21
  25. package/dest/validator.d.ts.map +1 -1
  26. package/dest/validator.js +260 -263
  27. package/package.json +19 -19
  28. package/src/checkpoint_builder.ts +124 -35
  29. package/src/config.ts +33 -6
  30. package/src/duties/validation_service.ts +52 -54
  31. package/src/factory.ts +20 -3
  32. package/src/index.ts +1 -1
  33. package/src/key_store/ha_key_store.ts +1 -1
  34. package/src/metrics.ts +37 -1
  35. package/src/proposal_handler.ts +1207 -0
  36. package/src/validator.ts +338 -305
  37. package/dest/block_proposal_handler.d.ts +0 -63
  38. package/dest/block_proposal_handler.d.ts.map +0 -1
  39. package/dest/block_proposal_handler.js +0 -532
  40. package/src/block_proposal_handler.ts +0 -535
package/src/validator.ts CHANGED
@@ -1,38 +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 { 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';
28
28
  import type {
29
- CreateCheckpointProposalLastBlockData,
30
29
  ITxProvider,
31
30
  Validator,
32
31
  ValidatorClientFullConfig,
33
32
  WorldStateSynchronizer,
34
33
  } from '@aztec/stdlib/interfaces/server';
35
- import { type L1ToL2MessageSource, accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
34
+ import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
36
35
  import {
37
36
  type BlockProposal,
38
37
  type BlockProposalOptions,
@@ -40,36 +39,73 @@ import {
40
39
  CheckpointProposal,
41
40
  type CheckpointProposalCore,
42
41
  type CheckpointProposalOptions,
42
+ type CoordinationSignatureContext,
43
43
  } from '@aztec/stdlib/p2p';
44
44
  import type { CheckpointHeader } from '@aztec/stdlib/rollup';
45
- import type { BlockHeader, CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
45
+ import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
46
46
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
47
47
  import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
48
- import { createHASigner } from '@aztec/validator-ha-signer/factory';
49
- import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
48
+ import {
49
+ createHASigner,
50
+ createLocalSignerWithProtection,
51
+ createSignerFromSharedDb,
52
+ } from '@aztec/validator-ha-signer/factory';
53
+ import { DutyType, type SigningContext, type SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
50
54
  import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
51
55
 
52
56
  import { EventEmitter } from 'events';
53
57
  import type { TypedDataDefinition } from 'viem';
54
58
 
55
- import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
56
59
  import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
57
60
  import { ValidationService } from './duties/validation_service.js';
58
61
  import { HAKeyStore } from './key_store/ha_key_store.js';
59
62
  import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
60
63
  import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
61
64
  import { ValidatorMetrics } from './metrics.js';
65
+ import {
66
+ type BlockProposalValidationFailureReason,
67
+ type CheckpointProposalValidationFailureReason,
68
+ type CheckpointProposalValidationFailureResult,
69
+ ProposalHandler,
70
+ } from './proposal_handler.js';
62
71
 
63
72
  // We maintain a set of proposers who have proposed invalid blocks.
64
73
  // Just cap the set to avoid unbounded growth.
65
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;
66
78
 
67
79
  // What errors from the block proposal handler result in slashing
68
80
  const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT: BlockProposalValidationFailureReason[] = [
69
81
  'state_mismatch',
70
82
  'failed_txs',
83
+ 'global_variables_mismatch',
84
+ 'invalid_proposal',
85
+ 'parent_block_wrong_slot',
86
+ 'in_hash_mismatch',
71
87
  ];
72
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
+
73
109
  /**
74
110
  * Validator Client
75
111
  */
@@ -89,8 +125,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
89
125
 
90
126
  private lastEpochForCommitteeUpdateLoop: EpochNumber | undefined;
91
127
  private epochCacheUpdateLoop: RunningPromise;
128
+ /** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
129
+ private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
92
130
 
93
- 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);
94
136
 
95
137
  /** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
96
138
  private lastAttestedProposal?: CheckpointProposalCore;
@@ -99,14 +141,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
99
141
  private keyStore: ExtendedValidatorKeyStore,
100
142
  private epochCache: EpochCache,
101
143
  private p2pClient: P2P,
102
- private blockProposalHandler: BlockProposalHandler,
144
+ private proposalHandler: ProposalHandler,
103
145
  private blockSource: L2BlockSource,
104
146
  private checkpointsBuilder: FullNodeCheckpointsBuilder,
105
147
  private worldState: WorldStateSynchronizer,
106
148
  private l1ToL2MessageSource: L1ToL2MessageSource,
107
149
  private config: ValidatorClientFullConfig,
108
150
  private blobClient: BlobClientInterface,
109
- private haSigner: ValidatorHASigner | undefined,
151
+ private slashingProtectionSigner: ValidatorHASigner,
110
152
  private dateProvider: DateProvider = new DateProvider(),
111
153
  telemetry: TelemetryClient = getTelemetryClient(),
112
154
  log = createLogger('validator'),
@@ -119,11 +161,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
119
161
  this.tracer = telemetry.getTracer('Validator');
120
162
  this.metrics = new ValidatorMetrics(telemetry);
121
163
 
122
- 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
+ );
123
172
 
124
173
  // Refresh epoch cache every second to trigger alert if participation in committee changes
125
174
  this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
126
-
127
175
  const myAddresses = this.getValidatorAddresses();
128
176
  this.log.verbose(`Initialized validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
129
177
  }
@@ -160,6 +208,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
160
208
  this.log.trace(`No committee found for slot`);
161
209
  return;
162
210
  }
211
+ this.metrics.setCurrentEpoch(epoch);
163
212
  if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
164
213
  const me = this.getValidatorAddresses();
165
214
  const committeeSet = new Set(committee.map(v => v.toString()));
@@ -191,14 +240,23 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
191
240
  txProvider: ITxProvider,
192
241
  keyStoreManager: KeystoreManager,
193
242
  blobClient: BlobClientInterface,
243
+ reexecutionTracker: CheckpointReexecutionTracker,
194
244
  dateProvider: DateProvider = new DateProvider(),
195
245
  telemetry: TelemetryClient = getTelemetryClient(),
246
+ slashingProtectionDb?: SlashingProtectionDatabase,
196
247
  ) {
197
248
  const metrics = new ValidatorMetrics(telemetry);
198
249
  const blockProposalValidator = new BlockProposalValidator(epochCache, {
199
250
  txsPermitted: !config.disableTransactions,
251
+ maxTxsPerBlock: config.validateMaxTxsPerBlock,
252
+ maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
253
+ skipSlotValidation: config.skipProposalSlotValidation,
254
+ signatureContext: {
255
+ chainId: config.l1ChainId,
256
+ rollupAddress: config.rollupAddress,
257
+ },
200
258
  });
201
- const blockProposalHandler = new BlockProposalHandler(
259
+ const proposalHandler = new ProposalHandler(
202
260
  checkpointsBuilder,
203
261
  worldState,
204
262
  blockSource,
@@ -207,37 +265,55 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
207
265
  blockProposalValidator,
208
266
  epochCache,
209
267
  config,
268
+ blobClient,
269
+ reexecutionTracker,
210
270
  metrics,
211
271
  dateProvider,
212
272
  telemetry,
273
+ undefined,
213
274
  );
214
275
 
215
276
  const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
216
- let validatorKeyStore: ExtendedValidatorKeyStore = nodeKeystoreAdapter;
217
- let haSigner: ValidatorHASigner | undefined;
218
- if (config.haSigningEnabled) {
277
+ let slashingProtectionSigner: ValidatorHASigner;
278
+ if (slashingProtectionDb) {
279
+ // Shared database mode: use a pre-existing database (e.g. for testing HA setups).
280
+ ({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
281
+ telemetryClient: telemetry,
282
+ dateProvider,
283
+ }));
284
+ } else if (config.haSigningEnabled) {
285
+ // Multi-node HA mode: use PostgreSQL-backed distributed locking.
219
286
  // If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
220
287
  const haConfig = {
221
288
  ...config,
222
289
  maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000,
223
290
  };
224
- const { signer } = await createHASigner(haConfig, { telemetryClient: telemetry, dateProvider });
225
- haSigner = signer;
226
- validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
291
+ ({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
292
+ telemetryClient: telemetry,
293
+ dateProvider,
294
+ }));
295
+ } else {
296
+ // Single-node mode: use LMDB-backed local signing protection.
297
+ // This prevents double-signing if the node crashes and restarts mid-proposal.
298
+ ({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
299
+ telemetryClient: telemetry,
300
+ dateProvider,
301
+ }));
227
302
  }
303
+ const validatorKeyStore: ExtendedValidatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
228
304
 
229
305
  const validator = new ValidatorClient(
230
306
  validatorKeyStore,
231
307
  epochCache,
232
308
  p2pClient,
233
- blockProposalHandler,
309
+ proposalHandler,
234
310
  blockSource,
235
311
  checkpointsBuilder,
236
312
  worldState,
237
313
  l1ToL2MessageSource,
238
314
  config,
239
315
  blobClient,
240
- haSigner,
316
+ slashingProtectionSigner,
241
317
  dateProvider,
242
318
  telemetry,
243
319
  );
@@ -251,14 +327,21 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
251
327
  .filter(addr => !this.config.disabledValidators.some(disabled => disabled.equals(addr)));
252
328
  }
253
329
 
254
- public getBlockProposalHandler() {
255
- return this.blockProposalHandler;
330
+ public getProposalHandler() {
331
+ return this.proposalHandler;
256
332
  }
257
333
 
258
334
  public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
259
335
  return this.keyStore.signTypedDataWithAddress(addr, msg, context);
260
336
  }
261
337
 
338
+ private getSignatureContext(): CoordinationSignatureContext {
339
+ return {
340
+ chainId: this.config.l1ChainId,
341
+ rollupAddress: this.config.rollupAddress,
342
+ };
343
+ }
344
+
262
345
  public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
263
346
  return this.keyStore.getCoinbaseAddress(attestor);
264
347
  }
@@ -271,30 +354,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
271
354
  return this.config;
272
355
  }
273
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
+
274
365
  public updateConfig(config: Partial<ValidatorClientFullConfig>) {
275
366
  this.config = { ...this.config, ...config };
367
+ this.proposalHandler.updateConfig(config);
276
368
  }
277
369
 
278
370
  public reloadKeystore(newManager: KeystoreManager): void {
279
- if (this.config.haSigningEnabled && !this.haSigner) {
280
- this.log.warn(
281
- 'HA signing is enabled in config but was not initialized at startup. ' +
282
- 'Restart the node to enable HA signing.',
283
- );
284
- } else if (!this.config.haSigningEnabled && this.haSigner) {
285
- this.log.warn(
286
- 'HA signing was disabled via config update but the HA signer is still active. ' +
287
- 'Restart the node to fully disable HA signing.',
288
- );
289
- }
290
-
291
371
  const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
292
- if (this.haSigner) {
293
- this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
294
- } else {
295
- this.keyStore = newAdapter;
296
- }
297
- this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
372
+ this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
373
+ this.validationService = new ValidationService(
374
+ this.keyStore,
375
+ this.getSignatureContext(),
376
+ this.log.createChild('validation-service'),
377
+ );
298
378
  }
299
379
 
300
380
  public async start() {
@@ -341,7 +421,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
341
421
  checkpoint: CheckpointProposalCore,
342
422
  proposalSender: PeerId,
343
423
  ): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
344
- this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
424
+ this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
345
425
 
346
426
  // Duplicate proposal handler - triggers slashing for equivocation
347
427
  this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
@@ -353,6 +433,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
353
433
  this.handleDuplicateAttestation(info);
354
434
  });
355
435
 
436
+ this.p2pClient.registerCheckpointAttestationCallback((attestation: CheckpointAttestation) => {
437
+ this.handleCheckpointAttestation(attestation);
438
+ });
439
+
356
440
  const myAddresses = this.getValidatorAddresses();
357
441
  this.p2pClient.registerThisValidatorAddresses(myAddresses);
358
442
 
@@ -380,13 +464,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
380
464
  return false;
381
465
  }
382
466
 
383
- // Ignore proposals from ourselves (may happen in HA setups)
467
+ // Log self-proposals from HA peers (same validator key on different nodes)
384
468
  if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
385
- this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
469
+ this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
386
470
  proposer: proposer.toString(),
387
471
  slotNumber,
388
472
  });
389
- return false;
390
473
  }
391
474
 
392
475
  // Check if we're in the committee (for metrics purposes)
@@ -400,27 +483,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
400
483
  fishermanMode: this.config.fishermanMode || false,
401
484
  });
402
485
 
403
- // Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
404
- // In fisherman mode, we always reexecute to validate proposals.
405
- const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } =
406
- this.config;
407
- const shouldReexecute =
408
- fishermanMode ||
409
- (slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute) ||
410
- (partOfCommittee && validatorReexecute) ||
411
- alwaysReexecuteBlockProposals ||
412
- this.blobClient.canUpload();
413
-
414
- const validationResult = await this.blockProposalHandler.handleBlockProposal(
415
- proposal,
416
- proposalSender,
417
- !!shouldReexecute && !escapeHatchOpen,
418
- );
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);
419
488
 
420
489
  if (!validationResult.isValid) {
421
- this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
422
-
423
490
  const reason = validationResult.reason || 'unknown';
491
+
492
+ this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
493
+
424
494
  // Classify failure reason: bad proposal vs node issue
425
495
  const badProposalReasons: BlockProposalValidationFailureReason[] = [
426
496
  'invalid_proposal',
@@ -437,15 +507,18 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
437
507
  this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
438
508
  }
439
509
 
440
- // Slash invalid block proposals (can happen even when not in committee)
441
510
  if (
442
511
  !escapeHatchOpen &&
443
512
  validationResult.reason &&
444
- SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) &&
445
- slashBroadcastedInvalidBlockPenalty > 0n
513
+ SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
446
514
  ) {
447
- 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
+ });
448
520
  this.slashInvalidBlock(proposal);
521
+ this.markInvalidProposalSlot(proposal.slotNumber);
449
522
  }
450
523
  return false;
451
524
  }
@@ -475,68 +548,56 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
475
548
  proposal: CheckpointProposalCore,
476
549
  _proposalSender: PeerId,
477
550
  ): Promise<CheckpointAttestation[] | undefined> {
478
- const slotNumber = proposal.slotNumber;
551
+ const proposalSlotNumber = proposal.slotNumber;
479
552
  const proposer = proposal.getSender();
480
553
 
481
554
  // If escape hatch is open for this slot's epoch, do not attest.
482
- if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
483
- this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
555
+ if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
556
+ this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
484
557
  return undefined;
485
558
  }
486
559
 
487
- // Reject proposals with invalid signatures
488
- if (!proposer) {
489
- this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
560
+ // Early-out for equivocation: refuses if we've already attested to a higher slot.
561
+ if (!this.shouldAttestToSlot(proposalSlotNumber)) {
490
562
  return undefined;
491
563
  }
492
564
 
493
565
  // Ignore proposals from ourselves (may happen in HA setups)
494
- if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
495
- this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
566
+ if (proposer && this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
567
+ this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
496
568
  proposer: proposer.toString(),
497
- slotNumber,
569
+ proposalSlotNumber,
498
570
  });
499
571
  return undefined;
500
572
  }
501
573
 
502
- // Validate fee asset price modifier is within allowed range
503
- if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
504
- this.log.warn(
505
- `Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`,
506
- );
507
- return undefined;
508
- }
509
-
510
- // Check that I have any address in current committee before attesting
511
- const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
574
+ // Check that I have any address in the committee where this checkpoint will land before attesting
575
+ const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
512
576
  const partOfCommittee = inCommittee.length > 0;
513
577
 
514
578
  const proposalInfo = {
515
- slotNumber,
579
+ proposalSlotNumber,
516
580
  archive: proposal.archive.toString(),
517
- proposer: proposer.toString(),
518
- txCount: proposal.txHashes.length,
581
+ proposer: proposer?.toString(),
519
582
  };
520
- this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
583
+ this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
521
584
  ...proposalInfo,
522
- txHashes: proposal.txHashes.map(t => t.toString()),
523
585
  fishermanMode: this.config.fishermanMode || false,
524
586
  });
525
587
 
526
- // 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;
527
591
  if (this.config.skipCheckpointProposalValidation) {
528
- this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
592
+ this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
593
+ checkpointNumber = CheckpointNumber(0);
529
594
  } else {
530
- const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
595
+ const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
531
596
  if (!validationResult.isValid) {
532
597
  this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
533
598
  return undefined;
534
599
  }
535
- }
536
-
537
- // Upload blobs to filestore if we can (fire and forget)
538
- if (this.blobClient.canUpload()) {
539
- void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
600
+ checkpointNumber = validationResult.checkpointNumber;
540
601
  }
541
602
 
542
603
  // Check that I have any address in current committee before attesting
@@ -547,14 +608,28 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
547
608
  }
548
609
 
549
610
  // Provided all of the above checks pass, we can attest to the proposal
550
- this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
551
- ...proposalInfo,
552
- inCommittee: partOfCommittee,
553
- fishermanMode: this.config.fishermanMode || false,
554
- });
611
+ this.log.info(
612
+ `${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`,
613
+ {
614
+ ...proposalInfo,
615
+ inCommittee: partOfCommittee,
616
+ fishermanMode: this.config.fishermanMode || false,
617
+ },
618
+ );
555
619
 
556
620
  this.metrics.incSuccessfulAttestations(inCommittee.length);
557
621
 
622
+ // Track epoch participation per attester: count each (attester, epoch) pair at most once
623
+ const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
624
+ for (const attester of inCommittee) {
625
+ const key = attester.toString();
626
+ const lastEpoch = this.lastAttestedEpochByAttester.get(key);
627
+ if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
628
+ this.lastAttestedEpochByAttester.set(key, proposalEpoch);
629
+ this.metrics.incAttestedEpochCount(attester);
630
+ }
631
+ }
632
+
558
633
  // Determine which validators should attest
559
634
  let attestors: EthAddress[];
560
635
  if (partOfCommittee) {
@@ -573,14 +648,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
573
648
 
574
649
  if (this.config.fishermanMode) {
575
650
  // bail out early and don't save attestations to the pool in fisherman mode
576
- this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
651
+ this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
577
652
  ...proposalInfo,
578
653
  attestors: attestors.map(a => a.toString()),
579
654
  });
580
655
  return undefined;
581
656
  }
582
657
 
583
- return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
658
+ return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
584
659
  }
585
660
 
586
661
  /**
@@ -607,13 +682,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
607
682
  private async createCheckpointAttestationsFromProposal(
608
683
  proposal: CheckpointProposalCore,
609
684
  attestors: EthAddress[] = [],
685
+ checkpointNumber: CheckpointNumber,
610
686
  ): Promise<CheckpointAttestation[] | undefined> {
611
687
  // Equivocation check: must happen right before signing to minimize the race window
612
688
  if (!this.shouldAttestToSlot(proposal.slotNumber)) {
613
689
  return undefined;
614
690
  }
615
691
 
616
- const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
692
+ const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
617
693
 
618
694
  // Track the proposal we attested to (to prevent equivocation)
619
695
  this.lastAttestedProposal = proposal;
@@ -622,164 +698,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
622
698
  return attestations;
623
699
  }
624
700
 
625
- /**
626
- * Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
627
- * @returns Validation result with isValid flag and reason if invalid.
628
- */
629
- private async validateCheckpointProposal(
630
- proposal: CheckpointProposalCore,
631
- proposalInfo: LogData,
632
- ): Promise<{ isValid: true } | { isValid: false; reason: string }> {
633
- const slot = proposal.slotNumber;
634
-
635
- // Timeout block syncing at the start of the next slot
636
- const config = this.checkpointsBuilder.getConfig();
637
- const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
638
- const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
639
-
640
- // Wait for last block to sync by archive
641
- let lastBlockHeader: BlockHeader | undefined;
642
- try {
643
- lastBlockHeader = await retryUntil(
644
- async () => {
645
- await this.blockSource.syncImmediate();
646
- return this.blockSource.getBlockHeaderByArchive(proposal.archive);
647
- },
648
- `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
649
- timeoutSeconds,
650
- 0.5,
651
- );
652
- } catch (err) {
653
- if (err instanceof TimeoutError) {
654
- this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
655
- return { isValid: false, reason: 'last_block_not_found' };
656
- }
657
- this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
658
- return { isValid: false, reason: 'block_fetch_error' };
659
- }
660
-
661
- if (!lastBlockHeader) {
662
- this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
663
- return { isValid: false, reason: 'last_block_not_found' };
664
- }
665
-
666
- // Get all full blocks for the slot and checkpoint
667
- const blocks = await this.blockSource.getBlocksForSlot(slot);
668
- if (blocks.length === 0) {
669
- this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
670
- return { isValid: false, reason: 'no_blocks_for_slot' };
671
- }
672
-
673
- // Ensure the last block for this slot matches the archive in the checkpoint proposal
674
- if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
675
- this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
676
- return { isValid: false, reason: 'last_block_archive_mismatch' };
677
- }
678
-
679
- this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
680
- ...proposalInfo,
681
- blockNumbers: blocks.map(b => b.number),
682
- });
683
-
684
- // Get checkpoint constants from first block
685
- const firstBlock = blocks[0];
686
- const constants = this.extractCheckpointConstants(firstBlock);
687
- const checkpointNumber = firstBlock.checkpointNumber;
688
-
689
- // Get L1-to-L2 messages for this checkpoint
690
- const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
691
-
692
- // Collect the out hashes of all the checkpoints before this one in the same epoch
693
- const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
694
- const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
695
- .filter(c => c.checkpointNumber < checkpointNumber)
696
- .map(c => c.checkpointOutHash);
697
-
698
- // Fork world state at the block before the first block
699
- const parentBlockNumber = BlockNumber(firstBlock.number - 1);
700
- const fork = await this.worldState.fork(parentBlockNumber);
701
-
702
- try {
703
- // Create checkpoint builder with all existing blocks
704
- const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
705
- checkpointNumber,
706
- constants,
707
- proposal.feeAssetPriceModifier,
708
- l1ToL2Messages,
709
- previousCheckpointOutHashes,
710
- fork,
711
- blocks,
712
- this.log.getBindings(),
713
- );
714
-
715
- // Complete the checkpoint to get computed values
716
- const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
717
-
718
- // Compare checkpoint header with proposal
719
- if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
720
- this.log.warn(`Checkpoint header mismatch`, {
721
- ...proposalInfo,
722
- computed: computedCheckpoint.header.toInspect(),
723
- proposal: proposal.checkpointHeader.toInspect(),
724
- });
725
- return { isValid: false, reason: 'checkpoint_header_mismatch' };
726
- }
727
-
728
- // Compare archive root with proposal
729
- if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
730
- this.log.warn(`Archive root mismatch`, {
731
- ...proposalInfo,
732
- computed: computedCheckpoint.archive.root.toString(),
733
- proposal: proposal.archive.toString(),
734
- });
735
- return { isValid: false, reason: 'archive_mismatch' };
736
- }
737
-
738
- // Check that the accumulated epoch out hash matches the value in the proposal.
739
- // The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
740
- const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
741
- const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
742
- const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
743
- if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
744
- this.log.warn(`Epoch out hash mismatch`, {
745
- proposalEpochOutHash: proposalEpochOutHash.toString(),
746
- computedEpochOutHash: computedEpochOutHash.toString(),
747
- checkpointOutHash: checkpointOutHash.toString(),
748
- previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
749
- ...proposalInfo,
750
- });
751
- return { isValid: false, reason: 'out_hash_mismatch' };
752
- }
753
-
754
- this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
755
- return { isValid: true };
756
- } finally {
757
- await fork.close();
758
- }
759
- }
760
-
761
- /**
762
- * Extract checkpoint global variables from a block.
763
- */
764
- private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
765
- const gv = block.header.globalVariables;
766
- return {
767
- chainId: gv.chainId,
768
- version: gv.version,
769
- slotNumber: gv.slotNumber,
770
- timestamp: gv.timestamp,
771
- coinbase: gv.coinbase,
772
- feeRecipient: gv.feeRecipient,
773
- gasFees: gv.gasFees,
774
- };
775
- }
776
-
777
701
  /**
778
702
  * Uploads blobs for a checkpoint to the filestore (fire and forget).
779
703
  */
780
704
  protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
781
705
  try {
782
- const lastBlockHeader = await this.blockSource.getBlockHeaderByArchive(proposal.archive);
706
+ const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
783
707
  if (!lastBlockHeader) {
784
708
  this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
785
709
  return;
@@ -812,12 +736,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
812
736
  return;
813
737
  }
814
738
 
815
- // Trim the set if it's too big.
816
- if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
817
- // remove oldest proposer. `values` is guaranteed to be in insertion order.
818
- this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value!);
819
- }
820
-
821
739
  this.proposersOfInvalidBlocks.add(proposer.toString());
822
740
 
823
741
  this.emit(WANT_TO_SLASH_EVENT, [
@@ -830,20 +748,115 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
830
748
  ]);
831
749
  }
832
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
+
833
844
  /**
834
845
  * Handle detection of a duplicate proposal (equivocation).
835
846
  * Emits a slash event when a proposer sends multiple proposals for the same position.
836
847
  */
837
848
  private handleDuplicateProposal(info: DuplicateProposalInfo): void {
838
849
  const { slot, proposer, type } = info;
850
+ this.slotsWithProposalEquivocation.add(slot);
839
851
 
840
- 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}`, {
841
853
  proposer: proposer.toString(),
842
854
  slot,
843
855
  type,
856
+ amount: this.config.slashDuplicateProposalPenalty,
857
+ offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL),
844
858
  });
845
859
 
846
- // Emit slash event
847
860
  this.emit(WANT_TO_SLASH_EVENT, [
848
861
  {
849
862
  validator: proposer,
@@ -852,6 +865,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
852
865
  epochOrSlot: BigInt(slot),
853
866
  },
854
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
+ ]);
855
875
  }
856
876
 
857
877
  /**
@@ -861,9 +881,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
861
881
  private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
862
882
  const { slot, attester } = info;
863
883
 
864
- 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}`, {
865
885
  attester: attester.toString(),
866
886
  slot,
887
+ amount: this.config.slashDuplicateAttestationPenalty,
888
+ offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION),
867
889
  });
868
890
 
869
891
  this.emit(WANT_TO_SLASH_EVENT, [
@@ -878,6 +900,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
878
900
 
879
901
  async createBlockProposal(
880
902
  blockHeader: BlockHeader,
903
+ checkpointNumber: CheckpointNumber,
881
904
  indexWithinCheckpoint: IndexWithinCheckpoint,
882
905
  inHash: Fr,
883
906
  archive: Fr,
@@ -904,6 +927,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
904
927
  );
905
928
  const newProposal = await this.validationService.createBlockProposal(
906
929
  blockHeader,
930
+ checkpointNumber,
907
931
  indexWithinCheckpoint,
908
932
  inHash,
909
933
  archive,
@@ -911,7 +935,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
911
935
  proposerAddress,
912
936
  {
913
937
  ...options,
914
- broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
938
+ broadcastInvalidBlockProposal:
939
+ options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal,
915
940
  },
916
941
  );
917
942
  this.lastProposedBlock = newProposal;
@@ -921,8 +946,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
921
946
  async createCheckpointProposal(
922
947
  checkpointHeader: CheckpointHeader,
923
948
  archive: Fr,
949
+ checkpointNumber: CheckpointNumber,
924
950
  feeAssetPriceModifier: bigint,
925
- lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
951
+ lastBlockProposal: BlockProposal | undefined,
926
952
  proposerAddress: EthAddress | undefined,
927
953
  options: CheckpointProposalOptions = {},
928
954
  ): Promise<CheckpointProposal> {
@@ -943,12 +969,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
943
969
  const newProposal = await this.validationService.createCheckpointProposal(
944
970
  checkpointHeader,
945
971
  archive,
972
+ checkpointNumber,
946
973
  feeAssetPriceModifier,
947
- lastBlockInfo,
974
+ lastBlockProposal,
948
975
  proposerAddress,
949
976
  options,
950
977
  );
951
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);
952
986
  return newProposal;
953
987
  }
954
988
 
@@ -960,16 +994,24 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
960
994
  attestationsAndSigners: CommitteeAttestationsAndSigners,
961
995
  proposer: EthAddress,
962
996
  slot: SlotNumber,
963
- blockNumber: BlockNumber | CheckpointNumber,
997
+ checkpointNumber: CheckpointNumber,
964
998
  ): Promise<Signature> {
965
- return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
999
+ return await this.validationService.signAttestationsAndSigners(
1000
+ attestationsAndSigners,
1001
+ proposer,
1002
+ slot,
1003
+ checkpointNumber,
1004
+ );
966
1005
  }
967
1006
 
968
- async collectOwnAttestations(proposal: CheckpointProposal): Promise<CheckpointAttestation[]> {
1007
+ async collectOwnAttestations(
1008
+ proposal: CheckpointProposal,
1009
+ checkpointNumber: CheckpointNumber,
1010
+ ): Promise<CheckpointAttestation[]> {
969
1011
  const slot = proposal.slotNumber;
970
1012
  const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
971
1013
  this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
972
- const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
1014
+ const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
973
1015
 
974
1016
  if (!attestations) {
975
1017
  return [];
@@ -988,6 +1030,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
988
1030
  proposal: CheckpointProposal,
989
1031
  required: number,
990
1032
  deadline: Date,
1033
+ checkpointNumber: CheckpointNumber,
991
1034
  ): Promise<CheckpointAttestation[]> {
992
1035
  // Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
993
1036
  const slot = proposal.slotNumber;
@@ -1000,33 +1043,23 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
1000
1043
  throw new AttestationTimeoutError(0, required, slot);
1001
1044
  }
1002
1045
 
1003
- await this.collectOwnAttestations(proposal);
1046
+ await this.collectOwnAttestations(proposal, checkpointNumber);
1004
1047
 
1005
- const proposalId = proposal.archive.toString();
1048
+ const proposalPayloadHash = proposal.getPayloadHash();
1006
1049
  const myAddresses = this.getValidatorAddresses();
1007
1050
 
1008
1051
  let attestations: CheckpointAttestation[] = [];
1009
1052
  while (true) {
1010
- // Filter out attestations with a mismatching archive. This should NOT happen since we have verified
1011
- // the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
1012
- const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter(
1013
- attestation => {
1014
- if (!attestation.archive.equals(proposal.archive)) {
1015
- this.log.warn(
1016
- `Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`,
1017
- { attestationArchive: attestation.archive.toString(), proposalArchive: proposal.archive.toString() },
1018
- );
1019
- return false;
1020
- }
1021
- return true;
1022
- },
1023
- );
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);
1024
1057
 
1025
1058
  // Log new attestations we collected
1026
1059
  const oldSenders = attestations.map(attestation => attestation.getSender());
1027
1060
  for (const collected of collectedAttestations) {
1028
1061
  const collectedSender = collected.getSender();
1029
- // Skip attestations with invalid signatures
1062
+ // Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
1030
1063
  if (!collectedSender) {
1031
1064
  this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
1032
1065
  continue;