@aztec/slasher 0.0.1-commit.9d2bcf6d → 0.0.1-commit.9ebd450e8
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.
- package/README.md +51 -65
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +14 -14
- package/dest/factory/create_facade.d.ts +3 -3
- package/dest/factory/create_facade.d.ts.map +1 -1
- package/dest/factory/create_facade.js +25 -2
- package/dest/factory/create_implementation.d.ts +6 -7
- package/dest/factory/create_implementation.d.ts.map +1 -1
- package/dest/factory/create_implementation.js +8 -56
- package/dest/factory/get_settings.d.ts +4 -4
- package/dest/factory/get_settings.d.ts.map +1 -1
- package/dest/factory/get_settings.js +3 -3
- package/dest/factory/index.d.ts +2 -2
- package/dest/factory/index.d.ts.map +1 -1
- package/dest/factory/index.js +1 -1
- package/dest/generated/slasher-defaults.d.ts +3 -3
- package/dest/generated/slasher-defaults.js +3 -3
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/null_slasher_client.d.ts +3 -4
- package/dest/null_slasher_client.d.ts.map +1 -1
- package/dest/null_slasher_client.js +1 -4
- package/dest/slash_offenses_collector.d.ts +5 -8
- package/dest/slash_offenses_collector.d.ts.map +1 -1
- package/dest/slash_offenses_collector.js +9 -22
- package/dest/slasher_client.d.ts +112 -0
- package/dest/slasher_client.d.ts.map +1 -0
- package/dest/{tally_slasher_client.js → slasher_client.js} +26 -40
- package/dest/slasher_client_facade.d.ts +6 -8
- package/dest/slasher_client_facade.d.ts.map +1 -1
- package/dest/slasher_client_facade.js +6 -9
- package/dest/slasher_client_interface.d.ts +7 -21
- package/dest/slasher_client_interface.d.ts.map +1 -1
- package/dest/slasher_client_interface.js +1 -4
- package/dest/stores/offenses_store.d.ts +6 -12
- package/dest/stores/offenses_store.d.ts.map +1 -1
- package/dest/stores/offenses_store.js +5 -24
- package/dest/watchers/epoch_prune_watcher.d.ts +6 -5
- package/dest/watchers/epoch_prune_watcher.d.ts.map +1 -1
- package/dest/watchers/epoch_prune_watcher.js +47 -26
- package/package.json +9 -9
- package/src/config.ts +16 -14
- package/src/factory/create_facade.ts +32 -4
- package/src/factory/create_implementation.ts +24 -105
- package/src/factory/get_settings.ts +8 -8
- package/src/factory/index.ts +1 -1
- package/src/generated/slasher-defaults.ts +3 -3
- package/src/index.ts +1 -2
- package/src/null_slasher_client.ts +2 -6
- package/src/slash_offenses_collector.ts +16 -24
- package/src/{tally_slasher_client.ts → slasher_client.ts} +33 -49
- package/src/slasher_client_facade.ts +6 -11
- package/src/slasher_client_interface.ts +6 -21
- package/src/stores/offenses_store.ts +8 -33
- package/src/watchers/epoch_prune_watcher.ts +61 -26
- package/dest/empire_slasher_client.d.ts +0 -190
- package/dest/empire_slasher_client.d.ts.map +0 -1
- package/dest/empire_slasher_client.js +0 -564
- package/dest/stores/payloads_store.d.ts +0 -29
- package/dest/stores/payloads_store.d.ts.map +0 -1
- package/dest/stores/payloads_store.js +0 -128
- package/dest/tally_slasher_client.d.ts +0 -125
- package/dest/tally_slasher_client.d.ts.map +0 -1
- package/src/empire_slasher_client.ts +0 -649
- package/src/stores/payloads_store.ts +0 -149
|
@@ -6,9 +6,7 @@ export declare class SlasherOffensesStore {
|
|
|
6
6
|
private settings;
|
|
7
7
|
/** Map from offense key to offense data */
|
|
8
8
|
private offenses;
|
|
9
|
-
/**
|
|
10
|
-
private offensesSlashed;
|
|
11
|
-
/** Multimap from round to offense keys (only used for consensus based slashing) */
|
|
9
|
+
/** Multimap from round to offense keys */
|
|
12
10
|
private roundsOffenses;
|
|
13
11
|
private log;
|
|
14
12
|
constructor(kvStore: AztecAsyncKVStore, settings: {
|
|
@@ -16,22 +14,18 @@ export declare class SlasherOffensesStore {
|
|
|
16
14
|
epochDuration: number;
|
|
17
15
|
slashOffenseExpirationRounds?: number;
|
|
18
16
|
});
|
|
19
|
-
/** Returns all offenses
|
|
20
|
-
|
|
17
|
+
/** Returns all offenses */
|
|
18
|
+
getOffenses(): Promise<Offense[]>;
|
|
21
19
|
/** Returns all offenses tracked for the given round */
|
|
22
20
|
getOffensesForRound(round: bigint): Promise<Offense[]>;
|
|
23
|
-
/** Returns whether an offense is pending (ie not marked as slashed) */
|
|
24
|
-
hasPendingOffense(offense: OffenseIdentifier): Promise<boolean>;
|
|
25
21
|
/** Returns whether we have seen this offense */
|
|
26
22
|
hasOffense(offense: OffenseIdentifier): Promise<boolean>;
|
|
27
|
-
/** Adds a new offense
|
|
28
|
-
|
|
29
|
-
/** Marks the given offenses as slashed (regardless of whether they are known or not) */
|
|
30
|
-
markAsSlashed(offenses: OffenseIdentifier[]): Promise<void>;
|
|
23
|
+
/** Adds a new offense */
|
|
24
|
+
addOffense(offense: Offense): Promise<void>;
|
|
31
25
|
/** Prunes all offenses expired from the store */
|
|
32
26
|
clearExpiredOffenses(currentRound: bigint): Promise<number>;
|
|
33
27
|
/** Generate a unique key for an offense */
|
|
34
28
|
private getOffenseKey;
|
|
35
29
|
private getRoundKey;
|
|
36
30
|
}
|
|
37
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
31
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2ZmZW5zZXNfc3RvcmUuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zdG9yZXMvb2ZmZW5zZXNfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQXFDLE1BQU0saUJBQWlCLENBQUM7QUFDNUYsT0FBTyxFQUNMLEtBQUssT0FBTyxFQUNaLEtBQUssaUJBQWlCLEVBSXZCLE1BQU0sd0JBQXdCLENBQUM7QUFFaEMsZUFBTyxNQUFNLGNBQWMsSUFBSSxDQUFDO0FBRWhDLHFCQUFhLG9CQUFvQjtJQVU3QixPQUFPLENBQUMsT0FBTztJQUNmLE9BQU8sQ0FBQyxRQUFRO0lBVmxCLDJDQUEyQztJQUMzQyxPQUFPLENBQUMsUUFBUSxDQUFnQztJQUVoRCwwQ0FBMEM7SUFDMUMsT0FBTyxDQUFDLGNBQWMsQ0FBcUM7SUFFM0QsT0FBTyxDQUFDLEdBQUcsQ0FBMEM7SUFFckQsWUFDVSxPQUFPLEVBQUUsaUJBQWlCLEVBQzFCLFFBQVEsRUFBRTtRQUNoQixpQkFBaUIsRUFBRSxNQUFNLENBQUM7UUFDMUIsYUFBYSxFQUFFLE1BQU0sQ0FBQztRQUN0Qiw0QkFBNEIsQ0FBQyxFQUFFLE1BQU0sQ0FBQztLQUN2QyxFQUlGO0lBRUQsMkJBQTJCO0lBQ2QsV0FBVyxJQUFJLE9BQU8sQ0FBQyxPQUFPLEVBQUUsQ0FBQyxDQU03QztJQUVELHVEQUF1RDtJQUMxQyxtQkFBbUIsQ0FBQyxLQUFLLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxPQUFPLEVBQUUsQ0FBQyxDQVVsRTtJQUVELGdEQUFnRDtJQUNuQyxVQUFVLENBQUMsT0FBTyxFQUFFLGlCQUFpQixHQUFHLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FHcEU7SUFFRCx5QkFBeUI7SUFDWixVQUFVLENBQUMsT0FBTyxFQUFFLE9BQU8sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBUXZEO0lBRUQsaURBQWlEO0lBQ3BDLG9CQUFvQixDQUFDLFlBQVksRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQXNDdkU7SUFFRCwyQ0FBMkM7SUFDM0MsT0FBTyxDQUFDLGFBQWE7SUFJckIsT0FBTyxDQUFDLFdBQVc7Q0FHcEIifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"offenses_store.d.ts","sourceRoot":"","sources":["../../src/stores/offenses_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"offenses_store.d.ts","sourceRoot":"","sources":["../../src/stores/offenses_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAqC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,iBAAiB,EAIvB,MAAM,wBAAwB,CAAC;AAEhC,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,qBAAa,oBAAoB;IAU7B,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,QAAQ;IAVlB,2CAA2C;IAC3C,OAAO,CAAC,QAAQ,CAAgC;IAEhD,0CAA0C;IAC1C,OAAO,CAAC,cAAc,CAAqC;IAE3D,OAAO,CAAC,GAAG,CAA0C;IAErD,YACU,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE;QAChB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,aAAa,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,yBAAyB;IACZ,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAQvD;IAED,iDAAiD;IACpC,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAsCvE;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
|
-
/**
|
|
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
|
|
17
|
+
/** Returns all offenses */ async getOffenses() {
|
|
20
18
|
const offenses = [];
|
|
21
|
-
for await (const [
|
|
22
|
-
|
|
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,15 +32,11 @@ 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
|
|
39
|
+
/** Adds a new offense */ async addOffense(offense) {
|
|
50
40
|
const key = this.getOffenseKey(offense);
|
|
51
41
|
const round = getRoundForOffense(offense, this.settings);
|
|
52
42
|
await this.kvStore.transactionAsync(async ()=>{
|
|
@@ -55,14 +45,6 @@ export class SlasherOffensesStore {
|
|
|
55
45
|
});
|
|
56
46
|
this.log.trace(`Adding pending offense ${key} for round ${round}`);
|
|
57
47
|
}
|
|
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);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
48
|
/** Prunes all offenses expired from the store */ async clearExpiredOffenses(currentRound) {
|
|
67
49
|
const expirationRounds = this.settings.slashOffenseExpirationRounds ?? 0;
|
|
68
50
|
if (expirationRounds <= 0) {
|
|
@@ -89,7 +71,6 @@ export class SlasherOffensesStore {
|
|
|
89
71
|
for (const key of expiredOffenseKeys){
|
|
90
72
|
this.log.trace(`Deleting offense ${key}`);
|
|
91
73
|
await this.offenses.delete(key);
|
|
92
|
-
await this.offensesSlashed.delete(key);
|
|
93
74
|
}
|
|
94
75
|
for (const roundKey of expiredRoundKeys){
|
|
95
76
|
this.log.trace(`Deleting round info for ${roundKey}`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import
|
|
2
|
+
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { L2Block, type L2BlockSourceEventEmitter } from '@aztec/stdlib/block';
|
|
4
|
-
import type { ICheckpointsBuilder, ITxProvider,
|
|
4
|
+
import type { ICheckpointsBuilder, ITxProvider, SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
5
5
|
import { type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
6
6
|
import { type Watcher, type WatcherEmitter } from '../watcher.js';
|
|
7
7
|
declare const EpochPruneWatcherPenaltiesConfigKeys: readonly ["slashPrunePenalty", "slashDataWithholdingPenalty"];
|
|
@@ -29,10 +29,11 @@ export declare class EpochPruneWatcher extends EpochPruneWatcher_base implements
|
|
|
29
29
|
private handlePruneL2Blocks;
|
|
30
30
|
private emitSlashForEpoch;
|
|
31
31
|
private processPruneL2Blocks;
|
|
32
|
-
validateBlocks(blocks: L2Block[]): Promise<void>;
|
|
33
|
-
|
|
32
|
+
validateBlocks(blocks: L2Block[], epochNumber: EpochNumber): Promise<void>;
|
|
33
|
+
private validateCheckpoint;
|
|
34
|
+
private validateBlockInCheckpoint;
|
|
34
35
|
private getValidatorsForEpoch;
|
|
35
36
|
private validatorsToSlashingArgs;
|
|
36
37
|
}
|
|
37
38
|
export {};
|
|
38
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
39
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXBvY2hfcHJ1bmVfd2F0Y2hlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3dhdGNoZXJzL2Vwb2NoX3BydW5lX3dhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLG9CQUFvQixDQUFDO0FBQ2hELE9BQU8sRUFBZSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUkzRSxPQUFPLEVBRUwsT0FBTyxFQUNQLEtBQUsseUJBQXlCLEVBRy9CLE1BQU0scUJBQXFCLENBQUM7QUFFN0IsT0FBTyxLQUFLLEVBRVYsbUJBQW1CLEVBQ25CLFdBQVcsRUFFWCxhQUFhLEVBQ2QsTUFBTSxpQ0FBaUMsQ0FBQztBQUN6QyxPQUFPLEVBQUUsS0FBSyxtQkFBbUIsRUFBNEIsTUFBTSx5QkFBeUIsQ0FBQztBQVk3RixPQUFPLEVBQTZDLEtBQUssT0FBTyxFQUFFLEtBQUssY0FBYyxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBRTdHLFFBQUEsTUFBTSxvQ0FBb0MsK0RBQWdFLENBQUM7QUFFM0csS0FBSywwQkFBMEIsR0FBRyxJQUFJLENBQUMsYUFBYSxFQUFFLENBQUMsT0FBTyxvQ0FBb0MsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7O0FBRTdHOzs7OztHQUtHO0FBQ0gscUJBQWEsaUJBQWtCLFNBQVEsc0JBQTJDLFlBQVcsT0FBTztJQVNoRyxPQUFPLENBQUMsYUFBYTtJQUNyQixPQUFPLENBQUMsbUJBQW1CO0lBQzNCLE9BQU8sQ0FBQyxVQUFVO0lBQ2xCLE9BQU8sQ0FBQyxVQUFVO0lBQ2xCLE9BQU8sQ0FBQyxrQkFBa0I7SUFaNUIsT0FBTyxDQUFDLEdBQUcsQ0FBK0M7SUFHMUQsT0FBTyxDQUFDLHdCQUF3QixDQUF1QztJQUV2RSxPQUFPLENBQUMsU0FBUyxDQUE2QjtJQUU5QyxZQUNVLGFBQWEsRUFBRSx5QkFBeUIsRUFDeEMsbUJBQW1CLEVBQUUsbUJBQW1CLEVBQ3hDLFVBQVUsRUFBRSxVQUFVLEVBQ3RCLFVBQVUsRUFBRSxJQUFJLENBQUMsV0FBVyxFQUFFLGlCQUFpQixDQUFDLEVBQ2hELGtCQUFrQixFQUFFLG1CQUFtQixFQUMvQyxTQUFTLEVBQUUsMEJBQTBCLEVBT3RDO0lBRU0sS0FBSyxrQkFHWDtJQUVNLElBQUksa0JBR1Y7SUFFTSxZQUFZLENBQUMsTUFBTSxFQUFFLE9BQU8sQ0FBQyxhQUFhLENBQUMsR0FBRyxJQUFJLENBR3hEO0lBRUQsT0FBTyxDQUFDLG1CQUFtQjtZQU9iLGlCQUFpQjtZQVdqQixvQkFBb0I7SUF3QnJCLGNBQWMsQ0FBQyxNQUFNLEVBQUUsT0FBTyxFQUFFLEVBQUUsV0FBVyxFQUFFLFdBQVcsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBK0J0RjtZQUVhLGtCQUFrQjtZQXdDbEIseUJBQXlCO1lBaUN6QixxQkFBcUI7SUFTbkMsT0FBTyxDQUFDLHdCQUF3QjtDQWdCakMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"epoch_prune_watcher.d.ts","sourceRoot":"","sources":["../../src/watchers/epoch_prune_watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"epoch_prune_watcher.d.ts","sourceRoot":"","sources":["../../src/watchers/epoch_prune_watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAe,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAI3E,OAAO,EAEL,OAAO,EACP,KAAK,yBAAyB,EAG/B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAEV,mBAAmB,EACnB,WAAW,EAEX,aAAa,EACd,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,mBAAmB,EAA4B,MAAM,yBAAyB,CAAC;AAY7F,OAAO,EAA6C,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAE7G,QAAA,MAAM,oCAAoC,+DAAgE,CAAC;AAE3G,KAAK,0BAA0B,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,OAAO,oCAAoC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;;AAE7G;;;;;GAKG;AACH,qBAAa,iBAAkB,SAAQ,sBAA2C,YAAW,OAAO;IAShG,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,kBAAkB;IAZ5B,OAAO,CAAC,GAAG,CAA+C;IAG1D,OAAO,CAAC,wBAAwB,CAAuC;IAEvE,OAAO,CAAC,SAAS,CAA6B;IAE9C,YACU,aAAa,EAAE,yBAAyB,EACxC,mBAAmB,EAAE,mBAAmB,EACxC,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,IAAI,CAAC,WAAW,EAAE,iBAAiB,CAAC,EAChD,kBAAkB,EAAE,mBAAmB,EAC/C,SAAS,EAAE,0BAA0B,EAOtC;IAEM,KAAK,kBAGX;IAEM,IAAI,kBAGV;IAEM,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAGxD;IAED,OAAO,CAAC,mBAAmB;YAOb,iBAAiB;YAWjB,oBAAoB;IAwBrB,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BtF;YAEa,kBAAkB;YAwClB,yBAAyB;YAiCzB,qBAAqB;IASnC,OAAO,CAAC,wBAAwB;CAgBjC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BlockNumber
|
|
2
|
-
import { merge, pick } from '@aztec/foundation/collection';
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { chunkBy, merge, pick } from '@aztec/foundation/collection';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { L2BlockSourceEvents } from '@aztec/stdlib/block';
|
|
5
5
|
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
@@ -67,7 +67,7 @@ const EpochPruneWatcherPenaltiesConfigKeys = [
|
|
|
67
67
|
this.log.info(`Detected chain prune. Validating epoch ${epochNumber} with blocks ${epochBlocks[0]?.number} to ${epochBlocks[epochBlocks.length - 1]?.number}.`, {
|
|
68
68
|
blocks: epochBlocks.map((b)=>b.toBlockInfo())
|
|
69
69
|
});
|
|
70
|
-
await this.validateBlocks(epochBlocks);
|
|
70
|
+
await this.validateBlocks(epochBlocks, epochNumber);
|
|
71
71
|
this.log.info(`Pruned epoch ${epochNumber} was valid. Want to slash committee for not having it proven.`);
|
|
72
72
|
await this.emitSlashForEpoch(OffenseType.VALID_EPOCH_PRUNED, epochNumber);
|
|
73
73
|
} catch (error) {
|
|
@@ -81,19 +81,26 @@ const EpochPruneWatcherPenaltiesConfigKeys = [
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
async validateBlocks(blocks) {
|
|
84
|
+
async validateBlocks(blocks, epochNumber) {
|
|
85
85
|
if (blocks.length === 0) {
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
const
|
|
88
|
+
// Sort blocks by block number and group by checkpoint
|
|
89
|
+
const sortedBlocks = [
|
|
90
|
+
...blocks
|
|
91
|
+
].sort((a, b)=>a.number - b.number);
|
|
92
|
+
const blocksByCheckpoint = chunkBy(sortedBlocks, (b)=>b.checkpointNumber);
|
|
93
|
+
// Get prior checkpoints in the epoch (in case this was a partial prune) to extract the out hashes
|
|
94
|
+
const priorCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(epochNumber)).filter((c)=>c.checkpointNumber < sortedBlocks[0].checkpointNumber).map((c)=>c.checkpointOutHash);
|
|
95
|
+
let previousCheckpointOutHashes = [
|
|
96
|
+
...priorCheckpointOutHashes
|
|
97
|
+
];
|
|
98
|
+
const fork = await this.checkpointsBuilder.getFork(BlockNumber(sortedBlocks[0].header.globalVariables.blockNumber - 1));
|
|
90
99
|
try {
|
|
91
|
-
for (const
|
|
92
|
-
await this.
|
|
93
|
-
//
|
|
94
|
-
const checkpointOutHash = computeCheckpointOutHash(
|
|
95
|
-
block.body.txEffects.map((tx)=>tx.l2ToL1Msgs)
|
|
96
|
-
]);
|
|
100
|
+
for (const checkpointBlocks of blocksByCheckpoint){
|
|
101
|
+
await this.validateCheckpoint(checkpointBlocks, previousCheckpointOutHashes, fork);
|
|
102
|
+
// Compute checkpoint out hash from all blocks in this checkpoint
|
|
103
|
+
const checkpointOutHash = computeCheckpointOutHash(checkpointBlocks.map((b)=>b.body.txEffects.map((tx)=>tx.l2ToL1Msgs)));
|
|
97
104
|
previousCheckpointOutHashes = [
|
|
98
105
|
...previousCheckpointOutHashes,
|
|
99
106
|
checkpointOutHash
|
|
@@ -103,7 +110,30 @@ const EpochPruneWatcherPenaltiesConfigKeys = [
|
|
|
103
110
|
await fork.close();
|
|
104
111
|
}
|
|
105
112
|
}
|
|
106
|
-
async
|
|
113
|
+
async validateCheckpoint(checkpointBlocks, previousCheckpointOutHashes, fork) {
|
|
114
|
+
const checkpointNumber = checkpointBlocks[0].checkpointNumber;
|
|
115
|
+
this.log.debug(`Validating pruned checkpoint ${checkpointNumber} with ${checkpointBlocks.length} blocks`);
|
|
116
|
+
// Get L1ToL2Messages once for the entire checkpoint
|
|
117
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
118
|
+
// Build checkpoint constants from first block's global variables
|
|
119
|
+
const gv = checkpointBlocks[0].header.globalVariables;
|
|
120
|
+
const constants = {
|
|
121
|
+
chainId: gv.chainId,
|
|
122
|
+
version: gv.version,
|
|
123
|
+
slotNumber: gv.slotNumber,
|
|
124
|
+
timestamp: gv.timestamp,
|
|
125
|
+
coinbase: gv.coinbase,
|
|
126
|
+
feeRecipient: gv.feeRecipient,
|
|
127
|
+
gasFees: gv.gasFees
|
|
128
|
+
};
|
|
129
|
+
// Start checkpoint builder once for all blocks in this checkpoint
|
|
130
|
+
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(checkpointNumber, constants, 0n, l1ToL2Messages, previousCheckpointOutHashes, fork, this.log.getBindings());
|
|
131
|
+
// Validate all blocks in the checkpoint sequentially
|
|
132
|
+
for (const block of checkpointBlocks){
|
|
133
|
+
await this.validateBlockInCheckpoint(block, checkpointBuilder);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async validateBlockInCheckpoint(blockFromL1, checkpointBuilder) {
|
|
107
137
|
this.log.debug(`Validating pruned block ${blockFromL1.header.globalVariables.blockNumber}`);
|
|
108
138
|
const txHashes = blockFromL1.body.txEffects.map((txEffect)=>txEffect.txHash);
|
|
109
139
|
// We load txs from the mempool directly, since the TxCollector running in the background has already been
|
|
@@ -113,20 +143,11 @@ const EpochPruneWatcherPenaltiesConfigKeys = [
|
|
|
113
143
|
if (missingTxs && missingTxs.length > 0) {
|
|
114
144
|
throw new TransactionsNotAvailableError(missingTxs);
|
|
115
145
|
}
|
|
116
|
-
const checkpointNumber = CheckpointNumber.fromBlockNumber(blockFromL1.number);
|
|
117
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
118
146
|
const gv = blockFromL1.header.globalVariables;
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
coinbase: gv.coinbase,
|
|
124
|
-
feeRecipient: gv.feeRecipient,
|
|
125
|
-
gasFees: gv.gasFees
|
|
126
|
-
};
|
|
127
|
-
// Use checkpoint builder to validate the block
|
|
128
|
-
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes, fork, this.log.getBindings());
|
|
129
|
-
const { block, failedTxs, numTxs } = await checkpointBuilder.buildBlock(txs, gv.blockNumber, gv.timestamp, {});
|
|
147
|
+
const { block, failedTxs, numTxs } = await checkpointBuilder.buildBlock(txs, gv.blockNumber, gv.timestamp, {
|
|
148
|
+
isBuildingProposal: false,
|
|
149
|
+
minValidTxs: 0
|
|
150
|
+
});
|
|
130
151
|
if (numTxs !== txs.length) {
|
|
131
152
|
// This should be detected by state mismatch, but this makes it easier to debug.
|
|
132
153
|
throw new ValidatorError(`Built block with ${numTxs} txs, expected ${txs.length}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/slasher",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.9ebd450e8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -56,20 +56,20 @@
|
|
|
56
56
|
]
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
60
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
61
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
62
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
63
|
-
"@aztec/l1-artifacts": "0.0.1-commit.
|
|
64
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
65
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
59
|
+
"@aztec/epoch-cache": "0.0.1-commit.9ebd450e8",
|
|
60
|
+
"@aztec/ethereum": "0.0.1-commit.9ebd450e8",
|
|
61
|
+
"@aztec/foundation": "0.0.1-commit.9ebd450e8",
|
|
62
|
+
"@aztec/kv-store": "0.0.1-commit.9ebd450e8",
|
|
63
|
+
"@aztec/l1-artifacts": "0.0.1-commit.9ebd450e8",
|
|
64
|
+
"@aztec/stdlib": "0.0.1-commit.9ebd450e8",
|
|
65
|
+
"@aztec/telemetry-client": "0.0.1-commit.9ebd450e8",
|
|
66
66
|
"source-map-support": "^0.5.21",
|
|
67
67
|
"tslib": "^2.4.0",
|
|
68
68
|
"viem": "npm:@aztec/viem@2.38.2",
|
|
69
69
|
"zod": "^3.23.8"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
72
|
+
"@aztec/aztec.js": "0.0.1-commit.9ebd450e8",
|
|
73
73
|
"@jest/globals": "^30.0.0",
|
|
74
74
|
"@types/jest": "^30.0.0",
|
|
75
75
|
"@types/node": "^22.15.17",
|
package/src/config.ts
CHANGED
|
@@ -14,8 +14,6 @@ export type { SlasherConfig };
|
|
|
14
14
|
|
|
15
15
|
export const DefaultSlasherConfig: SlasherConfig = {
|
|
16
16
|
slashOverridePayload: undefined,
|
|
17
|
-
slashMinPenaltyPercentage: slasherDefaultEnv.SLASH_MIN_PENALTY_PERCENTAGE,
|
|
18
|
-
slashMaxPenaltyPercentage: slasherDefaultEnv.SLASH_MAX_PENALTY_PERCENTAGE,
|
|
19
17
|
slashValidatorsAlways: [], // Empty by default
|
|
20
18
|
slashValidatorsNever: [], // Empty by default
|
|
21
19
|
slashPrunePenalty: BigInt(slasherDefaultEnv.SLASH_PRUNE_PENALTY),
|
|
@@ -23,6 +21,8 @@ export const DefaultSlasherConfig: SlasherConfig = {
|
|
|
23
21
|
slashInactivityTargetPercentage: slasherDefaultEnv.SLASH_INACTIVITY_TARGET_PERCENTAGE,
|
|
24
22
|
slashInactivityConsecutiveEpochThreshold: slasherDefaultEnv.SLASH_INACTIVITY_CONSECUTIVE_EPOCH_THRESHOLD,
|
|
25
23
|
slashBroadcastedInvalidBlockPenalty: BigInt(slasherDefaultEnv.SLASH_INVALID_BLOCK_PENALTY),
|
|
24
|
+
slashDuplicateProposalPenalty: BigInt(slasherDefaultEnv.SLASH_DUPLICATE_PROPOSAL_PENALTY),
|
|
25
|
+
slashDuplicateAttestationPenalty: BigInt(slasherDefaultEnv.SLASH_DUPLICATE_ATTESTATION_PENALTY),
|
|
26
26
|
slashInactivityPenalty: BigInt(slasherDefaultEnv.SLASH_INACTIVITY_PENALTY),
|
|
27
27
|
slashProposeInvalidAttestationsPenalty: BigInt(slasherDefaultEnv.SLASH_PROPOSE_INVALID_ATTESTATIONS_PENALTY),
|
|
28
28
|
slashAttestDescendantOfInvalidPenalty: BigInt(slasherDefaultEnv.SLASH_ATTEST_DESCENDANT_OF_INVALID_PENALTY),
|
|
@@ -38,19 +38,9 @@ export const slasherConfigMappings: ConfigMappingsType<SlasherConfig> = {
|
|
|
38
38
|
slashOverridePayload: {
|
|
39
39
|
env: 'SLASH_OVERRIDE_PAYLOAD',
|
|
40
40
|
description: 'An Ethereum address for a slash payload to vote for unconditionally.',
|
|
41
|
-
parseEnv: (val: string) =>
|
|
41
|
+
parseEnv: (val: string) => EthAddress.fromString(val),
|
|
42
42
|
defaultValue: DefaultSlasherConfig.slashOverridePayload,
|
|
43
43
|
},
|
|
44
|
-
slashMinPenaltyPercentage: {
|
|
45
|
-
env: 'SLASH_MIN_PENALTY_PERCENTAGE',
|
|
46
|
-
description: 'Minimum penalty percentage for slashing offenses (0.1 is 10%).',
|
|
47
|
-
...floatConfigHelper(DefaultSlasherConfig.slashMinPenaltyPercentage),
|
|
48
|
-
},
|
|
49
|
-
slashMaxPenaltyPercentage: {
|
|
50
|
-
env: 'SLASH_MAX_PENALTY_PERCENTAGE',
|
|
51
|
-
description: 'Maximum penalty percentage for slashing offenses (2.0 is 200%).',
|
|
52
|
-
...floatConfigHelper(DefaultSlasherConfig.slashMaxPenaltyPercentage),
|
|
53
|
-
},
|
|
54
44
|
slashValidatorsAlways: {
|
|
55
45
|
env: 'SLASH_VALIDATORS_ALWAYS',
|
|
56
46
|
description: 'Comma-separated list of validator addresses that should always be slashed.',
|
|
@@ -88,6 +78,17 @@ export const slasherConfigMappings: ConfigMappingsType<SlasherConfig> = {
|
|
|
88
78
|
description: 'Penalty amount for slashing a validator for an invalid block proposed via p2p.',
|
|
89
79
|
...bigintConfigHelper(DefaultSlasherConfig.slashBroadcastedInvalidBlockPenalty),
|
|
90
80
|
},
|
|
81
|
+
slashDuplicateProposalPenalty: {
|
|
82
|
+
env: 'SLASH_DUPLICATE_PROPOSAL_PENALTY',
|
|
83
|
+
description: 'Penalty amount for slashing a validator for sending duplicate proposals.',
|
|
84
|
+
...bigintConfigHelper(DefaultSlasherConfig.slashDuplicateProposalPenalty),
|
|
85
|
+
},
|
|
86
|
+
slashDuplicateAttestationPenalty: {
|
|
87
|
+
env: 'SLASH_DUPLICATE_ATTESTATION_PENALTY',
|
|
88
|
+
description:
|
|
89
|
+
'Penalty amount for slashing a validator for signing attestations for different proposals at the same slot.',
|
|
90
|
+
...bigintConfigHelper(DefaultSlasherConfig.slashDuplicateAttestationPenalty),
|
|
91
|
+
},
|
|
91
92
|
slashInactivityTargetPercentage: {
|
|
92
93
|
env: 'SLASH_INACTIVITY_TARGET_PERCENTAGE',
|
|
93
94
|
description:
|
|
@@ -142,7 +143,8 @@ export const slasherConfigMappings: ConfigMappingsType<SlasherConfig> = {
|
|
|
142
143
|
...numberConfigHelper(DefaultSlasherConfig.slashMaxPayloadSize),
|
|
143
144
|
},
|
|
144
145
|
slashGracePeriodL2Slots: {
|
|
145
|
-
description:
|
|
146
|
+
description:
|
|
147
|
+
'Number of L2 slots after the network upgrade during which slashing offenses are ignored. The upgrade time is determined from the CanonicalRollupUpdated event.',
|
|
146
148
|
env: 'SLASH_GRACE_PERIOD_L2_SLOTS',
|
|
147
149
|
...numberConfigHelper(DefaultSlasherConfig.slashGracePeriodL2Slots),
|
|
148
150
|
},
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
2
|
+
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
3
3
|
import type { L1ReaderConfig } from '@aztec/ethereum/l1-reader';
|
|
4
4
|
import type { ViemClient } from '@aztec/ethereum/types';
|
|
5
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
5
6
|
import { unique } from '@aztec/foundation/collection';
|
|
6
7
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
7
8
|
import { createLogger } from '@aztec/foundation/log';
|
|
8
9
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
9
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
10
10
|
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
11
|
+
import { getSlotAtTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
11
12
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
13
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
12
14
|
|
|
13
15
|
import { SlasherClientFacade } from '../slasher_client_facade.js';
|
|
14
16
|
import type { SlasherClientInterface } from '../slasher_client_interface.js';
|
|
@@ -18,7 +20,7 @@ import type { Watcher } from '../watcher.js';
|
|
|
18
20
|
/** Creates a slasher client facade that updates itself whenever the rollup slasher changes */
|
|
19
21
|
export async function createSlasherFacade(
|
|
20
22
|
config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
21
|
-
l1Contracts: Pick<L1ReaderConfig['l1Contracts'], 'rollupAddress' | '
|
|
23
|
+
l1Contracts: Pick<L1ReaderConfig['l1Contracts'], 'rollupAddress' | 'registryAddress'>,
|
|
22
24
|
l1Client: ViemClient,
|
|
23
25
|
watchers: Watcher[],
|
|
24
26
|
dateProvider: DateProvider,
|
|
@@ -34,6 +36,32 @@ export async function createSlasherFacade(
|
|
|
34
36
|
const kvStore = await createStore('slasher', SCHEMA_VERSION, config, logger.getBindings());
|
|
35
37
|
const rollup = new RollupContract(l1Client, l1Contracts.rollupAddress);
|
|
36
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
|
+
|
|
37
65
|
const slashValidatorsNever = config.slashSelfAllowed
|
|
38
66
|
? config.slashValidatorsNever
|
|
39
67
|
: unique([...config.slashValidatorsNever, ...validatorAddresses].map(a => a.toString())).map(EthAddress.fromString);
|
|
@@ -43,11 +71,11 @@ export async function createSlasherFacade(
|
|
|
43
71
|
updatedConfig,
|
|
44
72
|
rollup,
|
|
45
73
|
l1Client,
|
|
46
|
-
l1Contracts.slashFactoryAddress,
|
|
47
74
|
watchers,
|
|
48
75
|
epochCache,
|
|
49
76
|
dateProvider,
|
|
50
77
|
kvStore,
|
|
78
|
+
rollupRegisteredAtL2Slot,
|
|
51
79
|
logger,
|
|
52
80
|
);
|
|
53
81
|
}
|
|
@@ -1,142 +1,61 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import {
|
|
3
|
-
EmpireSlashingProposerContract,
|
|
4
|
-
RollupContract,
|
|
5
|
-
TallySlashingProposerContract,
|
|
6
|
-
} from '@aztec/ethereum/contracts';
|
|
2
|
+
import { RollupContract, SlashingProposerContract } from '@aztec/ethereum/contracts';
|
|
7
3
|
import type { ViemClient } from '@aztec/ethereum/types';
|
|
8
|
-
import {
|
|
4
|
+
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
9
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
10
6
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
11
|
-
import type { DataStoreConfig } from '@aztec/kv-store/config';
|
|
12
7
|
import { AztecLMDBStoreV2 } from '@aztec/kv-store/lmdb-v2';
|
|
13
8
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
14
|
-
import {
|
|
9
|
+
import type { DataStoreConfig } from '@aztec/stdlib/kv-store';
|
|
15
10
|
|
|
16
|
-
import { EmpireSlasherClient, type EmpireSlasherSettings } from '../empire_slasher_client.js';
|
|
17
11
|
import { NullSlasherClient } from '../null_slasher_client.js';
|
|
12
|
+
import { SlasherClient } from '../slasher_client.js';
|
|
18
13
|
import { SlasherOffensesStore } from '../stores/offenses_store.js';
|
|
19
|
-
import { SlasherPayloadsStore } from '../stores/payloads_store.js';
|
|
20
|
-
import { TallySlasherClient } from '../tally_slasher_client.js';
|
|
21
14
|
import type { Watcher } from '../watcher.js';
|
|
22
|
-
import {
|
|
15
|
+
import { getSlasherSettings } from './get_settings.js';
|
|
23
16
|
|
|
24
|
-
/** Creates a slasher client implementation
|
|
17
|
+
/** Creates a slasher client implementation based on the slasher proposer type in the rollup */
|
|
25
18
|
export async function createSlasherImplementation(
|
|
26
19
|
config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
27
20
|
rollup: RollupContract,
|
|
28
21
|
l1Client: ViemClient,
|
|
29
|
-
slashFactoryAddress: EthAddress | undefined,
|
|
30
22
|
watchers: Watcher[],
|
|
31
23
|
epochCache: EpochCache,
|
|
32
24
|
dateProvider: DateProvider,
|
|
33
25
|
kvStore: AztecLMDBStoreV2,
|
|
26
|
+
rollupRegisteredAtL2Slot: SlotNumber,
|
|
34
27
|
logger = createLogger('slasher'),
|
|
35
28
|
) {
|
|
36
29
|
const proposer = await rollup.getSlashingProposer();
|
|
37
30
|
if (!proposer) {
|
|
38
31
|
return new NullSlasherClient(config);
|
|
39
|
-
} else if (proposer.type === 'tally') {
|
|
40
|
-
return createTallySlasher(config, rollup, proposer, watchers, dateProvider, epochCache, kvStore, logger);
|
|
41
32
|
} else {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
return createSlasher(
|
|
34
|
+
config,
|
|
35
|
+
rollup,
|
|
36
|
+
proposer,
|
|
37
|
+
watchers,
|
|
38
|
+
dateProvider,
|
|
39
|
+
epochCache,
|
|
40
|
+
kvStore,
|
|
41
|
+
rollupRegisteredAtL2Slot,
|
|
42
|
+
logger,
|
|
43
|
+
);
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
async function
|
|
51
|
-
config: SlasherConfig & DataStoreConfig & { ethereumSlotDuration: number },
|
|
52
|
-
rollup: RollupContract,
|
|
53
|
-
slashingProposer: EmpireSlashingProposerContract,
|
|
54
|
-
slashFactoryContract: SlashFactoryContract,
|
|
55
|
-
watchers: Watcher[],
|
|
56
|
-
dateProvider: DateProvider,
|
|
57
|
-
kvStore: AztecLMDBStoreV2,
|
|
58
|
-
logger = createLogger('slasher'),
|
|
59
|
-
): Promise<EmpireSlasherClient> {
|
|
60
|
-
if (slashingProposer.type !== 'empire') {
|
|
61
|
-
throw new Error('Slashing proposer contract is not of type Empire');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const [
|
|
65
|
-
slashingExecutionDelayInRounds,
|
|
66
|
-
slashingPayloadLifetimeInRounds,
|
|
67
|
-
slashingRoundSize,
|
|
68
|
-
slashingQuorumSize,
|
|
69
|
-
epochDuration,
|
|
70
|
-
proofSubmissionEpochs,
|
|
71
|
-
l1GenesisTime,
|
|
72
|
-
slotDuration,
|
|
73
|
-
l1StartBlock,
|
|
74
|
-
slasher,
|
|
75
|
-
] = await Promise.all([
|
|
76
|
-
slashingProposer.getExecutionDelayInRounds(),
|
|
77
|
-
slashingProposer.getLifetimeInRounds(),
|
|
78
|
-
slashingProposer.getRoundSize(),
|
|
79
|
-
slashingProposer.getQuorumSize(),
|
|
80
|
-
rollup.getEpochDuration(),
|
|
81
|
-
rollup.getProofSubmissionEpochs(),
|
|
82
|
-
rollup.getL1GenesisTime(),
|
|
83
|
-
rollup.getSlotDuration(),
|
|
84
|
-
rollup.getL1StartBlock(),
|
|
85
|
-
rollup.getSlasherContract(),
|
|
86
|
-
]);
|
|
87
|
-
|
|
88
|
-
const settings: EmpireSlasherSettings = {
|
|
89
|
-
slashingExecutionDelayInRounds: Number(slashingExecutionDelayInRounds),
|
|
90
|
-
slashingPayloadLifetimeInRounds: Number(slashingPayloadLifetimeInRounds),
|
|
91
|
-
slashingRoundSize: Number(slashingRoundSize),
|
|
92
|
-
slashingQuorumSize: Number(slashingQuorumSize),
|
|
93
|
-
epochDuration: Number(epochDuration),
|
|
94
|
-
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
95
|
-
l1GenesisTime: l1GenesisTime,
|
|
96
|
-
slotDuration: Number(slotDuration),
|
|
97
|
-
l1StartBlock,
|
|
98
|
-
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
99
|
-
slashingAmounts: undefined,
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const payloadsStore = new SlasherPayloadsStore(kvStore, {
|
|
103
|
-
slashingPayloadLifetimeInRounds: settings.slashingPayloadLifetimeInRounds,
|
|
104
|
-
});
|
|
105
|
-
const offensesStore = new SlasherOffensesStore(kvStore, {
|
|
106
|
-
...settings,
|
|
107
|
-
slashOffenseExpirationRounds: config.slashOffenseExpirationRounds,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return new EmpireSlasherClient(
|
|
111
|
-
config,
|
|
112
|
-
settings,
|
|
113
|
-
slashFactoryContract,
|
|
114
|
-
slashingProposer,
|
|
115
|
-
slasher!,
|
|
116
|
-
rollup,
|
|
117
|
-
watchers,
|
|
118
|
-
dateProvider,
|
|
119
|
-
offensesStore,
|
|
120
|
-
payloadsStore,
|
|
121
|
-
logger,
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async function createTallySlasher(
|
|
47
|
+
async function createSlasher(
|
|
126
48
|
config: SlasherConfig & DataStoreConfig,
|
|
127
49
|
rollup: RollupContract,
|
|
128
|
-
slashingProposer:
|
|
50
|
+
slashingProposer: SlashingProposerContract,
|
|
129
51
|
watchers: Watcher[],
|
|
130
52
|
dateProvider: DateProvider,
|
|
131
53
|
epochCache: EpochCache,
|
|
132
54
|
kvStore: AztecLMDBStoreV2,
|
|
55
|
+
rollupRegisteredAtL2Slot: SlotNumber,
|
|
133
56
|
logger = createLogger('slasher'),
|
|
134
|
-
): Promise<
|
|
135
|
-
|
|
136
|
-
throw new Error('Slashing proposer contract is not of type tally');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const settings = await getTallySlasherSettings(rollup, slashingProposer);
|
|
57
|
+
): Promise<SlasherClient> {
|
|
58
|
+
const settings = { ...(await getSlasherSettings(rollup, slashingProposer)), rollupRegisteredAtL2Slot };
|
|
140
59
|
const slasher = await rollup.getSlasherContract();
|
|
141
60
|
|
|
142
61
|
const offensesStore = new SlasherOffensesStore(kvStore, {
|
|
@@ -144,7 +63,7 @@ async function createTallySlasher(
|
|
|
144
63
|
slashOffenseExpirationRounds: config.slashOffenseExpirationRounds,
|
|
145
64
|
});
|
|
146
65
|
|
|
147
|
-
return new
|
|
66
|
+
return new SlasherClient(
|
|
148
67
|
config,
|
|
149
68
|
settings,
|
|
150
69
|
slashingProposer,
|