@aztec/stdlib 2.0.0-nightly.20250822 → 2.0.0-nightly.20250823
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/dest/block/l2_block.d.ts +2 -0
- package/dest/block/l2_block.d.ts.map +1 -1
- package/dest/block/l2_block.js +6 -0
- package/dest/interfaces/aztec-node-admin.d.ts +29 -15
- package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-admin.js +7 -2
- package/dest/interfaces/epoch-prover.d.ts +1 -1
- package/dest/interfaces/slasher.d.ts +33 -17
- package/dest/interfaces/slasher.d.ts.map +1 -1
- package/dest/interfaces/slasher.js +8 -4
- package/dest/interfaces/world_state.d.ts +4 -4
- package/dest/interfaces/world_state.js +1 -1
- package/dest/l1-contracts/index.d.ts +2 -0
- package/dest/l1-contracts/index.d.ts.map +1 -0
- package/dest/l1-contracts/index.js +1 -0
- package/dest/l1-contracts/slash_factory.d.ts +44 -0
- package/dest/l1-contracts/slash_factory.d.ts.map +1 -0
- package/dest/l1-contracts/slash_factory.js +157 -0
- package/dest/slashing/empire.d.ts +31 -0
- package/dest/slashing/empire.d.ts.map +1 -0
- package/dest/slashing/empire.js +84 -0
- package/dest/slashing/helpers.d.ts +31 -0
- package/dest/slashing/helpers.d.ts.map +1 -0
- package/dest/slashing/helpers.js +62 -0
- package/dest/slashing/index.d.ts +6 -50
- package/dest/slashing/index.d.ts.map +1 -1
- package/dest/slashing/index.js +6 -54
- package/dest/slashing/interfaces.d.ts +11 -0
- package/dest/slashing/interfaces.d.ts.map +1 -0
- package/dest/slashing/interfaces.js +1 -0
- package/dest/slashing/serialization.d.ts +8 -0
- package/dest/slashing/serialization.d.ts.map +1 -0
- package/dest/slashing/serialization.js +78 -0
- package/dest/slashing/tally.d.ts +17 -0
- package/dest/slashing/tally.d.ts.map +1 -0
- package/dest/slashing/tally.js +36 -0
- package/dest/slashing/types.d.ts +161 -0
- package/dest/slashing/types.d.ts.map +1 -0
- package/dest/slashing/types.js +66 -0
- package/dest/stats/stats.d.ts +2 -2
- package/package.json +10 -8
- package/src/block/l2_block.ts +8 -0
- package/src/interfaces/aztec-node-admin.ts +11 -4
- package/src/interfaces/epoch-prover.ts +1 -1
- package/src/interfaces/slasher.ts +18 -9
- package/src/interfaces/world_state.ts +2 -2
- package/src/l1-contracts/index.ts +1 -0
- package/src/l1-contracts/slash_factory.ts +177 -0
- package/src/slashing/empire.ts +100 -0
- package/src/slashing/helpers.ts +87 -0
- package/src/slashing/index.ts +6 -74
- package/src/slashing/interfaces.ts +11 -0
- package/src/slashing/serialization.ts +103 -0
- package/src/slashing/tally.ts +51 -0
- package/src/slashing/types.ts +129 -0
- package/src/stats/stats.ts +2 -2
package/dest/block/l2_block.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"l2_block.d.ts","sourceRoot":"","sources":["../../src/block/l2_block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAG9E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC;;GAEG;AACH,qBAAa,OAAO;IAEhB,2DAA2D;IACpD,OAAO,EAAE,sBAAsB;IACtC,uBAAuB;IAChB,MAAM,EAAE,WAAW;IAC1B,qBAAqB;IACd,IAAI,EAAE,IAAI;IACjB,OAAO,CAAC,SAAS;;IANjB,2DAA2D;IACpD,OAAO,EAAE,sBAAsB;IACtC,uBAAuB;IAChB,MAAM,EAAE,WAAW;IAC1B,qBAAqB;IACd,IAAI,EAAE,IAAI,EACT,SAAS,GAAE,EAAE,GAAG,S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C,EAAE,CAAC;IAOhC;;;OAGG;IACH,QAAQ;;;;;;;;;IAuBR,WAAW,IAAI,SAAS;IAUxB,MAAM,CAAC,KAAK,EAAE,OAAO;CAGtB;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
|
package/dest/block/l2_block.js
CHANGED
|
@@ -75,6 +75,12 @@ import { makeAppendOnlyTreeSnapshot, makeHeader } from './l2_block_code_to_purge
|
|
|
75
75
|
get number() {
|
|
76
76
|
return this.header.getBlockNumber();
|
|
77
77
|
}
|
|
78
|
+
get slot() {
|
|
79
|
+
return this.header.getSlot();
|
|
80
|
+
}
|
|
81
|
+
get timestamp() {
|
|
82
|
+
return this.header.globalVariables.timestamp;
|
|
83
|
+
}
|
|
78
84
|
/**
|
|
79
85
|
* Returns the block's hash (hash of block header).
|
|
80
86
|
* @returns The block's hash.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defaultFetch } from '@aztec/foundation/json-rpc/client';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import type { ApiSchemaFor } from '../schemas/schemas.js';
|
|
4
|
-
import { type
|
|
4
|
+
import { type Offense, type SlashPayloadRound } from '../slashing/index.js';
|
|
5
5
|
import { type ComponentsVersions } from '../versioning/index.js';
|
|
6
6
|
import { type SequencerConfig } from './configs.js';
|
|
7
7
|
import { type ProverConfig } from './prover-client.js';
|
|
@@ -34,8 +34,10 @@ export interface AztecNodeAdmin {
|
|
|
34
34
|
pauseSync(): Promise<void>;
|
|
35
35
|
/** Resumes archiver and world state syncing. */
|
|
36
36
|
resumeSync(): Promise<void>;
|
|
37
|
-
/** Returns all monitored payloads by the slasher. */
|
|
38
|
-
|
|
37
|
+
/** Returns all monitored payloads by the slasher for the current round. */
|
|
38
|
+
getSlashPayloads(): Promise<SlashPayloadRound[]>;
|
|
39
|
+
/** Returns all offenses applicable for the given round. */
|
|
40
|
+
getSlashOffenses(round: bigint | 'all' | 'current'): Promise<Offense[]>;
|
|
39
41
|
}
|
|
40
42
|
export type AztecNodeAdminConfig = SequencerConfig & ProverConfig & SlasherConfig & {
|
|
41
43
|
maxTxPoolSize: number;
|
|
@@ -105,9 +107,9 @@ export declare const AztecNodeAdminConfigSchema: z.ZodObject<z.objectUtil.extend
|
|
|
105
107
|
slashPruneEnabled: z.ZodBoolean;
|
|
106
108
|
slashPrunePenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
107
109
|
slashPruneMaxPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
slashBroadcastedInvalidBlockEnabled: z.ZodBoolean;
|
|
111
|
+
slashBroadcastedInvalidBlockPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
112
|
+
slashBroadcastedInvalidBlockMaxPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
111
113
|
slashInactivityEnabled: z.ZodBoolean;
|
|
112
114
|
slashInactivityCreateTargetPercentage: z.ZodNumber;
|
|
113
115
|
slashInactivitySignalTargetPercentage: z.ZodNumber;
|
|
@@ -118,7 +120,11 @@ export declare const AztecNodeAdminConfigSchema: z.ZodObject<z.objectUtil.extend
|
|
|
118
120
|
slashProposeInvalidAttestationsMaxPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
119
121
|
slashAttestDescendantOfInvalidPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
120
122
|
slashAttestDescendantOfInvalidMaxPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
121
|
-
|
|
123
|
+
slashUnknownPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
124
|
+
slashUnknownMaxPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
125
|
+
slashOffenseExpirationRounds: z.ZodNumber;
|
|
126
|
+
slashMaxPayloadSize: z.ZodNumber;
|
|
127
|
+
slashGracePeriodL2Slots: z.ZodNumber;
|
|
122
128
|
}>, {
|
|
123
129
|
maxTxPoolSize: z.ZodNumber;
|
|
124
130
|
}>, "strip", z.ZodTypeAny, {
|
|
@@ -133,9 +139,9 @@ export declare const AztecNodeAdminConfigSchema: z.ZodObject<z.objectUtil.extend
|
|
|
133
139
|
slashPruneEnabled: boolean;
|
|
134
140
|
slashPrunePenalty: bigint;
|
|
135
141
|
slashPruneMaxPenalty: bigint;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
slashBroadcastedInvalidBlockEnabled: boolean;
|
|
143
|
+
slashBroadcastedInvalidBlockPenalty: bigint;
|
|
144
|
+
slashBroadcastedInvalidBlockMaxPenalty: bigint;
|
|
139
145
|
slashInactivityEnabled: boolean;
|
|
140
146
|
slashInactivityCreateTargetPercentage: number;
|
|
141
147
|
slashInactivitySignalTargetPercentage: number;
|
|
@@ -146,7 +152,11 @@ export declare const AztecNodeAdminConfigSchema: z.ZodObject<z.objectUtil.extend
|
|
|
146
152
|
slashProposeInvalidAttestationsMaxPenalty: bigint;
|
|
147
153
|
slashAttestDescendantOfInvalidPenalty: bigint;
|
|
148
154
|
slashAttestDescendantOfInvalidMaxPenalty: bigint;
|
|
149
|
-
|
|
155
|
+
slashUnknownPenalty: bigint;
|
|
156
|
+
slashUnknownMaxPenalty: bigint;
|
|
157
|
+
slashOffenseExpirationRounds: number;
|
|
158
|
+
slashMaxPayloadSize: number;
|
|
159
|
+
slashGracePeriodL2Slots: number;
|
|
150
160
|
maxTxPoolSize: number;
|
|
151
161
|
coinbase?: import("@aztec/foundation/schemas").EthAddress | undefined;
|
|
152
162
|
feeRecipient?: import("../aztec-address/index.js").AztecAddress | undefined;
|
|
@@ -191,9 +201,9 @@ export declare const AztecNodeAdminConfigSchema: z.ZodObject<z.objectUtil.extend
|
|
|
191
201
|
slashPruneEnabled: boolean;
|
|
192
202
|
slashPrunePenalty: string | number | bigint;
|
|
193
203
|
slashPruneMaxPenalty: string | number | bigint;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
204
|
+
slashBroadcastedInvalidBlockEnabled: boolean;
|
|
205
|
+
slashBroadcastedInvalidBlockPenalty: string | number | bigint;
|
|
206
|
+
slashBroadcastedInvalidBlockMaxPenalty: string | number | bigint;
|
|
197
207
|
slashInactivityEnabled: boolean;
|
|
198
208
|
slashInactivityCreateTargetPercentage: number;
|
|
199
209
|
slashInactivitySignalTargetPercentage: number;
|
|
@@ -204,6 +214,11 @@ export declare const AztecNodeAdminConfigSchema: z.ZodObject<z.objectUtil.extend
|
|
|
204
214
|
slashProposeInvalidAttestationsMaxPenalty: string | number | bigint;
|
|
205
215
|
slashAttestDescendantOfInvalidPenalty: string | number | bigint;
|
|
206
216
|
slashAttestDescendantOfInvalidMaxPenalty: string | number | bigint;
|
|
217
|
+
slashUnknownPenalty: string | number | bigint;
|
|
218
|
+
slashUnknownMaxPenalty: string | number | bigint;
|
|
219
|
+
slashOffenseExpirationRounds: number;
|
|
220
|
+
slashMaxPayloadSize: number;
|
|
221
|
+
slashGracePeriodL2Slots: number;
|
|
207
222
|
maxTxPoolSize: number;
|
|
208
223
|
coinbase?: any;
|
|
209
224
|
feeRecipient?: any;
|
|
@@ -236,7 +251,6 @@ export declare const AztecNodeAdminConfigSchema: z.ZodObject<z.objectUtil.extend
|
|
|
236
251
|
proverId?: any;
|
|
237
252
|
nodeUrl?: string | undefined;
|
|
238
253
|
slashOverridePayload?: string | undefined;
|
|
239
|
-
slasherPrivateKey?: any;
|
|
240
254
|
}>;
|
|
241
255
|
export declare const AztecNodeAdminApiSchema: ApiSchemaFor<AztecNodeAdmin>;
|
|
242
256
|
export declare function createAztecNodeAdminClient(url: string, versions?: Partial<ComponentsVersions>, fetch?: typeof defaultFetch): AztecNodeAdmin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aztec-node-admin.d.ts","sourceRoot":"","sources":["../../src/interfaces/aztec-node-admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAE1F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"aztec-node-admin.d.ts","sourceRoot":"","sources":["../../src/interfaces/aztec-node-admin.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAE1F,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,KAAK,OAAO,EAAiB,KAAK,iBAAiB,EAA2B,MAAM,sBAAsB,CAAC;AACpH,OAAO,EAAE,KAAK,kBAAkB,EAAgC,MAAM,wBAAwB,CAAC;AAC/F,OAAO,EAAE,KAAK,eAAe,EAAyB,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,KAAK,aAAa,EAAuB,MAAM,cAAc,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,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,QAAQ,GAAE,OAAO,CAAC,kBAAkB,CAAM,EAC1C,KAAK,sBAAe,GACnB,cAAc,CAMhB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createSafeJsonRpcClient, defaultFetch } from '@aztec/foundation/json-rpc/client';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
3
|
+
import { OffenseSchema, SlashPayloadRoundSchema } from '../slashing/index.js';
|
|
4
4
|
import { getVersioningResponseHandler } from '../versioning/index.js';
|
|
5
5
|
import { SequencerConfigSchema } from './configs.js';
|
|
6
6
|
import { ProverConfigSchema } from './prover-client.js';
|
|
@@ -15,7 +15,12 @@ export const AztecNodeAdminApiSchema = {
|
|
|
15
15
|
rollbackTo: z.function().args(z.number()).returns(z.void()),
|
|
16
16
|
pauseSync: z.function().returns(z.void()),
|
|
17
17
|
resumeSync: z.function().returns(z.void()),
|
|
18
|
-
|
|
18
|
+
getSlashPayloads: z.function().returns(z.array(SlashPayloadRoundSchema)),
|
|
19
|
+
getSlashOffenses: z.function().args(z.union([
|
|
20
|
+
z.bigint(),
|
|
21
|
+
z.literal('all'),
|
|
22
|
+
z.literal('current')
|
|
23
|
+
])).returns(z.array(OffenseSchema))
|
|
19
24
|
};
|
|
20
25
|
export function createAztecNodeAdminClient(url, versions = {}, fetch = defaultFetch) {
|
|
21
26
|
return createSafeJsonRpcClient(url, AztecNodeAdminApiSchema, {
|
|
@@ -23,7 +23,7 @@ export interface EpochProver extends Omit<IBlockFactory, 'setBlockCompleted'> {
|
|
|
23
23
|
/** Returns the block. */
|
|
24
24
|
setBlockCompleted(blockNumber: number, expectedBlockHeader?: BlockHeader): Promise<L2Block>;
|
|
25
25
|
/** Pads the epoch with empty block roots if needed and blocks until proven. Throws if proving has failed. */
|
|
26
|
-
|
|
26
|
+
finalizeEpoch(): Promise<{
|
|
27
27
|
publicInputs: RootRollupPublicInputs;
|
|
28
28
|
proof: Proof;
|
|
29
29
|
batchedBlobInputs: BatchedBlob;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { SecretValue } from '@aztec/foundation/config';
|
|
2
1
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
2
|
import { z } from 'zod';
|
|
3
|
+
export type SlasherClientType = 'empire' | 'tally';
|
|
4
4
|
export interface SlasherConfig {
|
|
5
5
|
slashOverridePayload?: EthAddress;
|
|
6
6
|
slashPayloadTtlSeconds: number;
|
|
7
7
|
slashPruneEnabled: boolean;
|
|
8
8
|
slashPrunePenalty: bigint;
|
|
9
9
|
slashPruneMaxPenalty: bigint;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
slashBroadcastedInvalidBlockEnabled: boolean;
|
|
11
|
+
slashBroadcastedInvalidBlockPenalty: bigint;
|
|
12
|
+
slashBroadcastedInvalidBlockMaxPenalty: bigint;
|
|
13
13
|
slashInactivityEnabled: boolean;
|
|
14
14
|
slashInactivityCreateTargetPercentage: number;
|
|
15
15
|
slashInactivitySignalTargetPercentage: number;
|
|
@@ -20,7 +20,11 @@ export interface SlasherConfig {
|
|
|
20
20
|
slashProposeInvalidAttestationsMaxPenalty: bigint;
|
|
21
21
|
slashAttestDescendantOfInvalidPenalty: bigint;
|
|
22
22
|
slashAttestDescendantOfInvalidMaxPenalty: bigint;
|
|
23
|
-
|
|
23
|
+
slashUnknownPenalty: bigint;
|
|
24
|
+
slashUnknownMaxPenalty: bigint;
|
|
25
|
+
slashOffenseExpirationRounds: number;
|
|
26
|
+
slashMaxPayloadSize: number;
|
|
27
|
+
slashGracePeriodL2Slots: number;
|
|
24
28
|
}
|
|
25
29
|
export declare const SlasherConfigSchema: z.ZodObject<{
|
|
26
30
|
slashOverridePayload: z.ZodOptional<z.ZodType<EthAddress, any, string>>;
|
|
@@ -28,9 +32,9 @@ export declare const SlasherConfigSchema: z.ZodObject<{
|
|
|
28
32
|
slashPruneEnabled: z.ZodBoolean;
|
|
29
33
|
slashPrunePenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
30
34
|
slashPruneMaxPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
slashBroadcastedInvalidBlockEnabled: z.ZodBoolean;
|
|
36
|
+
slashBroadcastedInvalidBlockPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
37
|
+
slashBroadcastedInvalidBlockMaxPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
34
38
|
slashInactivityEnabled: z.ZodBoolean;
|
|
35
39
|
slashInactivityCreateTargetPercentage: z.ZodNumber;
|
|
36
40
|
slashInactivitySignalTargetPercentage: z.ZodNumber;
|
|
@@ -41,15 +45,19 @@ export declare const SlasherConfigSchema: z.ZodObject<{
|
|
|
41
45
|
slashProposeInvalidAttestationsMaxPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
42
46
|
slashAttestDescendantOfInvalidPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
43
47
|
slashAttestDescendantOfInvalidMaxPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
44
|
-
|
|
48
|
+
slashUnknownPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
49
|
+
slashUnknownMaxPenalty: z.ZodPipeline<z.ZodUnion<[z.ZodBigInt, z.ZodNumber, z.ZodString]>, z.ZodBigInt>;
|
|
50
|
+
slashOffenseExpirationRounds: z.ZodNumber;
|
|
51
|
+
slashMaxPayloadSize: z.ZodNumber;
|
|
52
|
+
slashGracePeriodL2Slots: z.ZodNumber;
|
|
45
53
|
}, "strip", z.ZodTypeAny, {
|
|
46
54
|
slashPayloadTtlSeconds: number;
|
|
47
55
|
slashPruneEnabled: boolean;
|
|
48
56
|
slashPrunePenalty: bigint;
|
|
49
57
|
slashPruneMaxPenalty: bigint;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
slashBroadcastedInvalidBlockEnabled: boolean;
|
|
59
|
+
slashBroadcastedInvalidBlockPenalty: bigint;
|
|
60
|
+
slashBroadcastedInvalidBlockMaxPenalty: bigint;
|
|
53
61
|
slashInactivityEnabled: boolean;
|
|
54
62
|
slashInactivityCreateTargetPercentage: number;
|
|
55
63
|
slashInactivitySignalTargetPercentage: number;
|
|
@@ -60,16 +68,20 @@ export declare const SlasherConfigSchema: z.ZodObject<{
|
|
|
60
68
|
slashProposeInvalidAttestationsMaxPenalty: bigint;
|
|
61
69
|
slashAttestDescendantOfInvalidPenalty: bigint;
|
|
62
70
|
slashAttestDescendantOfInvalidMaxPenalty: bigint;
|
|
63
|
-
|
|
71
|
+
slashUnknownPenalty: bigint;
|
|
72
|
+
slashUnknownMaxPenalty: bigint;
|
|
73
|
+
slashOffenseExpirationRounds: number;
|
|
74
|
+
slashMaxPayloadSize: number;
|
|
75
|
+
slashGracePeriodL2Slots: number;
|
|
64
76
|
slashOverridePayload?: EthAddress | undefined;
|
|
65
77
|
}, {
|
|
66
78
|
slashPayloadTtlSeconds: number;
|
|
67
79
|
slashPruneEnabled: boolean;
|
|
68
80
|
slashPrunePenalty: string | number | bigint;
|
|
69
81
|
slashPruneMaxPenalty: string | number | bigint;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
82
|
+
slashBroadcastedInvalidBlockEnabled: boolean;
|
|
83
|
+
slashBroadcastedInvalidBlockPenalty: string | number | bigint;
|
|
84
|
+
slashBroadcastedInvalidBlockMaxPenalty: string | number | bigint;
|
|
73
85
|
slashInactivityEnabled: boolean;
|
|
74
86
|
slashInactivityCreateTargetPercentage: number;
|
|
75
87
|
slashInactivitySignalTargetPercentage: number;
|
|
@@ -80,7 +92,11 @@ export declare const SlasherConfigSchema: z.ZodObject<{
|
|
|
80
92
|
slashProposeInvalidAttestationsMaxPenalty: string | number | bigint;
|
|
81
93
|
slashAttestDescendantOfInvalidPenalty: string | number | bigint;
|
|
82
94
|
slashAttestDescendantOfInvalidMaxPenalty: string | number | bigint;
|
|
95
|
+
slashUnknownPenalty: string | number | bigint;
|
|
96
|
+
slashUnknownMaxPenalty: string | number | bigint;
|
|
97
|
+
slashOffenseExpirationRounds: number;
|
|
98
|
+
slashMaxPayloadSize: number;
|
|
99
|
+
slashGracePeriodL2Slots: number;
|
|
83
100
|
slashOverridePayload?: string | undefined;
|
|
84
|
-
slasherPrivateKey?: any;
|
|
85
101
|
}>;
|
|
86
102
|
//# sourceMappingURL=slasher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slasher.d.ts","sourceRoot":"","sources":["../../src/interfaces/slasher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"slasher.d.ts","sourceRoot":"","sources":["../../src/interfaces/slasher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAGhE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEnD,MAAM,WAAW,aAAa;IAC5B,oBAAoB,CAAC,EAAE,UAAU,CAAC;IAClC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mCAAmC,EAAE,OAAO,CAAC;IAC7C,mCAAmC,EAAE,MAAM,CAAC;IAC5C,sCAAsC,EAAE,MAAM,CAAC;IAC/C,sBAAsB,EAAE,OAAO,CAAC;IAChC,qCAAqC,EAAE,MAAM,CAAC;IAC9C,qCAAqC,EAAE,MAAM,CAAC;IAC9C,4BAA4B,EAAE,MAAM,CAAC;IACrC,yBAAyB,EAAE,MAAM,CAAC;IAClC,wCAAwC,EAAE,MAAM,CAAC;IACjD,sCAAsC,EAAE,MAAM,CAAC;IAC/C,yCAAyC,EAAE,MAAM,CAAC;IAClD,qCAAqC,EAAE,MAAM,CAAC;IAC9C,wCAAwC,EAAE,MAAM,CAAC;IACjD,mBAAmB,EAAE,MAAM,CAAC;IAC5B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,4BAA4B,EAAE,MAAM,CAAC;IACrC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,uBAAuB,EAAE,MAAM,CAAC;CACjC;AAED,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwBE,CAAC"}
|
|
@@ -6,9 +6,9 @@ export const SlasherConfigSchema = z.object({
|
|
|
6
6
|
slashPruneEnabled: z.boolean(),
|
|
7
7
|
slashPrunePenalty: schemas.BigInt,
|
|
8
8
|
slashPruneMaxPenalty: schemas.BigInt,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
slashBroadcastedInvalidBlockEnabled: z.boolean(),
|
|
10
|
+
slashBroadcastedInvalidBlockPenalty: schemas.BigInt,
|
|
11
|
+
slashBroadcastedInvalidBlockMaxPenalty: schemas.BigInt,
|
|
12
12
|
slashInactivityEnabled: z.boolean(),
|
|
13
13
|
slashInactivityCreateTargetPercentage: z.number(),
|
|
14
14
|
slashInactivitySignalTargetPercentage: z.number(),
|
|
@@ -19,5 +19,9 @@ export const SlasherConfigSchema = z.object({
|
|
|
19
19
|
slashProposeInvalidAttestationsMaxPenalty: schemas.BigInt,
|
|
20
20
|
slashAttestDescendantOfInvalidPenalty: schemas.BigInt,
|
|
21
21
|
slashAttestDescendantOfInvalidMaxPenalty: schemas.BigInt,
|
|
22
|
-
|
|
22
|
+
slashUnknownPenalty: schemas.BigInt,
|
|
23
|
+
slashUnknownMaxPenalty: schemas.BigInt,
|
|
24
|
+
slashOffenseExpirationRounds: z.number(),
|
|
25
|
+
slashMaxPayloadSize: z.number(),
|
|
26
|
+
slashGracePeriodL2Slots: z.number()
|
|
23
27
|
});
|
|
@@ -15,7 +15,7 @@ export declare enum WorldStateRunningState {
|
|
|
15
15
|
export interface WorldStateSyncStatus {
|
|
16
16
|
latestBlockNumber: number;
|
|
17
17
|
latestBlockHash: string;
|
|
18
|
-
|
|
18
|
+
finalizedBlockNumber: number;
|
|
19
19
|
oldestHistoricBlockNumber: number;
|
|
20
20
|
treesAreSynched: boolean;
|
|
21
21
|
}
|
|
@@ -66,19 +66,19 @@ export interface WorldStateSynchronizer extends ForkMerkleTreeOperations {
|
|
|
66
66
|
clear(): Promise<void>;
|
|
67
67
|
}
|
|
68
68
|
export declare const WorldStateSyncStatusSchema: z.ZodObject<{
|
|
69
|
-
|
|
69
|
+
finalizedBlockNumber: z.ZodNumber;
|
|
70
70
|
latestBlockNumber: z.ZodNumber;
|
|
71
71
|
latestBlockHash: z.ZodString;
|
|
72
72
|
oldestHistoricBlockNumber: z.ZodNumber;
|
|
73
73
|
treesAreSynched: z.ZodBoolean;
|
|
74
74
|
}, "strip", z.ZodTypeAny, {
|
|
75
|
-
|
|
75
|
+
finalizedBlockNumber: number;
|
|
76
76
|
latestBlockNumber: number;
|
|
77
77
|
latestBlockHash: string;
|
|
78
78
|
oldestHistoricBlockNumber: number;
|
|
79
79
|
treesAreSynched: boolean;
|
|
80
80
|
}, {
|
|
81
|
-
|
|
81
|
+
finalizedBlockNumber: number;
|
|
82
82
|
latestBlockNumber: number;
|
|
83
83
|
latestBlockHash: string;
|
|
84
84
|
oldestHistoricBlockNumber: number;
|
|
@@ -9,7 +9,7 @@ import { z } from 'zod';
|
|
|
9
9
|
return WorldStateRunningState;
|
|
10
10
|
}({});
|
|
11
11
|
export const WorldStateSyncStatusSchema = z.object({
|
|
12
|
-
|
|
12
|
+
finalizedBlockNumber: z.number().int().nonnegative(),
|
|
13
13
|
latestBlockNumber: z.number().int().nonnegative(),
|
|
14
14
|
latestBlockHash: z.string(),
|
|
15
15
|
oldestHistoricBlockNumber: z.number().int().nonnegative(),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/l1-contracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './slash_factory.js';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type L1TxRequest, type ViemClient } from '@aztec/ethereum';
|
|
2
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { type Hex, type Log } from 'viem';
|
|
4
|
+
import type { L1RollupConstants } from '../epoch-helpers/index.js';
|
|
5
|
+
import { type SlashPayload, type ValidatorSlash, type ValidatorSlashOffense } from '../slashing/index.js';
|
|
6
|
+
export declare class SlashFactoryContract {
|
|
7
|
+
readonly client: ViemClient;
|
|
8
|
+
private readonly logger;
|
|
9
|
+
private readonly contract;
|
|
10
|
+
constructor(client: ViemClient, address: Hex | EthAddress);
|
|
11
|
+
get address(): EthAddress;
|
|
12
|
+
buildCreatePayloadRequest(slashes: ValidatorSlash[]): L1TxRequest;
|
|
13
|
+
/** Tries to extract a SlashPayloadCreated event from the given logs. */
|
|
14
|
+
tryExtractSlashPayloadCreatedEvent(logs: Log[]): {
|
|
15
|
+
eventName: "SlashPayloadCreated";
|
|
16
|
+
args: {
|
|
17
|
+
payloadAddress: `0x${string}`;
|
|
18
|
+
validators: readonly `0x${string}`[];
|
|
19
|
+
amounts: readonly bigint[];
|
|
20
|
+
offenses: readonly (readonly bigint[])[];
|
|
21
|
+
};
|
|
22
|
+
} | undefined;
|
|
23
|
+
getSlashPayloadCreatedEvents(): Promise<SlashPayload[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Searches for a slash payload in the events emitted by the contract.
|
|
26
|
+
* This method cannot query for historical payload events, it queries for payloads that have not yet expired.
|
|
27
|
+
* @param payloadAddress The address of the payload to search for.
|
|
28
|
+
* @param constants The L1 rollup constants needed for time calculations.
|
|
29
|
+
*/
|
|
30
|
+
getSlashPayloadFromEvents(payloadAddress: EthAddress, settings: {
|
|
31
|
+
logsBatchSize?: number;
|
|
32
|
+
slashingRoundSize: number;
|
|
33
|
+
slashingPayloadLifetimeInRounds: number;
|
|
34
|
+
} & Pick<L1RollupConstants, 'slotDuration' | 'ethereumSlotDuration'>): Promise<Omit<SlashPayload, 'votes'> | undefined>;
|
|
35
|
+
getAddressAndIsDeployed(slashes: ValidatorSlash[]): Promise<{
|
|
36
|
+
address: EthAddress;
|
|
37
|
+
salt: Hex;
|
|
38
|
+
isDeployed: boolean;
|
|
39
|
+
}>;
|
|
40
|
+
private sortSlashes;
|
|
41
|
+
}
|
|
42
|
+
export declare function packValidatorSlashOffense(offense: ValidatorSlashOffense): bigint;
|
|
43
|
+
export declare function unpackValidatorSlashOffense(packed: bigint): ValidatorSlashOffense;
|
|
44
|
+
//# sourceMappingURL=slash_factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slash_factory.d.ts","sourceRoot":"","sources":["../../src/l1-contracts/slash_factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAmB,MAAM,iBAAiB,CAAC;AAErF,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAI3D,OAAO,EAA8B,KAAK,GAAG,EAAE,KAAK,GAAG,EAAmC,MAAM,MAAM,CAAC;AAEvG,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAEL,KAAK,YAAY,EACjB,K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
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { SlashFactoryAbi } from '@aztec/l1-artifacts/SlashFactoryAbi';
|
|
6
|
+
import { encodeFunctionData, getContract } from 'viem';
|
|
7
|
+
import { OffenseToBigInt, bigIntToOffense } from '../slashing/index.js';
|
|
8
|
+
export class SlashFactoryContract {
|
|
9
|
+
client;
|
|
10
|
+
logger;
|
|
11
|
+
contract;
|
|
12
|
+
constructor(client, address){
|
|
13
|
+
this.client = client;
|
|
14
|
+
this.logger = createLogger('contracts:slash_factory');
|
|
15
|
+
this.contract = getContract({
|
|
16
|
+
address: typeof address === 'string' ? address : address.toString(),
|
|
17
|
+
abi: SlashFactoryAbi,
|
|
18
|
+
client
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
get address() {
|
|
22
|
+
return EthAddress.fromString(this.contract.address);
|
|
23
|
+
}
|
|
24
|
+
buildCreatePayloadRequest(slashes) {
|
|
25
|
+
const sorted = this.sortSlashes(slashes);
|
|
26
|
+
return {
|
|
27
|
+
to: this.contract.address,
|
|
28
|
+
data: encodeFunctionData({
|
|
29
|
+
abi: SlashFactoryAbi,
|
|
30
|
+
functionName: 'createSlashPayload',
|
|
31
|
+
args: [
|
|
32
|
+
sorted.map((d)=>d.validator.toString()),
|
|
33
|
+
sorted.map((d)=>d.amount),
|
|
34
|
+
sorted.map((d)=>d.offenses.map(packValidatorSlashOffense))
|
|
35
|
+
]
|
|
36
|
+
})
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Tries to extract a SlashPayloadCreated event from the given logs. */ tryExtractSlashPayloadCreatedEvent(logs) {
|
|
40
|
+
return tryExtractEvent(logs, this.address.toString(), SlashFactoryAbi, 'SlashPayloadCreated');
|
|
41
|
+
}
|
|
42
|
+
async getSlashPayloadCreatedEvents() {
|
|
43
|
+
const events = await this.contract.getEvents.SlashPayloadCreated();
|
|
44
|
+
return Promise.all(events.map(async (event)=>{
|
|
45
|
+
const { validators, amounts, offenses } = event.args;
|
|
46
|
+
const slashes = validators.map((validator, i)=>({
|
|
47
|
+
validator: EthAddress.fromString(validator),
|
|
48
|
+
amount: amounts[i],
|
|
49
|
+
offenses: offenses[i].map(unpackValidatorSlashOffense)
|
|
50
|
+
}));
|
|
51
|
+
const block = await this.client.getBlock({
|
|
52
|
+
blockNumber: event.blockNumber,
|
|
53
|
+
includeTransactions: false
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
address: EthAddress.fromString(event.args.payloadAddress),
|
|
57
|
+
slashes,
|
|
58
|
+
timestamp: block.timestamp
|
|
59
|
+
};
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Searches for a slash payload in the events emitted by the contract.
|
|
64
|
+
* This method cannot query for historical payload events, it queries for payloads that have not yet expired.
|
|
65
|
+
* @param payloadAddress The address of the payload to search for.
|
|
66
|
+
* @param constants The L1 rollup constants needed for time calculations.
|
|
67
|
+
*/ async getSlashPayloadFromEvents(payloadAddress, settings) {
|
|
68
|
+
// We query for the log where the payload was emitted walking backwards until we go past payload expiration time
|
|
69
|
+
// Note that all log queries require a block range, and RPC providers cap the max range (eg quicknode is 10k blocks).
|
|
70
|
+
const { slashingRoundSize, slashingPayloadLifetimeInRounds, slotDuration, ethereumSlotDuration } = settings;
|
|
71
|
+
const currentBlockNumber = await this.client.getBlockNumber({
|
|
72
|
+
cacheTime: 0
|
|
73
|
+
});
|
|
74
|
+
// Why the +1 below? Just for good measure. Better err on the safe side.
|
|
75
|
+
const earliestBlockNumber = maxBigint(0n, currentBlockNumber - (BigInt(slashingPayloadLifetimeInRounds) + 1n) * BigInt(slashingRoundSize) * BigInt(slotDuration) / BigInt(ethereumSlotDuration));
|
|
76
|
+
this.logger.trace(`Starting search for slash payload ${payloadAddress} from block ${currentBlockNumber} with earliest block ${earliestBlockNumber}`);
|
|
77
|
+
const batchSize = BigInt(settings.logsBatchSize ?? 10000);
|
|
78
|
+
let toBlock = currentBlockNumber;
|
|
79
|
+
do {
|
|
80
|
+
const fromBlock = maxBigint(earliestBlockNumber, toBlock - batchSize);
|
|
81
|
+
this.logger.trace(`Searching for slash payload ${payloadAddress} in blocks ${fromBlock} to ${toBlock}`);
|
|
82
|
+
const logs = await this.contract.getEvents.SlashPayloadCreated({
|
|
83
|
+
payloadAddress: payloadAddress.toString()
|
|
84
|
+
}, {
|
|
85
|
+
fromBlock,
|
|
86
|
+
toBlock,
|
|
87
|
+
strict: true
|
|
88
|
+
});
|
|
89
|
+
// We found the payload, return it
|
|
90
|
+
if (logs.length > 0) {
|
|
91
|
+
const log = logs[0];
|
|
92
|
+
const { validators, amounts, offenses } = log.args;
|
|
93
|
+
// Convert the data to our internal types
|
|
94
|
+
const slashes = validators.map((validator, i)=>({
|
|
95
|
+
validator: EthAddress.fromString(validator),
|
|
96
|
+
amount: amounts[i],
|
|
97
|
+
offenses: offenses[i].map(unpackValidatorSlashOffense)
|
|
98
|
+
}));
|
|
99
|
+
// Get the timestamp from the block
|
|
100
|
+
const block = await this.client.getBlock({
|
|
101
|
+
blockNumber: log.blockNumber,
|
|
102
|
+
includeTransactions: false
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
address: payloadAddress,
|
|
106
|
+
slashes,
|
|
107
|
+
timestamp: block.timestamp
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
// If not found, we go back one batch
|
|
111
|
+
toBlock -= batchSize;
|
|
112
|
+
}while (toBlock > earliestBlockNumber)
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
async getAddressAndIsDeployed(slashes) {
|
|
116
|
+
const sortedSlashes = this.sortSlashes(slashes);
|
|
117
|
+
const [address, salt, isDeployed] = await this.contract.read.getAddressAndIsDeployed([
|
|
118
|
+
sortedSlashes.map((s)=>s.validator.toString()),
|
|
119
|
+
sortedSlashes.map((s)=>s.amount),
|
|
120
|
+
sortedSlashes.map((s)=>s.offenses.map(packValidatorSlashOffense))
|
|
121
|
+
]);
|
|
122
|
+
return {
|
|
123
|
+
address: EthAddress.fromString(address),
|
|
124
|
+
salt,
|
|
125
|
+
isDeployed
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
sortSlashes(slashes) {
|
|
129
|
+
const offenseSorter = (a, b)=>{
|
|
130
|
+
return a.epochOrSlot === b.epochOrSlot ? a.offenseType - b.offenseType : Number(a.epochOrSlot - b.epochOrSlot);
|
|
131
|
+
};
|
|
132
|
+
return [
|
|
133
|
+
...slashes
|
|
134
|
+
].map((slash)=>({
|
|
135
|
+
...slash,
|
|
136
|
+
offenses: [
|
|
137
|
+
...slash.offenses
|
|
138
|
+
].sort(offenseSorter)
|
|
139
|
+
})).sort((a, b)=>a.validator.toString().localeCompare(b.validator.toString()));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export function packValidatorSlashOffense(offense) {
|
|
143
|
+
const offenseId = OffenseToBigInt[offense.offenseType];
|
|
144
|
+
if (offenseId > (1 << 8) - 1) {
|
|
145
|
+
throw new Error(`Offense type ${offense.offenseType} cannot be packed into 8 bits`);
|
|
146
|
+
}
|
|
147
|
+
return (offenseId << 120n) + offense.epochOrSlot;
|
|
148
|
+
}
|
|
149
|
+
export function unpackValidatorSlashOffense(packed) {
|
|
150
|
+
const offenseId = packed >> 120n & 0xffn;
|
|
151
|
+
const epochOrSlot = packed & (1n << 120n) - 1n;
|
|
152
|
+
const offenseType = bigIntToOffense(offenseId);
|
|
153
|
+
return {
|
|
154
|
+
epochOrSlot,
|
|
155
|
+
offenseType
|
|
156
|
+
};
|
|
157
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Offense, OffenseIdentifier, SlashPayload, SlashPayloadRound, ValidatorSlash } from './types.js';
|
|
2
|
+
import { OffenseType } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the offense is uncontroversial as in it can be verified via L1 data alone,
|
|
5
|
+
* and does not depend on the local view of the node of the L2 p2p network.
|
|
6
|
+
* @param offense - The offense type to check
|
|
7
|
+
*/
|
|
8
|
+
export declare function isOffenseUncontroversial(offense: OffenseType): boolean;
|
|
9
|
+
/** Extracts offense identifiers (validator, epoch, offense type) from an Empire-based SlashPayload */
|
|
10
|
+
export declare function getOffenseIdentifiersFromPayload(payload: SlashPayload | SlashPayloadRound): OffenseIdentifier[];
|
|
11
|
+
/** Creates ValidatorSlashes used to create an Empire-based SlashPayload from a set of Offenses */
|
|
12
|
+
export declare function offensesToValidatorSlash(offenses: Offense[]): ValidatorSlash[];
|
|
13
|
+
/**
|
|
14
|
+
* Sorts offense data by:
|
|
15
|
+
* - Uncontroversial offenses first
|
|
16
|
+
* - Slash amount (descending)
|
|
17
|
+
* - Epoch or slot (ascending, ie oldest first)
|
|
18
|
+
* - Validator address (ascending)
|
|
19
|
+
* - Offense type (descending)
|
|
20
|
+
*/
|
|
21
|
+
export declare function offenseDataComparator(a: Offense, b: Offense): number;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the first round in which the offense is eligible for being included in an Empire-based slash payload.
|
|
24
|
+
* Should be equal to to the first round that starts strictly after the offense becomes detectable.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getFirstEligibleRoundForOffense(offense: OffenseIdentifier, constants: {
|
|
27
|
+
slashingRoundSize: number;
|
|
28
|
+
epochDuration: number;
|
|
29
|
+
proofSubmissionEpochs: number;
|
|
30
|
+
}): bigint;
|
|
31
|
+
//# sourceMappingURL=empire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"empire.d.ts","sourceRoot":"","sources":["../../src/slashing/empire.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC9G,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAMtE;AAED,sGAAsG;AACtG,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,YAAY,GAAG,iBAAiB,GAAG,iBAAiB,EAAE,CAQ/G;AAED,kGAAkG;AAClG,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,CAM9E;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,CAQpE;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,iBAAiB,EAC1B,SAAS,EAAE;IAAE,iBAAiB,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,qBAAqB,EAAE,MAAM,CAAA;CAAE,GAC7F,MAAM,CAqCR"}
|