@aztec/ethereum 0.87.1 → 0.87.2-nightly.20250524
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/config.js +3 -3
- package/dest/contracts/governance.d.ts +1 -1
- package/dest/contracts/rollup.d.ts +20 -7
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +26 -6
- package/dest/contracts/slashing_proposer.d.ts +17 -2
- package/dest/contracts/slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/slashing_proposer.js +84 -3
- package/dest/deploy_l1_contracts.d.ts +3138 -216
- package/dest/deploy_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_l1_contracts.js +85 -22
- package/dest/l1_contract_addresses.d.ts +5 -1
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +2 -1
- package/dest/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils.js +11 -2
- package/package.json +4 -4
- package/src/config.ts +3 -3
- package/src/contracts/rollup.ts +26 -5
- package/src/contracts/slashing_proposer.ts +113 -3
- package/src/deploy_l1_contracts.ts +112 -33
- package/src/l1_contract_addresses.ts +3 -1
- package/src/l1_tx_utils.ts +6 -2
package/dest/config.js
CHANGED
|
@@ -2,10 +2,10 @@ import { bigintConfigHelper, booleanConfigHelper, getConfigFromMappings, numberC
|
|
|
2
2
|
import { l1TxUtilsConfigMappings } from './l1_tx_utils.js';
|
|
3
3
|
export const DefaultL1ContractsConfig = {
|
|
4
4
|
ethereumSlotDuration: 12,
|
|
5
|
-
aztecSlotDuration:
|
|
6
|
-
aztecEpochDuration:
|
|
5
|
+
aztecSlotDuration: 36,
|
|
6
|
+
aztecEpochDuration: 32,
|
|
7
7
|
aztecTargetCommitteeSize: 48,
|
|
8
|
-
aztecProofSubmissionWindow:
|
|
8
|
+
aztecProofSubmissionWindow: 64,
|
|
9
9
|
minimumStake: BigInt(100e18),
|
|
10
10
|
slashingQuorum: 6,
|
|
11
11
|
slashingRoundSize: 10,
|
|
@@ -5,14 +5,13 @@ import { type Account, type GetContractReturnType, type Hex } from 'viem';
|
|
|
5
5
|
import type { DeployL1ContractsReturnType } from '../deploy_l1_contracts.js';
|
|
6
6
|
import type { L1ContractAddresses } from '../l1_contract_addresses.js';
|
|
7
7
|
import type { L1ReaderConfig } from '../l1_reader.js';
|
|
8
|
+
import type { L1TxUtils } from '../l1_tx_utils.js';
|
|
8
9
|
import type { ViemClient } from '../types.js';
|
|
9
10
|
import { SlashingProposerContract } from './slashing_proposer.js';
|
|
10
|
-
export type L1RollupContractAddresses = Pick<L1ContractAddresses, 'rollupAddress' | 'inboxAddress' | 'outboxAddress' | 'feeJuicePortalAddress' | 'feeJuiceAddress' | 'stakingAssetAddress' | 'rewardDistributorAddress' | 'slashFactoryAddress'>;
|
|
11
|
+
export type L1RollupContractAddresses = Pick<L1ContractAddresses, 'rollupAddress' | 'inboxAddress' | 'outboxAddress' | 'feeJuicePortalAddress' | 'feeJuiceAddress' | 'stakingAssetAddress' | 'rewardDistributorAddress' | 'slashFactoryAddress' | 'gseAddress'>;
|
|
11
12
|
export type EpochProofPublicInputArgs = {
|
|
12
13
|
previousArchive: `0x${string}`;
|
|
13
14
|
endArchive: `0x${string}`;
|
|
14
|
-
endTimestamp: bigint;
|
|
15
|
-
outHash: `0x${string}`;
|
|
16
15
|
proverId: `0x${string}`;
|
|
17
16
|
};
|
|
18
17
|
export declare class RollupContract {
|
|
@@ -107,14 +106,28 @@ export declare class RollupContract {
|
|
|
107
106
|
getSequencerRewards(address: Hex | EthAddress): Promise<bigint>;
|
|
108
107
|
getSpecificProverRewardsForEpoch(epoch: bigint, prover: Hex | EthAddress): Promise<bigint>;
|
|
109
108
|
getAttesters(): Promise<readonly `0x${string}`[]>;
|
|
110
|
-
|
|
111
|
-
stake: bigint;
|
|
112
|
-
withdrawer: `0x${string}`;
|
|
113
|
-
proposer: `0x${string}`;
|
|
109
|
+
getAttesterView(address: Hex | EthAddress): Promise<{
|
|
114
110
|
status: number;
|
|
111
|
+
effectiveBalance: bigint;
|
|
112
|
+
exit: {
|
|
113
|
+
amount: bigint;
|
|
114
|
+
exitableAt: bigint;
|
|
115
|
+
recipientOrWithdrawer: `0x${string}`;
|
|
116
|
+
isRecipient: boolean;
|
|
117
|
+
exists: boolean;
|
|
118
|
+
};
|
|
119
|
+
config: {
|
|
120
|
+
withdrawer: `0x${string}`;
|
|
121
|
+
proposer: `0x${string}`;
|
|
122
|
+
};
|
|
115
123
|
}>;
|
|
124
|
+
getStatus(address: Hex | EthAddress): Promise<number>;
|
|
116
125
|
getBlobPublicInputsHash(blockNumber: bigint): Promise<`0x${string}`>;
|
|
117
126
|
getStakingAsset(): Promise<`0x${string}`>;
|
|
118
127
|
getProposerForAttester(attester: Hex | EthAddress): Promise<`0x${string}`>;
|
|
128
|
+
setupEpoch(l1TxUtils: L1TxUtils): Promise<{
|
|
129
|
+
receipt: import("viem").TransactionReceipt;
|
|
130
|
+
gasPrice: import("../l1_tx_utils.js").GasPrice;
|
|
131
|
+
}>;
|
|
119
132
|
}
|
|
120
133
|
//# sourceMappingURL=rollup.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../../src/contracts/rollup.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAI1D,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../../src/contracts/rollup.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC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|
|
|
9
9
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
10
10
|
import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage';
|
|
11
11
|
import { SlasherAbi } from '@aztec/l1-artifacts/SlasherAbi';
|
|
12
|
-
import { getAddress, getContract } from 'viem';
|
|
12
|
+
import { encodeFunctionData, getAddress, getContract } from 'viem';
|
|
13
13
|
import { getPublicClient } from '../client.js';
|
|
14
14
|
import { formatViemError } from '../utils.js';
|
|
15
15
|
import { SlashingProposerContract } from './slashing_proposer.js';
|
|
@@ -213,13 +213,14 @@ export class RollupContract {
|
|
|
213
213
|
]);
|
|
214
214
|
}
|
|
215
215
|
async getRollupAddresses() {
|
|
216
|
-
const [inboxAddress, outboxAddress, feeJuicePortalAddress, rewardDistributorAddress, feeJuiceAddress, stakingAssetAddress] = (await Promise.all([
|
|
216
|
+
const [inboxAddress, outboxAddress, feeJuicePortalAddress, rewardDistributorAddress, feeJuiceAddress, stakingAssetAddress, gseAddress] = (await Promise.all([
|
|
217
217
|
this.rollup.read.getInbox(),
|
|
218
218
|
this.rollup.read.getOutbox(),
|
|
219
219
|
this.rollup.read.getFeeAssetPortal(),
|
|
220
220
|
this.rollup.read.getRewardDistributor(),
|
|
221
221
|
this.rollup.read.getFeeAsset(),
|
|
222
|
-
this.rollup.read.getStakingAsset()
|
|
222
|
+
this.rollup.read.getStakingAsset(),
|
|
223
|
+
this.rollup.read.getGSE()
|
|
223
224
|
])).map(EthAddress.fromString);
|
|
224
225
|
return {
|
|
225
226
|
rollupAddress: EthAddress.fromString(this.address),
|
|
@@ -228,7 +229,8 @@ export class RollupContract {
|
|
|
228
229
|
feeJuicePortalAddress,
|
|
229
230
|
feeJuiceAddress,
|
|
230
231
|
stakingAssetAddress,
|
|
231
|
-
rewardDistributorAddress
|
|
232
|
+
rewardDistributorAddress,
|
|
233
|
+
gseAddress
|
|
232
234
|
};
|
|
233
235
|
}
|
|
234
236
|
async getFeeJuicePortal() {
|
|
@@ -348,11 +350,19 @@ export class RollupContract {
|
|
|
348
350
|
getAttesters() {
|
|
349
351
|
return this.rollup.read.getAttesters();
|
|
350
352
|
}
|
|
351
|
-
|
|
353
|
+
getAttesterView(address) {
|
|
352
354
|
if (address instanceof EthAddress) {
|
|
353
355
|
address = address.toString();
|
|
354
356
|
}
|
|
355
|
-
return this.rollup.read.
|
|
357
|
+
return this.rollup.read.getAttesterView([
|
|
358
|
+
address
|
|
359
|
+
]);
|
|
360
|
+
}
|
|
361
|
+
getStatus(address) {
|
|
362
|
+
if (address instanceof EthAddress) {
|
|
363
|
+
address = address.toString();
|
|
364
|
+
}
|
|
365
|
+
return this.rollup.read.getStatus([
|
|
356
366
|
address
|
|
357
367
|
]);
|
|
358
368
|
}
|
|
@@ -372,6 +382,16 @@ export class RollupContract {
|
|
|
372
382
|
attester
|
|
373
383
|
]);
|
|
374
384
|
}
|
|
385
|
+
setupEpoch(l1TxUtils) {
|
|
386
|
+
return l1TxUtils.sendAndMonitorTransaction({
|
|
387
|
+
to: this.address,
|
|
388
|
+
data: encodeFunctionData({
|
|
389
|
+
abi: RollupAbi,
|
|
390
|
+
functionName: 'setupEpoch',
|
|
391
|
+
args: []
|
|
392
|
+
})
|
|
393
|
+
});
|
|
394
|
+
}
|
|
375
395
|
}
|
|
376
396
|
_ts_decorate([
|
|
377
397
|
memoize
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import EventEmitter from 'events';
|
|
2
3
|
import { type Hex } from 'viem';
|
|
3
|
-
import type { L1TxRequest } from '../l1_tx_utils.js';
|
|
4
|
+
import type { L1TxRequest, L1TxUtils } from '../l1_tx_utils.js';
|
|
4
5
|
import type { ViemClient } from '../types.js';
|
|
5
6
|
import { type IEmpireBase } from './empire_base.js';
|
|
6
|
-
export declare class
|
|
7
|
+
export declare class ProposalAlreadyExecutedError extends Error {
|
|
8
|
+
constructor(round: bigint);
|
|
9
|
+
}
|
|
10
|
+
export declare class SlashingProposerContract extends EventEmitter implements IEmpireBase {
|
|
7
11
|
readonly client: ViemClient;
|
|
8
12
|
private readonly proposer;
|
|
9
13
|
constructor(client: ViemClient, address: Hex);
|
|
@@ -16,6 +20,17 @@ export declare class SlashingProposerContract implements IEmpireBase {
|
|
|
16
20
|
leader: Hex;
|
|
17
21
|
executed: boolean;
|
|
18
22
|
}>;
|
|
23
|
+
getProposalVotes(rollupAddress: Hex, round: bigint, proposal: Hex): Promise<bigint>;
|
|
19
24
|
createVoteRequest(payload: Hex): L1TxRequest;
|
|
25
|
+
listenToExecutableProposals(callback: (args: {
|
|
26
|
+
proposal: `0x${string}`;
|
|
27
|
+
round: bigint;
|
|
28
|
+
}) => unknown): import("viem").WatchContractEventReturnType;
|
|
29
|
+
listenToProposalExecuted(callback: (args: {
|
|
30
|
+
round: bigint;
|
|
31
|
+
proposal: `0x${string}`;
|
|
32
|
+
}) => unknown): import("viem").WatchContractEventReturnType;
|
|
33
|
+
waitForRound(round: bigint, pollingIntervalSeconds?: number): Promise<boolean>;
|
|
34
|
+
executeRound(txUtils: L1TxUtils, round: bigint | number): Promise<void>;
|
|
20
35
|
}
|
|
21
36
|
//# sourceMappingURL=slashing_proposer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slashing_proposer.d.ts","sourceRoot":"","sources":["../../src/contracts/slashing_proposer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"slashing_proposer.d.ts","sourceRoot":"","sources":["../../src/contracts/slashing_proposer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAI3D,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,EAGL,KAAK,GAAG,EAGT,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CA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MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA4CrF"}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
2
3
|
import { SlashingProposerAbi } from '@aztec/l1-artifacts/SlashingProposerAbi';
|
|
3
|
-
import
|
|
4
|
+
import EventEmitter from 'events';
|
|
5
|
+
import { encodeFunctionData, getContract } from 'viem';
|
|
6
|
+
import { FormattedViemError } from '../utils.js';
|
|
4
7
|
import { encodeVote } from './empire_base.js';
|
|
5
|
-
export class
|
|
8
|
+
export class ProposalAlreadyExecutedError extends Error {
|
|
9
|
+
constructor(round){
|
|
10
|
+
super(`Proposal already executed: ${round}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class SlashingProposerContract extends EventEmitter {
|
|
6
14
|
client;
|
|
7
15
|
proposer;
|
|
8
16
|
constructor(client, address){
|
|
9
|
-
this.client = client;
|
|
17
|
+
super(), this.client = client;
|
|
10
18
|
this.proposer = getContract({
|
|
11
19
|
address,
|
|
12
20
|
abi: SlashingProposerAbi,
|
|
@@ -38,10 +46,83 @@ export class SlashingProposerContract {
|
|
|
38
46
|
executed: roundInfo[2]
|
|
39
47
|
};
|
|
40
48
|
}
|
|
49
|
+
getProposalVotes(rollupAddress, round, proposal) {
|
|
50
|
+
return this.proposer.read.yeaCount([
|
|
51
|
+
rollupAddress,
|
|
52
|
+
round,
|
|
53
|
+
proposal
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
41
56
|
createVoteRequest(payload) {
|
|
42
57
|
return {
|
|
43
58
|
to: this.address.toString(),
|
|
44
59
|
data: encodeVote(payload)
|
|
45
60
|
};
|
|
46
61
|
}
|
|
62
|
+
listenToExecutableProposals(callback) {
|
|
63
|
+
return this.proposer.watchEvent.ProposalExecutable({}, {
|
|
64
|
+
onLogs: (logs)=>{
|
|
65
|
+
for (const payload of logs){
|
|
66
|
+
const args = payload.args;
|
|
67
|
+
if (args.proposal && args.round) {
|
|
68
|
+
// why compiler can't figure it out? no one knows
|
|
69
|
+
callback(args);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
listenToProposalExecuted(callback) {
|
|
76
|
+
return this.proposer.watchEvent.ProposalExecuted({}, {
|
|
77
|
+
onLogs: (logs)=>{
|
|
78
|
+
for (const payload of logs){
|
|
79
|
+
const args = payload.args;
|
|
80
|
+
if (args.round && args.proposal) {
|
|
81
|
+
callback(args);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
waitForRound(round, pollingIntervalSeconds = 1) {
|
|
88
|
+
return retryUntil(async ()=>{
|
|
89
|
+
const currentRound = await this.proposer.read.getCurrentRound();
|
|
90
|
+
return currentRound >= round;
|
|
91
|
+
}, `Waiting for round ${round} to be reached`, 0, pollingIntervalSeconds);
|
|
92
|
+
}
|
|
93
|
+
async executeRound(txUtils, round) {
|
|
94
|
+
if (typeof round === 'number') {
|
|
95
|
+
round = BigInt(round);
|
|
96
|
+
}
|
|
97
|
+
const args = {
|
|
98
|
+
abi: SlashingProposerAbi,
|
|
99
|
+
functionName: 'executeProposal',
|
|
100
|
+
args: [
|
|
101
|
+
round
|
|
102
|
+
]
|
|
103
|
+
};
|
|
104
|
+
const data = encodeFunctionData(args);
|
|
105
|
+
const response = await txUtils.sendAndMonitorTransaction({
|
|
106
|
+
to: this.address.toString(),
|
|
107
|
+
data
|
|
108
|
+
}, {
|
|
109
|
+
// Gas estimation is more than 20% off for this tx.
|
|
110
|
+
gasLimitBufferPercentage: 100
|
|
111
|
+
}).catch((err)=>{
|
|
112
|
+
if (err instanceof FormattedViemError && err.message.includes('ProposalAlreadyExecuted')) {
|
|
113
|
+
throw new ProposalAlreadyExecutedError(round);
|
|
114
|
+
}
|
|
115
|
+
throw err;
|
|
116
|
+
});
|
|
117
|
+
if (response.receipt.status === 'reverted') {
|
|
118
|
+
const error = await txUtils.tryGetErrorFromRevertedTx(data, {
|
|
119
|
+
...args,
|
|
120
|
+
address: this.address.toString()
|
|
121
|
+
}, undefined, []);
|
|
122
|
+
if (error?.includes('ProposalAlreadyExecuted')) {
|
|
123
|
+
throw new ProposalAlreadyExecutedError(round);
|
|
124
|
+
}
|
|
125
|
+
throw new Error(error ?? 'Unknown error');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
47
128
|
}
|