@aztec/validator-client 0.0.1-commit.7d4e6cd → 0.0.1-commit.8227e42

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 (69) 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 +24 -25
  6. package/dest/checkpoint_builder.d.ts.map +1 -1
  7. package/dest/checkpoint_builder.js +62 -37
  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/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 +99 -0
  21. package/dest/key_store/ha_key_store.d.ts.map +1 -0
  22. package/dest/key_store/ha_key_store.js +208 -0
  23. package/dest/key_store/index.d.ts +2 -1
  24. package/dest/key_store/index.d.ts.map +1 -1
  25. package/dest/key_store/index.js +1 -0
  26. package/dest/key_store/interface.d.ts +36 -6
  27. package/dest/key_store/interface.d.ts.map +1 -1
  28. package/dest/key_store/local_key_store.d.ts +10 -5
  29. package/dest/key_store/local_key_store.d.ts.map +1 -1
  30. package/dest/key_store/local_key_store.js +8 -4
  31. package/dest/key_store/node_keystore_adapter.d.ts +18 -5
  32. package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
  33. package/dest/key_store/node_keystore_adapter.js +18 -4
  34. package/dest/key_store/web3signer_key_store.d.ts +10 -5
  35. package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
  36. package/dest/key_store/web3signer_key_store.js +8 -4
  37. package/dest/metrics.d.ts +4 -3
  38. package/dest/metrics.d.ts.map +1 -1
  39. package/dest/metrics.js +34 -5
  40. package/dest/validator.d.ts +43 -18
  41. package/dest/validator.d.ts.map +1 -1
  42. package/dest/validator.js +233 -94
  43. package/package.json +21 -17
  44. package/src/block_proposal_handler.ts +48 -69
  45. package/src/checkpoint_builder.ts +104 -43
  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/index.ts +0 -1
  50. package/src/key_store/ha_key_store.ts +269 -0
  51. package/src/key_store/index.ts +1 -0
  52. package/src/key_store/interface.ts +44 -5
  53. package/src/key_store/local_key_store.ts +13 -4
  54. package/src/key_store/node_keystore_adapter.ts +27 -4
  55. package/src/key_store/web3signer_key_store.ts +17 -4
  56. package/src/metrics.ts +45 -6
  57. package/src/validator.ts +303 -114
  58. package/dest/tx_validator/index.d.ts +0 -3
  59. package/dest/tx_validator/index.d.ts.map +0 -1
  60. package/dest/tx_validator/index.js +0 -2
  61. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  62. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  63. package/dest/tx_validator/nullifier_cache.js +0 -24
  64. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  65. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  66. package/dest/tx_validator/tx_validator_factory.js +0 -53
  67. package/src/tx_validator/index.ts +0 -2
  68. package/src/tx_validator/nullifier_cache.ts +0 -30
  69. package/src/tx_validator/tx_validator_factory.ts +0 -133
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,29 @@ 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
+ telemetryClient: telemetry,
131
+ dateProvider
132
+ });
133
+ haSigner = signer;
134
+ validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
135
+ }
136
+ const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, haSigner, dateProvider, telemetry);
117
137
  return validator;
118
138
  }
