@aztec/ethereum 0.0.1-commit.b2a5d0dd1 → 0.0.1-commit.b3d3157a
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/client.d.ts +11 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +35 -3
- package/dest/contracts/chain_state_override.d.ts +47 -7
- package/dest/contracts/chain_state_override.d.ts.map +1 -1
- package/dest/contracts/chain_state_override.js +57 -20
- package/dest/contracts/empire_base.d.ts +1 -3
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/fee_asset_price_oracle.d.ts +6 -2
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -1
- package/dest/contracts/fee_asset_price_oracle.js +11 -6
- package/dest/contracts/governance.d.ts +108 -33
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +193 -12
- package/dest/contracts/governance_proposer.d.ts +33 -3
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +51 -9
- package/dest/contracts/inbox.js +1 -1
- package/dest/contracts/multicall.d.ts +79 -13
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +117 -95
- package/dest/contracts/outbox.d.ts +27 -4
- package/dest/contracts/outbox.d.ts.map +1 -1
- package/dest/contracts/outbox.js +34 -7
- package/dest/contracts/rollup.d.ts +327 -57
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +102 -40
- package/dest/l1_artifacts.d.ts +5108 -155
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_contract_addresses.d.ts +61 -61
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +101 -76
- package/dest/l1_reader.d.ts +3 -5
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +3 -6
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +7 -1
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +21 -10
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +2 -1
- package/dest/l1_tx_utils/tx_delayer.d.ts +5 -3
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -1
- package/dest/l1_tx_utils/tx_delayer.js +7 -5
- package/dest/test/eth_cheat_codes.d.ts +7 -1
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +11 -0
- package/dest/test/rollup_cheat_codes.d.ts +27 -3
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +50 -6
- package/dest/utils.d.ts +9 -2
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +34 -6
- package/package.json +6 -6
- package/src/client.ts +39 -1
- package/src/contracts/chain_state_override.ts +77 -24
- package/src/contracts/empire_base.ts +0 -2
- package/src/contracts/fee_asset_price_oracle.ts +10 -5
- package/src/contracts/governance.ts +266 -9
- package/src/contracts/governance_proposer.ts +52 -5
- package/src/contracts/inbox.ts +1 -1
- package/src/contracts/multicall.ts +179 -105
- package/src/contracts/outbox.ts +42 -8
- package/src/contracts/rollup.ts +124 -42
- package/src/l1_contract_addresses.ts +120 -87
- package/src/l1_reader.ts +4 -9
- package/src/l1_tx_utils/l1_tx_utils.ts +27 -14
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +2 -1
- package/src/l1_tx_utils/tx_delayer.ts +16 -7
- package/src/test/eth_cheat_codes.ts +10 -0
- package/src/test/rollup_cheat_codes.ts +53 -5
- package/src/utils.ts +30 -6
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { FormattedViemError, formatViemError } from '../utils.js';
|
|
5
|
-
import { RollupContract } from './rollup.js';
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import { decodeFunctionResult, encodeFunctionData, multicall3Abi } from 'viem';
|
|
3
|
+
import { tryDecodeRevertReason } from '../utils.js';
|
|
6
4
|
export const MULTI_CALL_3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11';
|
|
5
|
+
/**
|
|
6
|
+
* Thrown by `Multicall3.forward` when the forwarder transaction lands but the receipt reports a
|
|
7
|
+
* reverted status. This is not expected (aggregate3 uses allowFailure: true), so callers should
|
|
8
|
+
* treat it as a fatal on-chain failure rather than retrying on a different publisher.
|
|
9
|
+
*/ export class MulticallForwarderRevertedError extends Error {
|
|
10
|
+
receipt;
|
|
11
|
+
constructor(receipt){
|
|
12
|
+
super(`Multicall3 forwarder tx reverted: ${receipt.transactionHash}`), this.receipt = receipt;
|
|
13
|
+
this.name = 'MulticallForwarderRevertedError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
7
16
|
/** ABI fragment for aggregate3Value — not included in viem's multicall3Abi. */ export const aggregate3ValueAbi = [
|
|
8
17
|
{
|
|
9
18
|
inputs: [
|
|
@@ -60,105 +69,118 @@ export const MULTI_CALL_3_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11'
|
|
|
60
69
|
}
|
|
61
70
|
];
|
|
62
71
|
export class Multicall3 {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Returns true iff Multicall3 bytecode is deployed at MULTI_CALL_3_ADDRESS. An empty result from
|
|
74
|
+
* a non-existent contract would otherwise silently validate any bundle that uses Multicall3.
|
|
75
|
+
*/ static async hasCode(l1TxUtils) {
|
|
76
|
+
const code = await l1TxUtils.getCode(EthAddress.fromString(MULTI_CALL_3_ADDRESS));
|
|
77
|
+
return !!code && code !== '0x';
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Simulates an aggregate3 call composed of the given requests via eth_simulateV1 and decodes the
|
|
81
|
+
* per-entry Result[]. Entries that revert are returned with a decoded revertReason (if the request
|
|
82
|
+
* provided an abi).
|
|
83
|
+
*
|
|
84
|
+
* Use this to pre-validate a bundle before sending it through `Multicall3.forward`. The caller can
|
|
85
|
+
* drop reverted entries from the bundle and re-simulate with the reduced list to get an accurate
|
|
86
|
+
* `gasUsed`.
|
|
87
|
+
*/ static async simulateAggregate3(requests, l1TxUtils, opts = {}) {
|
|
88
|
+
const calldata = encodeFunctionData({
|
|
89
|
+
abi: multicall3Abi,
|
|
90
|
+
functionName: 'aggregate3',
|
|
91
|
+
args: [
|
|
92
|
+
requests.map((r)=>({
|
|
93
|
+
target: r.to,
|
|
94
|
+
callData: r.data,
|
|
95
|
+
allowFailure: true
|
|
96
|
+
}))
|
|
97
|
+
]
|
|
98
|
+
});
|
|
99
|
+
const stateOverrides = [
|
|
100
|
+
...opts.stateOverrides ?? []
|
|
101
|
+
];
|
|
102
|
+
if (opts.fakeSenderBalance !== undefined) {
|
|
103
|
+
stateOverrides.push({
|
|
104
|
+
address: l1TxUtils.getSenderAddress().toString(),
|
|
105
|
+
balance: opts.fakeSenderBalance
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const simResult = await l1TxUtils.simulate({
|
|
109
|
+
to: MULTI_CALL_3_ADDRESS,
|
|
110
|
+
data: calldata,
|
|
111
|
+
gas: opts.gas
|
|
112
|
+
}, opts.blockOverrides, stateOverrides, multicall3Abi, {
|
|
113
|
+
fallbackGasEstimate: opts.fallbackGasEstimate
|
|
114
|
+
});
|
|
115
|
+
if (simResult.result === '0x') {
|
|
116
|
+
return {
|
|
117
|
+
kind: 'fallback',
|
|
118
|
+
gasUsed: simResult.gasUsed
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const decoded = decodeFunctionResult({
|
|
122
|
+
abi: multicall3Abi,
|
|
123
|
+
functionName: 'aggregate3',
|
|
124
|
+
data: simResult.result
|
|
125
|
+
});
|
|
126
|
+
const entries = decoded.map((entry, i)=>{
|
|
127
|
+
if (entry.success) {
|
|
128
|
+
return {
|
|
129
|
+
success: true,
|
|
130
|
+
returnData: entry.returnData
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const abi = requests[i].abi;
|
|
134
|
+
const revertReason = abi ? tryDecodeRevertReason(entry.returnData, abi) : undefined;
|
|
135
|
+
return {
|
|
136
|
+
success: false,
|
|
137
|
+
returnData: entry.returnData,
|
|
138
|
+
revertReason
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
return {
|
|
142
|
+
kind: 'decoded',
|
|
143
|
+
entries,
|
|
144
|
+
gasUsed: simResult.gasUsed
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Sends a batch of requests through aggregate3. Individual calls may fail (allowFailure: true),
|
|
149
|
+
* but the top-level multicall is expected to land successfully. Throws if the send fails or if
|
|
150
|
+
* the receipt reports a reverted status.
|
|
151
|
+
*/ static async forward(requests, l1TxUtils, gasConfig, blobConfig, opts = {}) {
|
|
152
|
+
if (opts.gasLimitRequired && !gasConfig?.gasLimit) {
|
|
153
|
+
throw new Error('Multicall gasLimit is required when gasLimitRequired is true');
|
|
154
|
+
}
|
|
155
|
+
const args = requests.filter((request)=>request.to !== null).map((r)=>({
|
|
66
156
|
target: r.to,
|
|
67
157
|
callData: r.data,
|
|
68
|
-
allowFailure:
|
|
158
|
+
allowFailure: true
|
|
69
159
|
}));
|
|
70
|
-
const
|
|
160
|
+
const encodedForwarderData = encodeFunctionData({
|
|
71
161
|
abi: multicall3Abi,
|
|
72
162
|
functionName: 'aggregate3',
|
|
73
163
|
args: [
|
|
74
164
|
args
|
|
75
165
|
]
|
|
76
|
-
};
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
receipt,
|
|
88
|
-
stats
|
|
89
|
-
};
|
|
90
|
-
} else {
|
|
91
|
-
logger.error('Forwarder transaction failed', undefined, {
|
|
92
|
-
receipt
|
|
93
|
-
});
|
|
94
|
-
const args = {
|
|
95
|
-
...forwarderFunctionData,
|
|
96
|
-
address: MULTI_CALL_3_ADDRESS
|
|
97
|
-
};
|
|
98
|
-
let errorMsg;
|
|
99
|
-
if (blobConfig) {
|
|
100
|
-
const maxFeePerBlobGas = blobConfig.maxFeePerBlobGas ?? state.gasPrice.maxFeePerBlobGas;
|
|
101
|
-
if (maxFeePerBlobGas === undefined) {
|
|
102
|
-
errorMsg = 'maxFeePerBlobGas is required to get the error message';
|
|
103
|
-
} else {
|
|
104
|
-
logger.debug('Trying to get error from reverted tx with blob config');
|
|
105
|
-
errorMsg = await l1TxUtils.tryGetErrorFromRevertedTx(encodedForwarderData, args, {
|
|
106
|
-
blobs: blobConfig.blobs,
|
|
107
|
-
kzg: blobConfig.kzg,
|
|
108
|
-
maxFeePerBlobGas
|
|
109
|
-
}, [
|
|
110
|
-
{
|
|
111
|
-
address: rollupAddress,
|
|
112
|
-
stateDiff: [
|
|
113
|
-
{
|
|
114
|
-
slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
|
|
115
|
-
value: toPaddedHex(0n, true)
|
|
116
|
-
}
|
|
117
|
-
]
|
|
118
|
-
}
|
|
119
|
-
]);
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
logger.debug('Trying to get error from reverted tx without blob config');
|
|
123
|
-
errorMsg = await l1TxUtils.tryGetErrorFromRevertedTx(encodedForwarderData, args, undefined, []);
|
|
124
|
-
}
|
|
125
|
-
return {
|
|
126
|
-
receipt,
|
|
127
|
-
errorMsg
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
} catch (err) {
|
|
131
|
-
if (err instanceof TimeoutError) {
|
|
132
|
-
throw err;
|
|
133
|
-
}
|
|
134
|
-
for (const request of requests){
|
|
135
|
-
logger.debug('Simulating request', {
|
|
136
|
-
request
|
|
137
|
-
});
|
|
138
|
-
const result = await l1TxUtils.simulate(request, undefined, [
|
|
139
|
-
{
|
|
140
|
-
address: rollupAddress,
|
|
141
|
-
stateDiff: [
|
|
142
|
-
{
|
|
143
|
-
slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
|
|
144
|
-
value: toPaddedHex(0n, true)
|
|
145
|
-
}
|
|
146
|
-
]
|
|
147
|
-
}
|
|
148
|
-
]).catch((err)=>formatViemError(err, request.abi));
|
|
149
|
-
if (result instanceof FormattedViemError) {
|
|
150
|
-
logger.error('Found error in simulation', result, {
|
|
151
|
-
to: request.to ?? 'null',
|
|
152
|
-
data: request.data
|
|
153
|
-
});
|
|
154
|
-
return result;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
logger.warn('Failed to get error from reverted tx', {
|
|
158
|
-
err
|
|
159
|
-
});
|
|
160
|
-
throw err;
|
|
166
|
+
});
|
|
167
|
+
const { receipt } = await l1TxUtils.sendAndMonitorTransaction({
|
|
168
|
+
to: MULTI_CALL_3_ADDRESS,
|
|
169
|
+
data: encodedForwarderData,
|
|
170
|
+
abi: multicall3Abi
|
|
171
|
+
}, gasConfig, blobConfig);
|
|
172
|
+
// This shouldn't happen. Any failure in individual calls is swallowed by forward since we set
|
|
173
|
+
// allowFailure to true for all calls, so a reverted status here would indicate a problem with
|
|
174
|
+
// the Multicall3 contract itself or the forwarder transaction (such as an out-of-gas).
|
|
175
|
+
if (receipt.status !== 'success') {
|
|
176
|
+
throw new MulticallForwarderRevertedError(receipt);
|
|
161
177
|
}
|
|
178
|
+
const stats = await l1TxUtils.getTransactionStats(receipt.transactionHash);
|
|
179
|
+
return {
|
|
180
|
+
receipt,
|
|
181
|
+
stats,
|
|
182
|
+
multicallData: encodedForwarderData
|
|
183
|
+
};
|
|
162
184
|
}
|
|
163
185
|
/** Batch multiple value transfers into a single aggregate3Value call on Multicall3. */ static async forwardValue(calls, l1TxUtils, logger) {
|
|
164
186
|
const args = calls.map((c)=>({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { EpochNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
4
|
import { OutboxAbi } from '@aztec/l1-artifacts/OutboxAbi';
|
|
4
5
|
import { type GetContractReturnType, type Hex } from 'viem';
|
|
@@ -23,19 +24,41 @@ export declare class OutboxContract {
|
|
|
23
24
|
private readonly outbox;
|
|
24
25
|
static getFromL1ContractsValues(deployL1ContractsValues: DeployAztecL1ContractsReturnType): OutboxContract;
|
|
25
26
|
static getFromConfig(config: L1ReaderConfig): OutboxContract;
|
|
26
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Storage slot of `epochs[epoch].roots[numCheckpointsInEpoch - 1]` in the Outbox contract.
|
|
29
|
+
*
|
|
30
|
+
* The Outbox lays out storage as `mapping(Epoch => EpochData) internal epochs` at base slot 0
|
|
31
|
+
* (ROLLUP and VERSION are immutable and do not occupy slots). For a mapping at slot `b`, the
|
|
32
|
+
* value for key `k` begins at `keccak256(abi.encode(k, b))`. `EpochData` starts with a fixed-
|
|
33
|
+
* size `bytes32[MAX_CHECKPOINTS_PER_EPOCH] roots` array, so `roots[i]` sits at the EpochData's
|
|
34
|
+
* base slot plus `i`. `numCheckpointsInEpoch` is 1-indexed (matches `Outbox.insert`/`consume`).
|
|
35
|
+
*/
|
|
36
|
+
static getEpochRootStorageSlot(epoch: EpochNumber, numCheckpointsInEpoch: number): bigint;
|
|
27
37
|
constructor(client: ViemClient, address: Hex | EthAddress);
|
|
28
38
|
get address(): `0x${string}`;
|
|
29
39
|
getContract(): GetContractReturnType<typeof OutboxAbi, ViemClient>;
|
|
30
40
|
hasMessageBeenConsumedAtEpoch(epoch: EpochNumber, leafId: bigint): Promise<boolean>;
|
|
31
|
-
getRootData(epoch: EpochNumber): Promise<`0x${string}`>;
|
|
32
|
-
|
|
41
|
+
getRootData(epoch: EpochNumber, numCheckpointsInEpoch: number): Promise<`0x${string}`>;
|
|
42
|
+
/**
|
|
43
|
+
* Returns every root stored for `epoch`. Slot `i` of the returned array holds the root inserted
|
|
44
|
+
* for `numCheckpointsInEpoch = i + 1`, or `Fr.ZERO` if no proof of that depth has been inserted
|
|
45
|
+
* yet. The array length is always `MAX_CHECKPOINTS_PER_EPOCH`.
|
|
46
|
+
*
|
|
47
|
+
* @param opts - Optional viem read options. Pass `blockNumber` to pin the read to a specific L1
|
|
48
|
+
* block, which is important for callers that want a consistent snapshot across multiple reads
|
|
49
|
+
* (e.g. the archiver's outbox-trees resolver, which pins to the node's synced L1 block).
|
|
50
|
+
*/
|
|
51
|
+
getRoots(epoch: EpochNumber, opts?: {
|
|
52
|
+
blockNumber?: bigint;
|
|
53
|
+
}): Promise<Fr[]>;
|
|
54
|
+
consume(message: ViemL2ToL1Msg, epoch: EpochNumber, numCheckpointsInEpoch: number, leafIndex: bigint, path: Hex[]): Promise<`0x${string}`>;
|
|
33
55
|
getMessageConsumedEvents(l1BlockHash: Hex): Promise<{
|
|
34
56
|
epoch: bigint;
|
|
35
57
|
root: Hex;
|
|
36
58
|
messageHash: Hex;
|
|
37
59
|
leafId: bigint;
|
|
60
|
+
numCheckpointsInEpoch: bigint;
|
|
38
61
|
}[]>;
|
|
39
62
|
private assertWallet;
|
|
40
63
|
}
|
|
41
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
64
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0Ym94LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29udHJhY3RzL291dGJveC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUNuRSxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDcEQsT0FBTyxFQUFFLFVBQV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c7SUFFRCxPQUFPLENBQUMsWUFBWTtDQU1yQiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../../src/contracts/outbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,GAAG,EAA4D,MAAM,MAAM,CAAC;AAGtH,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,iCAAiC,CAAC;AACxF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAiC,KAAK,UAAU,EAAoB,MAAM,aAAa,CAAC;AAE/F,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,GAAG,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,GAAG,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,EAAE,WAAW,CAAC;IACvB,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF,qBAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../../src/contracts/outbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,OAAO,EAAE,KAA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E,WAAW,EAAE,IAAI,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,EAAE,EAAE,CAAC,CAGxF;IAEM,OAAO,CACZ,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,WAAW,EAClB,qBAAqB,EAAE,MAAM,EAC7B,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,GAAG,EAAE,0BAIZ;IAEY,wBAAwB,CACnC,WAAW,EAAE,GAAG,GACf,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAC;QAAC,WAAW,EAAE,GAAG,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,qBAAqB,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC,CAS1G;IAED,OAAO,CAAC,YAAY;CAMrB"}
|
package/dest/contracts/outbox.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
1
2
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
3
|
import { OutboxAbi } from '@aztec/l1-artifacts/OutboxAbi';
|
|
3
4
|
import { encodeAbiParameters, getContract, hexToBigInt, keccak256 } from 'viem';
|
|
@@ -12,11 +13,19 @@ export class OutboxContract {
|
|
|
12
13
|
}
|
|
13
14
|
static getFromConfig(config) {
|
|
14
15
|
const client = getPublicClient(config);
|
|
15
|
-
const address = config.
|
|
16
|
+
const address = config.outboxAddress.toString();
|
|
16
17
|
return new OutboxContract(client, address);
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Storage slot of `epochs[epoch].roots[numCheckpointsInEpoch - 1]` in the Outbox contract.
|
|
21
|
+
*
|
|
22
|
+
* The Outbox lays out storage as `mapping(Epoch => EpochData) internal epochs` at base slot 0
|
|
23
|
+
* (ROLLUP and VERSION are immutable and do not occupy slots). For a mapping at slot `b`, the
|
|
24
|
+
* value for key `k` begins at `keccak256(abi.encode(k, b))`. `EpochData` starts with a fixed-
|
|
25
|
+
* size `bytes32[MAX_CHECKPOINTS_PER_EPOCH] roots` array, so `roots[i]` sits at the EpochData's
|
|
26
|
+
* base slot plus `i`. `numCheckpointsInEpoch` is 1-indexed (matches `Outbox.insert`/`consume`).
|
|
27
|
+
*/ static getEpochRootStorageSlot(epoch, numCheckpointsInEpoch) {
|
|
28
|
+
const epochDataSlot = hexToBigInt(keccak256(encodeAbiParameters([
|
|
20
29
|
{
|
|
21
30
|
type: 'uint256'
|
|
22
31
|
},
|
|
@@ -27,6 +36,7 @@ export class OutboxContract {
|
|
|
27
36
|
BigInt(epoch),
|
|
28
37
|
0n
|
|
29
38
|
])));
|
|
39
|
+
return epochDataSlot + BigInt(numCheckpointsInEpoch - 1);
|
|
30
40
|
}
|
|
31
41
|
constructor(client, address){
|
|
32
42
|
this.client = client;
|
|
@@ -51,16 +61,32 @@ export class OutboxContract {
|
|
|
51
61
|
leafId
|
|
52
62
|
]);
|
|
53
63
|
}
|
|
54
|
-
getRootData(epoch) {
|
|
64
|
+
getRootData(epoch, numCheckpointsInEpoch) {
|
|
55
65
|
return this.outbox.read.getRootData([
|
|
56
|
-
BigInt(epoch)
|
|
66
|
+
BigInt(epoch),
|
|
67
|
+
BigInt(numCheckpointsInEpoch)
|
|
57
68
|
]);
|
|
58
69
|
}
|
|
59
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Returns every root stored for `epoch`. Slot `i` of the returned array holds the root inserted
|
|
72
|
+
* for `numCheckpointsInEpoch = i + 1`, or `Fr.ZERO` if no proof of that depth has been inserted
|
|
73
|
+
* yet. The array length is always `MAX_CHECKPOINTS_PER_EPOCH`.
|
|
74
|
+
*
|
|
75
|
+
* @param opts - Optional viem read options. Pass `blockNumber` to pin the read to a specific L1
|
|
76
|
+
* block, which is important for callers that want a consistent snapshot across multiple reads
|
|
77
|
+
* (e.g. the archiver's outbox-trees resolver, which pins to the node's synced L1 block).
|
|
78
|
+
*/ async getRoots(epoch, opts) {
|
|
79
|
+
const raw = await this.outbox.read.getRoots([
|
|
80
|
+
BigInt(epoch)
|
|
81
|
+
], opts);
|
|
82
|
+
return raw.map((hex)=>Fr.fromString(hex));
|
|
83
|
+
}
|
|
84
|
+
consume(message, epoch, numCheckpointsInEpoch, leafIndex, path) {
|
|
60
85
|
const wallet = this.assertWallet();
|
|
61
86
|
return wallet.write.consume([
|
|
62
87
|
message,
|
|
63
88
|
BigInt(epoch),
|
|
89
|
+
BigInt(numCheckpointsInEpoch),
|
|
64
90
|
leafIndex,
|
|
65
91
|
path
|
|
66
92
|
]);
|
|
@@ -74,7 +100,8 @@ export class OutboxContract {
|
|
|
74
100
|
epoch: event.args.epoch,
|
|
75
101
|
root: event.args.root,
|
|
76
102
|
messageHash: event.args.messageHash,
|
|
77
|
-
leafId: event.args.leafId
|
|
103
|
+
leafId: event.args.leafId,
|
|
104
|
+
numCheckpointsInEpoch: event.args.numCheckpointsInEpoch
|
|
78
105
|
}));
|
|
79
106
|
}
|
|
80
107
|
assertWallet() {
|