@aztec/slasher 0.0.1-commit.e558bd1c → 0.0.1-commit.e57c76e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -78
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +35 -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 +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 +8 -7
- package/dest/generated/slasher-defaults.d.ts.map +1 -1
- package/dest/generated/slasher-defaults.js +7 -6
- package/dest/index.d.ts +6 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +5 -3
- 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 -34
- 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} +45 -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 +61 -38
- 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 +42 -29
- 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 +7 -6
- package/src/index.ts +5 -3
- package/src/null_slasher_client.ts +2 -6
- package/src/slash_offenses_collector.ts +70 -36
- package/src/{tally_slasher_client.ts → slasher_client.ts} +63 -54
- package/src/slasher_client_facade.ts +6 -11
- package/src/slasher_client_interface.ts +6 -21
- package/src/stores/offenses_store.ts +73 -47
- 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 -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/dest/watchers/epoch_prune_watcher.d.ts +0 -39
- package/dest/watchers/epoch_prune_watcher.d.ts.map +0 -1
- package/dest/watchers/epoch_prune_watcher.js +0 -175
- package/src/empire_slasher_client.ts +0 -649
- package/src/stores/payloads_store.ts +0 -149
- package/src/watchers/epoch_prune_watcher.ts +0 -251
|
@@ -0,0 +1,138 @@
|
|
|
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 BroadcastedInvalidCheckpointProposalWatcherConfigKeys = [
|
|
10
|
+
'slashBroadcastedInvalidCheckpointProposalPenalty'
|
|
11
|
+
];
|
|
12
|
+
const SCAN_SLOT_LAG = 1;
|
|
13
|
+
const DEFAULT_SCAN_SLOT_LOOKBACK = 4;
|
|
14
|
+
/** Detects truncated-checkpoint proposal offenses from retained signed P2P proposals. */ export class BroadcastedInvalidCheckpointProposalWatcher extends EventEmitter {
|
|
15
|
+
p2pClient;
|
|
16
|
+
l2BlockSource;
|
|
17
|
+
epochCache;
|
|
18
|
+
log;
|
|
19
|
+
runningPromise;
|
|
20
|
+
emittedOffenses;
|
|
21
|
+
scanSlotLookback;
|
|
22
|
+
config;
|
|
23
|
+
lastScannedSlot;
|
|
24
|
+
constructor(p2pClient, l2BlockSource, epochCache, config, scanSlotLookback = DEFAULT_SCAN_SLOT_LOOKBACK){
|
|
25
|
+
super(), this.p2pClient = p2pClient, this.l2BlockSource = l2BlockSource, this.epochCache = epochCache, this.log = createLogger('broadcasted-invalid-checkpoint-proposal-watcher');
|
|
26
|
+
const constants = epochCache.getL1Constants();
|
|
27
|
+
this.config = pick(config, ...BroadcastedInvalidCheckpointProposalWatcherConfigKeys);
|
|
28
|
+
this.scanSlotLookback = Math.max(1, scanSlotLookback);
|
|
29
|
+
// Bound emitted offenses to the number of slots we rescan. This watcher currently tracks one offense type,
|
|
30
|
+
// and at most one offense of that type can be emitted per slot.
|
|
31
|
+
const offenseTypes = 1;
|
|
32
|
+
this.emittedOffenses = FifoSet.withLimit(offenseTypes * this.scanSlotLookback);
|
|
33
|
+
const intervalMs = Math.max(1000, constants.ethereumSlotDuration * 1000 / 4);
|
|
34
|
+
this.runningPromise = new RunningPromise(()=>this.scan(), this.log, intervalMs);
|
|
35
|
+
this.log.info('BroadcastedInvalidCheckpointProposalWatcher initialized', {
|
|
36
|
+
scanSlotLookback: this.scanSlotLookback
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
updateConfig(config) {
|
|
40
|
+
this.config = merge(this.config, pick(config, ...BroadcastedInvalidCheckpointProposalWatcherConfigKeys));
|
|
41
|
+
this.log.verbose('BroadcastedInvalidCheckpointProposalWatcher config updated', this.config);
|
|
42
|
+
}
|
|
43
|
+
start() {
|
|
44
|
+
this.runningPromise.start();
|
|
45
|
+
return Promise.resolve();
|
|
46
|
+
}
|
|
47
|
+
stop() {
|
|
48
|
+
return this.runningPromise.stop();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Scans newly closed slots, plus a small lookback for late-arriving proposals. Anchors
|
|
52
|
+
* `currentSlot` at the archiver's last synced L2 slot.
|
|
53
|
+
*/ async scan() {
|
|
54
|
+
const currentSlot = await this.l2BlockSource.getSyncedL2SlotNumber() ?? this.epochCache.getSlotNow();
|
|
55
|
+
if (currentSlot <= SlotNumber(SCAN_SLOT_LAG)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const newestSlotToConsider = SlotNumber(currentSlot - 1 - SCAN_SLOT_LAG);
|
|
59
|
+
const oldestLookbackSlot = SlotNumber(Math.max(0, newestSlotToConsider - this.scanSlotLookback + 1));
|
|
60
|
+
const oldestUnscannedSlot = this.lastScannedSlot === undefined ? oldestLookbackSlot : SlotNumber(this.lastScannedSlot + 1);
|
|
61
|
+
const oldestSlot = SlotNumber(Math.min(oldestLookbackSlot, oldestUnscannedSlot));
|
|
62
|
+
for(let slot = oldestSlot; slot <= newestSlotToConsider; slot++){
|
|
63
|
+
await this.scanSlot(SlotNumber(slot));
|
|
64
|
+
}
|
|
65
|
+
this.lastScannedSlot = newestSlotToConsider;
|
|
66
|
+
}
|
|
67
|
+
/** Scans a single slot. Public for tests. */ async scanSlot(slot) {
|
|
68
|
+
const proposals = await this.p2pClient.getProposalsForSlot(slot);
|
|
69
|
+
const slashArgs = this.getSlashArgsForProposals(slot, proposals).filter((args)=>this.markAsNewOffense(args));
|
|
70
|
+
if (slashArgs.length === 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.log.info(`Detected broadcasted invalid checkpoint proposal offense`, {
|
|
74
|
+
slot,
|
|
75
|
+
offenses: slashArgs.map((args)=>({
|
|
76
|
+
validator: args.validator.toString(),
|
|
77
|
+
amount: args.amount,
|
|
78
|
+
offenseType: getOffenseTypeName(args.offenseType),
|
|
79
|
+
epochOrSlot: args.epochOrSlot
|
|
80
|
+
}))
|
|
81
|
+
});
|
|
82
|
+
this.emit(WANT_TO_SLASH_EVENT, slashArgs);
|
|
83
|
+
}
|
|
84
|
+
getSlashArgsForProposals(slot, proposals) {
|
|
85
|
+
const offenders = this.findOffenders(proposals.blockProposals, proposals.checkpointProposals);
|
|
86
|
+
// we expect one proposer per slot today.
|
|
87
|
+
return [
|
|
88
|
+
...offenders.values()
|
|
89
|
+
].map((validator)=>({
|
|
90
|
+
validator,
|
|
91
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
92
|
+
offenseType: OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL,
|
|
93
|
+
epochOrSlot: BigInt(slot)
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
findOffenders(blockProposals, checkpointProposals) {
|
|
97
|
+
const blocksBySigner = this.getSignedBlocksBySigner(blockProposals);
|
|
98
|
+
const offenders = new Map();
|
|
99
|
+
for (const checkpoint of checkpointProposals){
|
|
100
|
+
const checkpointSigner = checkpoint.getSender();
|
|
101
|
+
if (!checkpointSigner) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const signerKey = checkpointSigner.toString();
|
|
105
|
+
const signerBlocks = blocksBySigner.get(signerKey) ?? [];
|
|
106
|
+
const terminalBlocks = signerBlocks.filter(({ proposal })=>proposal.slotNumber === checkpoint.slotNumber && proposal.archive.equals(checkpoint.archive));
|
|
107
|
+
if (terminalBlocks.length === 0) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const hasTruncatedHigherBlock = terminalBlocks.some((terminalBlock)=>signerBlocks.some(({ proposal })=>proposal.slotNumber === checkpoint.slotNumber && proposal.indexWithinCheckpoint > terminalBlock.proposal.indexWithinCheckpoint));
|
|
111
|
+
if (hasTruncatedHigherBlock) {
|
|
112
|
+
offenders.set(signerKey, checkpointSigner);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return offenders;
|
|
116
|
+
}
|
|
117
|
+
getSignedBlocksBySigner(blockProposals) {
|
|
118
|
+
const blocksBySigner = new Map();
|
|
119
|
+
for (const proposal of blockProposals){
|
|
120
|
+
const signer = proposal.getSender();
|
|
121
|
+
if (!signer) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const signerKey = signer.toString();
|
|
125
|
+
const signerBlocks = blocksBySigner.get(signerKey) ?? [];
|
|
126
|
+
signerBlocks.push({
|
|
127
|
+
proposal,
|
|
128
|
+
signer
|
|
129
|
+
});
|
|
130
|
+
blocksBySigner.set(signerKey, signerBlocks);
|
|
131
|
+
}
|
|
132
|
+
return blocksBySigner;
|
|
133
|
+
}
|
|
134
|
+
markAsNewOffense(args) {
|
|
135
|
+
const key = `${args.validator.toString()}-${args.offenseType}-${args.epochOrSlot}`;
|
|
136
|
+
return this.emittedOffenses.addIfAbsent(key);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
2
|
+
import { type CheckpointEquivocationDetectedEvent, type L2BlockSourceEventEmitter } from '@aztec/stdlib/block';
|
|
3
|
+
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
4
|
+
import { type Watcher, type WatcherEmitter } from '../watcher.js';
|
|
5
|
+
declare const CheckpointEquivocationWatcherConfigKeys: readonly ["slashDuplicateProposalPenalty"];
|
|
6
|
+
type CheckpointEquivocationWatcherConfig = Pick<SlasherConfig, (typeof CheckpointEquivocationWatcherConfigKeys)[number]>;
|
|
7
|
+
type EquivocationEventSource = Pick<L2BlockSourceEventEmitter, 'events'>;
|
|
8
|
+
type ProposerLookup = Pick<EpochCacheInterface, 'getProposerAttesterAddressInSlot'>;
|
|
9
|
+
declare const CheckpointEquivocationWatcher_base: new () => WatcherEmitter;
|
|
10
|
+
/**
|
|
11
|
+
* Slashes the slot proposer for DUPLICATE_PROPOSAL when the archiver detects that a
|
|
12
|
+
* locally-stored proposed checkpoint disagrees with the L1-confirmed checkpoint at the
|
|
13
|
+
* same slot. Both are signed by the slot proposer (the proposed one by accepting it via
|
|
14
|
+
* P2P or building it locally; the L1 one by submission), so the proposer equivocated.
|
|
15
|
+
*/
|
|
16
|
+
export declare class CheckpointEquivocationWatcher extends CheckpointEquivocationWatcher_base implements Watcher {
|
|
17
|
+
private readonly l2BlockSource;
|
|
18
|
+
private readonly epochCache;
|
|
19
|
+
private readonly log;
|
|
20
|
+
private readonly handler;
|
|
21
|
+
private config;
|
|
22
|
+
constructor(l2BlockSource: EquivocationEventSource, epochCache: ProposerLookup, config: CheckpointEquivocationWatcherConfig);
|
|
23
|
+
updateConfig(config: Partial<CheckpointEquivocationWatcherConfig>): void;
|
|
24
|
+
start(): Promise<void>;
|
|
25
|
+
stop(): Promise<void>;
|
|
26
|
+
/** Public for tests. */
|
|
27
|
+
onEquivocationDetected(event: CheckpointEquivocationDetectedEvent): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hlY2twb2ludF9lcXVpdm9jYXRpb25fd2F0Y2hlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3dhdGNoZXJzL2NoZWNrcG9pbnRfZXF1aXZvY2F0aW9uX3dhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUc5RCxPQUFPLEVBQ0wsS0FBSyxtQ0FBbUMsRUFDeEMsS0FBSyx5QkFBeUIsRUFFL0IsTUFBTSxxQkFBcUIsQ0FBQztBQUM3QixPQUFPLEtBQUssRUFBRSxhQUFhLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUtyRSxPQUFPLEVBQTZDLEtBQUssT0FBTyxFQUFFLEtBQUssY0FBYyxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBRTdHLFFBQUEsTUFBTSx1Q0FBdUMsNENBQTZDLENBQUM7QUFFM0YsS0FBSyxtQ0FBbUMsR0FBRyxJQUFJLENBQzdDLGFBQWEsRUFDYix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|
|
|
1
|
+
import { merge, pick } from '@aztec/foundation/collection';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { L2BlockSourceEvents } from '@aztec/stdlib/block';
|
|
4
|
+
import { OffenseType, getOffenseTypeName } from '@aztec/stdlib/slashing';
|
|
5
|
+
import EventEmitter from 'node:events';
|
|
6
|
+
import { WANT_TO_SLASH_EVENT } from '../watcher.js';
|
|
7
|
+
const CheckpointEquivocationWatcherConfigKeys = [
|
|
8
|
+
'slashDuplicateProposalPenalty'
|
|
9
|
+
];
|
|
10
|
+
/**
|
|
11
|
+
* Slashes the slot proposer for DUPLICATE_PROPOSAL when the archiver detects that a
|
|
12
|
+
* locally-stored proposed checkpoint disagrees with the L1-confirmed checkpoint at the
|
|
13
|
+
* same slot. Both are signed by the slot proposer (the proposed one by accepting it via
|
|
14
|
+
* P2P or building it locally; the L1 one by submission), so the proposer equivocated.
|
|
15
|
+
*/ export class CheckpointEquivocationWatcher extends EventEmitter {
|
|
16
|
+
l2BlockSource;
|
|
17
|
+
epochCache;
|
|
18
|
+
log;
|
|
19
|
+
handler;
|
|
20
|
+
config;
|
|
21
|
+
constructor(l2BlockSource, epochCache, config){
|
|
22
|
+
super(), this.l2BlockSource = l2BlockSource, this.epochCache = epochCache, this.log = createLogger('checkpoint-equivocation-watcher');
|
|
23
|
+
this.config = pick(config, ...CheckpointEquivocationWatcherConfigKeys);
|
|
24
|
+
this.handler = (event)=>{
|
|
25
|
+
this.onEquivocationDetected(event).catch((err)=>this.log.error('Failed to handle checkpoint equivocation event', err));
|
|
26
|
+
};
|
|
27
|
+
this.log.info('CheckpointEquivocationWatcher initialized');
|
|
28
|
+
}
|
|
29
|
+
updateConfig(config) {
|
|
30
|
+
this.config = merge(this.config, pick(config, ...CheckpointEquivocationWatcherConfigKeys));
|
|
31
|
+
this.log.verbose('CheckpointEquivocationWatcher config updated', this.config);
|
|
32
|
+
}
|
|
33
|
+
start() {
|
|
34
|
+
this.l2BlockSource.events.on(L2BlockSourceEvents.CheckpointEquivocationDetected, this.handler);
|
|
35
|
+
return Promise.resolve();
|
|
36
|
+
}
|
|
37
|
+
stop() {
|
|
38
|
+
this.l2BlockSource.events.off(L2BlockSourceEvents.CheckpointEquivocationDetected, this.handler);
|
|
39
|
+
return Promise.resolve();
|
|
40
|
+
}
|
|
41
|
+
/** Public for tests. */ async onEquivocationDetected(event) {
|
|
42
|
+
const proposer = await this.epochCache.getProposerAttesterAddressInSlot(event.slotNumber);
|
|
43
|
+
if (!proposer) {
|
|
44
|
+
this.log.warn(`Cannot attribute checkpoint equivocation: no proposer for slot ${event.slotNumber}`, {
|
|
45
|
+
slotNumber: event.slotNumber,
|
|
46
|
+
checkpointNumber: event.checkpointNumber
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const slashArgs = {
|
|
51
|
+
validator: proposer,
|
|
52
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
53
|
+
offenseType: OffenseType.DUPLICATE_PROPOSAL,
|
|
54
|
+
epochOrSlot: BigInt(event.slotNumber)
|
|
55
|
+
};
|
|
56
|
+
this.log.info(`Detected checkpoint equivocation offense`, {
|
|
57
|
+
slotNumber: event.slotNumber,
|
|
58
|
+
checkpointNumber: event.checkpointNumber,
|
|
59
|
+
amount: slashArgs.amount,
|
|
60
|
+
offenseType: getOffenseTypeName(slashArgs.offenseType),
|
|
61
|
+
l1ArchiveRoot: event.l1ArchiveRoot.toString(),
|
|
62
|
+
proposedArchiveRoot: event.proposedArchiveRoot.toString(),
|
|
63
|
+
validator: proposer.toString()
|
|
64
|
+
});
|
|
65
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
66
|
+
slashArgs
|
|
67
|
+
]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
4
|
+
import type { L2BlockSource } from '@aztec/stdlib/block';
|
|
5
|
+
import type { CheckpointReexecutionTracker, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
6
|
+
import type { ITxProvider, P2PApi, SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
7
|
+
import { type CoordinationSignatureContext } from '@aztec/stdlib/p2p';
|
|
8
|
+
import { type Watcher, type WatcherEmitter } from '../watcher.js';
|
|
9
|
+
declare const DataWithholdingWatcherConfigKeys: readonly ["slashDataWithholdingPenalty", "slashDataWithholdingToleranceSlots"];
|
|
10
|
+
type DataWithholdingWatcherConfig = Pick<SlasherConfig, (typeof DataWithholdingWatcherConfigKeys)[number]>;
|
|
11
|
+
declare const DataWithholdingWatcher_base: new () => WatcherEmitter;
|
|
12
|
+
/**
|
|
13
|
+
* Detects data-withholding offenses by probing the local mempool for the txs in published
|
|
14
|
+
* checkpoints once they are old enough that an honest node should have collected them.
|
|
15
|
+
*
|
|
16
|
+
* Per AZIP-7: once `slashDataWithholdingToleranceSlots` full slots have elapsed after the
|
|
17
|
+
* checkpoint's slot — i.e. at `slotStart(checkpoint.slot + slashDataWithholdingToleranceSlots
|
|
18
|
+
* + 1)` — if any tx from the checkpoint's blocks is still missing locally, the checkpoint's
|
|
19
|
+
* attesters are considered at fault for not making the data available, and we emit a slash
|
|
20
|
+
* for them.
|
|
21
|
+
*
|
|
22
|
+
* The watcher ticks at quarter-eth-slot cadence (matching the Sentinel template). On boot it
|
|
23
|
+
* floors processing at the current slot — restart-time gaps are accepted and not back-filled,
|
|
24
|
+
* matching the Sentinel approach.
|
|
25
|
+
*/
|
|
26
|
+
export declare class DataWithholdingWatcher extends DataWithholdingWatcher_base implements Watcher {
|
|
27
|
+
private readonly epochCache;
|
|
28
|
+
private readonly l2BlockSource;
|
|
29
|
+
private readonly txProvider;
|
|
30
|
+
private readonly p2p;
|
|
31
|
+
private readonly reexecutionTracker;
|
|
32
|
+
private readonly signatureContext;
|
|
33
|
+
private readonly log;
|
|
34
|
+
private runningPromise;
|
|
35
|
+
private initialSlot;
|
|
36
|
+
private lastCheckedSlot;
|
|
37
|
+
private config;
|
|
38
|
+
constructor(epochCache: EpochCache, l2BlockSource: Pick<L2BlockSource, 'getCheckpoint' | 'getSyncedL2SlotNumber'>, txProvider: Pick<ITxProvider, 'hasTxs'>, p2p: Pick<P2PApi, 'getCheckpointAttestationsForSlot'>, reexecutionTracker: Pick<CheckpointReexecutionTracker, 'getTxsCollectedRecord'>, signatureContext: CoordinationSignatureContext, config: DataWithholdingWatcherConfig, log?: Logger);
|
|
39
|
+
start(): Promise<void>;
|
|
40
|
+
stop(): Promise<void>;
|
|
41
|
+
updateConfig(config: Partial<SlasherConfig>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Runs every tick. Walks newly-eligible slots and probes their checkpoints for data
|
|
44
|
+
* availability; emits a DATA_WITHHOLDING slash for any checkpoint whose txs are missing.
|
|
45
|
+
*/
|
|
46
|
+
work(): Promise<void>;
|
|
47
|
+
private processSlot;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the union of:
|
|
50
|
+
* 1. attesters whose signatures landed in the published checkpoint on L1, and
|
|
51
|
+
* 2. attesters we observed signing the same proposal on p2p (the proposer publishes as
|
|
52
|
+
* soon as it has hit committee quorum, so honest peer attestations that arrive after
|
|
53
|
+
* that point are dropped — but they still vouched for the data and
|
|
54
|
+
* should be slashed for withholding it).
|
|
55
|
+
*
|
|
56
|
+
*
|
|
57
|
+
* Exposed as protected so tests can substitute a deterministic recovery without having
|
|
58
|
+
* to construct real secp256k1 signatures.
|
|
59
|
+
*/
|
|
60
|
+
protected extractAttesters(published: PublishedCheckpoint): Promise<EthAddress[]>;
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0YV93aXRoaG9sZGluZ193YXRjaGVyLmQudHMiLCJzb3VyY2VSb290I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kB;IACnC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAEjC,OAAO,CAAC,QAAQ,CAAC,GAAG;IAbtB,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,WAAW,CAAyB;IAC5C,OAAO,CAAC,eAAe,CAAyB;IAChD,OAAO,CAAC,MAAM,CAA+B;IAE7C,YACmB,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,eAAe,GAAG,uBAAuB,CAAC,EAC7E,UAAU,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,EACvC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,kCAAkC,CAAC,EACrD,kBAAkB,EAAE,IAAI,CAAC,4BAA4B,EAAE,uBAAuB,CAAC,EAC/E,gBAAgB,EAAE,4BAA4B,EAC/D,MAAM,EAAE,4BAA4B,EACnB,GAAG,GAAE,MAAiD,EAOxE;IAEY,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAQlC;IAEM,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;IAEM,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAGxD;IAED;;;OAGG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CA8BjC;YAGa,WAAW;IA6EzB;;;;;;;;;;;OAWG;IACH,UAAgB,gBAAgB,CAAC,SAAS,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAmBtF;CACF"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { CheckpointProposalHash, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { compactArray, merge, pick } from '@aztec/foundation/collection';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { RunningPromise } from '@aztec/foundation/promise';
|
|
5
|
+
import { getAttestationInfoFromPublishedCheckpoint } from '@aztec/stdlib/block';
|
|
6
|
+
import { ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
7
|
+
import { OffenseType, getOffenseTypeName } from '@aztec/stdlib/slashing';
|
|
8
|
+
import EventEmitter from 'node:events';
|
|
9
|
+
import { WANT_TO_SLASH_EVENT } from '../watcher.js';
|
|
10
|
+
const DataWithholdingWatcherConfigKeys = [
|
|
11
|
+
'slashDataWithholdingPenalty',
|
|
12
|
+
'slashDataWithholdingToleranceSlots'
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Detects data-withholding offenses by probing the local mempool for the txs in published
|
|
16
|
+
* checkpoints once they are old enough that an honest node should have collected them.
|
|
17
|
+
*
|
|
18
|
+
* Per AZIP-7: once `slashDataWithholdingToleranceSlots` full slots have elapsed after the
|
|
19
|
+
* checkpoint's slot — i.e. at `slotStart(checkpoint.slot + slashDataWithholdingToleranceSlots
|
|
20
|
+
* + 1)` — if any tx from the checkpoint's blocks is still missing locally, the checkpoint's
|
|
21
|
+
* attesters are considered at fault for not making the data available, and we emit a slash
|
|
22
|
+
* for them.
|
|
23
|
+
*
|
|
24
|
+
* The watcher ticks at quarter-eth-slot cadence (matching the Sentinel template). On boot it
|
|
25
|
+
* floors processing at the current slot — restart-time gaps are accepted and not back-filled,
|
|
26
|
+
* matching the Sentinel approach.
|
|
27
|
+
*/ export class DataWithholdingWatcher extends EventEmitter {
|
|
28
|
+
epochCache;
|
|
29
|
+
l2BlockSource;
|
|
30
|
+
txProvider;
|
|
31
|
+
p2p;
|
|
32
|
+
reexecutionTracker;
|
|
33
|
+
signatureContext;
|
|
34
|
+
log;
|
|
35
|
+
runningPromise;
|
|
36
|
+
initialSlot;
|
|
37
|
+
lastCheckedSlot;
|
|
38
|
+
config;
|
|
39
|
+
constructor(epochCache, l2BlockSource, txProvider, p2p, reexecutionTracker, signatureContext, config, log = createLogger('data-withholding-watcher')){
|
|
40
|
+
super(), this.epochCache = epochCache, this.l2BlockSource = l2BlockSource, this.txProvider = txProvider, this.p2p = p2p, this.reexecutionTracker = reexecutionTracker, this.signatureContext = signatureContext, this.log = log;
|
|
41
|
+
this.config = pick(config, ...DataWithholdingWatcherConfigKeys);
|
|
42
|
+
const interval = epochCache.getL1Constants().ethereumSlotDuration * 1000 / 4;
|
|
43
|
+
this.runningPromise = new RunningPromise(this.work.bind(this), log, interval);
|
|
44
|
+
this.log.verbose(`DataWithholdingWatcher initialized`, this.config);
|
|
45
|
+
}
|
|
46
|
+
async start() {
|
|
47
|
+
// Floor processing at the archiver's synced slot rather than the wallclock — restart-time
|
|
48
|
+
// gaps before the archiver catches up are accepted and not back-filled. Falls back to the
|
|
49
|
+
// wallclock if the archiver isn't ready yet (cold start).
|
|
50
|
+
const syncedSlot = await this.l2BlockSource.getSyncedL2SlotNumber();
|
|
51
|
+
this.initialSlot = syncedSlot ?? this.epochCache.getSlotNow();
|
|
52
|
+
this.log.info(`Starting data-withholding watcher with initial slot ${this.initialSlot}`);
|
|
53
|
+
this.runningPromise.start();
|
|
54
|
+
}
|
|
55
|
+
stop() {
|
|
56
|
+
return this.runningPromise.stop();
|
|
57
|
+
}
|
|
58
|
+
updateConfig(config) {
|
|
59
|
+
this.config = merge(this.config, pick(config, ...DataWithholdingWatcherConfigKeys));
|
|
60
|
+
this.log.verbose('DataWithholdingWatcher config updated', this.config);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Runs every tick. Walks newly-eligible slots and probes their checkpoints for data
|
|
64
|
+
* availability; emits a DATA_WITHHOLDING slash for any checkpoint whose txs are missing.
|
|
65
|
+
*/ async work() {
|
|
66
|
+
if (this.initialSlot === undefined) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// tolerance is the number of full slots that must elapse after the checkpoint's slot
|
|
70
|
+
// before we declare its data missing. For checkpoint slot S, we therefore process S
|
|
71
|
+
// only once we are in slot `S + tolerance + 1` or later. Drive this off the archiver's
|
|
72
|
+
// synced slot rather than the wallclock so we don't make claims about slots we haven't
|
|
73
|
+
// fully ingested yet (archiver may lag behind L1).
|
|
74
|
+
const tolerance = this.config.slashDataWithholdingToleranceSlots;
|
|
75
|
+
const currentSlot = await this.l2BlockSource.getSyncedL2SlotNumber() ?? this.epochCache.getSlotNow();
|
|
76
|
+
if (currentSlot <= tolerance) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const targetSlot = SlotNumber(currentSlot - tolerance - 1);
|
|
80
|
+
if (targetSlot <= this.initialSlot) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const startSlot = this.lastCheckedSlot === undefined ? this.initialSlot : this.lastCheckedSlot;
|
|
84
|
+
for(let slot = SlotNumber(startSlot + 1); slot <= targetSlot; slot = SlotNumber(slot + 1)){
|
|
85
|
+
try {
|
|
86
|
+
await this.processSlot(slot);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
this.log.error(`Error processing slot ${slot} for data-withholding check`, err, {
|
|
89
|
+
slot
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
this.lastCheckedSlot = slot;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Probes the checkpoint at the given slot, if any, and emits a slash on missing txs. */ async processSlot(slot) {
|
|
96
|
+
const published = await this.l2BlockSource.getCheckpoint({
|
|
97
|
+
slot
|
|
98
|
+
});
|
|
99
|
+
if (!published) {
|
|
100
|
+
this.log.trace(`No published checkpoint at slot ${slot}`, {
|
|
101
|
+
slot
|
|
102
|
+
});
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const checkpointNumber = published.checkpoint.number;
|
|
106
|
+
// Per-block tx-collection records (true | false | undefined) for every block in this
|
|
107
|
+
// published checkpoint. Captured by the validator's proposal handler at the moment of
|
|
108
|
+
// tx collection (i.e. by the *re-execution* deadline). Used as a positive short-circuit
|
|
109
|
+
// only: a `true` for every block means we know the data was available locally, so this
|
|
110
|
+
// checkpoint cannot be a data-withholding offense. A `false` does *not* trigger a slash
|
|
111
|
+
// on its own — the re-execution deadline is much earlier than the data-withholding
|
|
112
|
+
// tolerance window, so missing txs at that earlier deadline may still arrive in time.
|
|
113
|
+
// Anything other than all-true falls through to the mempool probe, which respects the
|
|
114
|
+
// tolerance window.
|
|
115
|
+
const collectionRecords = published.checkpoint.blocks.map((block, idx)=>this.reexecutionTracker.getTxsCollectedRecord(block.header.getSlot(), idx));
|
|
116
|
+
if (collectionRecords.every((r)=>r === true)) {
|
|
117
|
+
this.log.trace(`All blocks for checkpoint at slot ${slot} were collected locally; skipping`, {
|
|
118
|
+
slot,
|
|
119
|
+
checkpointNumber
|
|
120
|
+
});
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const txHashes = published.checkpoint.blocks.flatMap((block)=>block.body.txEffects.map((txEffect)=>txEffect.txHash));
|
|
124
|
+
if (txHashes.length === 0) {
|
|
125
|
+
this.log.trace(`Checkpoint at slot ${slot} has no txs`, {
|
|
126
|
+
slot
|
|
127
|
+
});
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const availability = await this.txProvider.hasTxs(txHashes);
|
|
131
|
+
const missingTxs = txHashes.filter((_, i)=>!availability[i]);
|
|
132
|
+
if (missingTxs.length === 0) {
|
|
133
|
+
this.log.trace(`All ${txHashes.length} txs available for checkpoint at slot ${slot}`, {
|
|
134
|
+
slot
|
|
135
|
+
});
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const attesters = await this.extractAttesters(published);
|
|
139
|
+
if (attesters.length === 0) {
|
|
140
|
+
this.log.warn(`Detected data withholding at slot ${slot} but no recoverable attesters`, {
|
|
141
|
+
slot,
|
|
142
|
+
checkpointNumber,
|
|
143
|
+
missingTxs: missingTxs.map((h)=>h.toString()),
|
|
144
|
+
records: collectionRecords
|
|
145
|
+
});
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
this.log.info(`Detected data withholding offense at slot ${slot}`, {
|
|
149
|
+
slot,
|
|
150
|
+
checkpointNumber,
|
|
151
|
+
amount: this.config.slashDataWithholdingPenalty,
|
|
152
|
+
offenseType: getOffenseTypeName(OffenseType.DATA_WITHHOLDING),
|
|
153
|
+
missingTxs: missingTxs.map((h)=>h.toString()),
|
|
154
|
+
records: collectionRecords,
|
|
155
|
+
attesters: attesters.map((a)=>a.toString())
|
|
156
|
+
});
|
|
157
|
+
const args = attesters.map((validator)=>({
|
|
158
|
+
validator,
|
|
159
|
+
amount: this.config.slashDataWithholdingPenalty,
|
|
160
|
+
offenseType: OffenseType.DATA_WITHHOLDING,
|
|
161
|
+
epochOrSlot: BigInt(slot)
|
|
162
|
+
}));
|
|
163
|
+
this.emit(WANT_TO_SLASH_EVENT, args);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Returns the union of:
|
|
167
|
+
* 1. attesters whose signatures landed in the published checkpoint on L1, and
|
|
168
|
+
* 2. attesters we observed signing the same proposal on p2p (the proposer publishes as
|
|
169
|
+
* soon as it has hit committee quorum, so honest peer attestations that arrive after
|
|
170
|
+
* that point are dropped — but they still vouched for the data and
|
|
171
|
+
* should be slashed for withholding it).
|
|
172
|
+
*
|
|
173
|
+
*
|
|
174
|
+
* Exposed as protected so tests can substitute a deterministic recovery without having
|
|
175
|
+
* to construct real secp256k1 signatures.
|
|
176
|
+
*/ async extractAttesters(published) {
|
|
177
|
+
const fromL1 = getAttestationInfoFromPublishedCheckpoint(published, this.signatureContext).filter((info)=>info.status === 'recovered-from-signature').map((info)=>info.address);
|
|
178
|
+
const slot = published.checkpoint.header.slotNumber;
|
|
179
|
+
const proposalPayloadHash = CheckpointProposalHash.fromBuffer(ConsensusPayload.fromCheckpoint(published.checkpoint, this.signatureContext).getPayloadHash());
|
|
180
|
+
const fromP2p = await this.p2p.getCheckpointAttestationsForSlot(slot, proposalPayloadHash).then((attestations)=>attestations.map((a)=>a.getSender()));
|
|
181
|
+
// Dedupe
|
|
182
|
+
const all = new Map();
|
|
183
|
+
for (const addr of compactArray([
|
|
184
|
+
...fromL1,
|
|
185
|
+
...fromP2p
|
|
186
|
+
])){
|
|
187
|
+
all.set(addr.toString(), addr);
|
|
188
|
+
}
|
|
189
|
+
return [
|
|
190
|
+
...all.values()
|
|
191
|
+
];
|
|
192
|
+
}
|
|
193
|
+
}
|
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.e57c76e",
|
|
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.e57c76e",
|
|
60
|
+
"@aztec/ethereum": "0.0.1-commit.e57c76e",
|
|
61
|
+
"@aztec/foundation": "0.0.1-commit.e57c76e",
|
|
62
|
+
"@aztec/kv-store": "0.0.1-commit.e57c76e",
|
|
63
|
+
"@aztec/l1-artifacts": "0.0.1-commit.e57c76e",
|
|
64
|
+
"@aztec/stdlib": "0.0.1-commit.e57c76e",
|
|
65
|
+
"@aztec/telemetry-client": "0.0.1-commit.e57c76e",
|
|
66
66
|
"source-map-support": "^0.5.21",
|
|
67
67
|
"tslib": "^2.4.0",
|
|
68
68
|
"viem": "npm:@aztec/viem@2.38.2",
|
|
69
|
-
"zod": "^
|
|
69
|
+
"zod": "^4"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
72
|
+
"@aztec/aztec.js": "0.0.1-commit.e57c76e",
|
|
73
73
|
"@jest/globals": "^30.0.0",
|
|
74
74
|
"@types/jest": "^30.0.0",
|
|
75
75
|
"@types/node": "^22.15.17",
|