@aztec/ethereum 0.0.1-commit.7d4e6cd → 0.0.1-commit.858058eac
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.d.ts +15 -28
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +47 -56
- package/dest/contracts/empire_slashing_proposer.d.ts +1 -1
- package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/empire_slashing_proposer.js +13 -15
- package/dest/contracts/fee_asset_handler.d.ts +1 -1
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
- package/dest/contracts/fee_asset_handler.js +2 -0
- package/dest/contracts/governance.d.ts +3 -1
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +11 -1
- package/dest/contracts/governance_proposer.d.ts +1 -1
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +4 -1
- package/dest/contracts/inbox.d.ts +18 -1
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +32 -1
- package/dest/contracts/index.d.ts +2 -1
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +1 -0
- package/dest/contracts/log.d.ts +13 -0
- package/dest/contracts/log.d.ts.map +1 -0
- package/dest/contracts/log.js +1 -0
- package/dest/contracts/multicall.d.ts +1 -1
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +2 -1
- package/dest/contracts/rollup.d.ts +35 -3
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +76 -6
- package/dest/contracts/tally_slashing_proposer.d.ts +1 -1
- package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/tally_slashing_proposer.js +8 -1
- package/dest/deploy_aztec_l1_contracts.d.ts +6 -1
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
- package/dest/deploy_aztec_l1_contracts.js +26 -12
- package/dest/generated/l1-contracts-defaults.d.ts +30 -0
- package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
- package/dest/generated/l1-contracts-defaults.js +30 -0
- package/dest/l1_artifacts.d.ts +1394 -471
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_tx_utils/constants.d.ts +1 -1
- package/dest/l1_tx_utils/constants.js +2 -2
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +1 -1
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +6 -6
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +3 -3
- package/dest/publisher_manager.d.ts +3 -2
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +2 -2
- package/dest/queries.d.ts +2 -2
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +4 -1
- package/dest/test/eth_cheat_codes.d.ts +13 -1
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.d.ts +4 -2
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +10 -1
- package/dest/test/start_anvil.js +1 -1
- package/dest/utils.d.ts +2 -1
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +46 -0
- package/package.json +8 -7
- package/src/config.ts +56 -55
- package/src/contracts/README.md +157 -0
- package/src/contracts/empire_slashing_proposer.ts +16 -27
- package/src/contracts/fee_asset_handler.ts +2 -0
- package/src/contracts/governance.ts +10 -1
- package/src/contracts/governance_proposer.ts +4 -1
- package/src/contracts/inbox.ts +48 -1
- package/src/contracts/index.ts +1 -0
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +5 -2
- package/src/contracts/rollup.ts +111 -11
- package/src/contracts/tally_slashing_proposer.ts +5 -1
- package/src/deploy_aztec_l1_contracts.ts +27 -9
- package/src/generated/l1-contracts-defaults.ts +32 -0
- package/src/l1_tx_utils/constants.ts +2 -2
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +1 -1
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +1 -1
- package/src/l1_tx_utils/l1_tx_utils.ts +6 -6
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +3 -3
- package/src/publisher_manager.ts +4 -2
- package/src/queries.ts +3 -1
- package/src/test/rollup_cheat_codes.ts +11 -2
- package/src/test/start_anvil.ts +1 -1
- package/src/utils.ts +53 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# L1 Contract Wrappers
|
|
2
|
+
|
|
3
|
+
This folder contains TypeScript wrappers for L1 contracts defined in `l1-contracts/`. These wrappers are used by the node client to interact with the rollup and related contracts on Ethereum.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
The goal of wrapping is to shield consumers from L1-specific and viem-specific details. Clients using these wrappers interact with domain types and branded types native to the Aztec codebase, without needing to understand viem's ABI type system or deal with raw types like `Hex` and `bigint`.
|
|
8
|
+
|
|
9
|
+
## Type Safety
|
|
10
|
+
|
|
11
|
+
### Explicit Return Types
|
|
12
|
+
|
|
13
|
+
Every function in the contract wrappers must declare its return type explicitly. This is critical because viem's type inference over ABI types is slow and significantly impacts IDE performance.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// Good: Explicit return type
|
|
17
|
+
async getSlotNumber(): Promise<SlotNumber> {
|
|
18
|
+
return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Bad: Inferred return type (slow)
|
|
22
|
+
async getSlotNumber() {
|
|
23
|
+
return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Branded and Domain Types
|
|
28
|
+
|
|
29
|
+
Use branded types and domain-specific types instead of viem's autogenerated types for both arguments and return values:
|
|
30
|
+
|
|
31
|
+
- `CheckpointNumber`, `EpochNumber`, `SlotNumber` instead of `bigint`
|
|
32
|
+
- `EthAddress` instead of `` `0x${string}` `` or `Hex`
|
|
33
|
+
- `Fr`, `Buffer32` instead of `Hex` for hashes and field elements
|
|
34
|
+
- Custom domain types (e.g., `CheckpointLog`, `AttesterView`) instead of raw tuples
|
|
35
|
+
|
|
36
|
+
Type conversions happen inside wrapper methods, not at the call site:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
async getCheckpoint(checkpointNumber: CheckpointNumber): Promise<CheckpointLog> {
|
|
40
|
+
const result = await this.rollup.read.getCheckpoint([BigInt(checkpointNumber)]);
|
|
41
|
+
return {
|
|
42
|
+
archive: Fr.fromString(result.archive),
|
|
43
|
+
headerHash: Buffer32.fromString(result.headerHash),
|
|
44
|
+
blockCount: result.blockCount,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Wrapper Pattern
|
|
50
|
+
|
|
51
|
+
### Basic Structure
|
|
52
|
+
|
|
53
|
+
Each wrapper follows a consistent structure:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
export class FooContract {
|
|
57
|
+
private readonly foo: GetContractReturnType<typeof FooAbi, ViemClient>;
|
|
58
|
+
|
|
59
|
+
constructor(
|
|
60
|
+
public readonly client: ViemClient,
|
|
61
|
+
address: Hex | EthAddress,
|
|
62
|
+
) {
|
|
63
|
+
if (address instanceof EthAddress) {
|
|
64
|
+
address = address.toString();
|
|
65
|
+
}
|
|
66
|
+
this.foo = getContract({ address, abi: FooAbi, client });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public get address(): Hex {
|
|
70
|
+
return this.foo.address;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public getContract(): GetContractReturnType<typeof FooAbi, ViemClient> {
|
|
74
|
+
return this.foo;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The raw contract is exposed via `getContract()` for cases where direct access is needed, but most consumers should use the typed wrapper methods. Relying on `getContract()` is a code smell and should be avoided.
|
|
80
|
+
|
|
81
|
+
### Static Factory Methods
|
|
82
|
+
|
|
83
|
+
Wrappers may provide static factory methods for common initialization patterns:
|
|
84
|
+
|
|
85
|
+
- `getFromConfig(config)` - construct from configuration object
|
|
86
|
+
- `getFromL1ContractsValues(deployResult)` - construct from deployment result
|
|
87
|
+
|
|
88
|
+
### Wallet Assertions
|
|
89
|
+
|
|
90
|
+
For write operations that require a wallet, use an assertion helper:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
private assertWallet(): GetContractReturnType<typeof FooAbi, ExtendedViemWalletClient> {
|
|
94
|
+
if (!isExtendedClient(this.client)) {
|
|
95
|
+
throw new Error('Wallet client is required for this operation');
|
|
96
|
+
}
|
|
97
|
+
return this.foo as GetContractReturnType<typeof FooAbi, ExtendedViemWalletClient>;
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Event Handling
|
|
102
|
+
|
|
103
|
+
### Event Log Types
|
|
104
|
+
|
|
105
|
+
Event logs are wrapped in `L1EventLog<T>` to include L1 block context:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
type L1EventLog<T> = {
|
|
109
|
+
l1BlockNumber: bigint;
|
|
110
|
+
l1BlockHash: Buffer32;
|
|
111
|
+
l1TransactionHash: Hex;
|
|
112
|
+
args: T;
|
|
113
|
+
};
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Event Fetching
|
|
117
|
+
|
|
118
|
+
Methods that fetch events convert viem's raw logs to domain types:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
|
|
122
|
+
const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
|
|
123
|
+
return logs.map(log => ({
|
|
124
|
+
l1BlockNumber: log.blockNumber!,
|
|
125
|
+
l1BlockHash: Buffer32.fromString(log.blockHash!),
|
|
126
|
+
l1TransactionHash: log.transactionHash!,
|
|
127
|
+
args: {
|
|
128
|
+
checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
|
|
129
|
+
// ... convert other fields
|
|
130
|
+
},
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Event Listeners
|
|
136
|
+
|
|
137
|
+
For reactive event handling, wrapper methods convert arguments before invoking callbacks:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
public listenToCheckpointInvalidated(
|
|
141
|
+
callback: (args: { checkpointNumber: CheckpointNumber }) => unknown,
|
|
142
|
+
): WatchContractEventReturnType {
|
|
143
|
+
return this.rollup.watchEvent.CheckpointInvalidated({}, {
|
|
144
|
+
onLogs: logs => {
|
|
145
|
+
for (const log of logs) {
|
|
146
|
+
if (log.args.checkpointNumber !== undefined) {
|
|
147
|
+
callback({ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber) });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Error Handling
|
|
156
|
+
|
|
157
|
+
Custom error classes in `errors.ts` extend `Error` and set `this.name` for proper error identification. Include relevant context as public readonly properties.
|
|
@@ -6,7 +6,6 @@ import { EmpireSlashingProposerAbi } from '@aztec/l1-artifacts/EmpireSlashingPro
|
|
|
6
6
|
|
|
7
7
|
import EventEmitter from 'events';
|
|
8
8
|
import {
|
|
9
|
-
type EncodeFunctionDataParameters,
|
|
10
9
|
type GetContractReturnType,
|
|
11
10
|
type Hex,
|
|
12
11
|
type Log,
|
|
@@ -100,6 +99,7 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
100
99
|
public createSignalRequest(payload: Hex): L1TxRequest {
|
|
101
100
|
return {
|
|
102
101
|
to: this.address.toString(),
|
|
102
|
+
abi: EmpireSlashingProposerAbi,
|
|
103
103
|
data: encodeSignal(payload),
|
|
104
104
|
};
|
|
105
105
|
}
|
|
@@ -121,6 +121,7 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
121
121
|
);
|
|
122
122
|
return {
|
|
123
123
|
to: this.address.toString(),
|
|
124
|
+
abi: EmpireSlashingProposerAbi,
|
|
124
125
|
data: encodeSignalWithSignature(payload, signature),
|
|
125
126
|
};
|
|
126
127
|
}
|
|
@@ -180,6 +181,7 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
180
181
|
public buildExecuteRoundRequest(round: bigint): L1TxRequest {
|
|
181
182
|
return {
|
|
182
183
|
to: this.address.toString(),
|
|
184
|
+
abi: EmpireSlashingProposerAbi,
|
|
183
185
|
data: encodeFunctionData({
|
|
184
186
|
abi: EmpireSlashingProposerAbi,
|
|
185
187
|
functionName: 'submitRoundWinner',
|
|
@@ -222,24 +224,13 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
222
224
|
if (typeof round === 'number') {
|
|
223
225
|
round = BigInt(round);
|
|
224
226
|
}
|
|
225
|
-
const
|
|
226
|
-
abi: EmpireSlashingProposerAbi,
|
|
227
|
-
functionName: 'submitRoundWinner',
|
|
228
|
-
args: [round],
|
|
229
|
-
};
|
|
230
|
-
const data = encodeFunctionData(args);
|
|
227
|
+
const request = this.buildExecuteRoundRequest(round);
|
|
231
228
|
const response = await txUtils
|
|
232
|
-
.sendAndMonitorTransaction(
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
{
|
|
238
|
-
// Gas estimation is way off for this, likely because we are creating the contract/selector to call
|
|
239
|
-
// for the actual slashing dynamically.
|
|
240
|
-
gasLimitBufferPercentage: 50, // +50% gas
|
|
241
|
-
},
|
|
242
|
-
)
|
|
229
|
+
.sendAndMonitorTransaction(request, {
|
|
230
|
+
// Gas estimation is way off for this, likely because we are creating the contract/selector to call
|
|
231
|
+
// for the actual slashing dynamically.
|
|
232
|
+
gasLimitBufferPercentage: 50, // +50% gas
|
|
233
|
+
})
|
|
243
234
|
.catch(err => {
|
|
244
235
|
if (err instanceof FormattedViemError && err.message.includes('ProposalAlreadyExecuted')) {
|
|
245
236
|
throw new ProposalAlreadyExecutedError(round);
|
|
@@ -248,15 +239,13 @@ export class EmpireSlashingProposerContract extends EventEmitter implements IEmp
|
|
|
248
239
|
});
|
|
249
240
|
|
|
250
241
|
if (response.receipt.status === 'reverted') {
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
[],
|
|
259
|
-
);
|
|
242
|
+
const args = {
|
|
243
|
+
abi: EmpireSlashingProposerAbi,
|
|
244
|
+
functionName: 'submitRoundWinner' as const,
|
|
245
|
+
args: [round] as const,
|
|
246
|
+
address: this.address.toString(),
|
|
247
|
+
};
|
|
248
|
+
const error = await txUtils.tryGetErrorFromRevertedTx(request.data!, args, undefined, []);
|
|
260
249
|
if (error?.includes('ProposalAlreadyExecuted')) {
|
|
261
250
|
throw new ProposalAlreadyExecutedError(round);
|
|
262
251
|
}
|
|
@@ -43,6 +43,7 @@ export class FeeAssetHandlerContract {
|
|
|
43
43
|
}
|
|
44
44
|
return txUtils.sendAndMonitorTransaction({
|
|
45
45
|
to: this.address.toString(),
|
|
46
|
+
abi: FeeAssetHandlerAbi,
|
|
46
47
|
data: encodeFunctionData({
|
|
47
48
|
abi: FeeAssetHandlerAbi,
|
|
48
49
|
functionName: 'mint',
|
|
@@ -54,6 +55,7 @@ export class FeeAssetHandlerContract {
|
|
|
54
55
|
public setMintAmount(txUtils: L1TxUtils, amount: bigint) {
|
|
55
56
|
return txUtils.sendAndMonitorTransaction({
|
|
56
57
|
to: this.address.toString(),
|
|
58
|
+
abi: FeeAssetHandlerAbi,
|
|
57
59
|
data: encodeFunctionData({
|
|
58
60
|
abi: FeeAssetHandlerAbi,
|
|
59
61
|
functionName: 'setMintAmount',
|
|
@@ -174,6 +174,13 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
|
|
|
174
174
|
return this.governanceContract.read.powerAt([this.client.account.address, now.timestamp]);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
/** Returns the user's voting power for a specific proposal, checked at pendingThrough timestamp. */
|
|
178
|
+
public async getPowerForProposal(proposalId: bigint): Promise<bigint> {
|
|
179
|
+
const proposal = await this.getProposal(proposalId);
|
|
180
|
+
const pendingThrough = proposal.creation + proposal.config.votingDelay;
|
|
181
|
+
return this.governanceContract.read.powerAt([this.client.account.address, pendingThrough]);
|
|
182
|
+
}
|
|
183
|
+
|
|
177
184
|
public async vote({
|
|
178
185
|
proposalId,
|
|
179
186
|
voteAmount,
|
|
@@ -190,7 +197,7 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
|
|
|
190
197
|
const l1TxUtils = createL1TxUtilsFromViemWallet(this.client, { logger });
|
|
191
198
|
const retryDelaySeconds = 12;
|
|
192
199
|
|
|
193
|
-
voteAmount = voteAmount ?? (await this.
|
|
200
|
+
voteAmount = voteAmount ?? (await this.getPowerForProposal(proposalId));
|
|
194
201
|
|
|
195
202
|
let success = false;
|
|
196
203
|
for (let i = 0; i < retries; i++) {
|
|
@@ -204,6 +211,7 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
|
|
|
204
211
|
|
|
205
212
|
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
206
213
|
to: this.governanceContract.address,
|
|
214
|
+
abi: GovernanceAbi,
|
|
207
215
|
data: encodedVoteData,
|
|
208
216
|
});
|
|
209
217
|
|
|
@@ -258,6 +266,7 @@ export class GovernanceContract extends ReadOnlyGovernanceContract {
|
|
|
258
266
|
|
|
259
267
|
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
260
268
|
to: this.governanceContract.address,
|
|
269
|
+
abi: GovernanceAbi,
|
|
261
270
|
data: encodedExecuteData,
|
|
262
271
|
});
|
|
263
272
|
|
|
@@ -83,6 +83,7 @@ export class GovernanceProposerContract implements IEmpireBase {
|
|
|
83
83
|
public createSignalRequest(payload: Hex): L1TxRequest {
|
|
84
84
|
return {
|
|
85
85
|
to: this.address.toString(),
|
|
86
|
+
abi: GovernanceProposerAbi,
|
|
86
87
|
data: encodeSignal(payload),
|
|
87
88
|
};
|
|
88
89
|
}
|
|
@@ -104,6 +105,7 @@ export class GovernanceProposerContract implements IEmpireBase {
|
|
|
104
105
|
);
|
|
105
106
|
return {
|
|
106
107
|
to: this.address.toString(),
|
|
108
|
+
abi: GovernanceProposerAbi,
|
|
107
109
|
data: encodeSignalWithSignature(payload, signature),
|
|
108
110
|
};
|
|
109
111
|
}
|
|
@@ -117,8 +119,9 @@ export class GovernanceProposerContract implements IEmpireBase {
|
|
|
117
119
|
}> {
|
|
118
120
|
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
119
121
|
to: this.address.toString(),
|
|
122
|
+
abi: GovernanceProposerAbi,
|
|
120
123
|
data: encodeFunctionData({
|
|
121
|
-
abi:
|
|
124
|
+
abi: GovernanceProposerAbi,
|
|
122
125
|
functionName: 'submitRoundWinner',
|
|
123
126
|
args: [round],
|
|
124
127
|
}),
|
package/src/contracts/inbox.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Buffer16, Buffer32 } from '@aztec/foundation/buffer';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
4
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
5
|
import { InboxAbi } from '@aztec/l1-artifacts/InboxAbi';
|
|
4
6
|
|
|
@@ -8,8 +10,20 @@ import { getPublicClient } from '../client.js';
|
|
|
8
10
|
import type { DeployAztecL1ContractsReturnType } from '../deploy_aztec_l1_contracts.js';
|
|
9
11
|
import type { L1ReaderConfig } from '../l1_reader.js';
|
|
10
12
|
import type { ViemClient } from '../types.js';
|
|
13
|
+
import type { L1EventLog } from './log.js';
|
|
11
14
|
import { checkBlockTag } from './utils.js';
|
|
12
15
|
|
|
16
|
+
/** Arguments for the MessageSent event. */
|
|
17
|
+
export type MessageSentArgs = {
|
|
18
|
+
index: bigint;
|
|
19
|
+
leaf: Fr;
|
|
20
|
+
checkpointNumber: CheckpointNumber;
|
|
21
|
+
rollingHash: Buffer16;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Log type for MessageSent events. */
|
|
25
|
+
export type MessageSentLog = L1EventLog<MessageSentArgs>;
|
|
26
|
+
|
|
13
27
|
export class InboxContract {
|
|
14
28
|
private readonly inbox: GetContractReturnType<typeof InboxAbi, ViemClient>;
|
|
15
29
|
|
|
@@ -59,6 +73,39 @@ export class InboxContract {
|
|
|
59
73
|
treeInProgress: state.inProgress,
|
|
60
74
|
};
|
|
61
75
|
}
|
|
76
|
+
|
|
77
|
+
/** Fetches MessageSent events within the given block range. */
|
|
78
|
+
async getMessageSentEvents(fromBlock: bigint, toBlock: bigint): Promise<MessageSentLog[]> {
|
|
79
|
+
const logs = await this.inbox.getEvents.MessageSent({}, { fromBlock, toBlock });
|
|
80
|
+
return logs
|
|
81
|
+
.filter(log => log.blockNumber! >= fromBlock && log.blockNumber! <= toBlock)
|
|
82
|
+
.map(log => this.mapMessageSentLog(log));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Fetches MessageSent events for a specific message hash within the given block range. */
|
|
86
|
+
async getMessageSentEventByHash(hash: Hex, fromBlock: bigint, toBlock: bigint): Promise<MessageSentLog[]> {
|
|
87
|
+
const logs = await this.inbox.getEvents.MessageSent({ hash }, { fromBlock, toBlock });
|
|
88
|
+
return logs.map(log => this.mapMessageSentLog(log));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private mapMessageSentLog(log: {
|
|
92
|
+
blockNumber: bigint | null;
|
|
93
|
+
blockHash: `0x${string}` | null;
|
|
94
|
+
transactionHash: `0x${string}` | null;
|
|
95
|
+
args: { index?: bigint; hash?: `0x${string}`; checkpointNumber?: bigint; rollingHash?: `0x${string}` };
|
|
96
|
+
}): MessageSentLog {
|
|
97
|
+
return {
|
|
98
|
+
l1BlockNumber: log.blockNumber!,
|
|
99
|
+
l1BlockHash: Buffer32.fromString(log.blockHash!),
|
|
100
|
+
l1TransactionHash: log.transactionHash!,
|
|
101
|
+
args: {
|
|
102
|
+
index: log.args.index!,
|
|
103
|
+
leaf: Fr.fromString(log.args.hash!),
|
|
104
|
+
checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
|
|
105
|
+
rollingHash: Buffer16.fromString(log.args.rollingHash!),
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
62
109
|
}
|
|
63
110
|
|
|
64
111
|
export type InboxContractState = {
|
package/src/contracts/index.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
|
|
3
|
+
/** Base L1 event log with common fields. */
|
|
4
|
+
export type L1EventLog<T> = {
|
|
5
|
+
/** L1 block number where the event was emitted. */
|
|
6
|
+
l1BlockNumber: bigint;
|
|
7
|
+
/** L1 block hash. */
|
|
8
|
+
l1BlockHash: Buffer32;
|
|
9
|
+
/** L1 transaction hash that emitted the event. */
|
|
10
|
+
l1TransactionHash: `0x${string}`;
|
|
11
|
+
/** Event-specific arguments. */
|
|
12
|
+
args: T;
|
|
13
|
+
};
|
|
@@ -34,10 +34,13 @@ export class Multicall3 {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
const encodedForwarderData = encodeFunctionData(forwarderFunctionData);
|
|
37
|
-
|
|
38
37
|
try {
|
|
39
38
|
const { receipt, state } = await l1TxUtils.sendAndMonitorTransaction(
|
|
40
|
-
{
|
|
39
|
+
{
|
|
40
|
+
to: MULTI_CALL_3_ADDRESS,
|
|
41
|
+
data: encodedForwarderData,
|
|
42
|
+
abi: multicall3Abi,
|
|
43
|
+
},
|
|
41
44
|
gasConfig,
|
|
42
45
|
blobConfig,
|
|
43
46
|
);
|
package/src/contracts/rollup.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { memoize } from '@aztec/foundation/decorators';
|
|
|
5
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
6
|
import type { ViemSignature } from '@aztec/foundation/eth-signature';
|
|
7
7
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
8
|
+
import { EscapeHatchAbi } from '@aztec/l1-artifacts/EscapeHatchAbi';
|
|
8
9
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
9
10
|
import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage';
|
|
10
11
|
|
|
@@ -30,6 +31,7 @@ import type { ViemClient } from '../types.js';
|
|
|
30
31
|
import { formatViemError } from '../utils.js';
|
|
31
32
|
import { EmpireSlashingProposerContract } from './empire_slashing_proposer.js';
|
|
32
33
|
import { GSEContract } from './gse.js';
|
|
34
|
+
import type { L1EventLog } from './log.js';
|
|
33
35
|
import { SlasherContract } from './slasher_contract.js';
|
|
34
36
|
import { TallySlashingProposerContract } from './tally_slashing_proposer.js';
|
|
35
37
|
import { checkBlockTag } from './utils.js';
|
|
@@ -69,6 +71,7 @@ export type ViemHeader = {
|
|
|
69
71
|
blockHeadersHash: `0x${string}`;
|
|
70
72
|
blobsHash: `0x${string}`;
|
|
71
73
|
inHash: `0x${string}`;
|
|
74
|
+
outHash: `0x${string}`;
|
|
72
75
|
slotNumber: bigint;
|
|
73
76
|
timestamp: bigint;
|
|
74
77
|
coinbase: `0x${string}`;
|
|
@@ -105,7 +108,7 @@ export enum AttesterStatus {
|
|
|
105
108
|
export type FeeHeader = {
|
|
106
109
|
excessMana: bigint;
|
|
107
110
|
manaUsed: bigint;
|
|
108
|
-
|
|
111
|
+
ethPerFeeAsset: bigint;
|
|
109
112
|
congestionCost: bigint;
|
|
110
113
|
proverCost: bigint;
|
|
111
114
|
};
|
|
@@ -185,10 +188,28 @@ export type RollupStatusResponse = {
|
|
|
185
188
|
archiveOfMyCheckpoint: Fr;
|
|
186
189
|
};
|
|
187
190
|
|
|
191
|
+
/** Arguments for the CheckpointProposed event. */
|
|
192
|
+
export type CheckpointProposedArgs = {
|
|
193
|
+
checkpointNumber: CheckpointNumber;
|
|
194
|
+
archive: Fr;
|
|
195
|
+
versionedBlobHashes: Buffer[];
|
|
196
|
+
/** Hash of attestations. Undefined for older events (backwards compatibility). */
|
|
197
|
+
attestationsHash?: Buffer32;
|
|
198
|
+
/** Digest of the payload. Undefined for older events (backwards compatibility). */
|
|
199
|
+
payloadDigest?: Buffer32;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/** Log type for CheckpointProposed events. */
|
|
203
|
+
export type CheckpointProposedLog = L1EventLog<CheckpointProposedArgs>;
|
|
204
|
+
|
|
188
205
|
export class RollupContract {
|
|
189
206
|
private readonly rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
|
|
190
207
|
|
|
191
208
|
private static cachedStfStorageSlot: Hex | undefined;
|
|
209
|
+
private cachedEscapeHatch?: {
|
|
210
|
+
address: EthAddress;
|
|
211
|
+
contract: GetContractReturnType<typeof EscapeHatchAbi, ViemClient>;
|
|
212
|
+
};
|
|
192
213
|
|
|
193
214
|
static get checkBlobStorageSlot(): bigint {
|
|
194
215
|
const asString = RollupStorage.find(storage => storage.label === 'checkBlob')?.slot;
|
|
@@ -370,20 +391,24 @@ export class RollupContract {
|
|
|
370
391
|
slotDuration: number;
|
|
371
392
|
epochDuration: number;
|
|
372
393
|
proofSubmissionEpochs: number;
|
|
394
|
+
targetCommitteeSize: number;
|
|
373
395
|
}> {
|
|
374
|
-
const [l1StartBlock, l1GenesisTime, slotDuration, epochDuration, proofSubmissionEpochs] =
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
396
|
+
const [l1StartBlock, l1GenesisTime, slotDuration, epochDuration, proofSubmissionEpochs, targetCommitteeSize] =
|
|
397
|
+
await Promise.all([
|
|
398
|
+
this.getL1StartBlock(),
|
|
399
|
+
this.getL1GenesisTime(),
|
|
400
|
+
this.getSlotDuration(),
|
|
401
|
+
this.getEpochDuration(),
|
|
402
|
+
this.getProofSubmissionEpochs(),
|
|
403
|
+
this.getTargetCommitteeSize(),
|
|
404
|
+
]);
|
|
381
405
|
return {
|
|
382
406
|
l1StartBlock,
|
|
383
407
|
l1GenesisTime,
|
|
384
408
|
slotDuration,
|
|
385
409
|
epochDuration: Number(epochDuration),
|
|
386
410
|
proofSubmissionEpochs: Number(proofSubmissionEpochs),
|
|
411
|
+
targetCommitteeSize,
|
|
387
412
|
};
|
|
388
413
|
}
|
|
389
414
|
|
|
@@ -391,6 +416,58 @@ export class RollupContract {
|
|
|
391
416
|
return EthAddress.fromString(await this.rollup.read.getSlasher());
|
|
392
417
|
}
|
|
393
418
|
|
|
419
|
+
/**
|
|
420
|
+
* Returns the configured escape hatch contract address, or zero if disabled.
|
|
421
|
+
*/
|
|
422
|
+
async getEscapeHatchAddress(): Promise<EthAddress> {
|
|
423
|
+
return EthAddress.fromString(await this.rollup.read.getEscapeHatch());
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
private async getEscapeHatchContract(): Promise<
|
|
427
|
+
GetContractReturnType<typeof EscapeHatchAbi, ViemClient> | undefined
|
|
428
|
+
> {
|
|
429
|
+
const escapeHatchAddress = await this.getEscapeHatchAddress();
|
|
430
|
+
if (escapeHatchAddress.isZero()) {
|
|
431
|
+
return undefined;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// Cache the viem contract wrapper since it will be used frequently.
|
|
435
|
+
if (!this.cachedEscapeHatch || !this.cachedEscapeHatch.address.equals(escapeHatchAddress)) {
|
|
436
|
+
this.cachedEscapeHatch = {
|
|
437
|
+
address: escapeHatchAddress,
|
|
438
|
+
contract: getContract({
|
|
439
|
+
address: escapeHatchAddress.toString(),
|
|
440
|
+
abi: EscapeHatchAbi,
|
|
441
|
+
client: this.client,
|
|
442
|
+
}),
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return this.cachedEscapeHatch.contract;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Returns whether the escape hatch is open for the given epoch.
|
|
451
|
+
* If escape hatch is not configured, returns false.
|
|
452
|
+
*
|
|
453
|
+
* This function is intentionally defensive: any failure to query the escape hatch
|
|
454
|
+
* (RPC issues, transient errors, etc.) is treated as "closed" to avoid callers
|
|
455
|
+
* needing to sprinkle try/catch everywhere.
|
|
456
|
+
*/
|
|
457
|
+
async isEscapeHatchOpen(epoch: EpochNumber): Promise<boolean> {
|
|
458
|
+
try {
|
|
459
|
+
const escapeHatch = await this.getEscapeHatchContract();
|
|
460
|
+
if (!escapeHatch) {
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
const [isOpen] = await escapeHatch.read.isHatchOpen([BigInt(epoch)]);
|
|
465
|
+
return isOpen;
|
|
466
|
+
} catch {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
394
471
|
/**
|
|
395
472
|
* Returns a SlasherContract instance for interacting with the slasher contract.
|
|
396
473
|
*/
|
|
@@ -442,8 +519,8 @@ export class RollupContract {
|
|
|
442
519
|
};
|
|
443
520
|
}
|
|
444
521
|
|
|
445
|
-
|
|
446
|
-
return this.rollup.read.
|
|
522
|
+
getEthPerFeeAsset(): Promise<bigint> {
|
|
523
|
+
return this.rollup.read.getEthPerFeeAsset();
|
|
447
524
|
}
|
|
448
525
|
|
|
449
526
|
async getCommitteeAt(timestamp: bigint): Promise<EthAddress[] | undefined> {
|
|
@@ -528,7 +605,7 @@ export class RollupContract {
|
|
|
528
605
|
feeHeader: {
|
|
529
606
|
excessMana: result.feeHeader.excessMana,
|
|
530
607
|
manaUsed: result.feeHeader.manaUsed,
|
|
531
|
-
|
|
608
|
+
ethPerFeeAsset: result.feeHeader.ethPerFeeAsset,
|
|
532
609
|
congestionCost: result.feeHeader.congestionCost,
|
|
533
610
|
proverCost: result.feeHeader.proverCost,
|
|
534
611
|
},
|
|
@@ -732,6 +809,7 @@ export class RollupContract {
|
|
|
732
809
|
): L1TxRequest {
|
|
733
810
|
return {
|
|
734
811
|
to: this.address,
|
|
812
|
+
abi: RollupAbi,
|
|
735
813
|
data: encodeFunctionData({
|
|
736
814
|
abi: RollupAbi,
|
|
737
815
|
functionName: 'invalidateBadAttestation',
|
|
@@ -753,6 +831,7 @@ export class RollupContract {
|
|
|
753
831
|
): L1TxRequest {
|
|
754
832
|
return {
|
|
755
833
|
to: this.address,
|
|
834
|
+
abi: RollupAbi,
|
|
756
835
|
data: encodeFunctionData({
|
|
757
836
|
abi: RollupAbi,
|
|
758
837
|
functionName: 'invalidateInsufficientAttestations',
|
|
@@ -886,6 +965,7 @@ export class RollupContract {
|
|
|
886
965
|
setupEpoch(l1TxUtils: L1TxUtils) {
|
|
887
966
|
return l1TxUtils.sendAndMonitorTransaction({
|
|
888
967
|
to: this.address,
|
|
968
|
+
abi: RollupAbi,
|
|
889
969
|
data: encodeFunctionData({
|
|
890
970
|
abi: RollupAbi,
|
|
891
971
|
functionName: 'setupEpoch',
|
|
@@ -897,6 +977,7 @@ export class RollupContract {
|
|
|
897
977
|
vote(l1TxUtils: L1TxUtils, proposalId: bigint) {
|
|
898
978
|
return l1TxUtils.sendAndMonitorTransaction({
|
|
899
979
|
to: this.address,
|
|
980
|
+
abi: RollupAbi,
|
|
900
981
|
data: encodeFunctionData({
|
|
901
982
|
abi: RollupAbi,
|
|
902
983
|
functionName: 'vote',
|
|
@@ -965,4 +1046,23 @@ export class RollupContract {
|
|
|
965
1046
|
},
|
|
966
1047
|
);
|
|
967
1048
|
}
|
|
1049
|
+
|
|
1050
|
+
/** Fetches CheckpointProposed events within the given block range. */
|
|
1051
|
+
async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
|
|
1052
|
+
const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
|
|
1053
|
+
return logs
|
|
1054
|
+
.filter(log => log.blockNumber! >= fromBlock && log.blockNumber! <= toBlock)
|
|
1055
|
+
.map(log => ({
|
|
1056
|
+
l1BlockNumber: log.blockNumber!,
|
|
1057
|
+
l1BlockHash: Buffer32.fromString(log.blockHash!),
|
|
1058
|
+
l1TransactionHash: log.transactionHash!,
|
|
1059
|
+
args: {
|
|
1060
|
+
checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
|
|
1061
|
+
archive: Fr.fromString(log.args.archive!),
|
|
1062
|
+
versionedBlobHashes: log.args.versionedBlobHashes!.map(h => Buffer.from(h.slice(2), 'hex')),
|
|
1063
|
+
attestationsHash: log.args.attestationsHash ? Buffer32.fromString(log.args.attestationsHash) : undefined,
|
|
1064
|
+
payloadDigest: log.args.payloadDigest ? Buffer32.fromString(log.args.payloadDigest) : undefined,
|
|
1065
|
+
},
|
|
1066
|
+
}));
|
|
1067
|
+
}
|
|
968
1068
|
}
|