@aztec/validator-client 0.0.1-commit.6d3c34e → 0.0.1-commit.7ac86ea28

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 (57) hide show
  1. package/README.md +53 -24
  2. package/dest/block_proposal_handler.d.ts +9 -9
  3. package/dest/block_proposal_handler.d.ts.map +1 -1
  4. package/dest/block_proposal_handler.js +35 -54
  5. package/dest/checkpoint_builder.d.ts +21 -25
  6. package/dest/checkpoint_builder.d.ts.map +1 -1
  7. package/dest/checkpoint_builder.js +54 -34
  8. package/dest/config.d.ts +1 -1
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +12 -14
  11. package/dest/duties/validation_service.d.ts +20 -7
  12. package/dest/duties/validation_service.d.ts.map +1 -1
  13. package/dest/duties/validation_service.js +75 -22
  14. package/dest/factory.d.ts +2 -2
  15. package/dest/factory.d.ts.map +1 -1
  16. package/dest/factory.js +1 -1
  17. package/dest/key_store/ha_key_store.d.ts +99 -0
  18. package/dest/key_store/ha_key_store.d.ts.map +1 -0
  19. package/dest/key_store/ha_key_store.js +208 -0
  20. package/dest/key_store/index.d.ts +2 -1
  21. package/dest/key_store/index.d.ts.map +1 -1
  22. package/dest/key_store/index.js +1 -0
  23. package/dest/key_store/interface.d.ts +36 -6
  24. package/dest/key_store/interface.d.ts.map +1 -1
  25. package/dest/key_store/local_key_store.d.ts +10 -5
  26. package/dest/key_store/local_key_store.d.ts.map +1 -1
  27. package/dest/key_store/local_key_store.js +8 -4
  28. package/dest/key_store/node_keystore_adapter.d.ts +18 -5
  29. package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
  30. package/dest/key_store/node_keystore_adapter.js +18 -4
  31. package/dest/key_store/web3signer_key_store.d.ts +10 -5
  32. package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
  33. package/dest/key_store/web3signer_key_store.js +8 -4
  34. package/dest/metrics.d.ts +4 -3
  35. package/dest/metrics.d.ts.map +1 -1
  36. package/dest/metrics.js +34 -5
  37. package/dest/tx_validator/tx_validator_factory.d.ts +4 -3
  38. package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
  39. package/dest/tx_validator/tx_validator_factory.js +17 -16
  40. package/dest/validator.d.ts +43 -18
  41. package/dest/validator.d.ts.map +1 -1
  42. package/dest/validator.js +230 -94
  43. package/package.json +21 -17
  44. package/src/block_proposal_handler.ts +48 -69
  45. package/src/checkpoint_builder.ts +92 -38
  46. package/src/config.ts +11 -13
  47. package/src/duties/validation_service.ts +100 -25
  48. package/src/factory.ts +1 -0
  49. package/src/key_store/ha_key_store.ts +269 -0
  50. package/src/key_store/index.ts +1 -0
  51. package/src/key_store/interface.ts +44 -5
  52. package/src/key_store/local_key_store.ts +13 -4
  53. package/src/key_store/node_keystore_adapter.ts +27 -4
  54. package/src/key_store/web3signer_key_store.ts +17 -4
  55. package/src/metrics.ts +45 -6
  56. package/src/tx_validator/tx_validator_factory.ts +52 -31
  57. package/src/validator.ts +303 -114
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,11 +9,16 @@ 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';
12
+ import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
13
+ import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
11
14
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
12
15
  import { getTelemetryClient } from '@aztec/telemetry-client';
16
+ import { createHASigner } from '@aztec/validator-ha-signer/factory';
17
+ import { DutyType } from '@aztec/validator-ha-signer/types';
13
18
  import { EventEmitter } from 'events';
14
19
  import { BlockProposalHandler } from './block_proposal_handler.js';
15
20
  import { ValidationService } from './duties/validation_service.js';
21
+ import { HAKeyStore } from './key_store/ha_key_store.js';
16
22
  import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
17
23
  import { ValidatorMetrics } from './metrics.js';
18
24
  // We maintain a set of proposers who have proposed invalid blocks.
@@ -36,6 +42,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
36
42
  l1ToL2MessageSource;
37
43
  config;
38
44
  blobClient;