119
139
  getValidatorAddresses() {
@@ -122,8 +142,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
122
142
  getBlockProposalHandler() {
123
143
  return this.blockProposalHandler;
124
144
  }
125
- signWithAddress(addr, msg) {
126
- return this.keyStore.signTypedDataWithAddress(addr, msg);
145
+ signWithAddress(addr, msg, context) {
146
+ return this.keyStore.signTypedDataWithAddress(addr, msg, context);
127
147
  }
128
148
  getCoinbaseForAttestor(attestor) {
129
149
  return this.keyStore.getCoinbaseAddress(attestor);
@@ -140,11 +160,26 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
140
160
  ...config
141
161
  };
142
162
  }
163
+ reloadKeystore(newManager) {
164
+ if (this.config.haSigningEnabled && !this.haSigner) {
165
+ this.log.warn('HA signing is enabled in config but was not initialized at startup. ' + 'Restart the node to enable HA signing.');
166
+ } else if (!this.config.haSigningEnabled && this.haSigner) {
167
+ 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.');
168
+ }
169
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
170
+ if (this.haSigner) {
171
+ this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
172
+ } else {
173
+ this.keyStore = newAdapter;
174
+ }
175
+ this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
176
+ }
143
177
  async start() {
144
178
  if (this.epochCacheUpdateLoop.isRunning()) {
145
179
  this.log.warn(`Validator client already started`);
146
180
  return;
147
181
  }
182
+ await this.keyStore.start();
148
183
  await this.registerHandlers();
149
184
  const myAddresses = this.getValidatorAddresses();
150
185
  const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
@@ -157,6 +192,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
157
192
  }
158
193
  async stop() {
159
194
  await this.epochCacheUpdateLoop.stop();
195
+ await this.keyStore.stop();
160
196
  }
161
197
  /** Register handlers on the p2p client */ async registerHandlers() {
162
198
  if (!this.hasRegisteredHandlers) {
@@ -170,6 +206,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
170
206
  // and processed separately via the block handler above.
171
207
  const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
172
208
  this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
209
+ // Duplicate proposal handler - triggers slashing for equivocation
210
+ this.p2pClient.registerDuplicateProposalCallback((info)=>{
211
+ this.handleDuplicateProposal(info);
212
+ });
213
+ // Duplicate attestation handler - triggers slashing for attestation equivocation
214
+ this.p2pClient.registerDuplicateAttestationCallback((info)=>{
215
+ this.handleDuplicateAttestation(info);
216
+ });
173
217
  const myAddresses = this.getValidatorAddresses();
174
218
  this.p2pClient.registerThisValidatorAddresses(myAddresses);
175
219
  await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
@@ -181,12 +225,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
181
225
  * @returns true if the proposal is valid, false otherwise
182
226
  */ async validateBlockProposal(proposal, proposalSender) {
183
227
  const slotNumber = proposal.slotNumber;
228
+ // Note: During escape hatch, we still want to "validate" proposals for observability,
229
+ // but we intentionally reject them and disable slashing invalid block and attestation flow.
230
+ const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
184
231
  const proposer = proposal.getSender();
185
232
  // Reject proposals with invalid signatures
186
233
  if (!proposer) {
187
234
  this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
188
235
  return false;
189
236
  }
237
+ // Ignore proposals from ourselves (may happen in HA setups)
238
+ if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
239
+ this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
240
+ proposer: proposer.toString(),
241
+ slotNumber
242
+ });
243
+ return false;
244
+ }
190
245
  // Check if we're in the committee (for metrics purposes)
191
246
  const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
192
247
  const partOfCommittee = inCommittee.length > 0;
@@ -203,7 +258,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
203
258
  // In fisherman mode, we always reexecute to validate proposals.
204
259
  const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
205
260
  const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
206
- const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
261
+ const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
207
262
  if (!validationResult.isValid) {
208
263
  this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
209
264
  const reason = validationResult.reason || 'unknown';
@@ -222,7 +277,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
222
277
  this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
223
278
  }
224
279
  // 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) {
280
+ if (!escapeHatchOpen && validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
226
281
  this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
227
282
  this.slashInvalidBlock(proposal);
228
283
  }
@@ -231,11 +286,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
231
286
  this.log.info(`Validated block proposal for slot ${slotNumber}`, {
232
287
  ...proposalInfo,
233
288
  inCommittee: partOfCommittee,
234
- fishermanMode: this.config.fishermanMode || false
289
+ fishermanMode: this.config.fishermanMode || false,
290
+ escapeHatchOpen
235
291
  });
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);
292
+ if (escapeHatchOpen) {
293
+ this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
294
+ return false;
295
+ }
239
296
  return true;
240
297
  }
241
298
  /**
@@ -246,11 +303,29 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
246
303
  */ async attestToCheckpointProposal(proposal, _proposalSender) {
247
304
  const slotNumber = proposal.slotNumber;
248
305
  const proposer = proposal.getSender();
306
+ // If escape hatch is open for this slot's epoch, do not attest.
307
+ if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
308
+ this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
309
+ return undefined;
310
+ }
249
311
  // Reject proposals with invalid signatures
250
312
  if (!proposer) {
251
313
  this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
252
314
  return undefined;
253
315
  }
