@aztec/validator-client 0.0.1-commit.3469e52 → 0.0.1-commit.35158ae7e

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 (50) hide show
  1. package/README.md +63 -19
  2. package/dest/block_proposal_handler.d.ts +9 -10
  3. package/dest/block_proposal_handler.d.ts.map +1 -1
  4. package/dest/block_proposal_handler.js +135 -82
  5. package/dest/checkpoint_builder.d.ts +27 -15
  6. package/dest/checkpoint_builder.d.ts.map +1 -1
  7. package/dest/checkpoint_builder.js +136 -45
  8. package/dest/config.d.ts +1 -1
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +30 -7
  11. package/dest/duties/validation_service.d.ts +2 -2
  12. package/dest/duties/validation_service.d.ts.map +1 -1
  13. package/dest/duties/validation_service.js +6 -12
  14. package/dest/factory.d.ts +3 -1
  15. package/dest/factory.d.ts.map +1 -1
  16. package/dest/factory.js +3 -2
  17. package/dest/index.d.ts +1 -2
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +0 -1
  20. package/dest/key_store/ha_key_store.d.ts +1 -1
  21. package/dest/key_store/ha_key_store.d.ts.map +1 -1
  22. package/dest/key_store/ha_key_store.js +3 -3
  23. package/dest/metrics.d.ts +12 -3
  24. package/dest/metrics.d.ts.map +1 -1
  25. package/dest/metrics.js +46 -5
  26. package/dest/validator.d.ts +41 -15
  27. package/dest/validator.d.ts.map +1 -1
  28. package/dest/validator.js +230 -69
  29. package/package.json +19 -17
  30. package/src/block_proposal_handler.ts +165 -109
  31. package/src/checkpoint_builder.ts +185 -52
  32. package/src/config.ts +30 -7
  33. package/src/duties/validation_service.ts +12 -11
  34. package/src/factory.ts +4 -0
  35. package/src/index.ts +0 -1
  36. package/src/key_store/ha_key_store.ts +3 -3
  37. package/src/metrics.ts +63 -6
  38. package/src/validator.ts +294 -86
  39. package/dest/tx_validator/index.d.ts +0 -3
  40. package/dest/tx_validator/index.d.ts.map +0 -1
  41. package/dest/tx_validator/index.js +0 -2
  42. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  43. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  44. package/dest/tx_validator/nullifier_cache.js +0 -24
  45. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  46. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  47. package/dest/tx_validator/tx_validator_factory.js +0 -54
  48. package/src/tx_validator/index.ts +0 -2
  49. package/src/tx_validator/nullifier_cache.ts +0 -30
  50. package/src/tx_validator/tx_validator_factory.ts +0 -135
package/dest/validator.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { getBlobsPerL1Block } from '@aztec/blob-lib';
2
- import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
3
+ import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
4
  import { TimeoutError } from '@aztec/foundation/error';
4
5
  import { createLogger } from '@aztec/foundation/log';
5
6
  import { retryUntil } from '@aztec/foundation/retry';
@@ -8,10 +9,12 @@ import { sleep } from '@aztec/foundation/sleep';
8
9
  import { DateProvider } from '@aztec/foundation/timer';
9
10
  import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
10
11
  import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
11
- import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
12
+ import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
13
+ import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
14
+ import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
12
15
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
13
16
  import { getTelemetryClient } from '@aztec/telemetry-client';