45
+ haSigner;
39
46
  dateProvider;
40
47
  tracer;
41
48
  validationService;
@@ -43,17 +50,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
43
50
  log;
44
51
  // Whether it has already registered handlers on the p2p client
45
52
  hasRegisteredHandlers;
46
- // Used to check if we are sending the same proposal twice
47
- previousProposal;
53
+ /** Tracks the last block proposal we created, to detect duplicate proposal attempts. */ lastProposedBlock;
54
+ /** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
48
55
  lastEpochForCommitteeUpdateLoop;
49
56
  epochCacheUpdateLoop;
50
57
  proposersOfInvalidBlocks;
51
- // TODO(palla/mbps): Remove this once checkpoint validation is stable and we can validate all blocks properly.
52
- // Tracks slots for which we have successfully validated a block proposal, so we can attest to checkpoint proposals for those slots.
53
- // eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
54
- validatedBlockSlots;
55
- constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
56
- 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();
58
+ /** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
59
+ constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, haSigner, 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.haSigner = haSigner, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.proposersOfInvalidBlocks = new Set();
57
61
  // Create child logger with fisherman prefix if in fisherman mode
58
62
  this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
59
63
  this.tracer = telemetry.getTracer('Validator');
@@ -107,13 +111,26 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
107
111
  this.log.error(`Error updating epoch committee`, err);
108
112
  }
109
113
  }
110
- static new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
114
+ static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
111
115
  const metrics = new ValidatorMetrics(telemetry);
112
116
  const blockProposalValidator = new BlockProposalValidator(epochCache, {
113
117
  txsPermitted: !config.disableTransactions
114
118
  });
115
- const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, config, metrics, dateProvider, telemetry);
116
- const validator = new ValidatorClient(NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager), epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider, telemetry);
119
+ const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, metrics, dateProvider, telemetry);
120
+ const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
121
+ let validatorKeyStore = nodeKeystoreAdapter;
122
+ let haSigner;
123
+ if (config.haSigningEnabled) {
124
+ // If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
125
+ const haConfig = {
126
+ ...config,
127
+ maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
128
+ };
129
+ const { signer } = await createHASigner(haConfig);
130
+ haSigner = signer;
131
+ validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
132
+ }
133
+ const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, haSigner, dateProvider, telemetry);
117
134
  return validator;
118
135
  }
119
136
  getValidatorAddresses() {
@@ -122,8 +139,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
122
139
  getBlockProposalHandler() {
123
140
  return this.blockProposalHandler;
124
141
  }
125
- signWithAddress(addr, msg) {
126
- return this.keyStore.signTypedDataWithAddress(addr, msg);
142
+ signWithAddress(addr, msg, context) {
143
+ return this.keyStore.signTypedDataWithAddress(addr, msg, context);
127
144
  }
128
145
  getCoinbaseForAttestor(attestor) {
129
146
  return this.keyStore.getCoinbaseAddress(attestor);
@@ -140,11 +157,26 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
140
157
  ...config
141
158
  };
142
159
  }
160
+ reloadKeystore(newManager) {
161
+ if (this.config.haSigningEnabled && !this.haSigner) {
162
+ this.log.warn('HA signing is enabled in config but was not initialized at startup. ' + 'Restart the node to enable HA signing.');
163
+ } else if (!this.config.haSigningEnabled && this.haSigner) {
164
+ this.log.warn('HA signing was disabled via config update but the HA signer is still active. ' + 'Restart the node to fully disable HA signing.');
165
+ }
166
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
167
+ if (this.haSigner) {
168
+ this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
169
+ } else {
170
+ this.keyStore = newAdapter;
171
+ }
172
+ this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
173
+ }
143
174
  async start() {
144
175
  if (this.epochCacheUpdateLoop.isRunning()) {
145
176
  this.log.warn(`Validator client already started`);
146
177
  return;
147
178
  }
179
+ await this.keyStore.start();
148
180
  await this.registerHandlers();
149
181
  const myAddresses = this.getValidatorAddresses();
150
182
  const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
@@ -157,6 +189,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
157
189
  }
158
190
  async stop() {
159
191
  await this.epochCacheUpdateLoop.stop();
192
+ await this.keyStore.stop();
160
193
  }
161
194
  /** Register handlers on the p2p client */ async registerHandlers() {
162
195
  if (!this.hasRegisteredHandlers) {
@@ -170,6 +203,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
170
203
  // and processed separately via the block handler above.
171
204
  const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
172
205
  this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
206
+ // Duplicate proposal handler - triggers slashing for equivocation
207
+ this.p2pClient.registerDuplicateProposalCallback((info)=>{
208
+ this.handleDuplicateProposal(info);
209
+ });
210
+ // Duplicate attestation handler - triggers slashing for attestation equivocation
211
+ this.p2pClient.registerDuplicateAttestationCallback((info)=>{
212
+ this.handleDuplicateAttestation(info);
213
+ });
173
214
  const myAddresses = this.getValidatorAddresses();
174
215
  this.p2pClient.registerThisValidatorAddresses(myAddresses);
175
216
  await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
@@ -181,12 +222,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
181
222
  * @returns true if the proposal is valid, false otherwise
182
223
  */ async validateBlockProposal(proposal, proposalSender) {
183
224
  const slotNumber = proposal.slotNumber;
225
+ // Note: During escape hatch, we still want to "validate" proposals for observability,
226
+ // but we intentionally reject them and disable slashing invalid block and attestation flow.
227
+ const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
184
228
  const proposer = proposal.getSender();
185
229
  // Reject proposals with invalid signatures
186
230
  if (!proposer) {
187
231
  this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
188
232
  return false;
189
233
  }
234
+ // Ignore proposals from ourselves (may happen in HA setups)
235
+ if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
236
+ this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
237
+ proposer: proposer.toString(),
238
+ slotNumber
239
+ });
240
+ return false;
241
+ }
190
242
  // Check if we're in the committee (for metrics purposes)
