@aztec/slasher 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0
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 +90 -76
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +41 -29
- 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 +26 -3
- 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 +8 -6
- package/dest/generated/slasher-defaults.d.ts.map +1 -1
- package/dest/generated/slasher-defaults.js +7 -5
- package/dest/index.d.ts +6 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +5 -3
- package/dest/metrics.d.ts +7 -0
- package/dest/metrics.d.ts.map +1 -0
- package/dest/metrics.js +11 -0
- 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 +10 -9
- package/dest/slash_offenses_collector.d.ts.map +1 -1
- package/dest/slash_offenses_collector.js +50 -30
- package/dest/{tally_slasher_client.d.ts → slasher_client.d.ts} +17 -28
- package/dest/slasher_client.d.ts.map +1 -0
- package/dest/{tally_slasher_client.js → slasher_client.js} +55 -45
- 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 +12 -12
- package/dest/stores/offenses_store.d.ts.map +1 -1
- package/dest/stores/offenses_store.js +64 -39
- package/dest/watcher.d.ts +8 -1
- package/dest/watcher.d.ts.map +1 -1
- package/dest/watcher.js +1 -0
- package/dest/watchers/attestations_block_watcher.d.ts +26 -13
- package/dest/watchers/attestations_block_watcher.d.ts.map +1 -1
- package/dest/watchers/attestations_block_watcher.js +76 -61
- package/dest/watchers/attested_invalid_proposal_watcher.d.ts +42 -0
- package/dest/watchers/attested_invalid_proposal_watcher.d.ts.map +1 -0
- package/dest/watchers/attested_invalid_proposal_watcher.js +117 -0
- package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.d.ts +38 -0
- package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.d.ts.map +1 -0
- package/dest/watchers/broadcasted_invalid_checkpoint_proposal_watcher.js +138 -0
- package/dest/watchers/checkpoint_equivocation_watcher.d.ts +30 -0
- package/dest/watchers/checkpoint_equivocation_watcher.d.ts.map +1 -0
- package/dest/watchers/checkpoint_equivocation_watcher.js +69 -0
- package/dest/watchers/data_withholding_watcher.d.ts +63 -0
- package/dest/watchers/data_withholding_watcher.d.ts.map +1 -0
- package/dest/watchers/data_withholding_watcher.js +193 -0
- package/package.json +10 -10
- package/src/config.ts +48 -29
- package/src/factory/create_facade.ts +33 -5
- 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 +7 -5
- package/src/index.ts +5 -3
- package/src/metrics.ts +19 -0
- package/src/null_slasher_client.ts +2 -6
- package/src/slash_offenses_collector.ts +70 -32
- package/src/{tally_slasher_client.ts → slasher_client.ts} +72 -54
- package/src/slasher_client_facade.ts +6 -11
- package/src/slasher_client_interface.ts +6 -21
- package/src/stores/offenses_store.ts +76 -48
- package/src/watcher.ts +8 -0
- package/src/watchers/attestations_block_watcher.ts +88 -82
- package/src/watchers/attested_invalid_proposal_watcher.ts +168 -0
- package/src/watchers/broadcasted_invalid_checkpoint_proposal_watcher.ts +192 -0
- package/src/watchers/checkpoint_equivocation_watcher.ts +96 -0
- package/src/watchers/data_withholding_watcher.ts +225 -0
- 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 -572
- 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 -125
- package/dest/tally_slasher_client.d.ts.map +0 -1
- package/dest/watchers/epoch_prune_watcher.d.ts +0 -38
- package/dest/watchers/epoch_prune_watcher.d.ts.map +0 -1
- package/dest/watchers/epoch_prune_watcher.js +0 -158
- package/src/empire_slasher_client.ts +0 -657
- package/src/stores/payloads_store.ts +0 -146
- package/src/watchers/epoch_prune_watcher.ts +0 -220
|
@@ -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,27 +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
|
|
39
|
+
/** Adds a new offense. Returns false if the offense is already pending. */ async addOffense(offense) {
|
|
50
40
|
const key = this.getOffenseKey(offense);
|
|
51
|
-
await this.offenses.set(key, serializeOffense(offense));
|
|
52
41
|
const round = getRoundForOffense(offense, this.settings);
|
|
53
|
-
await this.
|
|
54
|
-
|
|
42
|
+
const added = await this.kvStore.transactionAsync(async ()=>{
|
|
43
|
+
if (await this.offenses.getAsync(key) !== undefined) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
await this.offenses.set(key, serializeOffense(offense));
|
|
47
|
+
await this.roundsOffenses.set(this.getRoundKey(round), key);
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
if (added) {
|
|
51
|
+
this.log.trace(`Adding pending offense ${key} for round ${round}`);
|
|
52
|
+
}
|
|
53
|
+
return added;
|
|
55
54
|
}
|
|
56
|
-
/**
|
|
57
|
-
await this.kvStore.transactionAsync(async ()=>{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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;
|
|
61
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;
|
|
62
89
|
});
|
|
63
90
|
}
|
|
64
91
|
/** Prunes all offenses expired from the store */ async clearExpiredOffenses(currentRound) {
|
|
@@ -70,31 +97,29 @@ export class SlasherOffensesStore {
|
|
|
70
97
|
if (expiredBefore < 0) {
|
|
71
98
|
return 0; // Not enough rounds have passed to expire anything
|
|
72
99
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
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
|
+
}
|
|
87
113
|
for (const key of expiredOffenseKeys){
|
|
88
114
|
this.log.trace(`Deleting offense ${key}`);
|
|
89
115
|
await this.offenses.delete(key);
|
|
90
|
-
await this.offensesSlashed.delete(key);
|
|
91
116
|
}
|
|
92
117
|
for (const roundKey of expiredRoundKeys){
|
|
93
118
|
this.log.trace(`Deleting round info for ${roundKey}`);
|
|
94
119
|
await this.roundsOffenses.delete(roundKey);
|
|
95
120
|
}
|
|
121
|
+
return expiredOffenseKeys.size;
|
|
96
122
|
});
|
|
97
|
-
return expiredOffenseKeys.size;
|
|
98
123
|
}
|
|
99
124
|
/** Generate a unique key for an offense */ getOffenseKey(offense) {
|
|
100
125
|
return `${offense.validator.toString()}:${offense.offenseType}:${offense.epochOrSlot}`;
|
package/dest/watcher.d.ts
CHANGED
|
@@ -3,14 +3,21 @@ import type { TypedEventEmitter } from '@aztec/foundation/types';
|
|
|
3
3
|
import { OffenseType } from '@aztec/stdlib/slashing';
|
|
4
4
|
import type { SlasherConfig } from './config.js';
|
|
5
5
|
export declare const WANT_TO_SLASH_EVENT: "want-to-slash";
|
|
6
|
+
export declare const WANT_TO_CLEAR_SLASH_EVENT: "want-to-clear-slash";
|
|
6
7
|
export interface WantToSlashArgs {
|
|
7
8
|
validator: EthAddress;
|
|
8
9
|
amount: bigint;
|
|
9
10
|
offenseType: OffenseType;
|
|
10
11
|
epochOrSlot: bigint;
|
|
11
12
|
}
|
|
13
|
+
export interface WantToClearSlashArgs {
|
|
14
|
+
offenseType: OffenseType;
|
|
15
|
+
epochOrSlot: bigint;
|
|
16
|
+
validators?: EthAddress[];
|
|
17
|
+
}
|
|
12
18
|
export interface WatcherEventMap {
|
|
13
19
|
[WANT_TO_SLASH_EVENT]: (args: WantToSlashArgs[]) => void;
|
|
20
|
+
[WANT_TO_CLEAR_SLASH_EVENT]: (args: WantToClearSlashArgs[]) => void;
|
|
14
21
|
}
|
|
15
22
|
export type WatcherEmitter = TypedEventEmitter<WatcherEventMap>;
|
|
16
23
|
export type Watcher = WatcherEmitter & {
|
|
@@ -18,4 +25,4 @@ export type Watcher = WatcherEmitter & {
|
|
|
18
25
|
stop?: () => Promise<void>;
|
|
19
26
|
updateConfig: (config: Partial<SlasherConfig>) => void;
|
|
20
27
|
};
|
|
21
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
28
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid2F0Y2hlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3dhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBQzNELE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDakUsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBRXJELE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSxNQ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@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../src/watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,eAAO,MAAM,mBAAmB,iBAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../src/watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,eAAO,MAAM,mBAAmB,iBAA2B,CAAC;AAC5D,eAAO,MAAM,yBAAyB,uBAAiC,CAAC;AAExE,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,UAAU,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,EAAE,CAAC;CAC3B;AAGD,MAAM,WAAW,eAAe;IAC9B,CAAC,mBAAmB,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;IACzD,CAAC,yBAAyB,CAAC,EAAE,CAAC,IAAI,EAAE,oBAAoB,EAAE,KAAK,IAAI,CAAC;CACrE;AAED,MAAM,MAAM,cAAc,GAAG,iBAAiB,CAAC,eAAe,CAAC,CAAC;AAEhE,MAAM,MAAM,OAAO,GAAG,cAAc,GAAG;IACrC,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;CACxD,CAAC"}
|
package/dest/watcher.js
CHANGED
|
@@ -1,34 +1,47 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import { type
|
|
2
|
+
import { type LoggerBindings } from '@aztec/foundation/log';
|
|
3
|
+
import { type DescendentOfInvalidAttestationsCheckpointEvent, type InvalidCheckpointDetectedEvent, type L2BlockSourceEventEmitter } from '@aztec/stdlib/block';
|
|
3
4
|
import type { SlasherConfig } from '../config.js';
|
|
4
5
|
import { type Watcher, type WatcherEmitter } from '../watcher.js';
|
|
5
|
-
declare const AttestationsBlockWatcherConfigKeys: readonly ["
|
|
6
|
+
declare const AttestationsBlockWatcherConfigKeys: readonly ["slashProposeDescendantOfCheckpointWithInvalidAttestationsPenalty", "slashProposeInvalidAttestationsPenalty"];
|
|
6
7
|
type AttestationsBlockWatcherConfig = Pick<SlasherConfig, (typeof AttestationsBlockWatcherConfigKeys)[number]>;
|
|
7
8
|
declare const AttestationsBlockWatcher_base: new () => WatcherEmitter;
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Watches the archiver for checkpoints whose publication is itself a slashable offense.
|
|
11
|
+
*
|
|
12
|
+
* Two cases are handled, both targeting the proposer of the offending checkpoint:
|
|
13
|
+
*
|
|
14
|
+
* - Invalid-attestations checkpoint: the proposer published a checkpoint to L1 whose
|
|
15
|
+
* attestations are either insufficient (below quorum) or incorrect (signature from a
|
|
16
|
+
* non-committee member, malformed signature, etc.). Slashed via
|
|
17
|
+
* {@link OffenseType.PROPOSED_INSUFFICIENT_ATTESTATIONS} or
|
|
18
|
+
* {@link OffenseType.PROPOSED_INCORRECT_ATTESTATIONS}.
|
|
19
|
+
*
|
|
20
|
+
* - Descendant of an invalid checkpoint: the proposer published a checkpoint that extends a
|
|
21
|
+
* previously-rejected one. The descendant may itself have valid attestations, but it is still
|
|
22
|
+
* unusable. Triggered by the archiver's `CheckpointBuiltOnInvalidAncestorDetected` event
|
|
23
|
+
* when the descendant has valid attestations (skipped before ingestion). Slashes the descendant's
|
|
24
|
+
* proposer via {@link OffenseType.PROPOSED_DESCENDANT_OF_CHECKPOINT_WITH_INVALID_ATTESTATIONS}.
|
|
13
25
|
*/
|
|
14
26
|
export declare class AttestationsBlockWatcher extends AttestationsBlockWatcher_base implements Watcher {
|
|
15
27
|
private l2BlockSource;
|
|
16
28
|
private epochCache;
|
|
17
29
|
private log;
|
|
18
|
-
private maxInvalidCheckpoints;
|
|
19
|
-
private invalidArchiveRoots;
|
|
20
30
|
private config;
|
|
21
31
|
private boundHandleInvalidCheckpoint;
|
|
22
|
-
|
|
32
|
+
private boundHandleDescendantOfInvalid;
|
|
33
|
+
constructor(l2BlockSource: L2BlockSourceEventEmitter, epochCache: EpochCache, config: AttestationsBlockWatcherConfig, bindings?: LoggerBindings);
|
|
23
34
|
updateConfig(newConfig: Partial<AttestationsBlockWatcherConfig>): void;
|
|
24
35
|
start(): Promise<void>;
|
|
25
36
|
stop(): Promise<void>;
|
|
26
37
|
/** Event handler for invalid checkpoints as reported by the archiver. Public for testing purposes. */
|
|
27
38
|
handleInvalidCheckpoint(event: InvalidCheckpointDetectedEvent): void;
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Event handler for valid-attestations checkpoints that build on a previously-rejected ancestor.
|
|
41
|
+
* The archiver emits this when ingesting the descendant, and we slash its proposer.
|
|
42
|
+
*/
|
|
43
|
+
handleDescendantOfInvalid(event: DescendentOfInvalidAttestationsCheckpointEvent): Promise<void>;
|
|
30
44
|
private getOffenseFromInvalidationReason;
|
|
31
|
-
private addInvalidCheckpoint;
|
|
32
45
|
}
|
|
33
46
|
export {};
|
|
34
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
47
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0ZXN0YXRpb25zX2Jsb2NrX3dhdGNoZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93YXRjaGVycy9hdHRlc3RhdGlvbnNfYmxvY2tfd2F0Y2hlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFHaEQsT0FBTyxFQUFlLEtBQUssY0FBYyxFQUFnQixNQUFNLHVCQUF1QixDQUFDO0FBQ3ZGLE9BQU8sRUFDTCxLQUFLLDhDQUE4QyxFQUNuRCxLQUFLLDhCQUE4QixFQUNuQyxLQUFLLHlCQUF5QixFQUcvQixNQUFNLHFCQUFxQixDQUFDO0FBTTdCLE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSxNQUFNLGNBQWMsQ0FBQztBQUNsRCxPQUFPLEVBQTZDLEtBQUssT0FBTyxFQUFFLEtBQUssY0FBYyxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBRTdHLFFBQUEsTUFBTSxrQ0FBa0MseUhBRzlCLENBQUM7QUFFWCxLQUFLLDhCQUE4QixHQUFHLElBQUksQ0FBQyxhQUFhLEVBQUUsQ0FBQyxPQUFPLGtDQUFrQyxDQUFDLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQzs7QUFFL0c7Ozs7Ozs7Ozs7Ozs7Ozs7R0FnQkc7QUFDSCxxQkFBYSx3QkFBeUIsU0FBUSw2QkFBMkMsWUFBVyxPQUFPO0lBeUJ2RyxPQUFPLENBQUMsYUFBYTtJQUNyQixPQUFPLENBQUMsVUFBVTtJQXpCcEIsT0FBTyxDQUFDLEdBQUcsQ0FBUztJQUNwQixPQUFPLENBQUMsTUFBTSxDQUFpQztJQUUvQyxPQUFPLENBQUMsNEJBQTRCLENBU2xDO0lBRUYsT0FBTyxDQUFDLDhCQUE4QixDQU9wQztJQUVGLFlBQ1UsYUFBYSxFQUFFLHlCQUF5QixFQUN4QyxVQUFVLEVBQUUsVUFBVSxFQUM5QixNQUFNLEVBQUUsOEJBQThCLEVBQ3RDLFFBQVEsQ0FBQyxFQUFFLGNBQWMsRUFNMUI7SUFFTSxZQUFZLENBQUMsU0FBUyxFQUFFLE9BQU8sQ0FBQyw4QkFBOEIsQ0FBQyxRQUdyRTtJQUVNLEtBQUssa0JBVVg7SUFFTSxJQUFJLGtCQVVWO0lBRUQsc0dBQXNHO0lBQy9GLHVCQUF1QixDQUFDLEtBQUssRUFBRSw4QkFBOEIsR0FBRyxJQUFJLENBcUMxRTtJQUVEOzs7T0FHRztJQUNVLHlCQUF5QixDQUFDLEtBQUssRUFBRSw4Q0FBOEMsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBaUMzRztJQUVELE9BQU8sQ0FBQyxnQ0FBZ0M7Q0FZekMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attestations_block_watcher.d.ts","sourceRoot":"","sources":["../../src/watchers/attestations_block_watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"attestations_block_watcher.d.ts","sourceRoot":"","sources":["../../src/watchers/attestations_block_watcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAe,KAAK,cAAc,EAAgB,MAAM,uBAAuB,CAAC;AACvF,OAAO,EACL,KAAK,8CAA8C,EACnD,KAAK,8BAA8B,EACnC,KAAK,yBAAyB,EAG/B,MAAM,qBAAqB,CAAC;AAM7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAA6C,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAE7G,QAAA,MAAM,kCAAkC,yHAG9B,CAAC;AAEX,KAAK,8BAA8B,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,OAAO,kCAAkC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;;AAE/G;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,wBAAyB,SAAQ,6BAA2C,YAAW,OAAO;IAyBvG,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,UAAU;IAzBpB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,MAAM,CAAiC;IAE/C,OAAO,CAAC,4BAA4B,CASlC;IAEF,OAAO,CAAC,8BAA8B,CAOpC;IAEF,YACU,aAAa,EAAE,yBAAyB,EACxC,UAAU,EAAE,UAAU,EAC9B,MAAM,EAAE,8BAA8B,EACtC,QAAQ,CAAC,EAAE,cAAc,EAM1B;IAEM,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,8BAA8B,CAAC,QAGrE;IAEM,KAAK,kBAUX;IAEM,IAAI,kBAUV;IAED,sGAAsG;IAC/F,uBAAuB,CAAC,KAAK,EAAE,8BAA8B,GAAG,IAAI,CAqC1E;IAED;;;OAGG;IACU,yBAAyB,CAAC,KAAK,EAAE,8CAA8C,GAAG,OAAO,CAAC,IAAI,CAAC,CAiC3G;IAED,OAAO,CAAC,gCAAgC;CAYzC"}
|
|
@@ -1,31 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { merge, pick } from '@aztec/foundation/collection';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { L2BlockSourceEvents } from '@aztec/stdlib/block';
|
|
5
|
-
import {
|
|
5
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
6
|
+
import { OffenseType, getOffenseTypeName } from '@aztec/stdlib/slashing';
|
|
6
7
|
import EventEmitter from 'node:events';
|
|
7
8
|
import { WANT_TO_SLASH_EVENT } from '../watcher.js';
|
|
8
9
|
const AttestationsBlockWatcherConfigKeys = [
|
|
9
|
-
'
|
|
10
|
+
'slashProposeDescendantOfCheckpointWithInvalidAttestationsPenalty',
|
|
10
11
|
'slashProposeInvalidAttestationsPenalty'
|
|
11
12
|
];
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* Watches the archiver for checkpoints whose publication is itself a slashable offense.
|
|
15
|
+
*
|
|
16
|
+
* Two cases are handled, both targeting the proposer of the offending checkpoint:
|
|
17
|
+
*
|
|
18
|
+
* - Invalid-attestations checkpoint: the proposer published a checkpoint to L1 whose
|
|
19
|
+
* attestations are either insufficient (below quorum) or incorrect (signature from a
|
|
20
|
+
* non-committee member, malformed signature, etc.). Slashed via
|
|
21
|
+
* {@link OffenseType.PROPOSED_INSUFFICIENT_ATTESTATIONS} or
|
|
22
|
+
* {@link OffenseType.PROPOSED_INCORRECT_ATTESTATIONS}.
|
|
23
|
+
*
|
|
24
|
+
* - Descendant of an invalid checkpoint: the proposer published a checkpoint that extends a
|
|
25
|
+
* previously-rejected one. The descendant may itself have valid attestations, but it is still
|
|
26
|
+
* unusable. Triggered by the archiver's `CheckpointBuiltOnInvalidAncestorDetected` event
|
|
27
|
+
* when the descendant has valid attestations (skipped before ingestion). Slashes the descendant's
|
|
28
|
+
* proposer via {@link OffenseType.PROPOSED_DESCENDANT_OF_CHECKPOINT_WITH_INVALID_ATTESTATIONS}.
|
|
17
29
|
*/ export class AttestationsBlockWatcher extends EventEmitter {
|
|
18
30
|
l2BlockSource;
|
|
19
31
|
epochCache;
|
|
20
32
|
log;
|
|
21
|
-
// Only keep track of the last N invalid checkpoints
|
|
22
|
-
maxInvalidCheckpoints;
|
|
23
|
-
// All invalid archive roots seen
|
|
24
|
-
invalidArchiveRoots;
|
|
25
33
|
config;
|
|
26
34
|
boundHandleInvalidCheckpoint;
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
boundHandleDescendantOfInvalid;
|
|
36
|
+
constructor(l2BlockSource, epochCache, config, bindings){
|
|
37
|
+
super(), this.l2BlockSource = l2BlockSource, this.epochCache = epochCache, this.boundHandleInvalidCheckpoint = (event)=>{
|
|
29
38
|
try {
|
|
30
39
|
this.handleInvalidCheckpoint(event);
|
|
31
40
|
} catch (err) {
|
|
@@ -34,7 +43,15 @@ const AttestationsBlockWatcherConfigKeys = [
|
|
|
34
43
|
reason: event.validationResult.reason
|
|
35
44
|
});
|
|
36
45
|
}
|
|
46
|
+
}, this.boundHandleDescendantOfInvalid = (event)=>{
|
|
47
|
+
this.handleDescendantOfInvalid(event).catch((err)=>{
|
|
48
|
+
this.log.error('Error handling descendant of invalid checkpoint', err, {
|
|
49
|
+
checkpointNumber: event.checkpoint.checkpointNumber,
|
|
50
|
+
ancestorCheckpointNumber: event.ancestorCheckpointNumber
|
|
51
|
+
});
|
|
52
|
+
});
|
|
37
53
|
};
|
|
54
|
+
this.log = createLogger('slasher:attestations-block-watcher', bindings);
|
|
38
55
|
this.config = pick(config, ...AttestationsBlockWatcherConfigKeys);
|
|
39
56
|
this.log.info('AttestationsBlockWatcher initialized');
|
|
40
57
|
}
|
|
@@ -44,57 +61,24 @@ const AttestationsBlockWatcherConfigKeys = [
|
|
|
44
61
|
}
|
|
45
62
|
start() {
|
|
46
63
|
this.l2BlockSource.events.on(L2BlockSourceEvents.InvalidAttestationsCheckpointDetected, this.boundHandleInvalidCheckpoint);
|
|
64
|
+
this.l2BlockSource.events.on(L2BlockSourceEvents.DescendentOfInvalidAttestationsCheckpointDetected, this.boundHandleDescendantOfInvalid);
|
|
47
65
|
return Promise.resolve();
|
|
48
66
|
}
|
|
49
67
|
stop() {
|
|
50
68
|
this.l2BlockSource.events.removeListener(L2BlockSourceEvents.InvalidAttestationsCheckpointDetected, this.boundHandleInvalidCheckpoint);
|
|
69
|
+
this.l2BlockSource.events.removeListener(L2BlockSourceEvents.DescendentOfInvalidAttestationsCheckpointDetected, this.boundHandleDescendantOfInvalid);
|
|
51
70
|
return Promise.resolve();
|
|
52
71
|
}
|
|
53
72
|
/** Event handler for invalid checkpoints as reported by the archiver. Public for testing purposes. */ handleInvalidCheckpoint(event) {
|
|
54
73
|
const { validationResult } = event;
|
|
55
|
-
const checkpoint = validationResult
|
|
56
|
-
// Check if we already have processed this checkpoint, archiver may emit the same event multiple times
|
|
57
|
-
if (this.invalidArchiveRoots.has(checkpoint.archive.toString())) {
|
|
58
|
-
this.log.trace(`Already processed invalid checkpoint ${checkpoint.checkpointNumber}`);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
74
|
+
const { reason, checkpoint } = validationResult;
|
|
61
75
|
this.log.verbose(`Detected invalid checkpoint ${checkpoint.checkpointNumber}`, {
|
|
62
76
|
...checkpoint,
|
|
63
77
|
reason: validationResult.valid === false ? validationResult.reason : 'unknown'
|
|
64
78
|
});
|
|
65
|
-
|
|
66
|
-
this.addInvalidCheckpoint(event.validationResult.checkpoint);
|
|
67
|
-
// Slash the proposer of the invalid checkpoint
|
|
68
|
-
this.slashProposer(event.validationResult);
|
|
69
|
-
// Check if the parent of this checkpoint is invalid as well, if so, we will slash its attestors as well
|
|
70
|
-
this.slashAttestorsOnAncestorInvalid(event.validationResult);
|
|
71
|
-
}
|
|
72
|
-
slashAttestorsOnAncestorInvalid(validationResult) {
|
|
73
|
-
const checkpoint = validationResult.checkpoint;
|
|
74
|
-
const parentArchive = checkpoint.lastArchive.toString();
|
|
75
|
-
if (this.invalidArchiveRoots.has(parentArchive)) {
|
|
76
|
-
const attestors = validationResult.attestors;
|
|
77
|
-
this.log.info(`Want to slash attestors of checkpoint ${checkpoint.checkpointNumber} built on invalid checkpoint`, {
|
|
78
|
-
...checkpoint,
|
|
79
|
-
...attestors,
|
|
80
|
-
parentArchive
|
|
81
|
-
});
|
|
82
|
-
this.emit(WANT_TO_SLASH_EVENT, attestors.map((attestor)=>({
|
|
83
|
-
validator: attestor,
|
|
84
|
-
amount: this.config.slashAttestDescendantOfInvalidPenalty,
|
|
85
|
-
offenseType: OffenseType.ATTESTED_DESCENDANT_OF_INVALID,
|
|
86
|
-
epochOrSlot: BigInt(SlotNumber(checkpoint.slotNumber))
|
|
87
|
-
})));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
slashProposer(validationResult) {
|
|
91
|
-
const { reason, checkpoint } = validationResult;
|
|
92
|
-
const checkpointNumber = checkpoint.checkpointNumber;
|
|
93
|
-
const slot = checkpoint.slotNumber;
|
|
79
|
+
const { checkpointNumber, slotNumber: slot } = checkpoint;
|
|
94
80
|
const epochCommitteeInfo = {
|
|
95
|
-
|
|
96
|
-
seed: validationResult.seed,
|
|
97
|
-
epoch: validationResult.epoch,
|
|
81
|
+
...validationResult,
|
|
98
82
|
isEscapeHatchOpen: false
|
|
99
83
|
};
|
|
100
84
|
const proposer = this.epochCache.getProposerFromEpochCommittee(epochCommitteeInfo, slot);
|
|
@@ -110,9 +94,48 @@ const AttestationsBlockWatcherConfigKeys = [
|
|
|
110
94
|
offenseType: offense,
|
|
111
95
|
epochOrSlot: BigInt(slot)
|
|
112
96
|
};
|
|
113
|
-
this.log.info(`
|
|
97
|
+
this.log.info(`Detected invalid attestations checkpoint proposer offense`, {
|
|
114
98
|
...checkpoint,
|
|
115
|
-
|
|
99
|
+
reason,
|
|
100
|
+
validator: args.validator.toString(),
|
|
101
|
+
amount: args.amount,
|
|
102
|
+
offenseType: getOffenseTypeName(args.offenseType),
|
|
103
|
+
epochOrSlot: args.epochOrSlot
|
|
104
|
+
});
|
|
105
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
106
|
+
args
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Event handler for valid-attestations checkpoints that build on a previously-rejected ancestor.
|
|
111
|
+
* The archiver emits this when ingesting the descendant, and we slash its proposer.
|
|
112
|
+
*/ async handleDescendantOfInvalid(event) {
|
|
113
|
+
const { checkpoint, ancestorCheckpointNumber, ancestorArchiveRoot } = event;
|
|
114
|
+
const slot = checkpoint.slotNumber;
|
|
115
|
+
const epoch = EpochNumber(getEpochAtSlot(slot, this.epochCache.getL1Constants()));
|
|
116
|
+
const epochCommitteeInfo = await this.epochCache.getCommitteeForEpoch(epoch);
|
|
117
|
+
const proposer = this.epochCache.getProposerFromEpochCommittee({
|
|
118
|
+
...epochCommitteeInfo,
|
|
119
|
+
epoch
|
|
120
|
+
}, slot);
|
|
121
|
+
if (!proposer) {
|
|
122
|
+
this.log.warn(`No proposer found for invalid descendant checkpoint ${checkpoint.checkpointNumber} at slot ${slot}`);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const args = {
|
|
126
|
+
validator: proposer,
|
|
127
|
+
amount: this.config.slashProposeDescendantOfCheckpointWithInvalidAttestationsPenalty,
|
|
128
|
+
offenseType: OffenseType.PROPOSED_DESCENDANT_OF_CHECKPOINT_WITH_INVALID_ATTESTATIONS,
|
|
129
|
+
epochOrSlot: BigInt(slot)
|
|
130
|
+
};
|
|
131
|
+
this.log.info(`Detected invalid descendant checkpoint proposer offense`, {
|
|
132
|
+
...checkpoint,
|
|
133
|
+
ancestorCheckpointNumber,
|
|
134
|
+
ancestorArchiveRoot: ancestorArchiveRoot.toString(),
|
|
135
|
+
validator: args.validator.toString(),
|
|
136
|
+
amount: args.amount,
|
|
137
|
+
offenseType: getOffenseTypeName(args.offenseType),
|
|
138
|
+
epochOrSlot: args.epochOrSlot
|
|
116
139
|
});
|
|
117
140
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
118
141
|
args
|
|
@@ -131,12 +154,4 @@ const AttestationsBlockWatcherConfigKeys = [
|
|
|
131
154
|
}
|
|
132
155
|
}
|
|
133
156
|
}
|
|
134
|
-
addInvalidCheckpoint(checkpoint) {
|
|
135
|
-
this.invalidArchiveRoots.add(checkpoint.archive.toString());
|
|
136
|
-
// Prune old entries if we exceed the maximum
|
|
137
|
-
if (this.invalidArchiveRoots.size > this.maxInvalidCheckpoints) {
|
|
138
|
-
const oldestKey = this.invalidArchiveRoots.keys().next().value;
|
|
139
|
-
this.invalidArchiveRoots.delete(oldestKey);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
157
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
4
|
+
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
5
|
+
import type { P2PClient, SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
6
|
+
import { type Watcher, type WatcherEmitter } from '../watcher.js';
|
|
7
|
+
declare const AttestedInvalidProposalWatcherConfigKeys: readonly ["slashAttestInvalidCheckpointProposalPenalty"];
|
|
8
|
+
type AttestedInvalidProposalWatcherConfig = Pick<SlasherConfig, (typeof AttestedInvalidProposalWatcherConfigKeys)[number]>;
|
|
9
|
+
type P2PCheckpointAttestationSource = Pick<P2PClient, 'getCheckpointAttestationsForSlot'>;
|
|
10
|
+
type AttestedInvalidProposalWatcherOptions = {
|
|
11
|
+
scanSlotLookback?: number;
|
|
12
|
+
log?: Logger;
|
|
13
|
+
};
|
|
14
|
+
export type InvalidProposalSlotSource = {
|
|
15
|
+
hasInvalidProposals(slot: SlotNumber): boolean;
|
|
16
|
+
hasProposalEquivocation(slot: SlotNumber): boolean;
|
|
17
|
+
};
|
|
18
|
+
declare const AttestedInvalidProposalWatcher_base: new () => WatcherEmitter;
|
|
19
|
+
export declare class AttestedInvalidProposalWatcher extends AttestedInvalidProposalWatcher_base implements Watcher {
|
|
20
|
+
private readonly p2pClient;
|
|
21
|
+
private readonly invalidProposalSlotSource;
|
|
22
|
+
private readonly l2BlockSource;
|
|
23
|
+
private readonly epochCache;
|
|
24
|
+
private readonly log;
|
|
25
|
+
private readonly runningPromise;
|
|
26
|
+
private readonly emittedOffenses;
|
|
27
|
+
private readonly scanSlotLookback;
|
|
28
|
+
private config;
|
|
29
|
+
private lastScannedSlot;
|
|
30
|
+
constructor(p2pClient: P2PCheckpointAttestationSource, invalidProposalSlotSource: InvalidProposalSlotSource, l2BlockSource: Pick<L2BlockSource, 'getSyncedL2SlotNumber'>, epochCache: Pick<EpochCacheInterface, 'getSlotNow' | 'getL1Constants'>, config: AttestedInvalidProposalWatcherConfig, options?: AttestedInvalidProposalWatcherOptions);
|
|
31
|
+
updateConfig(config: Partial<SlasherConfig>): void;
|
|
32
|
+
start(): Promise<void>;
|
|
33
|
+
stop(): Promise<void>;
|
|
34
|
+
scan(): Promise<void>;
|
|
35
|
+
/** Scans a single invalid-proposal slot. */
|
|
36
|
+
scanSlot(slot: SlotNumber): Promise<void>;
|
|
37
|
+
private getSlashArgs;
|
|
38
|
+
private getSlashArgsForAttester;
|
|
39
|
+
private markAsNewOffense;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0ZXN0ZWRfaW52YWxpZF9wcm9wb3NhbF93YXRjaGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvd2F0Y2hlcnMvYXR0ZXN0ZWRfaW52YWxpZF9wcm9wb3NhbF93YXRjaGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDOUQsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBSTdELE9BQU8sRUFBRSxLQUFLLE1BQU0sRUFBZ0IsTUFBTSx1QkFBdUIsQ0FBQztB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AAe,CAA2D;IAC3F,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,eAAe,CAAyB;IAEhD,YACmB,SAAS,EAAE,8BAA8B,EACzC,yBAAyB,EAAE,yBAAyB,EACpD,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,uBAAuB,CAAC,EAC3D,UAAU,EAAE,IAAI,CAAC,mBAAmB,EAAE,YAAY,GAAG,gBAAgB,CAAC,EACvF,MAAM,EAAE,oCAAoC,EAC5C,OAAO,GAAE,qCAA0C,EAWpD;IAEM,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAGxD;IAEM,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAG5B;IAEM,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;IAEY,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAqBjC;IAED,4CAA4C;IAC/B,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAmCrD;IAED,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,gBAAgB;CAIzB"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { merge, pick } from '@aztec/foundation/collection';
|
|
3
|
+
import { FifoSet } from '@aztec/foundation/fifo-set';
|
|
4
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
6
|
+
import { OffenseType, getOffenseTypeName } from '@aztec/stdlib/slashing';
|
|
7
|
+
import EventEmitter from 'node:events';
|
|
8
|
+
import { WANT_TO_SLASH_EVENT } from '../watcher.js';
|
|
9
|
+
const AttestedInvalidProposalWatcherConfigKeys = [
|
|
10
|
+
'slashAttestInvalidCheckpointProposalPenalty'
|
|
11
|
+
];
|
|
12
|
+
const SCAN_SLOT_LAG = 1;
|
|
13
|
+
const DEFAULT_SCAN_SLOT_LOOKBACK = 4;
|
|
14
|
+
const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
|
|
15
|
+
export class AttestedInvalidProposalWatcher extends EventEmitter {
|
|
16
|
+
p2pClient;
|
|
17
|
+
invalidProposalSlotSource;
|
|
18
|
+
l2BlockSource;
|
|
19
|
+
epochCache;
|
|
20
|
+
log;
|
|
21
|
+
runningPromise;
|
|
22
|
+
emittedOffenses;
|
|
23
|
+
scanSlotLookback;
|
|
24
|
+
config;
|
|
25
|
+
lastScannedSlot;
|
|
26
|
+
constructor(p2pClient, invalidProposalSlotSource, l2BlockSource, epochCache, config, options = {}){
|
|
27
|
+
super(), this.p2pClient = p2pClient, this.invalidProposalSlotSource = invalidProposalSlotSource, this.l2BlockSource = l2BlockSource, this.epochCache = epochCache, this.emittedOffenses = FifoSet.withLimit(MAX_TRACKED_BAD_ATTESTATIONS);
|
|
28
|
+
const constants = epochCache.getL1Constants();
|
|
29
|
+
this.log = options.log ?? createLogger('attested-invalid-proposal-watcher');
|
|
30
|
+
this.config = pick(config, ...AttestedInvalidProposalWatcherConfigKeys);
|
|
31
|
+
this.scanSlotLookback = Math.max(1, options.scanSlotLookback ?? DEFAULT_SCAN_SLOT_LOOKBACK);
|
|
32
|
+
const intervalMs = Math.max(1000, constants.ethereumSlotDuration * 1000 / 4);
|
|
33
|
+
this.runningPromise = new RunningPromise(()=>this.scan(), this.log, intervalMs);
|
|
34
|
+
this.log.info('AttestedInvalidProposalWatcher initialized', {
|
|
35
|
+
scanSlotLookback: this.scanSlotLookback
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
updateConfig(config) {
|
|
39
|
+
this.config = merge(this.config, pick(config, ...AttestedInvalidProposalWatcherConfigKeys));
|
|
40
|
+
this.log.verbose('AttestedInvalidProposalWatcher config updated', this.config);
|
|
41
|
+
}
|
|
42
|
+
start() {
|
|
43
|
+
this.runningPromise.start();
|
|
44
|
+
return Promise.resolve();
|
|
45
|
+
}
|
|
46
|
+
stop() {
|
|
47
|
+
return this.runningPromise.stop();
|
|
48
|
+
}
|
|
49
|
+
async scan() {
|
|
50
|
+
const currentSlot = await this.l2BlockSource.getSyncedL2SlotNumber() ?? this.epochCache.getSlotNow();
|
|
51
|
+
// genesis
|
|
52
|
+
if (currentSlot <= SlotNumber(SCAN_SLOT_LAG)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const newestSlotToConsider = SlotNumber(currentSlot - SCAN_SLOT_LAG);
|
|
56
|
+
const oldestSlot = this.lastScannedSlot === undefined ? SlotNumber(Math.max(0, newestSlotToConsider - this.scanSlotLookback + 1)) : SlotNumber(this.lastScannedSlot + 1);
|
|
57
|
+
if (oldestSlot > newestSlotToConsider) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
for(let slot = oldestSlot; slot <= newestSlotToConsider; slot++){
|
|
61
|
+
await this.scanSlot(slot);
|
|
62
|
+
}
|
|
63
|
+
this.lastScannedSlot = newestSlotToConsider;
|
|
64
|
+
}
|
|
65
|
+
/** Scans a single invalid-proposal slot. */ async scanSlot(slot) {
|
|
66
|
+
if (this.invalidProposalSlotSource.hasProposalEquivocation(slot) || !this.invalidProposalSlotSource.hasInvalidProposals(slot)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
let attestations;
|
|
70
|
+
try {
|
|
71
|
+
attestations = await this.p2pClient.getCheckpointAttestationsForSlot(slot);
|
|
72
|
+
} catch (err) {
|
|
73
|
+
this.log.warn('Error getting checkpoint attestations for invalid proposal slot', {
|
|
74
|
+
err,
|
|
75
|
+
slot
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const slashArgs = attestations.map((attestation)=>this.getSlashArgs(slot, attestation)).filter((args)=>args !== undefined).filter((args)=>this.markAsNewOffense(args));
|
|
80
|
+
if (slashArgs.length === 0) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.log.info('Detected attestations to invalid checkpoint proposal', {
|
|
84
|
+
slot,
|
|
85
|
+
offenses: slashArgs.map((args)=>({
|
|
86
|
+
validator: args.validator.toString(),
|
|
87
|
+
amount: args.amount,
|
|
88
|
+
offenseType: getOffenseTypeName(args.offenseType),
|
|
89
|
+
epochOrSlot: args.epochOrSlot
|
|
90
|
+
}))
|
|
91
|
+
});
|
|
92
|
+
this.emit(WANT_TO_SLASH_EVENT, slashArgs);
|
|
93
|
+
}
|
|
94
|
+
getSlashArgs(slot, attestation) {
|
|
95
|
+
const attester = attestation.getSender();
|
|
96
|
+
if (!attester) {
|
|
97
|
+
this.log.warn('Cannot slash checkpoint attestation with invalid signature', {
|
|
98
|
+
slot,
|
|
99
|
+
archive: attestation.archive.toString()
|
|
100
|
+
});
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
return this.getSlashArgsForAttester(slot, attester);
|
|
104
|
+
}
|
|
105
|
+
getSlashArgsForAttester(slot, attester) {
|
|
106
|
+
return {
|
|
107
|
+
validator: attester,
|
|
108
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
109
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
110
|
+
epochOrSlot: BigInt(slot)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
markAsNewOffense(args) {
|
|
114
|
+
const key = `${args.validator.toString()}-${args.offenseType}-${args.epochOrSlot}`;
|
|
115
|
+
return this.emittedOffenses.addIfAbsent(key);
|
|
116
|
+
}
|
|
117
|
+
}
|