14
- import { createHASigner } from '@aztec/validator-ha-signer/factory';
17
+ import { createHASigner, createLocalSignerWithProtection, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
15
18
  import { DutyType } from '@aztec/validator-ha-signer/types';
16
19
  import { EventEmitter } from 'events';
17
20
  import { BlockProposalHandler } from './block_proposal_handler.js';
@@ -40,6 +43,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
40
43
  l1ToL2MessageSource;
41
44
  config;
42
45
  blobClient;
46
+ slashingProtectionSigner;
43
47
  dateProvider;
44
48
  tracer;
45
49
  validationService;
@@ -47,17 +51,15 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
47
51
  log;
48
52
  // Whether it has already registered handlers on the p2p client
49
53
  hasRegisteredHandlers;
50
- // Used to check if we are sending the same proposal twice
51
- previousProposal;
54
+ /** Tracks the last block proposal we created, to detect duplicate proposal attempts. */ lastProposedBlock;
55
+ /** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
52
56
  lastEpochForCommitteeUpdateLoop;
53
57
  epochCacheUpdateLoop;
58
+ /** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
54
59
  proposersOfInvalidBlocks;
55
- // TODO(palla/mbps): Remove this once checkpoint validation is stable and we can validate all blocks properly.
56
- // Tracks slots for which we have successfully validated a block proposal, so we can attest to checkpoint proposals for those slots.
57
- // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
58
- validatedBlockSlots;
59
- constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
60
- super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.blockProposalHandler = blockProposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.proposersOfInvalidBlocks = new Set(), this.validatedBlockSlots = new Set();
60
+ /** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
61
+ constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
62
+ super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.blockProposalHandler = blockProposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.slashingProtectionSigner = slashingProtectionSigner, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.lastAttestedEpochByAttester = new Map(), this.proposersOfInvalidBlocks = new Set();
61
63
  // Create child logger with fisherman prefix if in fisherman mode
62
64
  this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
63
65
  this.tracer = telemetry.getTracer('Validator');
@@ -96,6 +98,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
96
98
  this.log.trace(`No committee found for slot`);
97
99
  return;
98
100
  }
101
+ this.metrics.setCurrentEpoch(epoch);
99
102
  if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
100
103
  const me = this.getValidatorAddresses();
101
104
  const committeeSet = new Set(committee.map((v)=>v.toString()));
@@ -111,23 +114,42 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
111
114
  this.log.error(`Error updating epoch committee`, err);
112
115
  }
113
116
  }
114
- static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
117
+ static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
115
118
  const metrics = new ValidatorMetrics(telemetry);
116
119
  const blockProposalValidator = new BlockProposalValidator(epochCache, {
117
- txsPermitted: !config.disableTransactions
120
+ txsPermitted: !config.disableTransactions,
121
+ maxTxsPerBlock: config.validateMaxTxsPerBlock
118
122
  });
119
123
  const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, metrics, dateProvider, telemetry);
120
- let validatorKeyStore = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
121
- if (config.haSigningEnabled) {
124
+ const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
125
+ let slashingProtectionSigner;
126
+ if (slashingProtectionDb) {
127
+ // Shared database mode: use a pre-existing database (e.g. for testing HA setups).
128
+ ({ signer: slashingProtectionSigner } = createSignerFromSharedDb(slashingProtectionDb, config, {
129
+ telemetryClient: telemetry,
130
+ dateProvider
131
+ }));
132
+ } else if (config.haSigningEnabled) {
133
+ // Multi-node HA mode: use PostgreSQL-backed distributed locking.
122
134
  // If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
123
135
  const haConfig = {
124
136
  ...config,
125
137
  maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
126
138
  };
127
- const { signer } = await createHASigner(haConfig);
128
- validatorKeyStore = new HAKeyStore(validatorKeyStore, signer);
139
+ ({ signer: slashingProtectionSigner } = await createHASigner(haConfig, {
140
+ telemetryClient: telemetry,
141
+ dateProvider
142
+ }));
143
+ } else {
144
+ // Single-node mode: use LMDB-backed local signing protection.
145
+ // This prevents double-signing if the node crashes and restarts mid-proposal.
146
+ ({ signer: slashingProtectionSigner } = await createLocalSignerWithProtection(config, {
147
+ telemetryClient: telemetry,
148
+ dateProvider
149
+ }));
129
150
  }
130
- const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider, telemetry);
151
+ const validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, slashingProtectionSigner);
152
+ const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, slashingProtectionSigner, dateProvider, telemetry);
131
153
  return validator;
132
154
  }
133
155
  getValidatorAddresses() {
@@ -154,6 +176,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
154
176
  ...config
155
177
  };
156
178
  }
179
+ reloadKeystore(newManager) {
180
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
181
+ this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
182
+ this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
183
+ }
157
184
  async start() {
158
185
  if (this.epochCacheUpdateLoop.isRunning()) {
159
186
  this.log.warn(`Validator client already started`);
@@ -186,6 +213,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
186
213
  // and processed separately via the block handler above.
187
214
  const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
188
215
  this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
216
+ // Duplicate proposal handler - triggers slashing for equivocation
217
+ this.p2pClient.registerDuplicateProposalCallback((info)=>{
218
+ this.handleDuplicateProposal(info);
219
+ });
220
+ // Duplicate attestation handler - triggers slashing for attestation equivocation
221
+ this.p2pClient.registerDuplicateAttestationCallback((info)=>{
222
+ this.handleDuplicateAttestation(info);
223
+ });
189
224
  const myAddresses = this.getValidatorAddresses();
190
225
  this.p2pClient.registerThisValidatorAddresses(myAddresses);
191
226
  await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
@@ -206,6 +241,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
206
241
  this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
207
242
  return false;
208
243
  }
244
+ // Log self-proposals from HA peers (same validator key on different nodes)
245
+ if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
246
+ this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
247
+ proposer: proposer.toString(),
248
+ slotNumber
249
+ });
250
+ }
209
251
  // Check if we're in the committee (for metrics purposes)
210
252
  const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
211
253
  const partOfCommittee = inCommittee.length > 0;
@@ -224,8 +266,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
224
266
  const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
225
267
  const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
226
268
  if (!validationResult.isValid) {
227
- this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
228
269
  const reason = validationResult.reason || 'unknown';
270
+ this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
229
271
  // Classify failure reason: bad proposal vs node issue
230
272
  const badProposalReasons = [
231
273
  'invalid_proposal',
@@ -257,9 +299,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
257
299
  this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
258
300
  return false;
259
301
  }
260
- // TODO(palla/mbps): Remove this once checkpoint validation is stable.
261
- // Track that we successfully validated a block for this slot, so we can attest to checkpoint proposals for it.
262
- this.validatedBlockSlots.add(slotNumber);
263
302
  return true;
264
303
  }
265
304
  /**
@@ -268,42 +307,46 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
268
307
  * the lastBlock is extracted and processed separately via the block handler.
269
308
  * @returns Checkpoint attestations if valid, undefined otherwise
270
309
  */ async attestToCheckpointProposal(proposal, _proposalSender) {
271
- const slotNumber = proposal.slotNumber;
310
+ const proposalSlotNumber = proposal.slotNumber;
272
311
  const proposer = proposal.getSender();
273
312
  // If escape hatch is open for this slot's epoch, do not attest.
274
- if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
275
- this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
313
+ if (await this.epochCache.isEscapeHatchOpenAtSlot(proposalSlotNumber)) {
314
+ this.log.warn(`Escape hatch open for slot ${proposalSlotNumber}, skipping checkpoint attestation handling`);
276
315
  return undefined;
277
316
  }
278
317
  // Reject proposals with invalid signatures
279
318
  if (!proposer) {
280
- this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
319
+ this.log.warn(`Received checkpoint proposal with invalid signature for proposal slot ${proposalSlotNumber}`);
281
320
  return undefined;
282
321
  }
283
- // Check that I have any address in current committee before attesting
284
- const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
322
+ // Ignore proposals from ourselves (may happen in HA setups)
323
+ if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
324
+ this.log.debug(`Ignoring block proposal from self for slot ${proposalSlotNumber}`, {
325
+ proposer: proposer.toString(),
326
+ proposalSlotNumber
327
+ });
328
+ return undefined;
329
+ }
330
+ // Validate fee asset price modifier is within allowed range
331
+ if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
332
+ this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposalSlotNumber}`);
333
+ return undefined;
334
+ }
335
+ // Check that I have any address in the committee where this checkpoint will land before attesting
336
+ const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
285
337
  const partOfCommittee = inCommittee.length > 0;
286
338
  const proposalInfo = {
287
- slotNumber,
339
+ proposalSlotNumber,
288
340
  archive: proposal.archive.toString(),
289
- proposer: proposer.toString(),
290
- txCount: proposal.txHashes.length
341
+ proposer: proposer.toString()
291
342
  };
292
- this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
343
+ this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
293
344
  ...proposalInfo,
294
- txHashes: proposal.txHashes.map((t)=>t.toString()),
295
345
  fishermanMode: this.config.fishermanMode || false
296
346
  });
297
- // TODO(palla/mbps): Remove this once checkpoint validation is stable.
298
- // Check that we have successfully validated a block for this slot before attesting to the checkpoint.
299
- if (!this.validatedBlockSlots.has(slotNumber)) {
300
- this.log.warn(`No validated block found for slot ${slotNumber}, refusing to attest to checkpoint`, proposalInfo);
301
- return undefined;
302
- }
303
347
  // Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
304
- // TODO(palla/mbps): Change default to false once checkpoint validation is stable.
305
- if (this.config.skipCheckpointProposalValidation !== false) {
306
- this.log.verbose(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
348
+ if (this.config.skipCheckpointProposalValidation) {
349
+ this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
307
350
  } else {
308
351
  const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
309
352
  if (!validationResult.isValid) {
@@ -322,12 +365,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
322
365
  return undefined;
323
366
  }
324
367
  // Provided all of the above checks pass, we can attest to the proposal
325
- this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
368
+ this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${proposalSlotNumber}`, {
326
369
  ...proposalInfo,
327
370
  inCommittee: partOfCommittee,
328
371
  fishermanMode: this.config.fishermanMode || false
329
372
  });