191
243
  const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
192
244
  const partOfCommittee = inCommittee.length > 0;
@@ -203,7 +255,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
203
255
  // In fisherman mode, we always reexecute to validate proposals.
204
256
  const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
205
257
  const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
206
- const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
258
+ const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
207
259
  if (!validationResult.isValid) {
208
260
  this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
209
261
  const reason = validationResult.reason || 'unknown';
@@ -222,7 +274,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
222
274
  this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
223
275
  }
224
276
  // Slash invalid block proposals (can happen even when not in committee)
225
- if (validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
277
+ if (!escapeHatchOpen && validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
226
278
  this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
227
279
  this.slashInvalidBlock(proposal);
228
280
  }
@@ -231,11 +283,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
231
283
  this.log.info(`Validated block proposal for slot ${slotNumber}`, {
232
284
  ...proposalInfo,
233
285
  inCommittee: partOfCommittee,
234
- fishermanMode: this.config.fishermanMode || false
286
+ fishermanMode: this.config.fishermanMode || false,
287
+ escapeHatchOpen
235
288
  });
236
- // TODO(palla/mbps): Remove this once checkpoint validation is stable.
237
- // Track that we successfully validated a block for this slot, so we can attest to checkpoint proposals for it.
238
- this.validatedBlockSlots.add(slotNumber);
289
+ if (escapeHatchOpen) {
290
+ this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
291
+ return false;
292
+ }
239
293
  return true;
240
294
  }
241
295
  /**
@@ -246,11 +300,29 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
246
300
  */ async attestToCheckpointProposal(proposal, _proposalSender) {
247
301
  const slotNumber = proposal.slotNumber;
248
302
  const proposer = proposal.getSender();
303
+ // If escape hatch is open for this slot's epoch, do not attest.
304
+ if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
305
+ this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
306
+ return undefined;
307
+ }
249
308
  // Reject proposals with invalid signatures
250
309
  if (!proposer) {
251
310
  this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
252
311
  return undefined;
253
312
  }
