@aztec/slasher 0.0.1-commit.fce3e4f → 0.0.1-commit.ffe5b04ea

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 (54) hide show
  1. package/README.md +24 -14
  2. package/dest/config.d.ts +1 -1
  3. package/dest/config.d.ts.map +1 -1
  4. package/dest/config.js +29 -17
  5. package/dest/empire_slasher_client.d.ts +2 -2
  6. package/dest/empire_slasher_client.d.ts.map +1 -1
  7. package/dest/empire_slasher_client.js +0 -8
  8. package/dest/factory/create_facade.d.ts +5 -4
  9. package/dest/factory/create_facade.d.ts.map +1 -1
  10. package/dest/factory/create_facade.js +26 -3
  11. package/dest/factory/create_implementation.d.ts +5 -4
  12. package/dest/factory/create_implementation.d.ts.map +1 -1
  13. package/dest/factory/create_implementation.js +11 -7
  14. package/dest/factory/get_settings.d.ts +3 -3
  15. package/dest/factory/get_settings.d.ts.map +1 -1
  16. package/dest/generated/slasher-defaults.d.ts +21 -0
  17. package/dest/generated/slasher-defaults.d.ts.map +1 -0
  18. package/dest/generated/slasher-defaults.js +21 -0
  19. package/dest/slash_offenses_collector.d.ts +5 -2
  20. package/dest/slash_offenses_collector.d.ts.map +1 -1
  21. package/dest/slash_offenses_collector.js +2 -2
  22. package/dest/slasher_client_facade.d.ts +5 -4
  23. package/dest/slasher_client_facade.d.ts.map +1 -1
  24. package/dest/slasher_client_facade.js +4 -2
  25. package/dest/stores/offenses_store.d.ts +1 -1
  26. package/dest/stores/offenses_store.d.ts.map +1 -1
  27. package/dest/stores/offenses_store.js +4 -2
  28. package/dest/stores/payloads_store.d.ts +1 -1
  29. package/dest/stores/payloads_store.d.ts.map +1 -1
  30. package/dest/stores/payloads_store.js +6 -3
  31. package/dest/tally_slasher_client.d.ts +2 -2
  32. package/dest/tally_slasher_client.d.ts.map +1 -1
  33. package/dest/tally_slasher_client.js +10 -5
  34. package/dest/watchers/attestations_block_watcher.d.ts +7 -6
  35. package/dest/watchers/attestations_block_watcher.d.ts.map +1 -1
  36. package/dest/watchers/attestations_block_watcher.js +40 -34
  37. package/dest/watchers/epoch_prune_watcher.d.ts +9 -7
  38. package/dest/watchers/epoch_prune_watcher.d.ts.map +1 -1
  39. package/dest/watchers/epoch_prune_watcher.js +56 -15
  40. package/package.json +16 -14
  41. package/src/config.ts +32 -17
  42. package/src/empire_slasher_client.ts +1 -9
  43. package/src/factory/create_facade.ts +35 -5
  44. package/src/factory/create_implementation.ts +30 -5
  45. package/src/factory/get_settings.ts +3 -3
  46. package/src/generated/slasher-defaults.ts +23 -0
  47. package/src/slash_offenses_collector.ts +8 -3
  48. package/src/slasher_client_facade.ts +4 -2
  49. package/src/stores/offenses_store.ts +4 -2
  50. package/src/stores/payloads_store.ts +7 -4
  51. package/src/tally_slasher_client.ts +12 -6
  52. package/src/watcher.ts +1 -1
  53. package/src/watchers/attestations_block_watcher.ts +57 -44
  54. package/src/watchers/epoch_prune_watcher.ts +84 -24
package/package.json CHANGED
@@ -1,20 +1,22 @@
1
1
  {
2
2
  "name": "@aztec/slasher",
3
- "version": "0.0.1-commit.fce3e4f",
3
+ "version": "0.0.1-commit.ffe5b04ea",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
7
7
  "./config": "./dest/config.js"
8
8
  },
9
9
  "inherits": [
10
- "../package.common.json"
10
+ "../package.common.json",
11
+ "./package.local.json"
11
12
  ],
12
13
  "scripts": {
13
- "build": "yarn clean && tsgo -b",
14
- "build:dev": "tsgo -b --watch",
14
+ "build": "yarn clean && ../scripts/tsc.sh",
15
+ "build:dev": "../scripts/tsc.sh --watch",
15
16
  "clean": "rm -rf ./dest .tsbuildinfo",
16
17
  "bb": "node --no-warnings ./dest/bb/index.js",
17
- "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
18
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
19
+ "generate": "./scripts/generate.sh"
18
20
  },