316
+ // Ignore proposals from ourselves (may happen in HA setups)
317
+ if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
318
+ this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
319
+ proposer: proposer.toString(),
320
+ slotNumber
321
+ });
322
+ return undefined;
323
+ }
324
+ // Validate fee asset price modifier is within allowed range
325
+ if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
326
+ this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${slotNumber}`);
327
+ return undefined;
328
+ }
254
329
  // Check that I have any address in current committee before attesting
255
330
  const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
256
331
  const partOfCommittee = inCommittee.length > 0;
@@ -265,16 +340,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
265
340
  txHashes: proposal.txHashes.map((t)=>t.toString()),
266
341
  fishermanMode: this.config.fishermanMode || false
267
342
  });
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
343
  // 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);
344
+ if (this.config.skipCheckpointProposalValidation) {
345
+ this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
278
346
  } else {
279
347
  const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
280
348
  if (!validationResult.isValid) {
@@ -321,11 +389,32 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
321
389
  });
322
390
  return undefined;
323
391
  }
324
- return this.createCheckpointAttestationsFromProposal(proposal, attestors);
392
+ return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
393
+ }
394
+ /**
395
+ * Checks if we should attest to a slot based on equivocation prevention rules.
396
+ * @returns true if we should attest, false if we should skip
397
+ */ shouldAttestToSlot(slotNumber) {
398
+ // If attestToEquivocatedProposals is true, always allow
399
+ if (this.config.attestToEquivocatedProposals) {
400
+ return true;
401
+ }
402
+ // Check if incoming slot is strictly greater than last attested
403
+ if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
404
+ this.log.warn(`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`);
405
+ return false;
406
+ }
407
+ return true;
325
408
  }
326
409
  async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
410
+ // Equivocation check: must happen right before signing to minimize the race window
411
+ if (!this.shouldAttestToSlot(proposal.slotNumber)) {
412
+ return undefined;
413
+ }
327
414
  const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
328
- await this.p2pClient.addCheckpointAttestations(attestations);
415
+ // Track the proposal we attested to (to prevent equivocation)
416
+ this.lastAttestedProposal = proposal;
417
+ await this.p2pClient.addOwnCheckpointAttestations(attestations);
329
418
  return attestations;
330
419
  }
331
420
  /**
@@ -333,7 +422,10 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
333
422
  * @returns Validation result with isValid flag and reason if invalid.
334
423
  */ async validateCheckpointProposal(proposal, proposalInfo) {
335
424
  const slot = proposal.slotNumber;
336
- const timeoutSeconds = 10;
425
+ // Timeout block syncing at the start of the next slot
426
+ const config = this.checkpointsBuilder.getConfig();
427
+ const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
428
+ const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
337
429
  // Wait for last block to sync by archive
338
430
  let lastBlockHeader;
339
431
  try {
@@ -362,18 +454,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
362
454
  reason: 'last_block_not_found'
363
455
  };
364
456
  }
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
457
  // Get all full blocks for the slot and checkpoint
376
- const blocks = await this.getBlocksForSlot(slot, lastBlockHeader, checkpointNumber);
458
+ const blocks = await this.blockSource.getBlocksForSlot(slot);
377
459
  if (blocks.length === 0) {
378
460
  this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
379
461
  return {
@@ -381,6 +463,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
381
463
  reason: 'no_blocks_for_slot'
382
464
  };
383
465
  }
466
+ // Ensure the last block for this slot matches the archive in the checkpoint proposal
467
+ if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
468
+ this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
469
+ return {
470
+ isValid: false,
471
+ reason: 'last_block_archive_mismatch'
472
+ };
473
+ }
384
474
  this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
385
475
  ...proposalInfo,
386
476
  blockNumbers: blocks.map((b)=>b.number)
@@ -388,14 +478,18 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
388
478
  // Get checkpoint constants from first block
389
479
  const firstBlock = blocks[0];
390
480
  const constants = this.extractCheckpointConstants(firstBlock);
481
+ const checkpointNumber = firstBlock.checkpointNumber;
391
482
  // Get L1-to-L2 messages for this checkpoint
392
483
  const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
484
+ // Collect the out hashes of all the checkpoints before this one in the same epoch
485
+ const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
486
+ const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch)).filter((c)=>c.checkpointNumber < checkpointNumber).map((c)=>c.checkpointOutHash);
393
487
  // Fork world state at the block before the first block
394
488
  const parentBlockNumber = BlockNumber(firstBlock.number - 1);
395
489
  const fork = await this.worldState.fork(parentBlockNumber);
396
490
  try {
397
491
  // Create checkpoint builder with all existing blocks
398
- const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, fork, blocks);
492
+ const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
399
493
  // Complete the checkpoint to get computed values
400
494
  const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
401
495
  // Compare checkpoint header with proposal
@@ -422,6 +516,27 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
422
516
  reason: 'archive_mismatch'
423
517
  };
424
518
  }
519
+ // Check that the accumulated epoch out hash matches the value in the proposal.
520
+ // The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
521
+ const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
522
+ const computedEpochOutHash = accumulateCheckpointOutHashes([
523
+ ...previousCheckpointOutHashes,
524
+ checkpointOutHash
525
+ ]);
526
+ const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
527
+ if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
528
+ this.log.warn(`Epoch out hash mismatch`, {
529
+ proposalEpochOutHash: proposalEpochOutHash.toString(),
530
+ computedEpochOutHash: computedEpochOutHash.toString(),
531
+ checkpointOutHash: checkpointOutHash.toString(),
532
+ previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
533
+ ...proposalInfo
534
+ });
535
+ return {
536
+ isValid: false,
537
+ reason: 'out_hash_mismatch'
538
+ };
539
+ }
425
540
  this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
426
541
  return {
427
542
  isValid: true
@@ -431,36 +546,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
431
546
  }
432
547
  }
433
548
  /**
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
549
  * Extract checkpoint global variables from a block.
465
550
  */ extractCheckpointConstants(block) {
466
551
  const gv = block.header.globalVariables;
@@ -468,6 +553,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
468
553
  chainId: gv.chainId,
469
554
  version: gv.version,
470
555
  slotNumber: gv.slotNumber,
556
+ timestamp: gv.timestamp,
471
557
  coinbase: gv.coinbase,
472
558
  feeRecipient: gv.feeRecipient,
473
559
  gasFees: gv.gasFees
@@ -482,19 +568,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
482
568
  this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
483
569
  return;
484
570
  }
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);
571
+ const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
492
572
  if (blocks.length === 0) {
493
573
  this.log.warn(`No blocks found for blob upload`, proposalInfo);
494
574
  return;
495
575
  }
496
576
  const blobFields = blocks.flatMap((b)=>b.toBlobFields());
497
- const blobs = getBlobsPerL1Block(blobFields);
577
+ const blobs = await getBlobsPerL1Block(blobFields);
498
578
  await this.blobClient.sendBlobsToFilestore(blobs);
499
579
  this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
500
580
  ...proposalInfo,
@@ -526,29 +606,81 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
526
606
  }
527
607
  ]);
528
608
  }
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
- // }
609
+ /**
610
+ * Handle detection of a duplicate proposal (equivocation).
611
+ * Emits a slash event when a proposer sends multiple proposals for the same position.
612
+ */ handleDuplicateProposal(info) {
613
+ const { slot, proposer, type } = info;
614
+ this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
615
+ proposer: proposer.toString(),
616
+ slot,
617
+ type
618
+ });
619
+ // Emit slash event
620
+ this.emit(WANT_TO_SLASH_EVENT, [
621
+ {
622
+ validator: proposer,
623
+ amount: this.config.slashDuplicateProposalPenalty,
624
+ offenseType: OffenseType.DUPLICATE_PROPOSAL,
625
+ epochOrSlot: BigInt(slot)
626
+ }
627
+ ]);
628
+ }
629
+ /**
630
+ * Handle detection of a duplicate attestation (equivocation).
631
+ * Emits a slash event when an attester signs attestations for different proposals at the same slot.
632
+ */ handleDuplicateAttestation(info) {
633
+ const { slot, attester } = info;
634
+ this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
635
+ attester: attester.toString(),
636
+ slot
637
+ });
638
+ this.emit(WANT_TO_SLASH_EVENT, [
639
+ {
640
+ validator: attester,
641
+ amount: this.config.slashDuplicateAttestationPenalty,
642
+ offenseType: OffenseType.DUPLICATE_ATTESTATION,
643
+ epochOrSlot: BigInt(slot)
644
+ }
645
+ ]);
646
+ }
647
+ async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
648
+ // Validate that we're not creating a proposal for an older or equal position
649
+ if (this.lastProposedBlock) {
650
+ const lastSlot = this.lastProposedBlock.slotNumber;
651
+ const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
652
+ const newSlot = blockHeader.globalVariables.slotNumber;
653
+ if (newSlot < lastSlot || newSlot === lastSlot && indexWithinCheckpoint <= lastIndex) {
654
+ throw new Error(`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` + `already proposed block for slot ${lastSlot} index ${lastIndex}`);
655
+ }
656
+ }
535
657
  this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
536
658
  const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
537
659
  ...options,
538
660
  broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
539
661
  });
540
- this.previousProposal = newProposal;
662
+ this.lastProposedBlock = newProposal;
541
663
  return newProposal;
542
664
  }
543
- async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options) {
665
+ async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options = {}) {
666
+ // Validate that we're not creating a proposal for an older or equal slot
667
+ if (this.lastProposedCheckpoint) {
668
+ const lastSlot = this.lastProposedCheckpoint.slotNumber;
669
+ const newSlot = checkpointHeader.slotNumber;
670
+ if (newSlot <= lastSlot) {
671
+ throw new Error(`Cannot create checkpoint proposal for slot ${newSlot}: ` + `already proposed checkpoint for slot ${lastSlot}`);
672
+ }
673
+ }
544
674
  this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
545
- return await this.validationService.createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options);
675
+ const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options);
676
+ this.lastProposedCheckpoint = newProposal;
677
+ return newProposal;
546
678
  }
547
679
  async broadcastBlockProposal(proposal) {
548
680
  await this.p2pClient.broadcastProposal(proposal);
549
681
  }
550
- async signAttestationsAndSigners(attestationsAndSigners, proposer) {
551
- return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
682
+ async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
683
+ return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
552
684
  }
553
685
  async collectOwnAttestations(proposal) {
554
686
  const slot = proposal.slotNumber;
@@ -557,6 +689,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
557
689
  inCommittee
558
690
  });
559
691
  const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
692
+ if (!attestations) {
693
+ return [];
694
+ }
560
695
  // We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
561
696
  // other nodes can see that our validators did attest to this block proposal, and do not slash us
562
697
  // due to inactivity for missed attestations.
@@ -630,7 +765,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
630
765
  return Buffer.alloc(0);
631
766
  }
632
767
  const payloadToSign = authRequest.getPayloadToSign();
633
- const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign);
768
+ // AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
769
+ const context = {
770
+ dutyType: DutyType.AUTH_REQUEST
771
+ };
772
+ const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
634
773
  const authResponse = new AuthResponse(statusMessage, signature);
635
774
  return authResponse.toBuffer();
636
775
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/validator-client",
3
- "version": "0.0.1-commit.7d4e6cd",
3
+ "version": "0.0.1-commit.8227e42",
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.7d4e6cd",
68
- "@aztec/blob-lib": "0.0.1-commit.7d4e6cd",
69
- "@aztec/constants": "0.0.1-commit.7d4e6cd",
70
- "@aztec/epoch-cache": "0.0.1-commit.7d4e6cd",
71
- "@aztec/ethereum": "0.0.1-commit.7d4e6cd",
72
- "@aztec/foundation": "0.0.1-commit.7d4e6cd",
73
- "@aztec/node-keystore": "0.0.1-commit.7d4e6cd",
74
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.7d4e6cd",
75
- "@aztec/p2p": "0.0.1-commit.7d4e6cd",
76
- "@aztec/protocol-contracts": "0.0.1-commit.7d4e6cd",
77
- "@aztec/prover-client": "0.0.1-commit.7d4e6cd",
78
- "@aztec/simulator": "0.0.1-commit.7d4e6cd",
79
- "@aztec/slasher": "0.0.1-commit.7d4e6cd",
80
- "@aztec/stdlib": "0.0.1-commit.7d4e6cd",
81
- "@aztec/telemetry-client": "0.0.1-commit.7d4e6cd",
67
+ "@aztec/blob-client": "0.0.1-commit.8227e42",
68
+ "@aztec/blob-lib": "0.0.1-commit.8227e42",
69
+ "@aztec/constants": "0.0.1-commit.8227e42",
70
+ "@aztec/epoch-cache": "0.0.1-commit.8227e42",
71
+ "@aztec/ethereum": "0.0.1-commit.8227e42",
72
+ "@aztec/foundation": "0.0.1-commit.8227e42",
73
+ "@aztec/node-keystore": "0.0.1-commit.8227e42",
74
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.8227e42",
75
+ "@aztec/p2p": "0.0.1-commit.8227e42",
76
+ "@aztec/protocol-contracts": "0.0.1-commit.8227e42",
77
+ "@aztec/prover-client": "0.0.1-commit.8227e42",
78
+ "@aztec/simulator": "0.0.1-commit.8227e42",
79
+ "@aztec/slasher": "0.0.1-commit.8227e42",
80
+ "@aztec/stdlib": "0.0.1-commit.8227e42",
81
+ "@aztec/telemetry-client": "0.0.1-commit.8227e42",
82
+ "@aztec/validator-ha-signer": "0.0.1-commit.8227e42",
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.8227e42",
90
+ "@aztec/world-state": "0.0.1-commit.8227e42",
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",