@aztec/slasher 0.0.1-commit.e558bd1c → 0.0.1-commit.e57c76e

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 (92) hide show
  1. package/README.md +78 -78
  2. package/dest/config.d.ts +1 -1
  3. package/dest/config.d.ts.map +1 -1
  4. package/dest/config.js +35 -29
  5. package/dest/factory/create_facade.d.ts +3 -3
  6. package/dest/factory/create_facade.d.ts.map +1 -1
  7. package/dest/factory/create_facade.js +25 -2
  8. package/dest/factory/create_implementation.d.ts +6 -7
  9. package/dest/factory/create_implementation.d.ts.map +1 -1
  10. package/dest/factory/create_implementation.js +8 -56
  11. package/dest/factory/get_settings.d.ts +4 -4
  12. package/dest/factory/get_settings.d.ts.map +1 -1
  13. package/dest/factory/get_settings.js +3 -3
  14. package/dest/factory/index.d.ts +2 -2
  15. package/dest/factory/index.d.ts.map +1 -1
  16. package/dest/factory/index.js +1 -1
  17. package/dest/generated/slasher-defaults.d.ts +8 -7
  18. package/dest/generated/slasher-defaults.d.ts.map +1 -1
  19. package/dest/generated/slasher-defaults.js +7 -6
  20. package/dest/index.d.ts +6 -4
  21. package/dest/index.d.ts.map +1 -1
  22. package/dest/index.js +5 -3
  23. package/dest/null_slasher_client.d.ts +3 -4
  24. package/dest/null_slasher_client.d.ts.map +1 -1
  25. package/dest/null_slasher_client.js +1 -4
  26. package/dest/slash_offenses_collector.d.ts +10 -9
  27. package/dest/slash_offenses_collector.d.ts.map +1 -1
  28. package/dest/slash_offenses_collector.js +50 -34
  29. package/dest/slasher_client.d.ts +112 -0
  30. package/dest/slasher_client.d.ts.map +1 -0
  31. package/dest/{tally_slasher_client.js → slasher_client.js} +45 -45
  32. package/dest/slasher_client_facade.d.ts +6 -8
  33. package/dest/slasher_client_facade.d.ts.map +1 -1
  34. package/dest/slasher_client_facade.js +6 -9
  35. package/dest/slasher_client_interface.d.ts +7 -21
  36. package/dest/slasher_client_interface.d.ts.map +1 -1
  37. package/dest/slasher_client_interface.js +1 -4
  38. package/dest/stores/offenses_store.d.ts +12 -12
  39. package/dest/stores/offenses_store.d.ts.map +1 -1
  40. package/dest/stores/offenses_store.js +61 -38
  41. package/dest/watcher.d.ts +8 -1
  42. package/dest/watcher.d.ts.map +1 -1
  43. package/dest/watcher.js +1 -0
  44. package/dest/watchers/attestations_block_watcher.d.ts +26 -13
  45. package/dest/watchers/attestations_block_watcher.d.ts.map +1 -1
  46. package/dest/watchers/attestations_block_watcher.js +76 -61
  47. package/dest/watchers/attested_invalid_proposal_watcher.d.ts +42 -0
  48. package/dest/watchers/attested_invalid_proposal_watcher.d.ts.map +1 -0
  49. package/dest/watchers/attested_invalid_proposal_watcher.js +117 -0
  50. package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.d.ts +38 -0
  51. package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.d.ts.map +1 -0
  52. package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.js +138 -0
  53. package/dest/watchers/checkpoint_equivocation_watcher.d.ts +30 -0
  54. package/dest/watchers/checkpoint_equivocation_watcher.d.ts.map +1 -0
  55. package/dest/watchers/checkpoint_equivocation_watcher.js +69 -0
  56. package/dest/watchers/data_withholding_watcher.d.ts +63 -0
  57. package/dest/watchers/data_withholding_watcher.d.ts.map +1 -0
  58. package/dest/watchers/data_withholding_watcher.js +193 -0
  59. package/package.json +10 -10
  60. package/src/config.ts +42 -29
  61. package/src/factory/create_facade.ts +32 -4
  62. package/src/factory/create_implementation.ts +24 -105
  63. package/src/factory/get_settings.ts +8 -8
  64. package/src/factory/index.ts +1 -1
  65. package/src/generated/slasher-defaults.ts +7 -6
  66. package/src/index.ts +5 -3
  67. package/src/null_slasher_client.ts +2 -6
  68. package/src/slash_offenses_collector.ts +70 -36
  69. package/src/{tally_slasher_client.ts → slasher_client.ts} +63 -54
  70. package/src/slasher_client_facade.ts +6 -11
  71. package/src/slasher_client_interface.ts +6 -21
  72. package/src/stores/offenses_store.ts +73 -47
  73. package/src/watcher.ts +8 -0
  74. package/src/watchers/attestations_block_watcher.ts +88 -82
  75. package/src/watchers/attested_invalid_proposal_watcher.ts +168 -0
  76. package/src/watchers/broadcasted_invalid_checkpoint_proposal_watcher.ts +192 -0
  77. package/src/watchers/checkpoint_equivocation_watcher.ts +96 -0
  78. package/src/watchers/data_withholding_watcher.ts +225 -0
  79. package/dest/empire_slasher_client.d.ts +0 -190
  80. package/dest/empire_slasher_client.d.ts.map +0 -1
  81. package/dest/empire_slasher_client.js +0 -564
  82. package/dest/stores/payloads_store.d.ts +0 -29
  83. package/dest/stores/payloads_store.d.ts.map +0 -1
  84. package/dest/stores/payloads_store.js +0 -128
  85. package/dest/tally_slasher_client.d.ts +0 -125
  86. package/dest/tally_slasher_client.d.ts.map +0 -1
  87. package/dest/watchers/epoch_prune_watcher.d.ts +0 -39
  88. package/dest/watchers/epoch_prune_watcher.d.ts.map +0 -1
  89. package/dest/watchers/epoch_prune_watcher.js +0 -175
  90. package/src/empire_slasher_client.ts +0 -649
  91. package/src/stores/payloads_store.ts +0 -149
  92. package/src/watchers/epoch_prune_watcher.ts +0 -251