19
21
  "jest": {
20
22
  "moduleNameMapper": {
@@ -54,25 +56,25 @@
54
56
  ]
55
57
  },
56
58
  "dependencies": {
57
- "@aztec/epoch-cache": "0.0.1-commit.fce3e4f",
58
- "@aztec/ethereum": "0.0.1-commit.fce3e4f",
59
- "@aztec/foundation": "0.0.1-commit.fce3e4f",
60
- "@aztec/kv-store": "0.0.1-commit.fce3e4f",
61
- "@aztec/l1-artifacts": "0.0.1-commit.fce3e4f",
62
- "@aztec/stdlib": "0.0.1-commit.fce3e4f",
63
- "@aztec/telemetry-client": "0.0.1-commit.fce3e4f",
59
+ "@aztec/epoch-cache": "0.0.1-commit.ffe5b04ea",
60
+ "@aztec/ethereum": "0.0.1-commit.ffe5b04ea",
61
+ "@aztec/foundation": "0.0.1-commit.ffe5b04ea",
62
+ "@aztec/kv-store": "0.0.1-commit.ffe5b04ea",
63
+ "@aztec/l1-artifacts": "0.0.1-commit.ffe5b04ea",
64
+ "@aztec/stdlib": "0.0.1-commit.ffe5b04ea",
65
+ "@aztec/telemetry-client": "0.0.1-commit.ffe5b04ea",
64
66
  "source-map-support": "^0.5.21",
65
67
  "tslib": "^2.4.0",
66
68
  "viem": "npm:@aztec/viem@2.38.2",
67
69
  "zod": "^3.23.8"
68
70
  },