330
373
  this.metrics.incSuccessfulAttestations(inCommittee.length);
374
+ // Track epoch participation per attester: count each (attester, epoch) pair at most once
375
+ const proposalEpoch = getEpochAtSlot(proposalSlotNumber, this.epochCache.getL1Constants());
376
+ for (const attester of inCommittee){
377
+ const key = attester.toString();
378
+ const lastEpoch = this.lastAttestedEpochByAttester.get(key);
379
+ if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
380
+ this.lastAttestedEpochByAttester.set(key, proposalEpoch);
381
+ this.metrics.incAttestedEpochCount(attester);
382
+ }
383
+ }
331
384
  // Determine which validators should attest
332
385
  let attestors;
333
386
  if (partOfCommittee) {
@@ -344,17 +397,38 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
344
397
  }
345
398
  if (this.config.fishermanMode) {
346
399
  // bail out early and don't save attestations to the pool in fisherman mode
347
- this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
400
+ this.log.info(`Creating checkpoint attestations for slot ${proposalSlotNumber}`, {
348
401
  ...proposalInfo,
349
402
  attestors: attestors.map((a)=>a.toString())
350
403
  });
351
404
  return undefined;
352
405
  }
353
- return this.createCheckpointAttestationsFromProposal(proposal, attestors);
406
+ return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
407
+ }
408
+ /**
409
+ * Checks if we should attest to a slot based on equivocation prevention rules.
410
+ * @returns true if we should attest, false if we should skip
411
+ */ shouldAttestToSlot(slotNumber) {
412
+ // If attestToEquivocatedProposals is true, always allow
413
+ if (this.config.attestToEquivocatedProposals) {
414
+ return true;
415
+ }
416
+ // Check if incoming slot is strictly greater than last attested
417
+ if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
418
+ this.log.warn(`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`);
419
+ return false;
420
+ }
421
+ return true;
354
422
  }
