@aztec-labs/ethereum 6.0.0-nightly.20260829
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/README.md +3 -0
- package/dest/account.d.ts +2 -0
- package/dest/account.d.ts.map +1 -0
- package/dest/account.js +4 -0
- package/dest/chain.d.ts +25 -0
- package/dest/chain.d.ts.map +1 -0
- package/dest/chain.js +53 -0
- package/dest/client.d.ts +42 -0
- package/dest/client.d.ts.map +1 -0
- package/dest/client.js +104 -0
- package/dest/config.d.ts +103 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +233 -0
- package/dest/constants.d.ts +4 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -0
- package/dest/contracts/chain_state_override.d.ts +81 -0
- package/dest/contracts/chain_state_override.d.ts.map +1 -0
- package/dest/contracts/chain_state_override.js +139 -0
- package/dest/contracts/empire_base.d.ts +30 -0
- package/dest/contracts/empire_base.d.ts.map +1 -0
- package/dest/contracts/empire_base.js +84 -0
- package/dest/contracts/errors.d.ts +7 -0
- package/dest/contracts/errors.d.ts.map +1 -0
- package/dest/contracts/errors.js +12 -0
- package/dest/contracts/fee_asset_handler.d.ts +20 -0
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
- package/dest/contracts/fee_asset_handler.js +59 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
- package/dest/contracts/fee_asset_price_oracle.js +656 -0
- package/dest/contracts/fee_juice.d.ts +14 -0
- package/dest/contracts/fee_juice.d.ts.map +1 -0
- package/dest/contracts/fee_juice.js +59 -0
- package/dest/contracts/governance.d.ts +192 -0
- package/dest/contracts/governance.d.ts.map +1 -0
- package/dest/contracts/governance.js +471 -0
- package/dest/contracts/governance_proposer.d.ts +63 -0
- package/dest/contracts/governance_proposer.d.ts.map +1 -0
- package/dest/contracts/governance_proposer.js +536 -0
- package/dest/contracts/gse.d.ts +38 -0
- package/dest/contracts/gse.d.ts.map +1 -0
- package/dest/contracts/gse.js +81 -0
- package/dest/contracts/inbox.d.ts +94 -0
- package/dest/contracts/inbox.d.ts.map +1 -0
- package/dest/contracts/inbox.js +141 -0
- package/dest/contracts/index.d.ts +18 -0
- package/dest/contracts/index.d.ts.map +1 -0
- package/dest/contracts/index.js +17 -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 +138 -0
- package/dest/contracts/multicall.d.ts.map +1 -0
- package/dest/contracts/multicall.js +266 -0
- package/dest/contracts/outbox.d.ts +64 -0
- package/dest/contracts/outbox.d.ts.map +1 -0
- package/dest/contracts/outbox.js +113 -0
- package/dest/contracts/registry.d.ts +31 -0
- package/dest/contracts/registry.d.ts.map +1 -0
- package/dest/contracts/registry.js +142 -0
- package/dest/contracts/rollup.d.ts +5836 -0
- package/dest/contracts/rollup.d.ts.map +1 -0
- package/dest/contracts/rollup.js +1612 -0
- package/dest/contracts/slasher_contract.d.ts +44 -0
- package/dest/contracts/slasher_contract.d.ts.map +1 -0
- package/dest/contracts/slasher_contract.js +75 -0
- package/dest/contracts/slashing_proposer.d.ts +174 -0
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/slashing_proposer.js +755 -0
- package/dest/contracts/utils.d.ts +3 -0
- package/dest/contracts/utils.d.ts.map +1 -0
- package/dest/contracts/utils.js +11 -0
- package/dest/contracts/watch_event.d.ts +36 -0
- package/dest/contracts/watch_event.d.ts.map +1 -0
- package/dest/contracts/watch_event.js +66 -0
- package/dest/deploy_aztec_l1_contracts.d.ts +267 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +424 -0
- package/dest/deploy_l1_contract.d.ts +68 -0
- package/dest/deploy_l1_contract.d.ts.map +1 -0
- package/dest/deploy_l1_contract.js +312 -0
- package/dest/eth-signer/eth-signer.d.ts +21 -0
- package/dest/eth-signer/eth-signer.d.ts.map +1 -0
- package/dest/eth-signer/eth-signer.js +5 -0
- package/dest/eth-signer/index.d.ts +2 -0
- package/dest/eth-signer/index.d.ts.map +1 -0
- package/dest/eth-signer/index.js +1 -0
- package/dest/forwarder_proxy.d.ts +32 -0
- package/dest/forwarder_proxy.d.ts.map +1 -0
- package/dest/forwarder_proxy.js +93 -0
- package/dest/foundry_binary.d.ts +13 -0
- package/dest/foundry_binary.d.ts.map +1 -0
- package/dest/foundry_binary.js +52 -0
- package/dest/l1_artifacts.d.ts +81896 -0
- package/dest/l1_artifacts.d.ts.map +1 -0
- package/dest/l1_artifacts.js +151 -0
- package/dest/l1_contract_addresses.d.ts +73 -0
- package/dest/l1_contract_addresses.d.ts.map +1 -0
- package/dest/l1_contract_addresses.js +120 -0
- package/dest/l1_reader.d.ts +18 -0
- package/dest/l1_reader.d.ts.map +1 -0
- package/dest/l1_reader.js +35 -0
- package/dest/l1_tx_utils/config.d.ts +65 -0
- package/dest/l1_tx_utils/config.d.ts.map +1 -0
- package/dest/l1_tx_utils/config.js +109 -0
- package/dest/l1_tx_utils/constants.d.ts +12 -0
- package/dest/l1_tx_utils/constants.d.ts.map +1 -0
- package/dest/l1_tx_utils/constants.js +39 -0
- package/dest/l1_tx_utils/factory.d.ts +32 -0
- package/dest/l1_tx_utils/factory.d.ts.map +1 -0
- package/dest/l1_tx_utils/factory.js +22 -0
- package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
- package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
- package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
- package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
- package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
- package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
- package/dest/l1_tx_utils/index-blobs.js +2 -0
- package/dest/l1_tx_utils/index.d.ts +13 -0
- package/dest/l1_tx_utils/index.d.ts.map +1 -0
- package/dest/l1_tx_utils/index.js +13 -0
- package/dest/l1_tx_utils/interfaces.d.ts +76 -0
- package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
- package/dest/l1_tx_utils/interfaces.js +4 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +252 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.js +568 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +113 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_tx_utils.js +720 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +83 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +357 -0
- package/dest/l1_tx_utils/signer.d.ts +4 -0
- package/dest/l1_tx_utils/signer.d.ts.map +1 -0
- package/dest/l1_tx_utils/signer.js +16 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
- package/dest/l1_tx_utils/tx_delayer.js +223 -0
- package/dest/l1_tx_utils/types.d.ts +93 -0
- package/dest/l1_tx_utils/types.d.ts.map +1 -0
- package/dest/l1_tx_utils/types.js +36 -0
- package/dest/l1_tx_utils/utils.d.ts +4 -0
- package/dest/l1_tx_utils/utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/utils.js +14 -0
- package/dest/l1_types.d.ts +6 -0
- package/dest/l1_types.d.ts.map +1 -0
- package/dest/l1_types.js +1 -0
- package/dest/publisher_manager.d.ts +42 -0
- package/dest/publisher_manager.d.ts.map +1 -0
- package/dest/publisher_manager.js +199 -0
- package/dest/queries.d.ts +25 -0
- package/dest/queries.d.ts.map +1 -0
- package/dest/queries.js +144 -0
- package/dest/test/blob_kzg_warmup.d.ts +19 -0
- package/dest/test/blob_kzg_warmup.d.ts.map +1 -0
- package/dest/test/blob_kzg_warmup.js +64 -0
- package/dest/test/chain_monitor.d.ts +126 -0
- package/dest/test/chain_monitor.d.ts.map +1 -0
- package/dest/test/chain_monitor.js +314 -0
- package/dest/test/eth_cheat_codes.d.ts +260 -0
- package/dest/test/eth_cheat_codes.d.ts.map +1 -0
- package/dest/test/eth_cheat_codes.js +608 -0
- package/dest/test/eth_cheat_codes_with_state.d.ts +18 -0
- package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -0
- package/dest/test/eth_cheat_codes_with_state.js +34 -0
- package/dest/test/index.d.ts +8 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +7 -0
- package/dest/test/recording_rpc_server.d.ts +18 -0
- package/dest/test/recording_rpc_server.d.ts.map +1 -0
- package/dest/test/recording_rpc_server.js +68 -0
- package/dest/test/rollup_cheat_codes.d.ts +142 -0
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
- package/dest/test/rollup_cheat_codes.js +338 -0
- package/dest/test/start_anvil.d.ts +40 -0
- package/dest/test/start_anvil.d.ts.map +1 -0
- package/dest/test/start_anvil.js +210 -0
- package/dest/test/upgrade_utils.d.ts +12 -0
- package/dest/test/upgrade_utils.d.ts.map +1 -0
- package/dest/test/upgrade_utils.js +111 -0
- package/dest/types.d.ts +68 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +3 -0
- package/dest/utils.d.ts +45 -0
- package/dest/utils.d.ts.map +1 -0
- package/dest/utils.js +260 -0
- package/dest/zkPassportVerifierAddress.d.ts +15 -0
- package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
- package/dest/zkPassportVerifierAddress.js +11 -0
- package/package.json +122 -0
- package/src/account.ts +5 -0
- package/src/chain.ts +71 -0
- package/src/client.ts +165 -0
- package/src/config.ts +342 -0
- package/src/constants.ts +4 -0
- package/src/contracts/README.md +157 -0
- package/src/contracts/chain_state_override.ts +203 -0
- package/src/contracts/empire_base.ts +89 -0
- package/src/contracts/errors.ts +13 -0
- package/src/contracts/fee_asset_handler.ts +66 -0
- package/src/contracts/fee_asset_price_oracle.ts +284 -0
- package/src/contracts/fee_juice.ts +57 -0
- package/src/contracts/governance.ts +597 -0
- package/src/contracts/governance_proposer.ts +181 -0
- package/src/contracts/gse.ts +105 -0
- package/src/contracts/inbox.ts +223 -0
- package/src/contracts/index.ts +17 -0
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +298 -0
- package/src/contracts/outbox.ts +132 -0
- package/src/contracts/registry.ts +161 -0
- package/src/contracts/rollup.ts +1502 -0
- package/src/contracts/slasher_contract.ts +89 -0
- package/src/contracts/slashing_proposer.ts +397 -0
- package/src/contracts/utils.ts +14 -0
- package/src/contracts/watch_event.ts +109 -0
- package/src/deploy_aztec_l1_contracts.ts +663 -0
- package/src/deploy_l1_contract.ts +361 -0
- package/src/eth-signer/eth-signer.ts +24 -0
- package/src/eth-signer/index.ts +1 -0
- package/src/forwarder_proxy.ts +107 -0
- package/src/foundry_binary.ts +57 -0
- package/src/l1_artifacts.ts +231 -0
- package/src/l1_contract_addresses.ts +149 -0
- package/src/l1_reader.ts +57 -0
- package/src/l1_tx_utils/README.md +177 -0
- package/src/l1_tx_utils/config.ts +181 -0
- package/src/l1_tx_utils/constants.ts +29 -0
- package/src/l1_tx_utils/factory.ts +64 -0
- package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +162 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +244 -0
- package/src/l1_tx_utils/fee-strategies/types.ts +55 -0
- package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +107 -0
- package/src/l1_tx_utils/index-blobs.ts +2 -0
- package/src/l1_tx_utils/index.ts +15 -0
- package/src/l1_tx_utils/interfaces.ts +86 -0
- package/src/l1_tx_utils/l1_fee_analyzer.ts +874 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +840 -0
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +459 -0
- package/src/l1_tx_utils/signer.ts +27 -0
- package/src/l1_tx_utils/tx_delayer.ts +302 -0
- package/src/l1_tx_utils/types.ts +116 -0
- package/src/l1_tx_utils/utils.ts +15 -0
- package/src/l1_types.ts +6 -0
- package/src/publisher_manager.ts +239 -0
- package/src/queries.ts +189 -0
- package/src/test/blob_kzg_warmup.ts +65 -0
- package/src/test/chain_monitor.ts +389 -0
- package/src/test/eth_cheat_codes.ts +624 -0
- package/src/test/eth_cheat_codes_with_state.ts +38 -0
- package/src/test/index.ts +7 -0
- package/src/test/recording_rpc_server.ts +69 -0
- package/src/test/rollup_cheat_codes.ts +398 -0
- package/src/test/start_anvil.ts +255 -0
- package/src/test/upgrade_utils.ts +109 -0
- package/src/types.ts +97 -0
- package/src/utils.ts +344 -0
- package/src/zkPassportVerifierAddress.ts +15 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type Server, createServer } from 'node:http';
|
|
2
|
+
|
|
3
|
+
/** A JSON-RPC endpoint that records the method of every request it receives. */
|
|
4
|
+
export type RecordingRpcServer = {
|
|
5
|
+
/** URL the server listens on. */
|
|
6
|
+
url: string;
|
|
7
|
+
/** Methods of the JSON-RPC requests received so far, in arrival order. */
|
|
8
|
+
methods: string[];
|
|
9
|
+
/** Stops the server. */
|
|
10
|
+
close: () => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Starts a JSON-RPC server that records the method of every request it receives, so tests can assert on what a
|
|
15
|
+
* client actually put on the wire. Requests are forwarded to `forwardTo` when given; otherwise the server answers
|
|
16
|
+
* `eth_chainId` with the anvil chain id and rejects anything else.
|
|
17
|
+
*/
|
|
18
|
+
export async function startRecordingRpcServer(opts: { forwardTo?: string } = {}): Promise<RecordingRpcServer> {
|
|
19
|
+
const methods: string[] = [];
|
|
20
|
+
|
|
21
|
+
const server: Server = createServer((req, res) => {
|
|
22
|
+
const chunks: Buffer[] = [];
|
|
23
|
+
req.on('data', chunk => chunks.push(Buffer.from(chunk)));
|
|
24
|
+
req.on('end', () => {
|
|
25
|
+
void (async () => {
|
|
26
|
+
const body = Buffer.concat(chunks).toString();
|
|
27
|
+
const parsed: unknown = body.length > 0 ? JSON.parse(body) : undefined;
|
|
28
|
+
const requests = Array.isArray(parsed) ? parsed : [parsed];
|
|
29
|
+
for (const request of requests) {
|
|
30
|
+
const method = (request as { method?: string } | undefined)?.method;
|
|
31
|
+
if (typeof method === 'string') {
|
|
32
|
+
methods.push(method);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (opts.forwardTo) {
|
|
37
|
+
const response = await fetch(opts.forwardTo, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: { 'content-type': 'application/json' },
|
|
40
|
+
body,
|
|
41
|
+
});
|
|
42
|
+
res.writeHead(response.status, { 'content-type': 'application/json' });
|
|
43
|
+
res.end(await response.text());
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const id = (requests[0] as { id?: number } | undefined)?.id ?? 1;
|
|
48
|
+
const result =
|
|
49
|
+
methods[methods.length - 1] === 'eth_chainId'
|
|
50
|
+
? { jsonrpc: '2.0', id, result: '0x7a69' }
|
|
51
|
+
: { jsonrpc: '2.0', id, error: { code: -32601, message: 'method not handled by test server' } };
|
|
52
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
53
|
+
res.end(JSON.stringify(result));
|
|
54
|
+
})();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve));
|
|
59
|
+
const address = server.address();
|
|
60
|
+
if (!address || typeof address === 'string') {
|
|
61
|
+
throw new Error('Expected recording RPC server to listen on a TCP port');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
url: `http://127.0.0.1:${address.port}`,
|
|
66
|
+
methods,
|
|
67
|
+
close: () => new Promise<void>(resolve => server.close(() => resolve())),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
2
|
+
|
|
3
|
+
import { OutboxContract, RollupContract } from '@aztec-labs/ethereum/contracts';
|
|
4
|
+
import type { L1ContractAddresses } from '@aztec-labs/ethereum/l1-contract-addresses';
|
|
5
|
+
import type { ViemPublicClient } from '@aztec-labs/ethereum/types';
|
|
6
|
+
import { CheckpointNumber, EpochNumber, SlotNumber } from '@aztec-labs/foundation/branded-types';
|
|
7
|
+
import { EthAddress } from '@aztec-labs/foundation/eth-address';
|
|
8
|
+
import { createLogger } from '@aztec-labs/foundation/log';
|
|
9
|
+
import { retryUntil } from '@aztec-labs/foundation/retry';
|
|
10
|
+
import type { DateProvider } from '@aztec-labs/foundation/timer';
|
|
11
|
+
import {
|
|
12
|
+
type GetContractReturnType,
|
|
13
|
+
type Hex,
|
|
14
|
+
createPublicClient,
|
|
15
|
+
fallback,
|
|
16
|
+
getContract,
|
|
17
|
+
hexToBigInt,
|
|
18
|
+
http,
|
|
19
|
+
keccak256,
|
|
20
|
+
} from 'viem';
|
|
21
|
+
|
|
22
|
+
import { EthCheatCodes } from './eth_cheat_codes.js';
|
|
23
|
+
|
|
24
|
+
/** Cheat codes for the L1 rollup contract. */
|
|
25
|
+
export class RollupCheatCodes {
|
|
26
|
+
private client: ViemPublicClient;
|
|
27
|
+
private rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>;
|
|
28
|
+
|
|
29
|
+
private logger = createLogger('aztecjs:cheat_codes');
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
private ethCheatCodes: EthCheatCodes,
|
|
33
|
+
addresses: Pick<L1ContractAddresses, 'rollupAddress'>,
|
|
34
|
+
) {
|
|
35
|
+
this.client = createPublicClient({
|
|
36
|
+
chain: ethCheatCodes.chain,
|
|
37
|
+
transport: fallback(ethCheatCodes.rpcUrls.map(url => http(url, { batch: false }))),
|
|
38
|
+
});
|
|
39
|
+
this.rollup = getContract({
|
|
40
|
+
abi: RollupAbi,
|
|
41
|
+
address: addresses.rollupAddress.toString(),
|
|
42
|
+
client: this.client,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static create(
|
|
47
|
+
rpcUrls: string[],
|
|
48
|
+
addresses: Pick<L1ContractAddresses, 'rollupAddress'>,
|
|
49
|
+
dateProvider: DateProvider,
|
|
50
|
+
): RollupCheatCodes {
|
|
51
|
+
const ethCheatCodes = new EthCheatCodes(rpcUrls, dateProvider);
|
|
52
|
+
return new RollupCheatCodes(ethCheatCodes, addresses);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Returns the current slot */
|
|
56
|
+
public async getSlot(): Promise<SlotNumber> {
|
|
57
|
+
const ts = BigInt((await this.client.getBlock()).timestamp);
|
|
58
|
+
return this.getSlotAt(ts);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Returns the slot number at a given timestamp. */
|
|
62
|
+
public async getSlotAt(timestamp: bigint): Promise<SlotNumber> {
|
|
63
|
+
return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([timestamp]));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Returns the timestamp for the start of a given slot. */
|
|
67
|
+
public async getTimestampForSlot(slot: SlotNumber): Promise<bigint> {
|
|
68
|
+
return await this.rollup.read.getTimestampForSlot([BigInt(slot)]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Returns the number of seconds until the start of the given slot based on L1 block timestamp. */
|
|
72
|
+
public async getSecondsUntilSlot(slot: SlotNumber): Promise<number> {
|
|
73
|
+
const [currentTimestamp, targetTimestamp] = await Promise.all([
|
|
74
|
+
this.client.getBlock().then(b => BigInt(b.timestamp)),
|
|
75
|
+
this.rollup.read.getTimestampForSlot([BigInt(slot)]),
|
|
76
|
+
]);
|
|
77
|
+
return Math.max(0, Number(targetTimestamp - currentTimestamp));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Returns the current epoch */
|
|
81
|
+
public async getEpoch(): Promise<EpochNumber> {
|
|
82
|
+
const slotNumber = await this.getSlot();
|
|
83
|
+
return EpochNumber.fromBigInt(await this.rollup.read.getEpochAtSlot([BigInt(slotNumber)]));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Returns the pending and proven chain tips
|
|
88
|
+
* @returns The pending and proven chain tips
|
|
89
|
+
*/
|
|
90
|
+
public async getTips(): Promise<{
|
|
91
|
+
/** The pending chain tip */ pending: CheckpointNumber;
|
|
92
|
+
/** The proven chain tip */ proven: CheckpointNumber;
|
|
93
|
+
}> {
|
|
94
|
+
const { pending, proven } = await this.rollup.read.getTips();
|
|
95
|
+
return {
|
|
96
|
+
pending: CheckpointNumber.fromBigInt(pending),
|
|
97
|
+
proven: CheckpointNumber.fromBigInt(proven),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Logs the current state of the rollup contract.
|
|
103
|
+
*/
|
|
104
|
+
public async debugRollup() {
|
|
105
|
+
const rollup = new RollupContract(this.client, this.rollup.address);
|
|
106
|
+
const pendingNum = await rollup.getCheckpointNumber();
|
|
107
|
+
const provenNum = await rollup.getProvenCheckpointNumber();
|
|
108
|
+
const validators = await rollup.getAttesters();
|
|
109
|
+
const committee = await rollup.getCurrentEpochCommittee();
|
|
110
|
+
const archive = await rollup.archive();
|
|
111
|
+
const slot = await this.getSlot();
|
|
112
|
+
const epochNum = await rollup.getEpochNumberForSlotNumber(slot);
|
|
113
|
+
|
|
114
|
+
this.logger.info(`Pending checkpoint num: ${pendingNum}`);
|
|
115
|
+
this.logger.info(`Proven checkpoint num: ${provenNum}`);
|
|
116
|
+
this.logger.info(`Validators: ${validators.map(v => v.toString()).join(', ')}`);
|
|
117
|
+
this.logger.info(`Committee: ${committee?.map(v => v.toString()).join(', ')}`);
|
|
118
|
+
this.logger.info(`Archive: ${archive}`);
|
|
119
|
+
this.logger.info(`Epoch num: ${epochNum}`);
|
|
120
|
+
this.logger.info(`Slot: ${slot}`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Fetches the epoch and slot duration config from the rollup contract */
|
|
124
|
+
public async getConfig(): Promise<{
|
|
125
|
+
/** Epoch duration */ epochDuration: bigint;
|
|
126
|
+
/** Slot duration */ slotDuration: number;
|
|
127
|
+
}> {
|
|
128
|
+
const [epochDuration, slotDuration] = await Promise.all([
|
|
129
|
+
this.rollup.read.getEpochDuration(),
|
|
130
|
+
this.rollup.read.getSlotDuration(),
|
|
131
|
+
]);
|
|
132
|
+
return { epochDuration, slotDuration: Number(slotDuration) };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Advances time to the beginning of the given epoch
|
|
137
|
+
* @param epoch - The epoch to advance to
|
|
138
|
+
* @param opts - Options
|
|
139
|
+
*/
|
|
140
|
+
public async advanceToEpoch(
|
|
141
|
+
epoch: EpochNumber,
|
|
142
|
+
opts: {
|
|
143
|
+
/** Offset in seconds */
|
|
144
|
+
offset?: number;
|
|
145
|
+
} = {},
|
|
146
|
+
) {
|
|
147
|
+
const { epochDuration: slotsInEpoch } = await this.getConfig();
|
|
148
|
+
const slotNumber = SlotNumber(Number(epoch) * Number(slotsInEpoch));
|
|
149
|
+
const timestamp = (await this.rollup.read.getTimestampForSlot([BigInt(slotNumber)])) + BigInt(opts.offset ?? 0);
|
|
150
|
+
try {
|
|
151
|
+
await this.ethCheatCodes.warp(Number(timestamp), { ...opts, silent: true, resetBlockInterval: true });
|
|
152
|
+
this.logger.warn(`Warped to epoch ${epoch}`, { offset: opts.offset, timestamp });
|
|
153
|
+
} catch (err) {
|
|
154
|
+
this.logger.warn(`Warp to epoch ${epoch} failed: ${err}`);
|
|
155
|
+
}
|
|
156
|
+
return timestamp;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Warps time in L1 until the next epoch */
|
|
160
|
+
public async advanceToNextEpoch() {
|
|
161
|
+
const slot = await this.getSlot();
|
|
162
|
+
const { epochDuration, slotDuration } = await this.getConfig();
|
|
163
|
+
const slotsUntilNextEpoch = epochDuration - (BigInt(slot) % epochDuration) + 1n;
|
|
164
|
+
const timeToNextEpoch = slotsUntilNextEpoch * BigInt(slotDuration);
|
|
165
|
+
const l1Timestamp = BigInt((await this.client.getBlock()).timestamp);
|
|
166
|
+
await this.ethCheatCodes.warp(Number(l1Timestamp + timeToNextEpoch), {
|
|
167
|
+
silent: true,
|
|
168
|
+
resetBlockInterval: true,
|
|
169
|
+
});
|
|
170
|
+
this.logger.warn(`Advanced to next epoch`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Warps time in L1 until the beginning of the next slot. */
|
|
174
|
+
public async advanceToNextSlot() {
|
|
175
|
+
const currentSlot = await this.getSlot();
|
|
176
|
+
const nextSlot = SlotNumber(currentSlot + 1);
|
|
177
|
+
const timestamp = await this.rollup.read.getTimestampForSlot([BigInt(nextSlot)]);
|
|
178
|
+
await this.ethCheatCodes.warp(Number(timestamp), { silent: true, resetBlockInterval: true });
|
|
179
|
+
this.logger.warn(`Advanced to slot ${nextSlot}`);
|
|
180
|
+
return [timestamp, nextSlot];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Warps L1 time to the start of an explicit absolute slot. Unlike `advanceSlots(N)` which is
|
|
185
|
+
* relative to the current L1 timestamp at call time and therefore races with real-time
|
|
186
|
+
* progression between query and warp, this lands at the slot regardless of latency.
|
|
187
|
+
*
|
|
188
|
+
* Throws if the requested slot is in the past relative to current L1 time (anvil cannot
|
|
189
|
+
* rewind).
|
|
190
|
+
*/
|
|
191
|
+
public async advanceToSlot(slot: SlotNumber) {
|
|
192
|
+
const timestamp = await this.rollup.read.getTimestampForSlot([BigInt(slot)]);
|
|
193
|
+
await this.ethCheatCodes.warp(Number(timestamp), { silent: true, resetBlockInterval: true });
|
|
194
|
+
this.logger.warn(`Advanced to slot ${slot}`, { timestamp });
|
|
195
|
+
return timestamp;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Warps time in L1 equivalent to however many slots.
|
|
200
|
+
* @param howMany - The number of slots to advance.
|
|
201
|
+
*/
|
|
202
|
+
public async advanceSlots(howMany: number) {
|
|
203
|
+
const l1Timestamp = (await this.client.getBlock()).timestamp;
|
|
204
|
+
const slotDuration = Number(await this.rollup.read.getSlotDuration());
|
|
205
|
+
const timeToWarp = BigInt(howMany) * BigInt(slotDuration);
|
|
206
|
+
await this.ethCheatCodes.warp(l1Timestamp + timeToWarp, { silent: true, resetBlockInterval: true });
|
|
207
|
+
const [slot, epoch] = await Promise.all([this.getSlot(), this.getEpoch()]);
|
|
208
|
+
this.logger.warn(`Advanced ${howMany} slots up to slot ${slot} in epoch ${epoch}`);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Marks the specified checkpoint (or latest if none) as proven
|
|
213
|
+
* @param maybeCheckpointNumber - The checkpoint number to mark as proven (defaults to latest pending)
|
|
214
|
+
*/
|
|
215
|
+
public markAsProven(maybeCheckpointNumber?: CheckpointNumber) {
|
|
216
|
+
return this.ethCheatCodes.execWithPausedAnvil(async () => {
|
|
217
|
+
const tipsBefore = await this.getTips();
|
|
218
|
+
const { pending, proven } = tipsBefore;
|
|
219
|
+
|
|
220
|
+
let checkpointNumber = maybeCheckpointNumber;
|
|
221
|
+
if (checkpointNumber === undefined || checkpointNumber > pending) {
|
|
222
|
+
checkpointNumber = pending;
|
|
223
|
+
}
|
|
224
|
+
if (checkpointNumber <= proven) {
|
|
225
|
+
this.logger.debug(`Checkpoint ${checkpointNumber} is already proven`);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// @note @LHerskind this is heavily dependent on the storage layout and size of values
|
|
230
|
+
// The rollupStore is a struct and if the size of elements or the struct changes, this can break
|
|
231
|
+
const provenCheckpointNumberSlot = hexToBigInt(RollupContract.stfStorageSlot);
|
|
232
|
+
|
|
233
|
+
// Need to pack it as a single 32 byte word
|
|
234
|
+
const newValue = (BigInt(tipsBefore.pending) << 128n) | BigInt(checkpointNumber);
|
|
235
|
+
await this.ethCheatCodes.store(EthAddress.fromString(this.rollup.address), provenCheckpointNumberSlot, newValue);
|
|
236
|
+
|
|
237
|
+
const tipsAfter = await this.getTips();
|
|
238
|
+
if (tipsAfter.pending < tipsAfter.proven) {
|
|
239
|
+
throw new Error('Overwrote pending tip to a checkpoint in the past');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
this.logger.info(
|
|
243
|
+
`Proven tip moved: ${tipsBefore.proven} -> ${tipsAfter.proven}. Pending tip: ${tipsAfter.pending}.`,
|
|
244
|
+
);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Polls the rollup until its current epoch reaches `epoch`. Unlike {@link advanceToEpoch} this does
|
|
250
|
+
* not warp the L1 clock; it only waits for the chain to reach `epoch` through external activity.
|
|
251
|
+
*/
|
|
252
|
+
public async waitForEpoch(epoch: EpochNumber, opts: { timeout?: number; interval?: number } = {}): Promise<void> {
|
|
253
|
+
await retryUntil(
|
|
254
|
+
async () => (await this.getEpoch()) >= epoch || undefined,
|
|
255
|
+
`rollup epoch >= ${epoch}`,
|
|
256
|
+
opts.timeout ?? 60,
|
|
257
|
+
opts.interval ?? 1,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Polls the rollup until its current slot reaches `slot`. Unlike {@link advanceToSlot} this does not
|
|
263
|
+
* warp the L1 clock; it only waits for the chain to reach `slot` through external activity.
|
|
264
|
+
*/
|
|
265
|
+
public async waitForSlot(slot: SlotNumber, opts: { timeout?: number; interval?: number } = {}): Promise<void> {
|
|
266
|
+
await retryUntil(
|
|
267
|
+
async () => (await this.getSlot()) >= slot || undefined,
|
|
268
|
+
`rollup slot >= ${slot}`,
|
|
269
|
+
opts.timeout ?? 60,
|
|
270
|
+
opts.interval ?? 1,
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Polls the rollup until its pending checkpoint settles below `checkpoint` on a freshly mined, non-zero
|
|
276
|
+
* checkpoint, and returns that new pending checkpoint number. Reads the L1 rollup contract directly
|
|
277
|
+
* rather than a node, since a rollback lands on L1 first.
|
|
278
|
+
*
|
|
279
|
+
* A prune can momentarily drop the pending checkpoint to 0 before the post-deadline propose mines its
|
|
280
|
+
* replacement, so a caller detecting a rollback wants the new lower checkpoint, not that transient
|
|
281
|
+
* empty state — hence the non-zero guard.
|
|
282
|
+
*/
|
|
283
|
+
public async waitForCheckpointBelow(
|
|
284
|
+
checkpoint: CheckpointNumber,
|
|
285
|
+
opts: { timeout?: number; interval?: number } = {},
|
|
286
|
+
): Promise<CheckpointNumber> {
|
|
287
|
+
return await retryUntil(
|
|
288
|
+
async () => {
|
|
289
|
+
const { pending } = await this.getTips();
|
|
290
|
+
return pending > 0 && pending < checkpoint ? pending : undefined;
|
|
291
|
+
},
|
|
292
|
+
`rollup checkpoint in (0, ${checkpoint})`,
|
|
293
|
+
opts.timeout ?? 60,
|
|
294
|
+
opts.interval ?? 1,
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
public insertOutbox(epoch: EpochNumber, numCheckpointsInEpoch: number, outHash: bigint) {
|
|
299
|
+
return this.ethCheatCodes.execWithPausedAnvil(async () => {
|
|
300
|
+
const outboxAddress = await this.rollup.read.getOutbox();
|
|
301
|
+
const epochRootSlot = OutboxContract.getEpochRootStorageSlot(epoch, numCheckpointsInEpoch);
|
|
302
|
+
await this.ethCheatCodes.store(EthAddress.fromString(outboxAddress), epochRootSlot, outHash);
|
|
303
|
+
this.logger.warn(
|
|
304
|
+
`Advanced outbox to epoch ${epoch} numCheckpointsInEpoch ${numCheckpointsInEpoch} with out hash ${outHash}`,
|
|
305
|
+
);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Executes an action impersonated as the owner of the Rollup contract.
|
|
311
|
+
* @param action - The action to execute
|
|
312
|
+
*/
|
|
313
|
+
public async asOwner(
|
|
314
|
+
action: (owner: Hex, rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>) => Promise<void>,
|
|
315
|
+
) {
|
|
316
|
+
const owner = await this.rollup.read.owner();
|
|
317
|
+
await this.ethCheatCodes.startImpersonating(owner);
|
|
318
|
+
await action(owner, this.rollup);
|
|
319
|
+
await this.ethCheatCodes.stopImpersonating(owner);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Sets up the epoch.
|
|
324
|
+
*/
|
|
325
|
+
public async setupEpoch() {
|
|
326
|
+
// Doesn't need to be done as owner, but the functionality is here...
|
|
327
|
+
await this.asOwner(async (account, rollup) => {
|
|
328
|
+
const hash = await rollup.write.setupEpoch({ account });
|
|
329
|
+
await this.client.waitForTransactionReceipt({ hash });
|
|
330
|
+
this.logger.warn(`Setup epoch`);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** Directly calls the L1 gas fee oracle. */
|
|
335
|
+
public async updateL1GasFeeOracle() {
|
|
336
|
+
await this.asOwner(async (account, rollup) => {
|
|
337
|
+
const hash = await rollup.write.updateL1GasFeeOracle({ account, chain: this.client.chain });
|
|
338
|
+
await this.client.waitForTransactionReceipt({ hash });
|
|
339
|
+
this.logger.warn(`Updated L1 gas fee oracle`);
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Bumps proving cost per mana.
|
|
345
|
+
* @param bumper - Callback to calculate the new proving cost per mana based on current value.
|
|
346
|
+
*/
|
|
347
|
+
public async bumpProvingCostPerMana(bumper: (before: bigint) => bigint) {
|
|
348
|
+
const currentCost = await this.rollup.read.getProvingCostPerManaInEth();
|
|
349
|
+
const newCost = bumper(currentCost);
|
|
350
|
+
await this.setProvingCostPerMana(newCost);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Directly updates proving cost per mana. Throws if the on-chain tx reverts
|
|
355
|
+
* (e.g. rate-limit cooldown, step cap, or floor) instead of silently succeeding.
|
|
356
|
+
* @param ethValue - The new proving cost per mana in ETH
|
|
357
|
+
*/
|
|
358
|
+
public async setProvingCostPerMana(ethValue: bigint) {
|
|
359
|
+
await this.asOwner(async (account, rollup) => {
|
|
360
|
+
const hash = await rollup.write.setProvingCostPerMana([ethValue], {
|
|
361
|
+
account,
|
|
362
|
+
chain: this.client.chain,
|
|
363
|
+
gasLimit: 1000000n,
|
|
364
|
+
});
|
|
365
|
+
const receipt = await this.client.waitForTransactionReceipt({ hash });
|
|
366
|
+
if (receipt.status !== 'success') {
|
|
367
|
+
throw new Error(
|
|
368
|
+
`setProvingCostPerMana(${ethValue}) reverted on L1 (tx ${hash}). ` +
|
|
369
|
+
`Likely FeeLib rate-limit (30-day cooldown or 1.5x step cap); ` +
|
|
370
|
+
`use clearProvingCostCooldown() between successive updates.`,
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
this.logger.warn(`Updated proving cost per mana to ${ethValue}`);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Resets the 30-day proving-cost update cooldown enforced by FeeLib.updateProvingCostPerMana
|
|
379
|
+
* by zeroing `FeeStore.provingCostLastUpdate` directly in contract storage. Use between
|
|
380
|
+
* successive setProvingCostPerMana / bumpProvingCostPerMana calls so the later update can
|
|
381
|
+
* land instead of reverting. Does not touch L1 time, so PXE/tx-expiration state stays intact.
|
|
382
|
+
*
|
|
383
|
+
* @note This is tightly coupled to the `FeeStore` layout in
|
|
384
|
+
* l1-contracts/src/core/libraries/rollup/FeeLib.sol:
|
|
385
|
+
* slot + 0: CompressedFeeConfig config (uint256)
|
|
386
|
+
* slot + 1: L1GasOracleValues l1GasOracleValues (14+14+4 bytes, packed)
|
|
387
|
+
* slot + 2: uint64 provingCostLastUpdate (only member — zeroing the slot is safe)
|
|
388
|
+
* If the struct layout changes, update the offset below.
|
|
389
|
+
*/
|
|
390
|
+
public async clearProvingCostCooldown() {
|
|
391
|
+
const feeStoreBaseSlot = hexToBigInt(keccak256(Buffer.from('aztec.fee.storage', 'utf-8')));
|
|
392
|
+
const provingCostLastUpdateSlot = feeStoreBaseSlot + 2n;
|
|
393
|
+
await this.ethCheatCodes.store(EthAddress.fromString(this.rollup.address), provingCostLastUpdateSlot, 0n, {
|
|
394
|
+
silent: true,
|
|
395
|
+
});
|
|
396
|
+
this.logger.warn(`Cleared proving-cost update cooldown`);
|
|
397
|
+
}
|
|
398
|
+
}
|