@aztec/validator-client 0.0.1-commit.5476d83 → 0.0.1-commit.5914bae

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 (61) hide show
  1. package/README.md +326 -0
  2. package/dest/checkpoint_builder.d.ts +79 -0
  3. package/dest/checkpoint_builder.d.ts.map +1 -0
  4. package/dest/checkpoint_builder.js +251 -0
  5. package/dest/config.d.ts +1 -1
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +36 -8
  8. package/dest/duties/validation_service.d.ts +42 -13
  9. package/dest/duties/validation_service.d.ts.map +1 -1
  10. package/dest/duties/validation_service.js +105 -28
  11. package/dest/factory.d.ts +19 -11
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +6 -5
  14. package/dest/index.d.ts +3 -2
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +2 -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 +9 -5
  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 +9 -5
  34. package/dest/metrics.d.ts +12 -3
  35. package/dest/metrics.d.ts.map +1 -1
  36. package/dest/metrics.js +46 -30
  37. package/dest/proposal_handler.d.ts +94 -0
  38. package/dest/proposal_handler.d.ts.map +1 -0
  39. package/dest/proposal_handler.js +852 -0
  40. package/dest/validator.d.ts +64 -22
  41. package/dest/validator.d.ts.map +1 -1
  42. package/dest/validator.js +278 -61
  43. package/package.json +23 -13
  44. package/src/checkpoint_builder.ts +417 -0
  45. package/src/config.ts +35 -7
  46. package/src/duties/validation_service.ts +156 -33
  47. package/src/factory.ts +26 -11
  48. package/src/index.ts +2 -1
  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 +14 -5
  53. package/src/key_store/node_keystore_adapter.ts +28 -5
  54. package/src/key_store/web3signer_key_store.ts +18 -5
  55. package/src/metrics.ts +63 -33
  56. package/src/proposal_handler.ts +903 -0
  57. package/src/validator.ts +433 -91
  58. package/dest/block_proposal_handler.d.ts +0 -52
  59. package/dest/block_proposal_handler.d.ts.map +0 -1
  60. package/dest/block_proposal_handler.js +0 -290
  61. package/src/block_proposal_handler.ts +0 -341
package/dest/validator.js CHANGED
@@ -4,13 +4,17 @@ import { sleep } from '@aztec/foundation/sleep';
4
4
  import { DateProvider } from '@aztec/foundation/timer';
5
5
  import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
6
6
  import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
7
+ import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
7
8
  import { AttestationTimeoutError } from '@aztec/stdlib/validators';
8
9
  import { getTelemetryClient } from '@aztec/telemetry-client';
10
+ import { createHASigner, createSignerFromSharedDb } from '@aztec/validator-ha-signer/factory';
11
+ import { DutyType } from '@aztec/validator-ha-signer/types';
9
12
  import { EventEmitter } from 'events';
10
- import { BlockProposalHandler } from './block_proposal_handler.js';
11
13
  import { ValidationService } from './duties/validation_service.js';
14
+ import { HAKeyStore } from './key_store/ha_key_store.js';
12
15
  import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
13
16
  import { ValidatorMetrics } from './metrics.js';
17
+ import { ProposalHandler } from './proposal_handler.js';
14
18
  // We maintain a set of proposers who have proposed invalid blocks.
15
19
  // Just cap the set to avoid unbounded growth.
16
20
  const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
@@ -25,8 +29,10 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
25
29
  keyStore;
26
30
  epochCache;
27
31
  p2pClient;
28
- blockProposalHandler;
32
+ proposalHandler;
29
33
  config;
34
+ blobClient;
35
+ haSigner;
30
36
  dateProvider;
31
37
  tracer;
32
38
  validationService;
@@ -34,13 +40,15 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
34
40
  log;
35
41
  // Whether it has already registered handlers on the p2p client
36
42
  hasRegisteredHandlers;
37
- // Used to check if we are sending the same proposal twice
38
- previousProposal;
43
+ /** Tracks the last block proposal we created, to detect duplicate proposal attempts. */ lastProposedBlock;
44
+ /** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
39
45
  lastEpochForCommitteeUpdateLoop;
40
46
  epochCacheUpdateLoop;
47
+ /** Tracks the last epoch in which each attester successfully submitted at least one attestation. */ lastAttestedEpochByAttester;
41
48
  proposersOfInvalidBlocks;