355
423
  async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
424
+ // Equivocation check: must happen right before signing to minimize the race window
425
+ if (!this.shouldAttestToSlot(proposal.slotNumber)) {
426
+ return undefined;
427
+ }
356
428
  const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
357
- await this.p2pClient.addCheckpointAttestations(attestations);
429
+ // Track the proposal we attested to (to prevent equivocation)
430
+ this.lastAttestedProposal = proposal;
431
+ await this.p2pClient.addOwnCheckpointAttestations(attestations);
358
432
  return attestations;
359
433
  }
360
434
  /**
@@ -362,7 +436,10 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
362
436
  * @returns Validation result with isValid flag and reason if invalid.
363
437
  */ async validateCheckpointProposal(proposal, proposalInfo) {
364
438
  const slot = proposal.slotNumber;
365
- const timeoutSeconds = 10;
439
+ // Timeout block syncing at the start of the next slot
440
+ const config = this.checkpointsBuilder.getConfig();
441
+ const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
442
+ const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
366
443
  // Wait for last block to sync by archive
367
444
  let lastBlockHeader;
368
445
  try {
@@ -400,6 +477,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
400
477
  reason: 'no_blocks_for_slot'
401
478
  };
402
479
  }
480
+ // Ensure the last block for this slot matches the archive in the checkpoint proposal
481
+ if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
482
+ this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
483
+ return {
484
+ isValid: false,
485
+ reason: 'last_block_archive_mismatch'
486
+ };
487
+ }
403
488
  this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