69
71
  "devDependencies": {
70
- "@aztec/aztec.js": "0.0.1-commit.fce3e4f",
72
+ "@aztec/aztec.js": "0.0.1-commit.ffe5b04ea",
71
73
  "@jest/globals": "^30.0.0",
72
74
  "@types/jest": "^30.0.0",
73
75
  "@types/node": "^22.15.17",
74
76
  "@types/source-map-support": "^0.5.10",
75
- "@typescript/native-preview": "7.0.0-dev.20251126.1",
77
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
76
78
  "jest": "^30.0.0",
77
79
  "jest-mock-extended": "^4.0.0",
78
80
  "ts-node": "^10.9.1",
package/src/config.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { DefaultL1ContractsConfig } from '@aztec/ethereum';
2
1
  import type { ConfigMappingsType } from '@aztec/foundation/config';
3
2
  import {
4
3
  bigintConfigHelper,
@@ -9,27 +8,31 @@ import {
9
8
  import { EthAddress } from '@aztec/foundation/eth-address';
10
9
  import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
11
10
 
11
+ import { slasherDefaultEnv } from './generated/slasher-defaults.js';
12
+
12
13
  export type { SlasherConfig };
13
14
 
14
15
  export const DefaultSlasherConfig: SlasherConfig = {
15
16
  slashOverridePayload: undefined,
16
- slashMinPenaltyPercentage: 0.5, // 50% of penalty
17
- slashMaxPenaltyPercentage: 2.0, //2x of penalty
17
+ slashMinPenaltyPercentage: slasherDefaultEnv.SLASH_MIN_PENALTY_PERCENTAGE,
18
+ slashMaxPenaltyPercentage: slasherDefaultEnv.SLASH_MAX_PENALTY_PERCENTAGE,
18
19
  slashValidatorsAlways: [], // Empty by default
19
20
  slashValidatorsNever: [], // Empty by default
20
- slashPrunePenalty: DefaultL1ContractsConfig.slashAmountSmall,
21
- slashDataWithholdingPenalty: DefaultL1ContractsConfig.slashAmountSmall,
22
- slashInactivityTargetPercentage: 0.9,
23
- slashInactivityConsecutiveEpochThreshold: 1, // Default to 1 for backward compatibility
24
- slashBroadcastedInvalidBlockPenalty: DefaultL1ContractsConfig.slashAmountSmall,
25
- slashInactivityPenalty: DefaultL1ContractsConfig.slashAmountSmall,
26
- slashProposeInvalidAttestationsPenalty: DefaultL1ContractsConfig.slashAmountSmall,
27
- slashAttestDescendantOfInvalidPenalty: DefaultL1ContractsConfig.slashAmountSmall,
28
- slashUnknownPenalty: DefaultL1ContractsConfig.slashAmountSmall,
29
- slashOffenseExpirationRounds: 4,
30
- slashMaxPayloadSize: 50,
31
- slashGracePeriodL2Slots: 0,
32
- slashExecuteRoundsLookBack: 4,
21
+ slashPrunePenalty: BigInt(slasherDefaultEnv.SLASH_PRUNE_PENALTY),
22
+ slashDataWithholdingPenalty: BigInt(slasherDefaultEnv.SLASH_DATA_WITHHOLDING_PENALTY),
23
+ slashInactivityTargetPercentage: slasherDefaultEnv.SLASH_INACTIVITY_TARGET_PERCENTAGE,
24
+ slashInactivityConsecutiveEpochThreshold: slasherDefaultEnv.SLASH_INACTIVITY_CONSECUTIVE_EPOCH_THRESHOLD,
25
+ slashBroadcastedInvalidBlockPenalty: BigInt(slasherDefaultEnv.SLASH_INVALID_BLOCK_PENALTY),
26
+ slashDuplicateProposalPenalty: BigInt(slasherDefaultEnv.SLASH_DUPLICATE_PROPOSAL_PENALTY),
27
+ slashDuplicateAttestationPenalty: BigInt(slasherDefaultEnv.SLASH_DUPLICATE_ATTESTATION_PENALTY),
28
+ slashInactivityPenalty: BigInt(slasherDefaultEnv.SLASH_INACTIVITY_PENALTY),
29
+ slashProposeInvalidAttestationsPenalty: BigInt(slasherDefaultEnv.SLASH_PROPOSE_INVALID_ATTESTATIONS_PENALTY),
30
+ slashAttestDescendantOfInvalidPenalty: BigInt(slasherDefaultEnv.SLASH_ATTEST_DESCENDANT_OF_INVALID_PENALTY),
31
+ slashUnknownPenalty: BigInt(slasherDefaultEnv.SLASH_UNKNOWN_PENALTY),
32
+ slashOffenseExpirationRounds: slasherDefaultEnv.SLASH_OFFENSE_EXPIRATION_ROUNDS,
33
+ slashMaxPayloadSize: slasherDefaultEnv.SLASH_MAX_PAYLOAD_SIZE,
34
+ slashGracePeriodL2Slots: slasherDefaultEnv.SLASH_GRACE_PERIOD_L2_SLOTS,
35
+ slashExecuteRoundsLookBack: slasherDefaultEnv.SLASH_EXECUTE_ROUNDS_LOOK_BACK,
33
36
  slashSelfAllowed: false,
34
37
  };
35
38
 
@@ -87,6 +90,17 @@ export const slasherConfigMappings: ConfigMappingsType<SlasherConfig> = {
87
90
  description: 'Penalty amount for slashing a validator for an invalid block proposed via p2p.',
88
91
  ...bigintConfigHelper(DefaultSlasherConfig.slashBroadcastedInvalidBlockPenalty),
89
92
  },
93
+ slashDuplicateProposalPenalty: {
94
+ env: 'SLASH_DUPLICATE_PROPOSAL_PENALTY',
95
+ description: 'Penalty amount for slashing a validator for sending duplicate proposals.',
96
+ ...bigintConfigHelper(DefaultSlasherConfig.slashDuplicateProposalPenalty),
97
+ },
98
+ slashDuplicateAttestationPenalty: {
99
+ env: 'SLASH_DUPLICATE_ATTESTATION_PENALTY',
100
+ description:
101
+ 'Penalty amount for slashing a validator for signing attestations for different proposals at the same slot.',
102
+ ...bigintConfigHelper(DefaultSlasherConfig.slashDuplicateAttestationPenalty),
103
+ },
90
104
  slashInactivityTargetPercentage: {
91
105
  env: 'SLASH_INACTIVITY_TARGET_PERCENTAGE',
92
106
  description:
@@ -141,7 +155,8 @@ export const slasherConfigMappings: ConfigMappingsType<SlasherConfig> = {
141
155
  ...numberConfigHelper(DefaultSlasherConfig.slashMaxPayloadSize),
142
156
  },
143
157
  slashGracePeriodL2Slots: {
144
- description: 'Number of L2 slots to wait before considering a slashing offense expired.',
158
+ description:
159
+ 'Number of L2 slots after the network upgrade during which slashing offenses are ignored. The upgrade time is determined from the CanonicalRollupUpdated event.',
145
160
  env: 'SLASH_GRACE_PERIOD_L2_SLOTS',
146
161
  ...numberConfigHelper(DefaultSlasherConfig.slashGracePeriodL2Slots),
147
162
  },
@@ -1,10 +1,9 @@
1
- import { EmpireSlashingProposerContract, RollupContract, SlasherContract } from '@aztec/ethereum';
1
+ import { EmpireSlashingProposerContract, RollupContract, SlasherContract } from '@aztec/ethereum/contracts';
2
2
  import { sumBigint } from '@aztec/foundation/bigint';
3
3
  import { SlotNumber } from '@aztec/foundation/branded-types';
4
4
  import { compactArray, filterAsync, maxBy, pick } from '@aztec/foundation/collection';
5
5
  import { EthAddress } from '@aztec/foundation/eth-address';
6
6
  import { createLogger } from '@aztec/foundation/log';
7
- import { sleep } from '@aztec/foundation/sleep';
8
7
  import type { DateProvider } from '@aztec/foundation/timer';
9
8
  import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
10
9
  import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
@@ -196,13 +195,6 @@ export class EmpireSlasherClient implements ProposerSlashActionProvider, Slasher
196
195
  this.roundMonitor.stop();
197
196
  await this.offensesCollector.stop();
198
197
 
199
- // Viem calls eth_uninstallFilter under the hood when uninstalling event watchers, but these calls are not awaited,
200
- // meaning that any error that happens during the uninstallation will not be caught. This causes errors during jest teardowns,
201
- // where we stop anvil after all other processes are stopped, so sometimes the eth_uninstallFilter call fails because anvil
202
- // is already stopped. We add a sleep here to give the uninstallation some time to complete, but the proper fix is for
203
- // viem to await the eth_uninstallFilter calls, or to catch any errors that happen during the uninstallation.
204
- // See https://github.com/wevm/viem/issues/3714.
205
- await sleep(2000);
206
198
  this.log.info('Empire Slasher client stopped');
207
199
  }
208
200
 
@@ -1,13 +1,16 @@
1
1
  import { EpochCache } from '@aztec/epoch-cache';
2
- import type { L1ReaderConfig, ViemClient } from '@aztec/ethereum';
3
- import { RollupContract } from '@aztec/ethereum/contracts';
2
+ import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
3
+ import type { L1ReaderConfig } from '@aztec/ethereum/l1-reader';
4
+ import type { ViemClient } from '@aztec/ethereum/types';
5
+ import { SlotNumber } from '@aztec/foundation/branded-types';
4
6
  import { unique } from '@aztec/foundation/collection';
5
7
  import { EthAddress } from '@aztec/foundation/eth-address';
6
8
  import { createLogger } from '@aztec/foundation/log';
7
9
  import { DateProvider } from '@aztec/foundation/timer';
8
- import type { DataStoreConfig } from '@aztec/kv-store/config';
9
10
  import { createStore } from '@aztec/kv-store/lmdb-v2';
11
+ import { getSlotAtTimestamp } from '@aztec/stdlib/epoch-helpers';
10
12
  import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
13
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
11
14
 
12
15
  import { SlasherClientFacade } from '../slasher_client_facade.js';
13
16
  import type { SlasherClientInterface } from '../slasher_client_interface.js';
@@ -17,7 +20,7 @@ import type { Watcher } from '../watcher.js';
17
20
  /** Creates a slasher client facade that updates itself whenever the rollup slasher changes */
18
21
  export async function createSlasherFacade(
19
22
  config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
20
- l1Contracts: Pick<L1ReaderConfig['l1Contracts'], 'rollupAddress' | 'slashFactoryAddress'>,
23
+ l1Contracts: Pick<L1ReaderConfig['l1Contracts'], 'rollupAddress' | 'slashFactoryAddress' | 'registryAddress'>,
21
24
  l1Client: ViemClient,
22
25
  watchers: Watcher[],
23
26
  dateProvider: DateProvider,
@@ -30,9 +33,35 @@ export async function createSlasherFacade(
30
33
  throw new Error('Cannot initialize SlasherClient without a Rollup address');
31
34
  }
32
35
 
33
- const kvStore = await createStore('slasher', SCHEMA_VERSION, config, createLogger('slasher:lmdb'));
36
+ const kvStore = await createStore('slasher', SCHEMA_VERSION, config, logger.getBindings());
34
37
  const rollup = new RollupContract(l1Client, l1Contracts.rollupAddress);
35
38
 
39
+ // Compute and cache the L2 slot at which the rollup was registered as canonical
40
+ const settingsMap = kvStore.openMap<string, number>('slasher-settings');
41
+ const cacheKey = `registeredSlot:${l1Contracts.rollupAddress}`;
42
+ let rollupRegisteredAtL2Slot = (await settingsMap.getAsync(cacheKey)) as SlotNumber | undefined;
43
+
44
+ if (rollupRegisteredAtL2Slot === undefined) {
45
+ const registry = new RegistryContract(l1Client, l1Contracts.registryAddress);
46
+ const l1StartBlock = await rollup.getL1StartBlock();
47
+ const registrationTimestamp = await registry.getCanonicalRollupRegistrationTimestamp(
48
+ l1Contracts.rollupAddress,
49
+ l1StartBlock,
50
+ );
51
+ if (registrationTimestamp !== undefined) {
52
+ const l1GenesisTime = await rollup.getL1GenesisTime();
53
+ const slotDuration = await rollup.getSlotDuration();
54
+ rollupRegisteredAtL2Slot = getSlotAtTimestamp(registrationTimestamp, {
55
+ l1GenesisTime,
56
+ slotDuration: Number(slotDuration),
57
+ });
58
+ } else {
59
+ rollupRegisteredAtL2Slot = SlotNumber(0);
60
+ }
61
+ await settingsMap.set(cacheKey, rollupRegisteredAtL2Slot);
62
+ logger.info(`Canonical rollup registered at L2 slot ${rollupRegisteredAtL2Slot}`);
63
+ }
64
+
36
65
  const slashValidatorsNever = config.slashSelfAllowed
37
66
  ? config.slashValidatorsNever
38
67
  : unique([...config.slashValidatorsNever, ...validatorAddresses].map(a => a.toString())).map(EthAddress.fromString);
@@ -47,6 +76,7 @@ export async function createSlasherFacade(
47
76
  epochCache,
48
77
  dateProvider,
49
78
  kvStore,
79
+ rollupRegisteredAtL2Slot,
50
80
  logger,
51
81
  );
52
82
  }
@@ -1,16 +1,17 @@
1
1
  import { EpochCache } from '@aztec/epoch-cache';
2
- import type { ViemClient } from '@aztec/ethereum';
3
2
  import {
4
3
  EmpireSlashingProposerContract,
5
4
  RollupContract,
6
5
  TallySlashingProposerContract,
7
6
  } from '@aztec/ethereum/contracts';
7
+ import type { ViemClient } from '@aztec/ethereum/types';
8
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
8
9
  import { EthAddress } from '@aztec/foundation/eth-address';
9
10
  import { createLogger } from '@aztec/foundation/log';
10
11
  import { DateProvider } from '@aztec/foundation/timer';
11
- import type { DataStoreConfig } from '@aztec/kv-store/config';
12
12
  import { AztecLMDBStoreV2 } from '@aztec/kv-store/lmdb-v2';
13
13
  import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
14
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
14
15
  import { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
15
16
 
16
17
  import { EmpireSlasherClient, type EmpireSlasherSettings } from '../empire_slasher_client.js';
@@ -31,19 +32,40 @@ export async function createSlasherImplementation(
31
32
  epochCache: EpochCache,
32
33
  dateProvider: DateProvider,
33
34
  kvStore: AztecLMDBStoreV2,
35
+ rollupRegisteredAtL2Slot: SlotNumber,
34
36
  logger = createLogger('slasher'),
35
37
  ) {
36
38
  const proposer = await rollup.getSlashingProposer();
37
39
  if (!proposer) {
38
40
  return new NullSlasherClient(config);
39
41
  } else if (proposer.type === 'tally') {
40
- return createTallySlasher(config, rollup, proposer, watchers, dateProvider, epochCache, kvStore, logger);
42
+ return createTallySlasher(
43
+ config,
44
+ rollup,
45
+ proposer,
46
+ watchers,
47
+ dateProvider,
48
+ epochCache,
49
+ kvStore,
50
+ rollupRegisteredAtL2Slot,
51
+ logger,
52
+ );
41
53
  } else {
42
54
  if (!slashFactoryAddress || slashFactoryAddress.equals(EthAddress.ZERO)) {
43
55
  throw new Error('Cannot initialize an empire-based SlasherClient without a SlashFactory address');
44
56
  }
45
57
  const slashFactory = new SlashFactoryContract(l1Client, slashFactoryAddress.toString());
46
- return createEmpireSlasher(config, rollup, proposer, slashFactory, watchers, dateProvider, kvStore, logger);
58
+ return createEmpireSlasher(
59
+ config,
60
+ rollup,
61
+ proposer,
62
+ slashFactory,
63
+ watchers,
64
+ dateProvider,
65
+ kvStore,
66
+ rollupRegisteredAtL2Slot,
67
+ logger,
68
+ );
47
69
  }
48
70
  }
49
71
 
@@ -55,6 +77,7 @@ async function createEmpireSlasher(
55
77
  watchers: Watcher[],
56
78
  dateProvider: DateProvider,
57
79
  kvStore: AztecLMDBStoreV2,
80
+ rollupRegisteredAtL2Slot: SlotNumber,
58
81
  logger = createLogger('slasher'),
59
82
  ): Promise<EmpireSlasherClient> {
60
83
  if (slashingProposer.type !== 'empire') {
@@ -97,6 +120,7 @@ async function createEmpireSlasher(
97
120
  l1StartBlock,
98
121
  ethereumSlotDuration: config.ethereumSlotDuration,
99
122
  slashingAmounts: undefined,
123
+ rollupRegisteredAtL2Slot,
100
124
  };
101
125
 
102
126
  const payloadsStore = new SlasherPayloadsStore(kvStore, {
@@ -130,13 +154,14 @@ async function createTallySlasher(
130
154
  dateProvider: DateProvider,
131
155
  epochCache: EpochCache,
132
156
  kvStore: AztecLMDBStoreV2,
157
+ rollupRegisteredAtL2Slot: SlotNumber,
133
158
  logger = createLogger('slasher'),
134
159
  ): Promise<TallySlasherClient> {
135
160
  if (slashingProposer.type !== 'tally') {
136
161
  throw new Error('Slashing proposer contract is not of type tally');
137
162
  }
138
163
 
139
- const settings = await getTallySlasherSettings(rollup, slashingProposer);
164
+ const settings = { ...(await getTallySlasherSettings(rollup, slashingProposer)), rollupRegisteredAtL2Slot };
140
165
  const slasher = await rollup.getSlasherContract();
141
166
 
142
167
  const offensesStore = new SlasherOffensesStore(kvStore, {
@@ -1,11 +1,11 @@
1
- import type { RollupContract, TallySlashingProposerContract } from '@aztec/ethereum';
1
+ import type { RollupContract, TallySlashingProposerContract } from '@aztec/ethereum/contracts';
2
2
 
3
3
  import type { TallySlasherSettings } from '../tally_slasher_client.js';
4
4
 
5
5
  export async function getTallySlasherSettings(
6
6
  rollup: RollupContract,
7
7
  slashingProposer?: TallySlashingProposerContract,
8
- ): Promise<TallySlasherSettings> {
8
+ ): Promise<Omit<TallySlasherSettings, 'rollupRegisteredAtL2Slot'>> {
9
9
  if (!slashingProposer) {
10
10
  const rollupSlashingProposer = await rollup.getSlashingProposer();
11
11
  if (!rollupSlashingProposer || rollupSlashingProposer.type !== 'tally') {
@@ -40,7 +40,7 @@ export async function getTallySlasherSettings(
40
40
  rollup.getTargetCommitteeSize(),
41
41
  ]);
42
42
 
43
- const settings: TallySlasherSettings = {
43
+ const settings: Omit<TallySlasherSettings, 'rollupRegisteredAtL2Slot'> = {
44
44
  slashingExecutionDelayInRounds: Number(slashingExecutionDelayInRounds),
45
45
  slashingRoundSize: Number(slashingRoundSize),
46
46
  slashingRoundSizeInEpochs: Number(slashingRoundSizeInEpochs),
@@ -0,0 +1,23 @@
1
+ // Auto-generated from spartan/environments/network-defaults.yml
2
+ // Do not edit manually - run yarn generate to regenerate
3
+
4
+ /** Default slasher configuration values from network-defaults.yml */
5
+ export const slasherDefaultEnv = {
6
+ SLASH_MIN_PENALTY_PERCENTAGE: 0.5,
7
+ SLASH_MAX_PENALTY_PERCENTAGE: 2,
8
+ SLASH_OFFENSE_EXPIRATION_ROUNDS: 4,
9
+ SLASH_MAX_PAYLOAD_SIZE: 80,
10
+ SLASH_EXECUTE_ROUNDS_LOOK_BACK: 4,
11
+ SLASH_PRUNE_PENALTY: 10000000000000000000,
12
+ SLASH_DATA_WITHHOLDING_PENALTY: 10000000000000000000,
13
+ SLASH_INACTIVITY_TARGET_PERCENTAGE: 0.9,
14
+ SLASH_INACTIVITY_CONSECUTIVE_EPOCH_THRESHOLD: 1,
15
+ SLASH_INACTIVITY_PENALTY: 10000000000000000000,
16
+ SLASH_PROPOSE_INVALID_ATTESTATIONS_PENALTY: 10000000000000000000,
17
+ SLASH_ATTEST_DESCENDANT_OF_INVALID_PENALTY: 10000000000000000000,
18
+ SLASH_DUPLICATE_PROPOSAL_PENALTY: 0,
19
+ SLASH_DUPLICATE_ATTESTATION_PENALTY: 0,
20
+ SLASH_UNKNOWN_PENALTY: 10000000000000000000,
21
+ SLASH_INVALID_BLOCK_PENALTY: 10000000000000000000,
22
+ SLASH_GRACE_PERIOD_L2_SLOTS: 0,
23
+ } as const;
@@ -1,3 +1,4 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import { createLogger } from '@aztec/foundation/log';
2
3
  import type { Prettify } from '@aztec/foundation/types';
3
4
  import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
@@ -9,7 +10,11 @@ import { WANT_TO_SLASH_EVENT, type WantToSlashArgs, type Watcher } from './watch
9
10
 
10
11
  export type SlashOffensesCollectorConfig = Prettify<Pick<SlasherConfig, 'slashGracePeriodL2Slots'>>;
11
12
  export type SlashOffensesCollectorSettings = Prettify<
12
- Pick<L1RollupConstants, 'epochDuration'> & { slashingAmounts: [bigint, bigint, bigint] | undefined }
13
+ Pick<L1RollupConstants, 'epochDuration'> & {
14
+ slashingAmounts: [bigint, bigint, bigint] | undefined;
15
+ /** L2 slot at which the rollup was registered as canonical in the Registry. Used to anchor the slash grace period. */
16
+ rollupRegisteredAtL2Slot: SlotNumber;
17
+ }
13
18
  >;
14
19
 
15
20
  /**
@@ -110,9 +115,9 @@ export class SlashOffensesCollector {
110
115
  return this.offensesStore.markAsSlashed(offenses);
111
116
  }
112
117
 
113
- /** Returns whether to skip an offense if it happened during the grace period at the beginning of the chain */
118
+ /** Returns whether to skip an offense if it happened during the grace period after the network upgrade */
114
119
  private shouldSkipOffense(offense: Offense): boolean {
115
120
  const offenseSlot = getSlotForOffense(offense, this.settings);
116
- return offenseSlot < this.config.slashGracePeriodL2Slots;
121
+ return offenseSlot < this.settings.rollupRegisteredAtL2Slot + this.config.slashGracePeriodL2Slots;
117
122
  }
118
123
  }
@@ -1,13 +1,13 @@
1
1
  import { EpochCache } from '@aztec/epoch-cache';
2
- import type { ViemClient } from '@aztec/ethereum';
3
2
  import { RollupContract } from '@aztec/ethereum/contracts';
3
+ import type { ViemClient } from '@aztec/ethereum/types';
4
4
  import type { SlotNumber } from '@aztec/foundation/branded-types';
5
5
  import { EthAddress } from '@aztec/foundation/eth-address';
6
6
  import { createLogger } from '@aztec/foundation/log';
7
7
  import { DateProvider } from '@aztec/foundation/timer';
8
- import type { DataStoreConfig } from '@aztec/kv-store/config';
9
8
  import { AztecLMDBStoreV2 } from '@aztec/kv-store/lmdb-v2';
10
9
  import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
10
+ import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
11
11
  import type { Offense, ProposerSlashAction, SlashPayloadRound } from '@aztec/stdlib/slashing';
12
12
 
13
13
  import { createSlasherImplementation } from './factory/create_implementation.js';
@@ -32,6 +32,7 @@ export class SlasherClientFacade implements SlasherClientInterface {
32
32
  private epochCache: EpochCache,
33
33
  private dateProvider: DateProvider,
34
34
  private kvStore: AztecLMDBStoreV2,
35
+ private rollupRegisteredAtL2Slot: SlotNumber,
35
36
  private logger = createLogger('slasher'),
36
37
  ) {}
37
38
 
@@ -88,6 +89,7 @@ export class SlasherClientFacade implements SlasherClientInterface {
88
89
  this.epochCache,
89
90
  this.dateProvider,
90
91
  this.kvStore,
92
+ this.rollupRegisteredAtL2Slot,
91
93
  this.logger,
92
94
  );
93
95
  }
@@ -76,9 +76,11 @@ export class SlasherOffensesStore {
76
76
  /** Adds a new offense (defaults to pending, but will be slashed if markAsSlashed had been called for it) */
77
77
  public async addPendingOffense(offense: Offense): Promise<void> {
78
78
  const key = this.getOffenseKey(offense);
79
- await this.offenses.set(key, serializeOffense(offense));
80
79
  const round = getRoundForOffense(offense, this.settings);
81
- await this.roundsOffenses.set(this.getRoundKey(round), key);
80
+ await this.kvStore.transactionAsync(async () => {
81
+ await this.offenses.set(key, serializeOffense(offense));
82
+ await this.roundsOffenses.set(this.getRoundKey(round), key);
83
+ });
82
84
  this.log.trace(`Adding pending offense ${key} for round ${round}`);
83
85
  }
84
86
 
@@ -118,10 +118,13 @@ export class SlasherPayloadsStore {
118
118
 
119
119
  public async incrementPayloadVotes(payloadAddress: EthAddress, round: bigint): Promise<bigint> {
120
120
  const key = this.getPayloadVotesKey(round, payloadAddress);
121
- const currentVotes = (await this.roundPayloadVotes.getAsync(key)) || 0n;
122
- const newVotes = currentVotes + 1n;
123
- await this.roundPayloadVotes.set(key, newVotes);
124
- return newVotes;
121
+ let newVotes: bigint;
122
+ await this.kvStore.transactionAsync(async () => {
123
+ const currentVotes = (await this.roundPayloadVotes.getAsync(key)) || 0n;
124
+ newVotes = currentVotes + 1n;
125
+ await this.roundPayloadVotes.set(key, newVotes);
126
+ });
127
+ return newVotes!;
125
128
  }
126
129
 
127
130
  public async addPayload(payload: SlashPayloadRound): Promise<void> {
@@ -5,7 +5,6 @@ import { maxBigint } from '@aztec/foundation/bigint';
5
5
  import { SlotNumber } from '@aztec/foundation/branded-types';
6
6
  import { compactArray, partition, times } from '@aztec/foundation/collection';
7
7
  import { createLogger } from '@aztec/foundation/log';
8
- import { sleep } from '@aztec/foundation/sleep';
9
8
  import type { DateProvider } from '@aztec/foundation/timer';
10
9
  import type { Prettify } from '@aztec/foundation/types';
11
10
  import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
@@ -47,7 +46,10 @@ export type TallySlasherSettings = Prettify<
47
46
  >;
48
47
 
49
48
  export type TallySlasherClientConfig = SlashOffensesCollectorConfig &
50
- Pick<SlasherConfig, 'slashValidatorsAlways' | 'slashValidatorsNever' | 'slashExecuteRoundsLookBack'>;
49
+ Pick<
50
+ SlasherConfig,
51
+ 'slashValidatorsAlways' | 'slashValidatorsNever' | 'slashExecuteRoundsLookBack' | 'slashMaxPayloadSize'
52
+ >;
51
53
 
52
54
  /**
53
55
  * The Tally Slasher client is responsible for managing slashable offenses using
@@ -138,8 +140,6 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
138
140
  this.roundMonitor.stop();
139
141
  await this.offensesCollector.stop();
140
142
 
141
- // Sleeping to sidestep viem issue with unwatching events
142
- await sleep(2000);
143
143
  this.log.info('Tally Slasher client stopped');
144
144
  }
145
145
 
@@ -281,8 +281,12 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
281
281
  return undefined;
282
282
  }
283
283
 
284
+ const slashActionsWithAmounts = slashActions.map(action => ({
285
+ validator: action.validator.toString(),
286
+ slashAmount: action.slashAmount.toString(),
287
+ }));
284
288
  this.log.info(`Round ${executableRound} is ready to execute with ${slashActions.length} slashes`, {
285
- slashActions,
289
+ slashActions: slashActionsWithAmounts,
286
290
  payloadAddress: payload.address.toString(),
287
291
  ...logData,
288
292
  });
@@ -357,11 +361,13 @@ export class TallySlasherClient implements ProposerSlashActionProvider, SlasherC
357
361
 
358
362
  const committees = await this.collectCommitteesActiveDuringRound(slashedRound);
359
363
  const epochsForCommittees = getEpochsForRound(slashedRound, this.settings);
364
+ const { slashMaxPayloadSize } = this.config;
360
365
  const votes = getSlashConsensusVotesFromOffenses(
361
366
  offensesToSlash,
362
367
  committees,
363
368
  epochsForCommittees.map(e => BigInt(e)),
364
- this.settings,
369
+ { ...this.settings, maxSlashedValidators: slashMaxPayloadSize },
370
+ this.log,
365
371
  );
366
372
  if (votes.every(v => v === 0)) {
367
373
  this.log.warn(`Computed votes for offenses are all zero. Skipping vote.`, {
package/src/watcher.ts CHANGED
@@ -10,7 +10,7 @@ export interface WantToSlashArgs {
10
10
  validator: EthAddress;
11
11
  amount: bigint;
12
12
  offenseType: OffenseType;
13
- epochOrSlot: bigint; // Epoch number for epoch-based offenses, block number for block-based
13
+ epochOrSlot: bigint; // Epoch number for epoch-based offenses, slot number for slot-based
14
14
  }
15
15
 
16
16
  // Event map for specific, known events of a watcher