313
+ // Ignore proposals from ourselves (may happen in HA setups)
314
+ if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
315
+ this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
316
+ proposer: proposer.toString(),
317
+ slotNumber
318
+ });
319
+ return undefined;
320
+ }
321
+ // Validate fee asset price modifier is within allowed range
322
+ if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
323
+ this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`);
324
+ return undefined;
325
+ }
254
326
  // Check that I have any address in current committee before attesting
255
327
  const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
256
328
  const partOfCommittee = inCommittee.length > 0;
@@ -265,16 +337,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
265
337
  txHashes: proposal.txHashes.map((t)=>t.toString()),
266
338
  fishermanMode: this.config.fishermanMode || false
267
339
  });
268
- // TODO(palla/mbps): Remove this once checkpoint validation is stable.
269
- // Check that we have successfully validated a block for this slot before attesting to the checkpoint.
270
- if (!this.validatedBlockSlots.has(slotNumber)) {
271
- this.log.warn(`No validated block found for slot ${slotNumber}, refusing to attest to checkpoint`, proposalInfo);
272
- return undefined;
273
- }
274
340
  // Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
275
- // TODO(palla/mbps): Change default to false once checkpoint validation is stable.
276
- if (this.config.skipCheckpointProposalValidation !== false) {
277
- this.log.verbose(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
341
+ if (this.config.skipCheckpointProposalValidation) {
342
+ this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
278
343
  } else {
279
344
  const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
280
345
  if (!validationResult.isValid) {
@@ -321,11 +386,32 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
321
386
  });
322
387
  return undefined;
323
388
  }
324
- return this.createCheckpointAttestationsFromProposal(proposal, attestors);
389
+ return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
390
+ }
391
+ /**
392
+ * Checks if we should attest to a slot based on equivocation prevention rules.
393
+ * @returns true if we should attest, false if we should skip
394
+ */ shouldAttestToSlot(slotNumber) {
395
+ // If attestToEquivocatedProposals is true, always allow
396
+ if (this.config.attestToEquivocatedProposals) {
397
+ return true;
398
+ }
399
+ // Check if incoming slot is strictly greater than last attested
400
+ if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
401
+ this.log.warn(`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`);
402
+ return false;
403
+ }
404
+ return true;
325
405
  }
326
406
  async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
407
+ // Equivocation check: must happen right before signing to minimize the race window
408
+ if (!this.shouldAttestToSlot(proposal.slotNumber)) {
409
+ return undefined;
410
+ }
327
411
  const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
328
- await this.p2pClient.addCheckpointAttestations(attestations);
412
+ // Track the proposal we attested to (to prevent equivocation)
413
+ this.lastAttestedProposal = proposal;
414
+ await this.p2pClient.addOwnCheckpointAttestations(attestations);
329
415
  return attestations;
330
416
  }
331
417
  /**
@@ -333,7 +419,10 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
333
419
  * @returns Validation result with isValid flag and reason if invalid.
334
420
  */ async validateCheckpointProposal(proposal, proposalInfo) {
335
421
  const slot = proposal.slotNumber;
336
- const timeoutSeconds = 10;
422
+ // Timeout block syncing at the start of the next slot
423
+ const config = this.checkpointsBuilder.getConfig();
424
+ const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
425
+ const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
337
426
  // Wait for last block to sync by archive
338
427
  let lastBlockHeader;
339
428
  try {
@@ -362,18 +451,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
362
451
  reason: 'last_block_not_found'
363
452
  };
364
453
  }
365
- // Get the last full block to determine checkpoint number
366
- const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
367
- if (!lastBlock) {
368
- this.log.warn(`Last block ${lastBlockHeader.getBlockNumber()} not found`, proposalInfo);
369
- return {
370
- isValid: false,
371
- reason: 'last_block_not_found'
372
- };
373
- }
374
- const checkpointNumber = lastBlock.checkpointNumber;
375
454
  // Get all full blocks for the slot and checkpoint
376
- const blocks = await this.getBlocksForSlot(slot, lastBlockHeader, checkpointNumber);
455
+ const blocks = await this.blockSource.getBlocksForSlot(slot);
377
456
  if (blocks.length === 0) {
378
457
  this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
379
458
  return {
@@ -381,6 +460,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
381
460
  reason: 'no_blocks_for_slot'
382
461
  };
383
462
  }
463
+ // Ensure the last block for this slot matches the archive in the checkpoint proposal
464
+ if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
465
+ this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
466
+ return {
467
+ isValid: false,
468
+ reason: 'last_block_archive_mismatch'
469
+ };
470
+ }
384
471
  this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
385
472
  ...proposalInfo,
386
473
  blockNumbers: blocks.map((b)=>b.number)
@@ -388,14 +475,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
388
475
  // Get checkpoint constants from first block
389
476
  const firstBlock = blocks[0];
390
477
  const constants = this.extractCheckpointConstants(firstBlock);
478
+ const checkpointNumber = firstBlock.checkpointNumber;
391
479
  // Get L1-to-L2 messages for this checkpoint
392
480
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
481
+ // Collect the out hashes of all the checkpoints before this one in the same epoch
482
+ const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
483
+ const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
393
484
  // Fork world state at the block before the first block
394
485
  const parentBlockNumber = BlockNumber(firstBlock.number - 1);
395
486
  const fork = await this.worldState.fork(parentBlockNumber);
396
487
  try {
397
488
  // Create checkpoint builder with all existing blocks
398
- const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, fork, blocks);
489
+ const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
399
490
  // Complete the checkpoint to get computed values
400
491
  const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
401
492
  // Compare checkpoint header with proposal
@@ -422,6 +513,27 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
422
513
  reason: 'archive_mismatch'
423
514
  };
424
515
  }
516
+ // Check that the accumulated epoch out hash matches the value in the proposal.
517
+ // The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
518
+ const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
519
+ const computedEpochOutHash = accumulateCheckpointOutHashes([
520
+ ...previousCheckpointOutHashes,
521
+ checkpointOutHash
522
+ ]);
523
+ const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
524
+ if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
525
+ this.log.warn(`Epoch out hash mismatch`, {
526
+ proposalEpochOutHash: proposalEpochOutHash.toString(),
527
+ computedEpochOutHash: computedEpochOutHash.toString(),
528
+ checkpointOutHash: checkpointOutHash.toString(),
529
+ previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
530
+ ...proposalInfo
531
+ });
532
+ return {
533
+ isValid: false,
534
+ reason: 'out_hash_mismatch'
535
+ };
536
+ }
425
537
  this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
426
538
  return {
427
539
  isValid: true
@@ -431,36 +543,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
431
543
  }
432
544
  }
433
545
  /**
434
- * Get all full blocks for a given slot and checkpoint by walking backwards from the last block.
435
- * Returns blocks in ascending order (earliest to latest).
436
- * TODO(palla/mbps): Add getL2BlocksForSlot() to L2BlockSource interface for efficiency.
437
- */ async getBlocksForSlot(slot, lastBlockHeader, checkpointNumber) {
438
- const blocks = [];
439
- let currentHeader = lastBlockHeader;
440
- const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
441
- while(currentHeader.getSlot() === slot){
442
- const block = await this.blockSource.getL2BlockNew(currentHeader.getBlockNumber());
443
- if (!block) {
444
- this.log.warn(`Block ${currentHeader.getBlockNumber()} not found while getting blocks for slot ${slot}`);
445
- break;
446
- }
447
- if (block.checkpointNumber !== checkpointNumber) {
448
- break;
449
- }
450
- blocks.unshift(block);
451
- const prevArchive = currentHeader.lastArchive.root;
452
- if (prevArchive.equals(genesisArchiveRoot)) {
453
- break;
454
- }
455
- const prevHeader = await this.blockSource.getBlockHeaderByArchive(prevArchive);
456
- if (!prevHeader || prevHeader.getSlot() !== slot) {
457
- break;
458
- }
459
- currentHeader = prevHeader;
460
- }
461
- return blocks;
462
- }
463
- /**
464
546
  * Extract checkpoint global variables from a block.
465
547
  */ extractCheckpointConstants(block) {
466
548
  const gv = block.header.globalVariables;
@@ -468,6 +550,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
468
550
  chainId: gv.chainId,
469
551
  version: gv.version,
470
552
  slotNumber: gv.slotNumber,
553
+ timestamp: gv.timestamp,
471
554
  coinbase: gv.coinbase,
472
555
  feeRecipient: gv.feeRecipient,
473
556
  gasFees: gv.gasFees
@@ -482,19 +565,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
482
565
  this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
483
566
  return;
484
567
  }
485
- // Get the last full block to determine checkpoint number
486
- const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
487
- if (!lastBlock) {
488
- this.log.warn(`Failed to get last block for blob upload`, proposalInfo);
489
- return;
490
- }
491
- const blocks = await this.getBlocksForSlot(proposal.slotNumber, lastBlockHeader, lastBlock.checkpointNumber);
568
+ const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
492
569
  if (blocks.length === 0) {
493
570
  this.log.warn(`No blocks found for blob upload`, proposalInfo);
494
571
  return;
495
572
  }
496
573
  const blobFields = blocks.flatMap((b)=>b.toBlobFields());
497
- const blobs = getBlobsPerL1Block(blobFields);
574
+ const blobs = await getBlobsPerL1Block(blobFields);
498
575
  await this.blobClient.sendBlobsToFilestore(blobs);
499
576
  this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
500
577
  ...proposalInfo,
@@ -526,29 +603,81 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
526
603
  }
527
604
  ]);
528
605
  }
529
- async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options) {
530
- // TODO(palla/mbps): Prevent double proposals properly
531
- // if (this.previousProposal?.slotNumber === blockHeader.globalVariables.slotNumber) {
532
- // this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
533
- // return Promise.resolve(undefined);
534
- // }
606
+ /**
607
+ * Handle detection of a duplicate proposal (equivocation).
608
+ * Emits a slash event when a proposer sends multiple proposals for the same position.
609
+ */ handleDuplicateProposal(info) {
610
+ const { slot, proposer, type } = info;
611
+ this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
612
+ proposer: proposer.toString(),
613
+ slot,
614
+ type
615
+ });
616
+ // Emit slash event
617
+ this.emit(WANT_TO_SLASH_EVENT, [
618
+ {
619
+ validator: proposer,
620
+ amount: this.config.slashDuplicateProposalPenalty,
621
+ offenseType: OffenseType.DUPLICATE_PROPOSAL,
622
+ epochOrSlot: BigInt(slot)
623
+ }
624
+ ]);
625
+ }
626
+ /**
627
+ * Handle detection of a duplicate attestation (equivocation).
628
+ * Emits a slash event when an attester signs attestations for different proposals at the same slot.
629
+ */ handleDuplicateAttestation(info) {
630
+ const { slot, attester } = info;
631
+ this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
632
+ attester: attester.toString(),
633
+ slot
634
+ });
635
+ this.emit(WANT_TO_SLASH_EVENT, [
636
+ {
637
+ validator: attester,
638
+ amount: this.config.slashDuplicateAttestationPenalty,
639
+ offenseType: OffenseType.DUPLICATE_ATTESTATION,
640
+ epochOrSlot: BigInt(slot)
641
+ }
642
+ ]);
643
+ }
644
+ async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
645
+ // Validate that we're not creating a proposal for an older or equal position
646
+ if (this.lastProposedBlock) {
647
+ const lastSlot = this.lastProposedBlock.slotNumber;
648
+ const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
649
+ const newSlot = blockHeader.globalVariables.slotNumber;
650
+ if (newSlot < lastSlot || newSlot === lastSlot && indexWithinCheckpoint <= lastIndex) {
651
+ throw new Error(`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` + `already proposed block for slot ${lastSlot} index ${lastIndex}`);
652
+ }
653
+ }
535
654
  this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
536
655
  const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
537
656
  ...options,
538
657
  broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
539
658
  });
540
- this.previousProposal = newProposal;
659
+ this.lastProposedBlock = newProposal;
541
660
  return newProposal;
542
661
  }
543
- async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options) {
662
+ async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options = {}) {
663
+ // Validate that we're not creating a proposal for an older or equal slot
664
+ if (this.lastProposedCheckpoint) {
665
+ const lastSlot = this.lastProposedCheckpoint.slotNumber;
666
+ const newSlot = checkpointHeader.slotNumber;
667
+ if (newSlot <= lastSlot) {
668
+ throw new Error(`Cannot create checkpoint proposal for slot ${newSlot}: ` + `already proposed checkpoint for slot ${lastSlot}`);
669
+ }
670
+ }
544
671
  this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
545
- return await this.validationService.createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options);
672
+ const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options);
673
+ this.lastProposedCheckpoint = newProposal;
674
+ return newProposal;
546
675
  }
547
676
  async broadcastBlockProposal(proposal) {
548
677
  await this.p2pClient.broadcastProposal(proposal);
549
678
  }
550
- async signAttestationsAndSigners(attestationsAndSigners, proposer) {
551
- return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
679
+ async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
680
+ return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
552
681
  }
553
682
  async collectOwnAttestations(proposal) {
554
683
  const slot = proposal.slotNumber;
@@ -557,6 +686,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
557
686
  inCommittee
558
687
  });
559
688
  const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
689
+ if (!attestations) {
690
+ return [];
691
+ }
560
692
  // We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
561
693
  // other nodes can see that our validators did attest to this block proposal, and do not slash us
562
694
  // due to inactivity for missed attestations.
@@ -630,7 +762,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
630
762
  return Buffer.alloc(0);
631
763
  }
632
764
  const payloadToSign = authRequest.getPayloadToSign();
633
- const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign);
765
+ // AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
766
+ const context = {
767
+ dutyType: DutyType.AUTH_REQUEST
768
+ };
769
+ const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
634
770
  const authResponse = new AuthResponse(statusMessage, signature);
635
771
  return authResponse.toBuffer();
636
772
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/validator-client",
3
- "version": "0.0.1-commit.6d3c34e",
3
+ "version": "0.0.1-commit.7ac86ea28",
4
4
  "main": "dest/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -64,31 +64,35 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/blob-client": "0.0.1-commit.6d3c34e",
68
- "@aztec/blob-lib": "0.0.1-commit.6d3c34e",
69
- "@aztec/constants": "0.0.1-commit.6d3c34e",
70
- "@aztec/epoch-cache": "0.0.1-commit.6d3c34e",
71
- "@aztec/ethereum": "0.0.1-commit.6d3c34e",
72
- "@aztec/foundation": "0.0.1-commit.6d3c34e",
73
- "@aztec/node-keystore": "0.0.1-commit.6d3c34e",
74
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.6d3c34e",
75
- "@aztec/p2p": "0.0.1-commit.6d3c34e",
76
- "@aztec/protocol-contracts": "0.0.1-commit.6d3c34e",
77
- "@aztec/prover-client": "0.0.1-commit.6d3c34e",
78
- "@aztec/simulator": "0.0.1-commit.6d3c34e",
79
- "@aztec/slasher": "0.0.1-commit.6d3c34e",
80
- "@aztec/stdlib": "0.0.1-commit.6d3c34e",
81
- "@aztec/telemetry-client": "0.0.1-commit.6d3c34e",
67
+ "@aztec/blob-client": "0.0.1-commit.7ac86ea28",
68
+ "@aztec/blob-lib": "0.0.1-commit.7ac86ea28",
69
+ "@aztec/constants": "0.0.1-commit.7ac86ea28",
70
+ "@aztec/epoch-cache": "0.0.1-commit.7ac86ea28",
71
+ "@aztec/ethereum": "0.0.1-commit.7ac86ea28",
72
+ "@aztec/foundation": "0.0.1-commit.7ac86ea28",
73
+ "@aztec/node-keystore": "0.0.1-commit.7ac86ea28",
74
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.7ac86ea28",
75
+ "@aztec/p2p": "0.0.1-commit.7ac86ea28",
76
+ "@aztec/protocol-contracts": "0.0.1-commit.7ac86ea28",
77
+ "@aztec/prover-client": "0.0.1-commit.7ac86ea28",
78
+ "@aztec/simulator": "0.0.1-commit.7ac86ea28",
79
+ "@aztec/slasher": "0.0.1-commit.7ac86ea28",
80
+ "@aztec/stdlib": "0.0.1-commit.7ac86ea28",
81
+ "@aztec/telemetry-client": "0.0.1-commit.7ac86ea28",
82
+ "@aztec/validator-ha-signer": "0.0.1-commit.7ac86ea28",
82
83
  "koa": "^2.16.1",
83
84
  "koa-router": "^13.1.1",
84
85
  "tslib": "^2.4.0",
85
86
  "viem": "npm:@aztec/viem@2.38.2"
86
87
  },
87
88
  "devDependencies": {
89
+ "@aztec/archiver": "0.0.1-commit.7ac86ea28",
90
+ "@aztec/world-state": "0.0.1-commit.7ac86ea28",
91
+ "@electric-sql/pglite": "^0.3.14",
88
92
  "@jest/globals": "^30.0.0",
89
93
  "@types/jest": "^30.0.0",
90
94
  "@types/node": "^22.15.17",
91
- "@typescript/native-preview": "7.0.0-dev.20251126.1",
95
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
92
96
  "jest": "^30.0.0",
93
97
  "jest-mock-extended": "^4.0.0",
94
98
  "ts-node": "^10.9.1",