404
489
  ...proposalInfo,
405
490
  blockNumbers: blocks.map((b)=>b.number)
@@ -410,18 +495,15 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
410
495
  const checkpointNumber = firstBlock.checkpointNumber;
411
496
  // Get L1-to-L2 messages for this checkpoint
412
497
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
413
- // Compute the previous checkpoint out hashes for the epoch.
414
- // TODO: There can be a more efficient way to get the previous checkpoint out hashes without having to fetch the
415
- // actual checkpoints and the blocks/txs in them.
498
+ // Collect the out hashes of all the checkpoints before this one in the same epoch
416
499
  const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
417
- const previousCheckpoints = (await this.blockSource.getCheckpointsForEpoch(epoch)).filter((b)=>b.number < checkpointNumber).sort((a, b)=>a.number - b.number);
418
- const previousCheckpointOutHashes = previousCheckpoints.map((c)=>c.getCheckpointOutHash());
500
+ const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
419
501
  // Fork world state at the block before the first block
420
502
  const parentBlockNumber = BlockNumber(firstBlock.number - 1);
421
503
  const fork = await this.worldState.fork(parentBlockNumber);
422
504
  try {
423
505
  // Create checkpoint builder with all existing blocks
424
- const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks);
506
+ const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
425
507
  // Complete the checkpoint to get computed values
426
508
  const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
427
509
  // Compare checkpoint header with proposal
@@ -448,13 +530,20 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
448
530
  reason: 'archive_mismatch'
449
531
  };
450
532
  }
451
- // Check that the accumulated out hash matches the value in the proposal.
452
- const computedOutHash = computedCheckpoint.getCheckpointOutHash();
453
- const proposalOutHash = proposal.checkpointHeader.epochOutHash;
454
- if (!computedOutHash.equals(proposalOutHash)) {
533
+ // Check that the accumulated epoch out hash matches the value in the proposal.
534
+ // The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
535
+ const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
536
+ const computedEpochOutHash = accumulateCheckpointOutHashes([
537
+ ...previousCheckpointOutHashes,
538
+ checkpointOutHash
539
+ ]);
540
+ const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
541
+ if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
455
542
  this.log.warn(`Epoch out hash mismatch`, {
456
- proposalOutHash: proposalOutHash.toString(),
457
- computedOutHash: computedOutHash.toString(),
543
+ proposalEpochOutHash: proposalEpochOutHash.toString(),
544
+ computedEpochOutHash: computedEpochOutHash.toString(),
545
+ checkpointOutHash: checkpointOutHash.toString(),
546
+ previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
458
547
  ...proposalInfo
459
548
  });
460
549
  return {
@@ -462,6 +551,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
462
551
  reason: 'out_hash_mismatch'
463
552
  };
464
553
  }
554
+ // Final round of validations on the checkpoint, just in case.
555
+ try {
556
+ validateCheckpoint(computedCheckpoint, {
557
+ rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
558
+ maxDABlockGas: this.config.validateMaxDABlockGas,
559
+ maxL2BlockGas: this.config.validateMaxL2BlockGas,
560
+ maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
561
+ maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint
562
+ });
563
+ } catch (err) {
564
+ this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
565
+ return {
566
+ isValid: false,
567
+ reason: 'checkpoint_validation_failed'
568
+ };
569
+ }
465
570
  this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
