@aztec/slasher 4.0.0-nightly.20260203 → 4.0.0-nightly.20260205
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.
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXBvY2hfcHJ1bmVfd2F0Y2hlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3dhdGNoZXJzL2Vw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RUFDeEMsbUJBQW1CLEVBQUUsbUJBQW1CLEVBQ3hDLFVBQVUsRUFBRSxVQUFVLEVBQ3RCLFVBQVUsRUFBRSxJQUFJLENBQUMsV0FBVyxFQUFFLGlCQUFpQixDQUFDLEVBQ2hELGtCQUFrQixFQUFFLG1CQUFtQixFQUMvQyxTQUFTLEVBQUUsMEJBQTBCLEVBT3RDO0lBRU0sS0FBSyxrQkFHWDtJQUVNLElBQUksa0JBR1Y7SUFFTSxZQUFZLENBQUMsTUFBTSxFQUFFLE9BQU8sQ0FBQyxhQUFhLENBQUMsR0FBRyxJQUFJLENBR3hEO0lBRUQsT0FBTyxDQUFDLG1CQUFtQjtZQU9iLGlCQUFpQjtZQVdqQixvQkFBb0I7SUF3QnJCLGNBQWMsQ0FBQyxNQUFNLEVBQUUsT0FBTyxFQUFFLEVBQUUsV0FBVyxFQUFFLFdBQVcsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBK0J0RjtZQUVhLGtCQUFrQjtZQXNDbEIseUJBQXlCO1lBOEJ6QixxQkFBcUI7SUFTbkMsT0FBTyxDQUFDLHdCQUF3QjtDQWdCakMifQ==
|
|
@@ -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,iCAAi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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.getCheckpointsForEpoch(epochNumber)).filter((c)=>c.number < sortedBlocks[0].checkpointNumber).map((c)=>c.getCheckpointOutHash());
|
|
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,19 +110,13 @@ const EpochPruneWatcherPenaltiesConfigKeys = [
|
|
|
103
110
|
await fork.close();
|
|
104
111
|
}
|
|
105
112
|
}
|
|
106
|
-
async
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
//
|
|
110
|
-
// trying to fetch them from nodes or via reqresp. If we haven't managed to collect them by now,
|
|
111
|
-
// it's likely that they are not available in the network at all.
|
|
112
|
-
const { txs, missingTxs } = await this.txProvider.getAvailableTxs(txHashes);
|
|
113
|
-
if (missingTxs && missingTxs.length > 0) {
|
|
114
|
-
throw new TransactionsNotAvailableError(missingTxs);
|
|
115
|
-
}
|
|
116
|
-
const checkpointNumber = CheckpointNumber.fromBlockNumber(blockFromL1.number);
|
|
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
117
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
118
|
-
|
|
118
|
+
// Build checkpoint constants from first block's global variables
|
|
119
|
+
const gv = checkpointBlocks[0].header.globalVariables;
|
|
119
120
|
const constants = {
|
|
120
121
|
chainId: gv.chainId,
|
|
121
122
|
version: gv.version,
|
|
@@ -124,8 +125,24 @@ const EpochPruneWatcherPenaltiesConfigKeys = [
|
|
|
124
125
|
feeRecipient: gv.feeRecipient,
|
|
125
126
|
gasFees: gv.gasFees
|
|
126
127
|
};
|
|
127
|
-
//
|
|
128
|
+
// Start checkpoint builder once for all blocks in this checkpoint
|
|
128
129
|
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes, fork, this.log.getBindings());
|
|
130
|
+
// Validate all blocks in the checkpoint sequentially
|
|
131
|
+
for (const block of checkpointBlocks){
|
|
132
|
+
await this.validateBlockInCheckpoint(block, checkpointBuilder);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async validateBlockInCheckpoint(blockFromL1, checkpointBuilder) {
|
|
136
|
+
this.log.debug(`Validating pruned block ${blockFromL1.header.globalVariables.blockNumber}`);
|
|
137
|
+
const txHashes = blockFromL1.body.txEffects.map((txEffect)=>txEffect.txHash);
|
|
138
|
+
// We load txs from the mempool directly, since the TxCollector running in the background has already been
|
|
139
|
+
// trying to fetch them from nodes or via reqresp. If we haven't managed to collect them by now,
|
|
140
|
+
// it's likely that they are not available in the network at all.
|
|
141
|
+
const { txs, missingTxs } = await this.txProvider.getAvailableTxs(txHashes);
|
|
142
|
+
if (missingTxs && missingTxs.length > 0) {
|
|
143
|
+
throw new TransactionsNotAvailableError(missingTxs);
|
|
144
|
+
}
|
|
145
|
+
const gv = blockFromL1.header.globalVariables;
|
|
129
146
|
const { block, failedTxs, numTxs } = await checkpointBuilder.buildBlock(txs, gv.blockNumber, gv.timestamp, {});
|
|
130
147
|
if (numTxs !== txs.length) {
|
|
131
148
|
// This should be detected by state mismatch, but this makes it easier to debug.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/slasher",
|
|
3
|
-
"version": "4.0.0-nightly.
|
|
3
|
+
"version": "4.0.0-nightly.20260205",
|
|
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": "4.0.0-nightly.
|
|
60
|
-
"@aztec/ethereum": "4.0.0-nightly.
|
|
61
|
-
"@aztec/foundation": "4.0.0-nightly.
|
|
62
|
-
"@aztec/kv-store": "4.0.0-nightly.
|
|
63
|
-
"@aztec/l1-artifacts": "4.0.0-nightly.
|
|
64
|
-
"@aztec/stdlib": "4.0.0-nightly.
|
|
65
|
-
"@aztec/telemetry-client": "4.0.0-nightly.
|
|
59
|
+
"@aztec/epoch-cache": "4.0.0-nightly.20260205",
|
|
60
|
+
"@aztec/ethereum": "4.0.0-nightly.20260205",
|
|
61
|
+
"@aztec/foundation": "4.0.0-nightly.20260205",
|
|
62
|
+
"@aztec/kv-store": "4.0.0-nightly.20260205",
|
|
63
|
+
"@aztec/l1-artifacts": "4.0.0-nightly.20260205",
|
|
64
|
+
"@aztec/stdlib": "4.0.0-nightly.20260205",
|
|
65
|
+
"@aztec/telemetry-client": "4.0.0-nightly.20260205",
|
|
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": "4.0.0-nightly.
|
|
72
|
+
"@aztec/aztec.js": "4.0.0-nightly.20260205",
|
|
73
73
|
"@jest/globals": "^30.0.0",
|
|
74
74
|
"@types/jest": "^30.0.0",
|
|
75
75
|
"@types/node": "^22.15.17",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
2
|
-
import { BlockNumber,
|
|
3
|
-
import { merge, pick } from '@aztec/foundation/collection';
|
|
2
|
+
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { chunkBy, merge, pick } from '@aztec/foundation/collection';
|
|
4
4
|
import type { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
6
6
|
import {
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from '@aztec/stdlib/block';
|
|
13
13
|
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
14
14
|
import type {
|
|
15
|
+
ICheckpointBlockBuilder,
|
|
15
16
|
ICheckpointsBuilder,
|
|
16
17
|
ITxProvider,
|
|
17
18
|
MerkleTreeWriteOperations,
|
|
@@ -106,7 +107,7 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
106
107
|
{ blocks: epochBlocks.map(b => b.toBlockInfo()) },
|
|
107
108
|
);
|
|
108
109
|
|
|
109
|
-
await this.validateBlocks(epochBlocks);
|
|
110
|
+
await this.validateBlocks(epochBlocks, epochNumber);
|
|
110
111
|
this.log.info(`Pruned epoch ${epochNumber} was valid. Want to slash committee for not having it proven.`);
|
|
111
112
|
await this.emitSlashForEpoch(OffenseType.VALID_EPOCH_PRUNED, epochNumber);
|
|
112
113
|
} catch (error) {
|
|
@@ -121,19 +122,32 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
public async validateBlocks(blocks: L2Block[]): Promise<void> {
|
|
125
|
+
public async validateBlocks(blocks: L2Block[], epochNumber: EpochNumber): Promise<void> {
|
|
125
126
|
if (blocks.length === 0) {
|
|
126
127
|
return;
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
|
|
130
|
-
const
|
|
130
|
+
// Sort blocks by block number and group by checkpoint
|
|
131
|
+
const sortedBlocks = [...blocks].sort((a, b) => a.number - b.number);
|
|
132
|
+
const blocksByCheckpoint = chunkBy(sortedBlocks, b => b.checkpointNumber);
|
|
133
|
+
|
|
134
|
+
// Get prior checkpoints in the epoch (in case this was a partial prune) to extract the out hashes
|
|
135
|
+
const priorCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsForEpoch(epochNumber))
|
|
136
|
+
.filter(c => c.number < sortedBlocks[0].checkpointNumber)
|
|
137
|
+
.map(c => c.getCheckpointOutHash());
|
|
138
|
+
let previousCheckpointOutHashes: Fr[] = [...priorCheckpointOutHashes];
|
|
139
|
+
|
|
140
|
+
const fork = await this.checkpointsBuilder.getFork(
|
|
141
|
+
BlockNumber(sortedBlocks[0].header.globalVariables.blockNumber - 1),
|
|
142
|
+
);
|
|
131
143
|
try {
|
|
132
|
-
for (const
|
|
133
|
-
await this.
|
|
144
|
+
for (const checkpointBlocks of blocksByCheckpoint) {
|
|
145
|
+
await this.validateCheckpoint(checkpointBlocks, previousCheckpointOutHashes, fork);
|
|
134
146
|
|
|
135
|
-
//
|
|
136
|
-
const checkpointOutHash = computeCheckpointOutHash(
|
|
147
|
+
// Compute checkpoint out hash from all blocks in this checkpoint
|
|
148
|
+
const checkpointOutHash = computeCheckpointOutHash(
|
|
149
|
+
checkpointBlocks.map(b => b.body.txEffects.map(tx => tx.l2ToL1Msgs)),
|
|
150
|
+
);
|
|
137
151
|
previousCheckpointOutHashes = [...previousCheckpointOutHashes, checkpointOutHash];
|
|
138
152
|
}
|
|
139
153
|
} finally {
|
|
@@ -141,25 +155,19 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
141
155
|
}
|
|
142
156
|
}
|
|
143
157
|
|
|
144
|
-
|
|
145
|
-
|
|
158
|
+
private async validateCheckpoint(
|
|
159
|
+
checkpointBlocks: L2Block[],
|
|
146
160
|
previousCheckpointOutHashes: Fr[],
|
|
147
161
|
fork: MerkleTreeWriteOperations,
|
|
148
162
|
): Promise<void> {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
// We load txs from the mempool directly, since the TxCollector running in the background has already been
|
|
152
|
-
// trying to fetch them from nodes or via reqresp. If we haven't managed to collect them by now,
|
|
153
|
-
// it's likely that they are not available in the network at all.
|
|
154
|
-
const { txs, missingTxs } = await this.txProvider.getAvailableTxs(txHashes);
|
|
155
|
-
|
|
156
|
-
if (missingTxs && missingTxs.length > 0) {
|
|
157
|
-
throw new TransactionsNotAvailableError(missingTxs);
|
|
158
|
-
}
|
|
163
|
+
const checkpointNumber = checkpointBlocks[0].checkpointNumber;
|
|
164
|
+
this.log.debug(`Validating pruned checkpoint ${checkpointNumber} with ${checkpointBlocks.length} blocks`);
|
|
159
165
|
|
|
160
|
-
|
|
166
|
+
// Get L1ToL2Messages once for the entire checkpoint
|
|
161
167
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
162
|
-
|
|
168
|
+
|
|
169
|
+
// Build checkpoint constants from first block's global variables
|
|
170
|
+
const gv = checkpointBlocks[0].header.globalVariables;
|
|
163
171
|
const constants: CheckpointGlobalVariables = {
|
|
164
172
|
chainId: gv.chainId,
|
|
165
173
|
version: gv.version,
|
|
@@ -169,7 +177,7 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
169
177
|
gasFees: gv.gasFees,
|
|
170
178
|
};
|
|
171
179
|
|
|
172
|
-
//
|
|
180
|
+
// Start checkpoint builder once for all blocks in this checkpoint
|
|
173
181
|
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(
|
|
174
182
|
checkpointNumber,
|
|
175
183
|
constants,
|
|
@@ -179,6 +187,28 @@ export class EpochPruneWatcher extends (EventEmitter as new () => WatcherEmitter
|
|
|
179
187
|
this.log.getBindings(),
|
|
180
188
|
);
|
|
181
189
|
|
|
190
|
+
// Validate all blocks in the checkpoint sequentially
|
|
191
|
+
for (const block of checkpointBlocks) {
|
|
192
|
+
await this.validateBlockInCheckpoint(block, checkpointBuilder);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private async validateBlockInCheckpoint(
|
|
197
|
+
blockFromL1: L2Block,
|
|
198
|
+
checkpointBuilder: ICheckpointBlockBuilder,
|
|
199
|
+
): Promise<void> {
|
|
200
|
+
this.log.debug(`Validating pruned block ${blockFromL1.header.globalVariables.blockNumber}`);
|
|
201
|
+
const txHashes = blockFromL1.body.txEffects.map(txEffect => txEffect.txHash);
|
|
202
|
+
// We load txs from the mempool directly, since the TxCollector running in the background has already been
|
|
203
|
+
// trying to fetch them from nodes or via reqresp. If we haven't managed to collect them by now,
|
|
204
|
+
// it's likely that they are not available in the network at all.
|
|
205
|
+
const { txs, missingTxs } = await this.txProvider.getAvailableTxs(txHashes);
|
|
206
|
+
|
|
207
|
+
if (missingTxs && missingTxs.length > 0) {
|
|
208
|
+
throw new TransactionsNotAvailableError(missingTxs);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const gv = blockFromL1.header.globalVariables;
|
|
182
212
|
const { block, failedTxs, numTxs } = await checkpointBuilder.buildBlock(txs, gv.blockNumber, gv.timestamp, {});
|
|
183
213
|
|
|
184
214
|
if (numTxs !== txs.length) {
|