@@ -2,11 +2,11 @@ import { EthAddress } from '@aztec/aztec.js/addresses';
2
2
  import { maxBigint } from '@aztec/foundation/bigint';
3
3
  import { compactArray, partition, times } from '@aztec/foundation/collection';
4
4
  import { createLogger } from '@aztec/foundation/log';
5
- import { OffenseType, getEpochsForRound, getSlashConsensusVotesFromOffenses } from '@aztec/stdlib/slashing';
5
+ import { OffenseType, getEpochsForRound, getOffenseTypeName, getSlashConsensusVotesFromOffenses } from '@aztec/stdlib/slashing';
6
6
  import { SlashOffensesCollector } from './slash_offenses_collector.js';
7
7
  import { SlashRoundMonitor } from './slash_round_monitor.js';
8
8
  /**
9
- * The Tally Slasher client is responsible for managing slashable offenses using
9
+ * The Slasher client is responsible for managing slashable offenses using
10
10
  * the consensus-based slashing model where proposers vote on individual validator offenses.
11
11
  *
12
12
  * The client subscribes to several slash watchers that emit offenses and tracks them. When the slasher is the
@@ -30,16 +30,10 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
30
30
  * - Validators that reach the quorum threshold are slashed. A vote for slashing N units is also considered
31
31
  * a vote for slashing N-1, N-2, ..., 1 units. The system slashes for the largest amount that reaches quorum.
32
32
  * - The client monitors executable rounds and triggers execution when appropriate.
33
- *
34
- * Differences from Empire model
35
- * - No fixed slash payloads - votes are for individual validator offenses encoded in bytes
36
- * - The L1 contract determines which offenses reach quorum rather than nodes agreeing on a payload
37
- * - Proposers vote directly on which validators to slash and by how much
38
- * - Uses a slash offset to vote on validators from past rounds (e.g., round N votes on round N-2)
39
- */ export class TallySlasherClient {
33
+ */ export class SlasherClient {
40
34
  config;
41
35
  settings;
42
- tallySlashingProposer;
36
+ slashingProposer;
43
37
  slasher;
44
38
  rollup;
45
39
  epochCache;
@@ -49,10 +43,10 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
49
43
  unwatchCallbacks;
50
44
  roundMonitor;
51
45
  offensesCollector;
52
- constructor(config, settings, tallySlashingProposer, slasher, rollup, watchers, epochCache, dateProvider, offensesStore, log = createLogger('slasher:consensus')){
46
+ constructor(config, settings, slashingProposer, slasher, rollup, watchers, epochCache, dateProvider, offensesStore, log = createLogger('slasher:consensus')){
53
47
  this.config = config;
54
48
  this.settings = settings;
55
- this.tallySlashingProposer = tallySlashingProposer;
49
+ this.slashingProposer = slashingProposer;
56
50
  this.slasher = slasher;
57
51
  this.rollup = rollup;
58
52
  this.epochCache = epochCache;
@@ -64,26 +58,24 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
64
58
  this.offensesCollector = new SlashOffensesCollector(config, settings, watchers, offensesStore);
65
59
  }
66
60
  async start() {
67
- this.log.debug('Starting Tally Slasher client...');
61
+ this.log.debug('Starting slasher client...');
68
62
  this.roundMonitor.start();
69
63
  await this.offensesCollector.start();
70
64
  // Listen for RoundExecuted events
71
- this.unwatchCallbacks.push(this.tallySlashingProposer.listenToRoundExecuted(({ round, slashCount, l1BlockHash })=>void this.handleRoundExecuted(round, slashCount, l1BlockHash).catch((err)=>this.log.error('Error handling round executed', err))));
65
+ this.unwatchCallbacks.push(this.slashingProposer.listenToRoundExecuted(({ round, slashCount, l1BlockHash })=>void this.handleRoundExecuted(round, slashCount, l1BlockHash).catch((err)=>this.log.error('Error handling round executed', err))));
72
66
  // Check for round changes
73
67
  this.unwatchCallbacks.push(this.roundMonitor.listenToNewRound((round)=>this.handleNewRound(round)));
74
- this.log.info(`Started tally slasher client`);
68
+ this.log.info(`Started slasher client`);
75
69
  return Promise.resolve();
76
70
  }
77
- /**
78
- * Stop the tally slasher client
79
- */ async stop() {
80
- this.log.debug('Stopping Tally Slasher client...');
71
+ /** Stop the slasher client */ async stop() {
72
+ this.log.debug('Stopping slasher client...');
81
73
  for (const unwatchCallback of this.unwatchCallbacks){
82
74
  unwatchCallback();
83
75
  }
84
76
  this.roundMonitor.stop();
85
77
  await this.offensesCollector.stop();
86
- this.log.info('Tally Slasher client stopped');
78
+ this.log.info('Slasher client stopped');
87
79
  }
88
80
  /** Returns the current config */ getConfig() {
89
81
  return this.config;
@@ -95,10 +87,10 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
95
87
  };
96
88
  }
97
89
  /** Triggered on a time basis when we enter a new slashing round. Clears expired offenses. */ async handleNewRound(round) {
98
- this.log.info(`Starting new tally slashing round ${round}`);
90
+ this.log.info(`Starting new slashing round ${round}`);
99
91
  await this.offensesCollector.handleNewRound(round);
100
92
  }
101
- /** Called when we see a RoundExecuted event on the TallySlashingProposer (just for logging). */ async handleRoundExecuted(round, slashCount, l1BlockHash) {
93
+ /** Called when we see a RoundExecuted event on the SlashingProposer (just for logging). */ async handleRoundExecuted(round, slashCount, l1BlockHash) {
102
94
  const slashes = await this.rollup.getSlashEvents(l1BlockHash);
103
95
  this.log.info(`Slashing round ${round} has been executed with ${slashCount} slashes`, {
104
96
  slashes
@@ -170,7 +162,7 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
170
162
  };
171
163
  this.log.debug(`Testing if slashing round ${executableRound} is executable`, logData);
172
164
  try {
173
- const roundInfo = await this.tallySlashingProposer.getRound(executableRound);
165
+ const roundInfo = await this.slashingProposer.getRound(executableRound);
174
166
  logData = {
175
167
  ...logData,
176
168
  roundInfo
@@ -186,19 +178,19 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
186
178
  return undefined;
187
179
  }
188
180
  // Check if round is ready to execute at the given slot
189
- const isReadyToExecute = await this.tallySlashingProposer.isRoundReadyToExecute(executableRound, slotNumber);
181
+ const isReadyToExecute = await this.slashingProposer.isRoundReadyToExecute(executableRound, slotNumber);
190
182
  if (!isReadyToExecute) {
191
183
  this.log.warn(`Round ${executableRound} is not ready to execute at slot ${slotNumber} according to contract check`, logData);
192
184
  return undefined;
193
185
  }
194
186
  // Check if the round yields any slashing at all
195
- const { actions: slashActions, committees } = await this.tallySlashingProposer.getTally(executableRound);
187
+ const { actions: slashActions, committees } = await this.slashingProposer.getTally(executableRound);
196
188
  if (slashActions.length === 0) {
197
189
  this.log.verbose(`Round ${executableRound} does not resolve in any slashing`, logData);
198
190
  return undefined;
199
191
  }
200
192
  // Check if the slash payload is vetoed
201
- const payload = await this.tallySlashingProposer.getPayload(executableRound);
193
+ const payload = await this.slashingProposer.getPayload(executableRound);
202
194
  const isVetoed = await this.slasher.isPayloadVetoed(payload.address);
203
195
  if (isVetoed) {
204
196
  this.log.warn(`Round ${executableRound} payload is vetoed (skipping execution)`, {
@@ -256,7 +248,7 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
256
248
  slotNumber,
257
249
  currentRound,
258
250
  slashedRound,
259
- offensesToForgive,
251
+ offensesFromAlwaysSlash: offensesFromAlwaysSlash.map(getOffenseLogData),
260
252
  slashValidatorsAlways: this.config.slashValidatorsAlways
261
253
  });
262
254
  }
@@ -265,7 +257,7 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
265
257
  slotNumber,
266
258
  currentRound,
267
259
  slashedRound,
268
- offensesToForgive,
260
+ offensesToForgive: offensesToForgive.map(getOffenseLogData),
269
261
  slashValidatorsNever: this.config.slashValidatorsNever
270
262
  });
271
263
  }
@@ -277,29 +269,36 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
277
269
  });
278
270
  return undefined;
279
271
  }
280
- const offensesToSlashLog = offensesToSlash.map((offense)=>({
281
- ...offense,
282
- amount: offense.amount.toString()
283
- }));
284
- this.log.info(`Voting to slash ${offensesToSlash.length} offenses`, {
272
+ this.log.debug(`Computing slash votes for ${offensesToSlash.length} offenses`, {
285
273
  slotNumber,
286
274
  currentRound,
287
275
  slashedRound,
288
- offensesToSlash: offensesToSlashLog
276
+ offensesToSlash: offensesToSlash.map(getOffenseLogData)
289
277
  });
290
278
  const committees = await this.collectCommitteesActiveDuringRound(slashedRound);
291
279
  const epochsForCommittees = getEpochsForRound(slashedRound, this.settings);
292
- const votes = getSlashConsensusVotesFromOffenses(offensesToSlash, committees, epochsForCommittees.map((e)=>BigInt(e)), this.settings);
280
+ const { slashMaxPayloadSize } = this.config;
281
+ const votes = getSlashConsensusVotesFromOffenses(offensesToSlash, committees, epochsForCommittees.map((e)=>BigInt(e)), {
282
+ ...this.settings,
283
+ maxSlashedValidators: slashMaxPayloadSize
284
+ }, this.log);
293
285
  if (votes.every((v)=>v === 0)) {
294
286
  this.log.warn(`Computed votes for offenses are all zero. Skipping vote.`, {
295
287
  slotNumber,
296
288
  currentRound,
297
289
  slashedRound,
298
- offensesToSlash,
290
+ offensesToSlash: offensesToSlash.map(getOffenseLogData),
299
291
  committees
300
292
  });
301
293
  return undefined;
302
294
  }
295
+ this.log.info(`Voting to slash ${offensesToSlash.length} offenses`, {
296
+ slotNumber,
297
+ slashedRound,
298
+ currentRound,
299
+ votes,
300
+ offensesToSlash: offensesToSlash.map(getOffenseLogData)
301
+ });
303
302
  this.log.debug(`Computed votes for slashing ${offensesToSlash.length} offenses`, {
304
303
  slashedRound,
305
304
  currentRound,
@@ -320,14 +319,8 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
320
319
  return Promise.all(epochsToSlash.map((epoch)=>this.epochCache.getCommitteeForEpoch(epoch).then((c)=>c.committee ?? emptyCommittee)));
321
320
  }
322
321
  /**
323
- * Get slash payloads is NOT SUPPORTED in tally model
324
- * @throws Error indicating this operation is not supported
325
- */ getSlashPayloads() {
326
- return Promise.reject(new Error('Tally slashing model does not support slash payloads'));
327
- }
328
- /**
329
322
  * Gather offenses to be slashed on a given round.
330
- * In tally slashing, round N slashes validators from round N - slashOffsetInRounds.
323
+ * Round N slashes validators from round N - slashOffsetInRounds.
331
324
  * @param round - The round to get offenses for, defaults to current round
332
325
  * @returns Array of pending offenses for the round with offset applied
333
326
  */ async gatherOffensesForRound(round) {
@@ -337,8 +330,8 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
337
330
  }
338
331
  return await this.offensesStore.getOffensesForRound(targetRound);
339
332
  }
340
- /** Returns all pending offenses stored */ getPendingOffenses() {
341
- return this.offensesStore.getPendingOffenses();
333
+ /** Returns all offenses stored */ getOffenses() {
334
+ return this.offensesStore.getOffenses();
342
335
  }
343
336
  /**
344
337
  * Returns the round to be slashed given the current round by applying the slash offset.
@@ -352,3 +345,10 @@ import { SlashRoundMonitor } from './slash_round_monitor.js';
352
345
  return round - BigInt(this.settings.slashingOffsetInRounds);
353
346
  }
354
347
  }
348
+ function getOffenseLogData(offense) {
349
+ return {
350
+ ...offense,
351
+ validator: offense.validator.toString(),
352
+ offenseType: getOffenseTypeName(offense.offenseType)
353
+ };
354
+ }
@@ -2,12 +2,11 @@ import { EpochCache } from '@aztec/epoch-cache';
2
2
  import { RollupContract } from '@aztec/ethereum/contracts';
3
3
  import type { ViemClient } from '@aztec/ethereum/types';
4
4
  import type { SlotNumber } from '@aztec/foundation/branded-types';
5
- import { EthAddress } from '@aztec/foundation/eth-address';
6
5
  import { DateProvider } from '@aztec/foundation/timer';
7
- import type { DataStoreConfig } from '@aztec/kv-store/config';
8
6
  import { AztecLMDBStoreV2 } from '@aztec/kv-store/lmdb-v2';
9
7
  import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
10
- import type { Offense, ProposerSlashAction, SlashPayloadRound } from '@aztec/stdlib/slashing';
8
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
9
+ import type { Offense, ProposerSlashAction } from '@aztec/stdlib/slashing';
11
10
  import type { SlasherClientInterface } from './slasher_client_interface.js';
12
11
  import type { Watcher } from './watcher.js';
13
12
  /**
@@ -19,26 +18,25 @@ export declare class SlasherClientFacade implements SlasherClientInterface {
19
18
  private config;
20
19
  private rollup;
21
20
  private l1Client;
22
- private slashFactoryAddress;
23
21
  private watchers;
24
22
  private epochCache;
25
23
  private dateProvider;
26
24
  private kvStore;
25
+ private rollupRegisteredAtL2Slot;
27
26
  private logger;
28
27
  private client;
29
28
  private unwatch;
30
29
  constructor(config: SlasherConfig & DataStoreConfig & {
31
30
  ethereumSlotDuration: number;
32
- }, rollup: RollupContract, l1Client: ViemClient, slashFactoryAddress: EthAddress | undefined, watchers: Watcher[], epochCache: EpochCache, dateProvider: DateProvider, kvStore: AztecLMDBStoreV2, logger?: import("@aztec/foundation/log").Logger);
31
+ }, rollup: RollupContract, l1Client: ViemClient, watchers: Watcher[], epochCache: EpochCache, dateProvider: DateProvider, kvStore: AztecLMDBStoreV2, rollupRegisteredAtL2Slot: SlotNumber, logger?: import("@aztec/foundation/log").Logger);
33
32
  start(): Promise<void>;
34
33
  stop(): Promise<void>;
35
34
  getConfig(): SlasherConfig;
36
35
  updateConfig(config: Partial<SlasherConfig>): void;
37
- getSlashPayloads(): Promise<SlashPayloadRound[]>;
38
36
  gatherOffensesForRound(round?: bigint): Promise<Offense[]>;
39
- getPendingOffenses(): Promise<Offense[]>;
37
+ getOffenses(): Promise<Offense[]>;
40
38
  getProposerActions(slotNumber: SlotNumber): Promise<ProposerSlashAction[]>;
41
39
  private createSlasherClient;
42
40
  private handleSlasherChange;
43
41
  }
44
- //# sourceMappingURL=data:application/json;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EY,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAIjC;IAEM,SAAS,IAAI,aAAa,CAEhC;IAEM,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAIxD;IAEM,sBAAsB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAEhE;IAEM,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAEvC;IAEM,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAEhF;IAED,OAAO,CAAC,mBAAmB;YAcb,mBAAmB;CAMlC"}
@@ -8,23 +8,23 @@ import { createSlasherImplementation } from './factory/create_implementation.js'
8
8
  config;
9
9
  rollup;
10
10
  l1Client;
11
- slashFactoryAddress;
12
11
  watchers;
13
12
  epochCache;
14
13
  dateProvider;
15
14
  kvStore;
15
+ rollupRegisteredAtL2Slot;
16
16
  logger;
17
17
  client;
18
18
  unwatch;
19
- constructor(config, rollup, l1Client, slashFactoryAddress, watchers, epochCache, dateProvider, kvStore, logger = createLogger('slasher')){
19
+ constructor(config, rollup, l1Client, watchers, epochCache, dateProvider, kvStore, rollupRegisteredAtL2Slot, logger = createLogger('slasher')){
20
20
  this.config = config;
21
21
  this.rollup = rollup;
22
22
  this.l1Client = l1Client;
23
- this.slashFactoryAddress = slashFactoryAddress;
24
23
  this.watchers = watchers;
25
24
  this.epochCache = epochCache;
26
25
  this.dateProvider = dateProvider;
27
26
  this.kvStore = kvStore;
27
+ this.rollupRegisteredAtL2Slot = rollupRegisteredAtL2Slot;
28
28
  this.logger = logger;
29
29
  }
30
30
  async start() {
@@ -52,20 +52,17 @@ import { createSlasherImplementation } from './factory/create_implementation.js'
52
52
  this.client?.updateConfig(config);
53
53
  this.watchers.forEach((watcher)=>watcher.updateConfig?.(config));
54
54
  }
55
- getSlashPayloads() {
56
- return this.client?.getSlashPayloads() ?? Promise.reject(new Error('Slasher client not initialized'));
57
- }
58
55
  gatherOffensesForRound(round) {
59
56
  return this.client?.gatherOffensesForRound(round) ?? Promise.reject(new Error('Slasher client not initialized'));
60
57
  }
61
- getPendingOffenses() {
62
- return this.client?.getPendingOffenses() ?? Promise.reject(new Error('Slasher client not initialized'));
58
+ getOffenses() {
59
+ return this.client?.getOffenses() ?? Promise.reject(new Error('Slasher client not initialized'));
63
60
  }
64
61
  getProposerActions(slotNumber) {
65
62
  return this.client?.getProposerActions(slotNumber) ?? Promise.reject(new Error('Slasher client not initialized'));
66
63
  }
67
64
  createSlasherClient() {
68
- return createSlasherImplementation(this.config, this.rollup, this.l1Client, this.slashFactoryAddress, this.watchers, this.epochCache, this.dateProvider, this.kvStore, this.logger);
65
+ return createSlasherImplementation(this.config, this.rollup, this.l1Client, this.watchers, this.epochCache, this.dateProvider, this.kvStore, this.rollupRegisteredAtL2Slot, this.logger);
69
66
  }
70
67
  async handleSlasherChange() {
71
68
  this.logger.warn('Slasher contract changed, recreating slasher client');
@@ -1,31 +1,17 @@
1
1
  import type { SlotNumber } from '@aztec/foundation/branded-types';
2
2
  import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
3
- import type { Offense, ProposerSlashAction, SlashPayloadRound } from '@aztec/stdlib/slashing';
4
- /**
5
- * Common interface for slasher clients used by the Aztec node.
6
- * Both Empire and Consensus slasher clients implement this interface.
7
- */
3
+ import type { Offense, ProposerSlashAction } from '@aztec/stdlib/slashing';
4
+ /** Common interface for slasher clients used by the Aztec node. */
8
5
  export interface SlasherClientInterface {
9
6
  /** Start the slasher client */
10
7
  start(): Promise<void>;
11
8
  /** Stop the slasher client */
12
9
  stop(): Promise<void>;
13
- /**
14
- * Get slash payloads for the Empire model.
15
- * The Consensus model should throw an error when this is called.
16
- */
17
- getSlashPayloads(): Promise<SlashPayloadRound[]>;
18
- /**
19
- * Gather offenses for a given round, defaults to current.
20
- * Used by both Empire and Consensus models.
21
- */
10
+ /** Gather offenses for a given round, defaults to current. */
22
11
  gatherOffensesForRound(round?: bigint): Promise<Offense[]>;
23
- /** Returns all pending offenses */
24
- getPendingOffenses(): Promise<Offense[]>;
25
- /**
26
- * Update the configuration.
27
- * Used by both Empire and Consensus models.
28
- */
12
+ /** Returns all offenses */
13
+ getOffenses(): Promise<Offense[]>;
14
+ /** Update the configuration. */
29
15
  updateConfig(config: Partial<SlasherConfig>): void;
30
16
  /**
31
17
  * Get the actions the proposer should take for slashing.
@@ -36,4 +22,4 @@ export interface SlasherClientInterface {
36
22
  /** Returns the current config */
37
23
  getConfig(): SlasherConfig;
38
24
  }
39
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhc2hlcl9jbGllbnRfaW50ZXJmYWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvc2xhc2hlcl9jbGllbnRfaW50ZXJmYWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFVBQVUsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ2xFLE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ3JFLE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSxtQkFBbUIsRUFBRSxpQkFBaUIsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBRTlGOzs7R0FHRztBQUNILE1BQU0sV0FBVyxzQkFBc0I7SUFDckMsK0JBQStCO0lBQy9CLEtBQUssSUFBSSxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7SUFFdkIsOEJBQThCO0lBQzlCLElBQUksSUFBSSxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7SUFFdEI7OztPQUdHO0lBQ0gsZ0JBQWdCLElBQUksT0FBTyxDQUFDLGlCQUFpQixFQUFFLENBQUMsQ0FBQztJQUVqRDs7O09BR0c7SUFDSCxzQkFBc0IsQ0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AAC,OAAO,EAAE,CAAC,CAAC;IAEzC;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IAEnD;;;;OAIG;IACH,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAE3E,iCAAiC;IACjC,SAAS,IAAI,aAAa,CAAC;CAC5B"}
1
+ {"version":3,"file":"slasher_client_interface.d.ts","sourceRoot":"","sources":["../src/slasher_client_interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE3E,mEAAmE;AACnE,MAAM,WAAW,sBAAsB;IACrC,+BAA+B;IAC/B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,8BAA8B;IAC9B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB,8DAA8D;IAC9D,sBAAsB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAE3D,2BAA2B;IAC3B,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAElC,gCAAgC;IAChC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IAEnD;;;;OAIG;IACH,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAE3E,iCAAiC;IACjC,SAAS,IAAI,aAAa,CAAC;CAC5B"}
@@ -1,4 +1 @@
1
- /**
2
- * Common interface for slasher clients used by the Aztec node.
3
- * Both Empire and Consensus slasher clients implement this interface.
4
- */ export { };
1
+ /** Common interface for slasher clients used by the Aztec node. */ export { };
@@ -1,14 +1,15 @@
1
1
  import type { AztecAsyncKVStore } from '@aztec/kv-store';
2
2
  import { type Offense, type OffenseIdentifier } from '@aztec/stdlib/slashing';
3
3
  export declare const SCHEMA_VERSION = 1;
4
+ type ClearOffensesFilter = Pick<Offense, 'offenseType' | 'epochOrSlot'> & {
5
+ validators?: Offense['validator'][];
6
+ };
4
7
  export declare class SlasherOffensesStore {
5
8
  private kvStore;
6
9
  private settings;
7
10
  /** Map from offense key to offense data */
8
11
  private offenses;
9
- /** Map from offense key to whether the offense has been executed (only used for empire based slashing) */
10
- private offensesSlashed;
11
- /** Multimap from round to offense keys (only used for consensus based slashing) */
12
+ /** Multimap from round to offense keys */
12
13
  private roundsOffenses;
13
14
  private log;
14
15
  constructor(kvStore: AztecAsyncKVStore, settings: {
@@ -16,22 +17,21 @@ export declare class SlasherOffensesStore {
16
17
  epochDuration: number;
17
18
  slashOffenseExpirationRounds?: number;
18
19
  });
19
- /** Returns all offenses not marked as slashed */
20
- getPendingOffenses(): Promise<Offense[]>;
20
+ /** Returns all offenses */
21
+ getOffenses(): Promise<Offense[]>;
21
22
  /** Returns all offenses tracked for the given round */
22
23
  getOffensesForRound(round: bigint): Promise<Offense[]>;
23
- /** Returns whether an offense is pending (ie not marked as slashed) */
24
- hasPendingOffense(offense: OffenseIdentifier): Promise<boolean>;
25
24
  /** Returns whether we have seen this offense */
26
25
  hasOffense(offense: OffenseIdentifier): Promise<boolean>;
27
- /** Adds a new offense (defaults to pending, but will be slashed if markAsSlashed had been called for it) */
28
- addPendingOffense(offense: Offense): Promise<void>;
29
- /** Marks the given offenses as slashed (regardless of whether they are known or not) */
30
- markAsSlashed(offenses: OffenseIdentifier[]): Promise<void>;
26
+ /** Adds a new offense. Returns false if the offense is already pending. */
27
+ addOffense(offense: Offense): Promise<boolean>;
28
+ /** Removes pending offenses matching the given offense type, epoch/slot, and optional validators. */
29
+ clearOffenses(filter: ClearOffensesFilter): Promise<number>;
31
30
  /** Prunes all offenses expired from the store */
32
31
  clearExpiredOffenses(currentRound: bigint): Promise<number>;
33
32
  /** Generate a unique key for an offense */
34
33
  private getOffenseKey;
35
34
  private getRoundKey;
36
35
  }
37
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2ZmZW5zZXNfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZXMvb2ZmZW5zZXNfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQW9ELE1BQU0saUJBQWlCLENBQUM7QUFDM0csT0FBTyxFQUNMLEtBQUssT0FBTyxFQUNaLEtBQUssaUJBQWlCLEVBSXZCLE1BQU0sd0JBQXdCLENBQUM7QUFFaEMsZUFBTyxNQUFNLGNBQWMsSUFBSSxDQUFDO0FBRWhDLHFCQUFhLG9CQUFvQjtJQWE3QixPQUFPLENBQUMsT0FBTztJQUNmLE9BQU8sQ0FBQyxRQUFRO0lBYmxCLDJDQUEyQztJQUMzQyxPQUFPLENBQUMsUUFBUSxDQUFnQztJQUVoRCwwR0FBMEc7SUFDMUcsT0FBTyxDQUFDLGVBQWUsQ0FBd0I7SUFFL0MsbUZBQW1GO0lBQ25GLE9BQU8sQ0FBQyxjQUFjLENBQXFDO0lBRTNELE9BQU8sQ0FBQyxHQUFHLENBQTBDO0lBRXJELFlBQ1UsT0FBTyxFQUFFLGlCQUFpQixFQUMxQixRQUFRLEVBQUU7UUFDaEIsaUJBQWlCLEVBQUUsTUFBTSxDQUFDO1FBQzFCLGFBQWEsRUFBRSxNQUFNLENBQUM7UUFDdEIsNEJBQTRCLENBQUMsRUFBRSxNQUFNLENBQUM7S0FDdkMsRUFLRjtJQUVELGlEQUFpRDtJQUNwQyxrQkFBa0IsSUFBSSxPQUFPLENBQUMsT0FBTyxFQUFFLENBQUMsQ0FVcE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a,EAAE,MAAM,CAAC;QACtB,4BAA4B,CAAC,EAAE,MAAM,CAAC;KACvC,EAIF;IAED,2BAA2B;IACd,WAAW,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAM7C;IAED,uDAAuD;IAC1C,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAUlE;IAED,gDAAgD;IACnC,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,CAGpE;IAED,2EAA2E;IAC9D,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAkB1D;IAED,qGAAqG;IACxF,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAmCvE;IAED,iDAAiD;IACpC,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqCvE;IAED,2CAA2C;IAC3C,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,WAAW;CAGpB"}
@@ -5,8 +5,7 @@ export class SlasherOffensesStore {
5
5
  kvStore;
6
6
  settings;
7
7
  /** Map from offense key to offense data */ offenses;
8
- /** Map from offense key to whether the offense has been executed (only used for empire based slashing) */ offensesSlashed;
9
- /** Multimap from round to offense keys (only used for consensus based slashing) */ roundsOffenses;
8
+ /** Multimap from round to offense keys */ roundsOffenses;
10
9
  log;
11
10
  constructor(kvStore, settings){
12
11
  this.kvStore = kvStore;
@@ -14,16 +13,11 @@ export class SlasherOffensesStore {
14
13
  this.log = createLogger('slasher:store:offenses');
15
14
  this.offenses = kvStore.openMap('offenses');
16
15
  this.roundsOffenses = kvStore.openMultiMap('rounds-offenses');
17
- this.offensesSlashed = kvStore.openSet('offenses-slashed');
18
16
  }
19
- /** Returns all offenses not marked as slashed */ async getPendingOffenses() {
17
+ /** Returns all offenses */ async getOffenses() {
20
18
  const offenses = [];
21
- for await (const [key, buffer] of this.offenses.entriesAsync()){
22
- if (await this.offensesSlashed.hasAsync(key)) {
23
- continue; // Skip executed offenses
24
- }
25
- const offense = deserializeOffense(buffer);
26
- offenses.push(offense);
19
+ for await (const [, buffer] of this.offenses.entriesAsync()){
20
+ offenses.push(deserializeOffense(buffer));
27
21
  }
28
22
  return offenses;
29
23
  }
@@ -38,29 +32,60 @@ export class SlasherOffensesStore {
38
32
  }
39
33
  return offenses;
40
34
  }
41
- /** Returns whether an offense is pending (ie not marked as slashed) */ async hasPendingOffense(offense) {
42
- const key = this.getOffenseKey(offense);
43
- return await this.offenses.getAsync(key) !== undefined && !await this.offensesSlashed.hasAsync(key);
44
- }
45
35
  /** Returns whether we have seen this offense */ async hasOffense(offense) {
46
36
  const key = this.getOffenseKey(offense);
47
37
  return await this.offenses.getAsync(key) !== undefined;
48
38
  }
49
- /** Adds a new offense (defaults to pending, but will be slashed if markAsSlashed had been called for it) */ async addPendingOffense(offense) {
39
+ /** Adds a new offense. Returns false if the offense is already pending. */ async addOffense(offense) {
50
40
  const key = this.getOffenseKey(offense);
51
41
  const round = getRoundForOffense(offense, this.settings);
52
- await this.kvStore.transactionAsync(async ()=>{
42
+ const added = await this.kvStore.transactionAsync(async ()=>{
43
+ if (await this.offenses.getAsync(key) !== undefined) {
44
+ return false;
45
+ }
53
46
  await this.offenses.set(key, serializeOffense(offense));
54
47
  await this.roundsOffenses.set(this.getRoundKey(round), key);
48
+ return true;
55
49
  });
56
- this.log.trace(`Adding pending offense ${key} for round ${round}`);
50
+ if (added) {
51
+ this.log.trace(`Adding pending offense ${key} for round ${round}`);
52
+ }
53
+ return added;
57
54
  }
58
- /** Marks the given offenses as slashed (regardless of whether they are known or not) */ async markAsSlashed(offenses) {
59
- await this.kvStore.transactionAsync(async ()=>{
60
- for (const offense of offenses){
61
- const key = this.getOffenseKey(offense);
62
- await this.offensesSlashed.add(key);
55
+ /** Removes pending offenses matching the given offense type, epoch/slot, and optional validators. */ async clearOffenses(filter) {
56
+ return await this.kvStore.transactionAsync(async ()=>{
57
+ const offensesToClear = new Map();
58
+ if (filter.validators && filter.validators.length > 0) {
59
+ for (const validator of filter.validators){
60
+ const identifier = {
61
+ validator,
62
+ offenseType: filter.offenseType,
63
+ epochOrSlot: filter.epochOrSlot
64
+ };
65
+ const key = this.getOffenseKey(identifier);
66
+ const buffer = await this.offenses.getAsync(key);
67
+ if (buffer) {
68
+ offensesToClear.set(key, deserializeOffense(buffer));
69
+ }
70
+ }
71
+ } else {
72
+ for await (const [key, buffer] of this.offenses.entriesAsync()){
73
+ const offense = deserializeOffense(buffer);
74
+ if (offense.offenseType === filter.offenseType && offense.epochOrSlot === filter.epochOrSlot) {
75
+ offensesToClear.set(key, offense);
76
+ }
77
+ }
78
+ }
79
+ if (offensesToClear.size === 0) {
80
+ return 0;
63
81
  }
82
+ for (const [key, offense] of offensesToClear){
83
+ const round = getRoundForOffense(offense, this.settings);
84
+ await this.offenses.delete(key);
85
+ await this.roundsOffenses.deleteValue(this.getRoundKey(round), key);
86
+ this.log.trace(`Cleared pending offense ${key} for round ${round}`);
87
+ }
88
+ return offensesToClear.size;
64
89
  });
65
90
  }
66
91
  /** Prunes all offenses expired from the store */ async clearExpiredOffenses(currentRound) {
@@ -72,31 +97,29 @@ export class SlasherOffensesStore {
72
97
  if (expiredBefore < 0) {
73
98
  return 0; // Not enough rounds have passed to expire anything
74
99
  }
75
- // Collect expired offenses and rounds
76
- const expiredRoundKeys = new Set();
77
- const expiredOffenseKeys = new Set();
78
- for await (const [roundKey, offenseKey] of this.roundsOffenses.entriesAsync({
79
- end: this.getRoundKey(expiredBefore)
80
- })){
81
- expiredOffenseKeys.add(offenseKey);
82
- expiredRoundKeys.add(roundKey);
83
- }
84
- if (expiredOffenseKeys.size === 0 && expiredRoundKeys.size === 0) {
85
- return 0; // Nothing to clean up
86
- }
87
- // Remove expired stuff in a transaction
88
- await this.kvStore.transactionAsync(async ()=>{
100
+ return await this.kvStore.transactionAsync(async ()=>{
101
+ // Collect expired offenses and rounds
102
+ const expiredRoundKeys = new Set();
103
+ const expiredOffenseKeys = new Set();
104
+ for await (const [roundKey, offenseKey] of this.roundsOffenses.entriesAsync({
105
+ end: this.getRoundKey(expiredBefore)
106
+ })){
107
+ expiredOffenseKeys.add(offenseKey);
108
+ expiredRoundKeys.add(roundKey);
109
+ }
110
+ if (expiredOffenseKeys.size === 0 && expiredRoundKeys.size === 0) {
111
+ return 0; // Nothing to clean up
112
+ }
89
113
  for (const key of expiredOffenseKeys){
90
114
  this.log.trace(`Deleting offense ${key}`);
91
115
  await this.offenses.delete(key);
92
- await this.offensesSlashed.delete(key);
93
116
  }
94
117
  for (const roundKey of expiredRoundKeys){
95
118
  this.log.trace(`Deleting round info for ${roundKey}`);
96
119
  await this.roundsOffenses.delete(roundKey);
97
120
  }
121
+ return expiredOffenseKeys.size;
98
122
  });
99
- return expiredOffenseKeys.size;
100
123
  }
101
124
  /** Generate a unique key for an offense */ getOffenseKey(offense) {
102
125
  return `${offense.validator.toString()}:${offense.offenseType}:${offense.epochOrSlot}`;