466
571
  return {
467
572
  isValid: true
@@ -478,6 +583,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
478
583
  chainId: gv.chainId,
479
584
  version: gv.version,
480
585
  slotNumber: gv.slotNumber,
586
+ timestamp: gv.timestamp,
481
587
  coinbase: gv.coinbase,
482
588
  feeRecipient: gv.feeRecipient,
483
589
  gasFees: gv.gasFees
@@ -498,7 +604,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
498
604
  return;
499
605
  }
500
606
  const blobFields = blocks.flatMap((b)=>b.toBlobFields());
501
- const blobs = getBlobsPerL1Block(blobFields);
607
+ const blobs = await getBlobsPerL1Block(blobFields);
502
608
  await this.blobClient.sendBlobsToFilestore(blobs);
503
609
  this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
504
610
  ...proposalInfo,
@@ -530,23 +636,75 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
530
636
  }
531
637
  ]);
532
638
  }
533
- async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options) {
534
- // TODO(palla/mbps): Prevent double proposals properly
535
- // if (this.previousProposal?.slotNumber === blockHeader.globalVariables.slotNumber) {
536
- // this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
537
- // return Promise.resolve(undefined);
538
- // }
639
+ /**
640
+ * Handle detection of a duplicate proposal (equivocation).
641
+ * Emits a slash event when a proposer sends multiple proposals for the same position.
642
+ */ handleDuplicateProposal(info) {
643
+ const { slot, proposer, type } = info;
644
+ this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
645
+ proposer: proposer.toString(),
646
+ slot,
647
+ type
648
+ });
649
+ // Emit slash event
650
+ this.emit(WANT_TO_SLASH_EVENT, [
651
+ {
652
+ validator: proposer,
653
+ amount: this.config.slashDuplicateProposalPenalty,
654
+ offenseType: OffenseType.DUPLICATE_PROPOSAL,
655
+ epochOrSlot: BigInt(slot)
656
+ }
657
+ ]);
658
+ }
659
+ /**
660
+ * Handle detection of a duplicate attestation (equivocation).
661
+ * Emits a slash event when an attester signs attestations for different proposals at the same slot.
662
+ */ handleDuplicateAttestation(info) {
663
+ const { slot, attester } = info;
664
+ this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
665
+ attester: attester.toString(),
666
+ slot
667
+ });
668
+ this.emit(WANT_TO_SLASH_EVENT, [
669
+ {
670
+ validator: attester,
671
+ amount: this.config.slashDuplicateAttestationPenalty,
672
+ offenseType: OffenseType.DUPLICATE_ATTESTATION,
673
+ epochOrSlot: BigInt(slot)
674
+ }
675
+ ]);
676
+ }
677
+ async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
678
+ // Validate that we're not creating a proposal for an older or equal position
679
+ if (this.lastProposedBlock) {
680
+ const lastSlot = this.lastProposedBlock.slotNumber;
681
+ const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
682
+ const newSlot = blockHeader.globalVariables.slotNumber;
683
+ if (newSlot < lastSlot || newSlot === lastSlot && indexWithinCheckpoint <= lastIndex) {
684
+ throw new Error(`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` + `already proposed block for slot ${lastSlot} index ${lastIndex}`);
685
+ }
686
+ }
539
687
  this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
540
688
  const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
541
689
  ...options,
542
690
  broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
543
691
  });
544
- this.previousProposal = newProposal;
692
+ this.lastProposedBlock = newProposal;
545
693
  return newProposal;
546
694
  }
547
- async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options) {
695
+ async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options = {}) {
696
+ // Validate that we're not creating a proposal for an older or equal slot
697
+ if (this.lastProposedCheckpoint) {
698
+ const lastSlot = this.lastProposedCheckpoint.slotNumber;
699
+ const newSlot = checkpointHeader.slotNumber;
700
+ if (newSlot <= lastSlot) {
701
+ throw new Error(`Cannot create checkpoint proposal for slot ${newSlot}: ` + `already proposed checkpoint for slot ${lastSlot}`);
702
+ }
703
+ }
548
704
  this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
549
- return await this.validationService.createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options);
705
+ const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options);
706
+ this.lastProposedCheckpoint = newProposal;
707
+ return newProposal;
550
708
  }