42
- constructor(keyStore, epochCache, p2pClient, blockProposalHandler, config, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
43
- super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.blockProposalHandler = blockProposalHandler, this.config = config, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.proposersOfInvalidBlocks = new Set();
49
+ /** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
50
+ constructor(keyStore, epochCache, p2pClient, proposalHandler, config, blobClient, haSigner, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
51
+ super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.proposalHandler = proposalHandler, this.config = config, this.blobClient = blobClient, this.haSigner = haSigner, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.lastAttestedEpochByAttester = new Map(), this.proposersOfInvalidBlocks = new Set();
44
52
  // Create child logger with fisherman prefix if in fisherman mode
45
53
  this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
46
54
  this.tracer = telemetry.getTracer('Validator');
@@ -79,6 +87,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
79
87
  this.log.trace(`No committee found for slot`);
80
88
  return;
81
89
  }
90
+ this.metrics.setCurrentEpoch(epoch);
82
91
  if (epoch !== this.lastEpochForCommitteeUpdateLoop) {
83
92
  const me = this.getValidatorAddresses();
84
93
  const committeeSet = new Set(committee.map((v)=>v.toString()));
@@ -94,27 +103,42 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
94
103
  this.log.error(`Error updating epoch committee`, err);
95
104
  }
96
105
  }
97
- static new(config, blockBuilder, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
106
+ static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), slashingProtectionDb) {
98
107
  const metrics = new ValidatorMetrics(telemetry);
99
108
  const blockProposalValidator = new BlockProposalValidator(epochCache, {
100
- txsPermitted: !config.disableTransactions
109
+ txsPermitted: !config.disableTransactions,
110
+ maxTxsPerBlock: config.validateMaxTxsPerBlock
101
111
  });
102
- const blockProposalHandler = new BlockProposalHandler(blockBuilder, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, config, metrics, dateProvider, telemetry);
103
- const validator = new ValidatorClient(NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager), epochCache, p2pClient, blockProposalHandler, config, dateProvider, telemetry);
112
+ const proposalHandler = new ProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, blobClient, metrics, dateProvider, telemetry);
113
+ const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
114
+ let validatorKeyStore = nodeKeystoreAdapter;
115
+ let haSigner;
116
+ if (slashingProtectionDb) {
117
+ // Shared database mode: use a pre-existing database (e.g. for testing HA setups).
118
+ const { signer } = createSignerFromSharedDb(slashingProtectionDb, config);
119
+ haSigner = signer;
120
+ validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
121
+ } else if (config.haSigningEnabled) {
122
+ // If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
123
+ const haConfig = {
124
+ ...config,
125
+ maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
126
+ };
127
+ const { signer } = await createHASigner(haConfig);
128
+ haSigner = signer;
129
+ validatorKeyStore = new HAKeyStore(nodeKeystoreAdapter, signer);
130
+ }
131
+ const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, proposalHandler, config, blobClient, haSigner, dateProvider, telemetry);
104
132
  return validator;
105
133
  }
106
134
  getValidatorAddresses() {
107
135
  return this.keyStore.getAddresses().filter((addr)=>!this.config.disabledValidators.some((disabled)=>disabled.equals(addr)));
108
136
  }
109
- getBlockProposalHandler() {
110
- return this.blockProposalHandler;
111
- }
112
- // Proxy method for backwards compatibility with tests
113
- reExecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages) {
114
- return this.blockProposalHandler.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
137
+ getProposalHandler() {
138
+ return this.proposalHandler;
115
139
  }
116
- signWithAddress(addr, msg) {
117
- return this.keyStore.signTypedDataWithAddress(addr, msg);
140
+ signWithAddress(addr, msg, context) {
141
+ return this.keyStore.signTypedDataWithAddress(addr, msg, context);
118
142
  }
119
143
  getCoinbaseForAttestor(attestor) {
120
144
  return this.keyStore.getCoinbaseAddress(attestor);
@@ -131,11 +155,26 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
131
155
  ...config
132
156
  };
133
157
  }
158
+ reloadKeystore(newManager) {
159
+ if (this.config.haSigningEnabled && !this.haSigner) {
160
+ this.log.warn('HA signing is enabled in config but was not initialized at startup. ' + 'Restart the node to enable HA signing.');
161
+ } else if (!this.config.haSigningEnabled && this.haSigner) {
162
+ 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.');
163
+ }
164
+ const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
165
+ if (this.haSigner) {
166
+ this.keyStore = new HAKeyStore(newAdapter, this.haSigner);
167
+ } else {
168
+ this.keyStore = newAdapter;
169
+ }
170
+ this.validationService = new ValidationService(this.keyStore, this.log.createChild('validation-service'));
171
+ }
134
172
  async start() {
135
173
  if (this.epochCacheUpdateLoop.isRunning()) {
136
174
  this.log.warn(`Validator client already started`);
137
175
  return;
138
176
  }
177
+ await this.keyStore.start();
139
178
  await this.registerHandlers();
140
179
  const myAddresses = this.getValidatorAddresses();
141
180
  const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
@@ -148,47 +187,75 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
148
187
  }
149
188
  async stop() {
150
189
  await this.epochCacheUpdateLoop.stop();
190
+ await this.keyStore.stop();
151
191
  }
152
192
  /** Register handlers on the p2p client */ async registerHandlers() {
153
193
  if (!this.hasRegisteredHandlers) {
154
194
  this.hasRegisteredHandlers = true;
155
195
  this.log.debug(`Registering validator handlers for p2p client`);
156
- const handler = (block, proposalSender)=>this.attestToProposal(block, proposalSender);
157
- this.p2pClient.registerBlockProposalHandler(handler);
196
+ // Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
197
+ const blockHandler = (block, proposalSender)=>this.validateBlockProposal(block, proposalSender);
198
+ this.p2pClient.registerBlockProposalHandler(blockHandler);
199
+ // Checkpoint proposal handler - validates and creates attestations
200
+ // The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
201
+ // and processed separately via the block handler above.
202
+ const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
203
+ this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
204
+ // Duplicate proposal handler - triggers slashing for equivocation
205
+ this.p2pClient.registerDuplicateProposalCallback((info)=>{
206
+ this.handleDuplicateProposal(info);
207
+ });
208
+ // Duplicate attestation handler - triggers slashing for attestation equivocation
209
+ this.p2pClient.registerDuplicateAttestationCallback((info)=>{
210
+ this.handleDuplicateAttestation(info);
211
+ });
158
212
  const myAddresses = this.getValidatorAddresses();
159
213
  this.p2pClient.registerThisValidatorAddresses(myAddresses);
160
214
  await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
161
215
  }
162
216
  }
163
- async attestToProposal(proposal, proposalSender) {
217
+ /**
218
+ * Validate a block proposal from a peer.
219
+ * Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
220
+ * @returns true if the proposal is valid, false otherwise
221
+ */ async validateBlockProposal(proposal, proposalSender) {
164
222
  const slotNumber = proposal.slotNumber;
223
+ // Note: During escape hatch, we still want to "validate" proposals for observability,
224
+ // but we intentionally reject them and disable slashing invalid block and attestation flow.
225
+ const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
165
226
  const proposer = proposal.getSender();
166
227
  // Reject proposals with invalid signatures
167
228
  if (!proposer) {
168
- this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
169
- return undefined;
229
+ this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
230
+ return false;
170
231
  }
171
- // Check that I have any address in current committee before attesting
232
+ // Log self-proposals from HA peers (same validator key on different nodes)
233
+ if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
234
+ this.log.verbose(`Processing block proposal from HA peer for slot ${slotNumber}`, {
235
+ proposer: proposer.toString(),
236
+ slotNumber
237
+ });
238
+ }
239
+ // Check if we're in the committee (for metrics purposes)
172
240
  const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
173
241
  const partOfCommittee = inCommittee.length > 0;
174
242
  const proposalInfo = {
175
243
  ...proposal.toBlockInfo(),
176
244
  proposer: proposer.toString()
177
245
  };
178
- this.log.info(`Received proposal for slot ${slotNumber}`, {
246
+ this.log.info(`Received block proposal for slot ${slotNumber}`, {
179
247
  ...proposalInfo,
180
248
  txHashes: proposal.txHashes.map((t)=>t.toString()),
181
249
  fishermanMode: this.config.fishermanMode || false
182
250
  });
183
- // Reexecute txs if we are part of the committee so we can attest, or if slashing is enabled so we can slash
184
- // invalid proposals even when not in the committee, or if we are configured to always reexecute for monitoring purposes.
251
+ // Reexecute txs if we are part of the committee, or if slashing is enabled, or if we are configured to always reexecute.
185
252
  // In fisherman mode, we always reexecute to validate proposals.
186
253
  const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
187
- const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals;
188
- const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
254
+ const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
255
+ const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
189
256
  if (!validationResult.isValid) {
190
- this.log.warn(`Proposal validation failed: ${validationResult.reason}`, proposalInfo);
191
257
  const reason = validationResult.reason || 'unknown';
258
+ this.log.warn(`Block proposal validation failed: ${reason}`, proposalInfo);
192
259
  // Classify failure reason: bad proposal vs node issue
193
260
  const badProposalReasons = [
194
261
  'invalid_proposal',
@@ -200,16 +267,71 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
200
267
  if (badProposalReasons.includes(reason)) {
201
268
  this.metrics.incFailedAttestationsBadProposal(1, reason, partOfCommittee);
202
269
  } else {
203
- // Node issues so we can't attest
270
+ // Node issues so we can't validate
204
271
  this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
205
272
  }
206
273
  // Slash invalid block proposals (can happen even when not in committee)
207
- if (validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
274
+ if (!escapeHatchOpen && validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
208
275
  this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
209
276
  this.slashInvalidBlock(proposal);
210
277
  }
278
+ return false;
279
+ }
280
+ this.log.info(`Validated block proposal for slot ${slotNumber}`, {
281
+ ...proposalInfo,
282
+ inCommittee: partOfCommittee,
283
+ fishermanMode: this.config.fishermanMode || false,
284
+ escapeHatchOpen
285
+ });
286
+ if (escapeHatchOpen) {
287
+ this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
288
+ return false;
289
+ }
290
+ return true;
291
+ }
292
+ /**
293
+ * Validate and attest to a checkpoint proposal from a peer.
294
+ * The proposal is received as CheckpointProposalCore (without lastBlock) since
295
+ * the lastBlock is extracted and processed separately via the block handler.
296
+ * @returns Checkpoint attestations if valid, undefined otherwise
297
+ */ async attestToCheckpointProposal(proposal, _proposalSender) {
298
+ const slotNumber = proposal.slotNumber;
299
+ const proposer = proposal.getSender();
300
+ // If escape hatch is open for this slot's epoch, do not attest.
301
+ if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
302
+ this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
211
303
  return undefined;
212
304
  }
305
+ // Ignore proposals from ourselves (may happen in HA setups)
306
+ if (proposer && this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
307
+ this.log.debug(`Ignoring block proposal from self for slot ${slotNumber}`, {
308
+ proposer: proposer.toString(),
309
+ slotNumber
310
+ });
311
+ return undefined;
312
+ }
313
+ // Check that I have any address in the committee where this checkpoint will land before attesting
314
+ const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
315
+ const partOfCommittee = inCommittee.length > 0;
316
+ const proposalInfo = {
317
+ slotNumber,
318
+ archive: proposal.archive.toString(),
319
+ proposer: proposer?.toString()
320
+ };
321
+ this.log.info(`Received checkpoint proposal for slot ${slotNumber}`, {
322
+ ...proposalInfo,
323
+ fishermanMode: this.config.fishermanMode || false
324
+ });
325
+ // Validate the checkpoint proposal and upload blobs (unless skipCheckpointProposalValidation is set)
326
+ if (this.config.skipCheckpointProposalValidation) {
327
+ this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
328
+ } else {
329
+ const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
330
+ if (!validationResult.isValid) {
331
+ this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
332
+ return undefined;
333
+ }
334
+ }
213
335
  // Check that I have any address in current committee before attesting
214
336
  // In fisherman mode, we still create attestations for validation even if not in committee
215
337
  if (!partOfCommittee && !this.config.fishermanMode) {
@@ -217,13 +339,22 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
217
339
  return undefined;
218
340
  }
219
341
  // Provided all of the above checks pass, we can attest to the proposal
220
- this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} proposal for slot ${slotNumber}`, {
342
+ this.log.info(`${partOfCommittee ? 'Attesting to' : 'Validated'} checkpoint proposal for slot ${slotNumber}`, {
221
343
  ...proposalInfo,
222
344
  inCommittee: partOfCommittee,
223
345
  fishermanMode: this.config.fishermanMode || false
224
346
  });
225
347
  this.metrics.incSuccessfulAttestations(inCommittee.length);
226
- // If the above function does not throw an error, then we can attest to the proposal
348
+ // Track epoch participation per attester: count each (attester, epoch) pair at most once
349
+ const proposalEpoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
350
+ for (const attester of inCommittee){
351
+ const key = attester.toString();
352
+ const lastEpoch = this.lastAttestedEpochByAttester.get(key);
353
+ if (lastEpoch === undefined || proposalEpoch > lastEpoch) {
354
+ this.lastAttestedEpochByAttester.set(key, proposalEpoch);
355
+ this.metrics.incAttestedEpochCount(attester);
356
+ }
357
+ }
227
358
  // Determine which validators should attest
228
359
  let attestors;
229
360
  if (partOfCommittee) {
@@ -240,13 +371,39 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
240
371
  }
241
372
  if (this.config.fishermanMode) {
242
373
  // bail out early and don't save attestations to the pool in fisherman mode
243
- this.log.info(`Creating attestations for proposal for slot ${slotNumber}`, {
374
+ this.log.info(`Creating checkpoint attestations for slot ${slotNumber}`, {
244
375
  ...proposalInfo,
245
376
  attestors: attestors.map((a)=>a.toString())
246
377
  });
247
378
  return undefined;
248
379
  }
249
- return this.createBlockAttestationsFromProposal(proposal, attestors);
380
+ return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
381
+ }
382
+ /**
383
+ * Checks if we should attest to a slot based on equivocation prevention rules.
384
+ * @returns true if we should attest, false if we should skip
385
+ */ shouldAttestToSlot(slotNumber) {
386
+ // If attestToEquivocatedProposals is true, always allow
387
+ if (this.config.attestToEquivocatedProposals) {
388
+ return true;
389
+ }
390
+ // Check if incoming slot is strictly greater than last attested
391
+ if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
392
+ this.log.warn(`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`);
393
+ return false;
394
+ }
395
+ return true;
396
+ }
397
+ async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
398
+ // Equivocation check: must happen right before signing to minimize the race window
399
+ if (!this.shouldAttestToSlot(proposal.slotNumber)) {
400
+ return undefined;
401
+ }
402
+ const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
403
+ // Track the proposal we attested to (to prevent equivocation)
404
+ this.lastAttestedProposal = proposal;
405
+ await this.p2pClient.addOwnCheckpointAttestations(attestations);
406
+ return attestations;
250
407
  }
251
408
  slashInvalidBlock(proposal) {
252
409
  const proposer = proposal.getSender();
@@ -270,42 +427,103 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
270
427
  }
271
428
  ]);
272
429
  }
273
- async createBlockProposal(blockNumber, header, archive, txs, proposerAddress, options) {
274
- if (this.previousProposal?.slotNumber === header.slotNumber) {
275
- this.log.verbose(`Already made a proposal for the same slot, skipping proposal`);
276
- return Promise.resolve(undefined);
430
+ /**
431
+ * Handle detection of a duplicate proposal (equivocation).
432
+ * Emits a slash event when a proposer sends multiple proposals for the same position.
433
+ */ handleDuplicateProposal(info) {
434
+ const { slot, proposer, type } = info;
435
+ this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
436
+ proposer: proposer.toString(),
437
+ slot,
438
+ type
439
+ });
440
+ // Emit slash event
441
+ this.emit(WANT_TO_SLASH_EVENT, [
442
+ {
443
+ validator: proposer,
444
+ amount: this.config.slashDuplicateProposalPenalty,
445
+ offenseType: OffenseType.DUPLICATE_PROPOSAL,
446
+ epochOrSlot: BigInt(slot)
447
+ }
448
+ ]);
449
+ }
450
+ /**
451
+ * Handle detection of a duplicate attestation (equivocation).
452
+ * Emits a slash event when an attester signs attestations for different proposals at the same slot.
453
+ */ handleDuplicateAttestation(info) {
454
+ const { slot, attester } = info;
455
+ this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
456
+ attester: attester.toString(),
457
+ slot
458
+ });
459
+ this.emit(WANT_TO_SLASH_EVENT, [
460
+ {
461
+ validator: attester,
462
+ amount: this.config.slashDuplicateAttestationPenalty,
463
+ offenseType: OffenseType.DUPLICATE_ATTESTATION,
464
+ epochOrSlot: BigInt(slot)
465
+ }
466
+ ]);
467
+ }
468
+ async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
469
+ // Validate that we're not creating a proposal for an older or equal position
470
+ if (this.lastProposedBlock) {
471
+ const lastSlot = this.lastProposedBlock.slotNumber;
472
+ const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
473
+ const newSlot = blockHeader.globalVariables.slotNumber;
474
+ if (newSlot < lastSlot || newSlot === lastSlot && indexWithinCheckpoint <= lastIndex) {
475
+ throw new Error(`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` + `already proposed block for slot ${lastSlot} index ${lastIndex}`);
476
+ }
277
477
  }
278
- const newProposal = await this.validationService.createBlockProposal(header, archive, txs, proposerAddress, {
478
+ this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
479
+ const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
279
480
  ...options,
280
481
  broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
281
482
  });
282
- this.previousProposal = newProposal;
483
+ this.lastProposedBlock = newProposal;
484
+ return newProposal;
485
+ }
486
+ async createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options = {}) {
487
+ // Validate that we're not creating a proposal for an older or equal slot
488
+ if (this.lastProposedCheckpoint) {
489
+ const lastSlot = this.lastProposedCheckpoint.slotNumber;
490
+ const newSlot = checkpointHeader.slotNumber;
491
+ if (newSlot <= lastSlot) {
492
+ throw new Error(`Cannot create checkpoint proposal for slot ${newSlot}: ` + `already proposed checkpoint for slot ${lastSlot}`);
493
+ }
494
+ }
495
+ this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
496
+ const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, feeAssetPriceModifier, lastBlockInfo, proposerAddress, options);
497
+ this.lastProposedCheckpoint = newProposal;
283
498
  return newProposal;
284
499
  }
285
500
  async broadcastBlockProposal(proposal) {
286
501
  await this.p2pClient.broadcastProposal(proposal);
287
502
  }
288
- async signAttestationsAndSigners(attestationsAndSigners, proposer) {
289
- return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
503
+ async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
504
+ return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
290
505
  }
291
506
  async collectOwnAttestations(proposal) {
292
- const slot = proposal.payload.header.slotNumber;
507
+ const slot = proposal.slotNumber;
293
508
  const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
294
509
  this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, {
295
510
  inCommittee
296
511
  });
297
- const attestations = await this.createBlockAttestationsFromProposal(proposal, inCommittee);
512
+ const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
513
+ if (!attestations) {
514
+ return [];
515
+ }
298
516
  // We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
299
517
  // other nodes can see that our validators did attest to this block proposal, and do not slash us
300
518
  // due to inactivity for missed attestations.
301
- void this.p2pClient.broadcastAttestations(attestations).catch((err)=>{
519
+ void this.p2pClient.broadcastCheckpointAttestations(attestations).catch((err)=>{
302
520
  this.log.error(`Failed to broadcast self-attestations for slot ${slot}`, err);
303
521
  });
304
522
  return attestations;
305
523
  }
306
524
  async collectAttestations(proposal, required, deadline) {
307
- // Wait and poll the p2pClient's attestation pool for this block until we have enough attestations
308
- const slot = proposal.payload.header.slotNumber;
525
+ // Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
526
+ const slot = proposal.slotNumber;
309
527
  this.log.debug(`Collecting ${required} attestations for slot ${slot} with deadline ${deadline.toISOString()}`);
310
528
  if (+deadline < this.dateProvider.now()) {
311
529
  this.log.error(`Deadline ${deadline.toISOString()} for collecting ${required} attestations for slot ${slot} is in the past`);
@@ -316,13 +534,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
316
534
  const myAddresses = this.getValidatorAddresses();
317
535
  let attestations = [];
318
536
  while(true){
319
- // Filter out attestations with a mismatching payload. This should NOT happen since we have verified
537
+ // Filter out attestations with a mismatching archive. This should NOT happen since we have verified
320
538
  // the proposer signature (ie our own) before accepting the attestation into the pool via the p2p client.
321
- const collectedAttestations = (await this.p2pClient.getAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
322
- if (!attestation.payload.equals(proposal.payload)) {
323
- this.log.warn(`Received attestation for slot ${slot} with mismatched payload from ${attestation.getSender()?.toString()}`, {
324
- attestationPayload: attestation.payload,
325
- proposalPayload: proposal.payload
539
+ const collectedAttestations = (await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalId)).filter((attestation)=>{
540
+ if (!attestation.archive.equals(proposal.archive)) {
541
+ this.log.warn(`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`, {
542
+ attestationArchive: attestation.archive.toString(),
543
+ proposalArchive: proposal.archive.toString()
326
544
  });
327
545
  return false;
328
546
  }
@@ -354,11 +572,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
354
572
  await sleep(this.config.attestationPollingIntervalMs);
355
573
  }
356
574
  }
357
- async createBlockAttestationsFromProposal(proposal, attestors = []) {
358
- const attestations = await this.validationService.attestToProposal(proposal, attestors);
359
- await this.p2pClient.addAttestations(attestations);
360
- return attestations;
361
- }
362
575
  async handleAuthRequest(peer, msg) {
363
576
  const authRequest = AuthRequest.fromBuffer(msg);
364
577
  const statusMessage = await this.p2pClient.handleAuthRequestFromPeer(authRequest, peer).catch((_)=>undefined);
@@ -373,7 +586,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
373
586
  return Buffer.alloc(0);
374
587
  }
375
588
  const payloadToSign = authRequest.getPayloadToSign();
376
- const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign);
589
+ // AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
590
+ const context = {
591
+ dutyType: DutyType.AUTH_REQUEST
592
+ };
593
+ const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
377
594
  const authResponse = new AuthResponse(statusMessage, signature);
378
595
  return authResponse.toBuffer();
379
596
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/validator-client",
3
- "version": "0.0.1-commit.5476d83",
3
+ "version": "0.0.1-commit.5914bae",
4
4
  "main": "dest/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "scripts": {
20
20
  "start": "node --no-warnings ./dest/bin",
21
- "build": "yarn clean && tsgo -b",
22
- "build:dev": "tsgo -b --watch",
21
+ "build": "yarn clean && ../scripts/tsc.sh",
22
+ "build:dev": "../scripts/tsc.sh --watch",
23
23
  "clean": "rm -rf ./dest .tsbuildinfo",
24
24
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
25
25
  },
@@ -64,25 +64,35 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/constants": "0.0.1-commit.5476d83",
68
- "@aztec/epoch-cache": "0.0.1-commit.5476d83",
69
- "@aztec/ethereum": "0.0.1-commit.5476d83",
70
- "@aztec/foundation": "0.0.1-commit.5476d83",
71
- "@aztec/node-keystore": "0.0.1-commit.5476d83",
72
- "@aztec/p2p": "0.0.1-commit.5476d83",
73
- "@aztec/slasher": "0.0.1-commit.5476d83",
74
- "@aztec/stdlib": "0.0.1-commit.5476d83",
75
- "@aztec/telemetry-client": "0.0.1-commit.5476d83",
67
+ "@aztec/blob-client": "0.0.1-commit.5914bae",
68
+ "@aztec/blob-lib": "0.0.1-commit.5914bae",
69
+ "@aztec/constants": "0.0.1-commit.5914bae",
70
+ "@aztec/epoch-cache": "0.0.1-commit.5914bae",
71
+ "@aztec/ethereum": "0.0.1-commit.5914bae",
72
+ "@aztec/foundation": "0.0.1-commit.5914bae",
73
+ "@aztec/node-keystore": "0.0.1-commit.5914bae",
74
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.5914bae",
75
+ "@aztec/p2p": "0.0.1-commit.5914bae",
76
+ "@aztec/protocol-contracts": "0.0.1-commit.5914bae",
77
+ "@aztec/prover-client": "0.0.1-commit.5914bae",
78
+ "@aztec/simulator": "0.0.1-commit.5914bae",
79
+ "@aztec/slasher": "0.0.1-commit.5914bae",
80
+ "@aztec/stdlib": "0.0.1-commit.5914bae",
81
+ "@aztec/telemetry-client": "0.0.1-commit.5914bae",
82
+ "@aztec/validator-ha-signer": "0.0.1-commit.5914bae",
76
83
  "koa": "^2.16.1",
77
84
  "koa-router": "^13.1.1",
78
85
  "tslib": "^2.4.0",
79
86
  "viem": "npm:@aztec/viem@2.38.2"
80
87
  },
81
88
  "devDependencies": {
89
+ "@aztec/archiver": "0.0.1-commit.5914bae",
90
+ "@aztec/world-state": "0.0.1-commit.5914bae",
91
+ "@electric-sql/pglite": "^0.3.14",
82
92
  "@jest/globals": "^30.0.0",
83
93
  "@types/jest": "^30.0.0",
84
94
  "@types/node": "^22.15.17",
85
- "@typescript/native-preview": "7.0.0-dev.20251126.1",
95
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
86
96
  "jest": "^30.0.0",
87
97
  "jest-mock-extended": "^4.0.0",
88
98
  "ts-node": "^10.9.1",