551
709
  async broadcastBlockProposal(proposal) {
552
710
  await this.p2pClient.broadcastProposal(proposal);
@@ -561,6 +719,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
561
719
  inCommittee
562
720
  });
563
721
  const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
722
+ if (!attestations) {
723
+ return [];
724
+ }
564
725
  // We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
565
726
  // other nodes can see that our validators did attest to this block proposal, and do not slash us
566
727
  // due to inactivity for missed attestations.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/validator-client",
3
- "version": "0.0.1-commit.3469e52",
3
+ "version": "0.0.1-commit.35158ae7e",
4
4
  "main": "dest/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -64,28 +64,30 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/blob-client": "0.0.1-commit.3469e52",
68
- "@aztec/blob-lib": "0.0.1-commit.3469e52",
69
- "@aztec/constants": "0.0.1-commit.3469e52",
70
- "@aztec/epoch-cache": "0.0.1-commit.3469e52",
71
- "@aztec/ethereum": "0.0.1-commit.3469e52",
72
- "@aztec/foundation": "0.0.1-commit.3469e52",
73
- "@aztec/node-keystore": "0.0.1-commit.3469e52",
74
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.3469e52",
75
- "@aztec/p2p": "0.0.1-commit.3469e52",
76
- "@aztec/protocol-contracts": "0.0.1-commit.3469e52",
77
- "@aztec/prover-client": "0.0.1-commit.3469e52",
78
- "@aztec/simulator": "0.0.1-commit.3469e52",
79
- "@aztec/slasher": "0.0.1-commit.3469e52",
80
- "@aztec/stdlib": "0.0.1-commit.3469e52",
81
- "@aztec/telemetry-client": "0.0.1-commit.3469e52",
82
- "@aztec/validator-ha-signer": "0.0.1-commit.3469e52",
67
+ "@aztec/blob-client": "0.0.1-commit.35158ae7e",
68
+ "@aztec/blob-lib": "0.0.1-commit.35158ae7e",
69
+ "@aztec/constants": "0.0.1-commit.35158ae7e",
70
+ "@aztec/epoch-cache": "0.0.1-commit.35158ae7e",
71
+ "@aztec/ethereum": "0.0.1-commit.35158ae7e",
72
+ "@aztec/foundation": "0.0.1-commit.35158ae7e",
73
+ "@aztec/node-keystore": "0.0.1-commit.35158ae7e",
74
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.35158ae7e",
75
+ "@aztec/p2p": "0.0.1-commit.35158ae7e",
76
+ "@aztec/protocol-contracts": "0.0.1-commit.35158ae7e",
77
+ "@aztec/prover-client": "0.0.1-commit.35158ae7e",
78
+ "@aztec/simulator": "0.0.1-commit.35158ae7e",
79
+ "@aztec/slasher": "0.0.1-commit.35158ae7e",
80
+ "@aztec/stdlib": "0.0.1-commit.35158ae7e",
81
+ "@aztec/telemetry-client": "0.0.1-commit.35158ae7e",
82
+ "@aztec/validator-ha-signer": "0.0.1-commit.35158ae7e",
83
83
  "koa": "^2.16.1",
84
84
  "koa-router": "^13.1.1",
85
85
  "tslib": "^2.4.0",
86
86
  "viem": "npm:@aztec/viem@2.38.2"
87
87
  },
88
88
  "devDependencies": {
89
+ "@aztec/archiver": "0.0.1-commit.35158ae7e",
90
+ "@aztec/world-state": "0.0.1-commit.35158ae7e",
89
91
  "@electric-sql/pglite": "^0.3.14",
90
92
  "@jest/globals": "^30.0.0",
91
93
  "@types/jest": "^30.0.0",