Skip to content

Commit 5d48500

Browse files
authored
chore: increase AZTEC_SLOT_DURATION (#8331)
Fixes #7850. Alters the aztec slot duration til 3 * ethereum slot duration = 36 seconds. - Updated the sandbox to no longer ignore the `--l1-rpc-url` option, it passed in test because they are all using the environment variables `ETHEREUM_HOST`. - Updated the watcher to check if running on an anvil with automine. - Added a `watcher` to the sandbox, such that it can jump time if automining as well. This was needed to work with `AZTEC_SLOT_DURATION > ETHEREUM_SLOT_DURATION`. - Moved the watcher into the `aztec.js` since it is now needed in multiple places and it seeded to avoid a cycle, but needed to import viem and l1-artifacts into it 😬 - Updates the `transfer.test.ts` to make multiple transfers in the same blocks to speed up the test, as 36s blocks with 50 blocks is 30 minutes which is longer than I would like to have that test run.
1 parent f7e4bfb commit 5d48500

File tree

22 files changed

+247
-125
lines changed

22 files changed

+247
-125
lines changed

l1-contracts/src/core/libraries/ConstantsGen.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ library Constants {
102102
uint256 internal constant INITIAL_L2_BLOCK_NUM = 1;
103103
uint256 internal constant BLOB_SIZE_IN_BYTES = 126976;
104104
uint256 internal constant ETHEREUM_SLOT_DURATION = 12;
105-
uint256 internal constant AZTEC_SLOT_DURATION = 12;
105+
uint256 internal constant AZTEC_SLOT_DURATION = 36;
106106
uint256 internal constant AZTEC_EPOCH_DURATION = 48;
107107
uint256 internal constant AZTEC_TARGET_COMMITTEE_SIZE = 48;
108108
uint256 internal constant GENESIS_ARCHIVE_ROOT =

l1-contracts/test/fixtures/empty_block_1.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"l2ToL1Messages": []
99
},
1010
"block": {
11-
"archive": "0x0f24dbb7e2a507326574582c3f44c08266eb441e926f2d68ca112f358585669f",
11+
"archive": "0x2e45afa261e3aac1f5afe60c9c839d54feafeb03a1fa1676265cb50fd7144202",
1212
"body": "0x00000000",
1313
"txsEffectsHash": "0x00e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d6",
1414
"decodedHeader": {
@@ -20,12 +20,12 @@
2020
},
2121
"globalVariables": {
2222
"blockNumber": 1,
23-
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000033",
23+
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000031",
2424
"chainId": 31337,
25-
"timestamp": 1724861610,
25+
"timestamp": 1725365629,
2626
"version": 1,
27-
"coinbase": "0x872bd7c2a38898f9fc254b86f0fd95475f7eec20",
28-
"feeRecipient": "0x2d78818b03bcaf7034fca9d658f1212c6b2aecd6839e03cc21e2846fc061202d",
27+
"coinbase": "0xe18d2e77cb7d56929128e82138140e07f81237f0",
28+
"feeRecipient": "0x249d3ad6f4117aa61fb1c3f901889be704af87fc9bb1686ba21218a3b50c36bf",
2929
"gasFees": {
3030
"feePerDaGas": 0,
3131
"feePerL2Gas": 0
@@ -56,8 +56,8 @@
5656
}
5757
}
5858
},
59-
"header": "0x1200a06aae1368abe36530b585bd7a4d2ba4de5037b82076412691a187d7621e00000001000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3000000100b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d0000008019a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc0000010023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001000000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000330000000000000000000000000000000000000000000000000000000066cf4caa872bd7c2a38898f9fc254b86f0fd95475f7eec202d78818b03bcaf7034fca9d658f1212c6b2aecd6839e03cc21e2846fc061202d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
60-
"publicInputsHash": "0x00a46e722d885c3bf479f8cf2a786adfde7a8c43740214163f7f9846914cbe6f",
59+
"header": "0x1200a06aae1368abe36530b585bd7a4d2ba4de5037b82076412691a187d7621e00000001000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3000000100b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d0000008019a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc0000010023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001000000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000310000000000000000000000000000000000000000000000000000000066d6fd7de18d2e77cb7d56929128e82138140e07f81237f0249d3ad6f4117aa61fb1c3f901889be704af87fc9bb1686ba21218a3b50c36bf000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
60+
"publicInputsHash": "0x0042736ccfe5affa7d43b08218d225ef79539cf41495e3db480aedf4ec65d918",
6161
"numTxs": 0
6262
}
6363
}

l1-contracts/test/fixtures/empty_block_2.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"l2ToL1Messages": []
99
},
1010
"block": {
11-
"archive": "0x25126f40ad58d24006e6db629c2efb1e0868a50d5c21aa342894137b2b08bc0b",
11+
"archive": "0x002edae6c81b7fcd630fd745c8e6fa957b8d4ac97b55baa072fae18f4a94b14e",
1212
"body": "0x00000000",
1313
"txsEffectsHash": "0x00e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d6",
1414
"decodedHeader": {
@@ -20,20 +20,20 @@
2020
},
2121
"globalVariables": {
2222
"blockNumber": 2,
23-
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000035",
23+
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000032",
2424
"chainId": 31337,
25-
"timestamp": 1724861634,
25+
"timestamp": 1725365665,
2626
"version": 1,
27-
"coinbase": "0x872bd7c2a38898f9fc254b86f0fd95475f7eec20",
28-
"feeRecipient": "0x2d78818b03bcaf7034fca9d658f1212c6b2aecd6839e03cc21e2846fc061202d",
27+
"coinbase": "0xe18d2e77cb7d56929128e82138140e07f81237f0",
28+
"feeRecipient": "0x249d3ad6f4117aa61fb1c3f901889be704af87fc9bb1686ba21218a3b50c36bf",
2929
"gasFees": {
3030
"feePerDaGas": 0,
3131
"feePerL2Gas": 0
3232
}
3333
},
3434
"lastArchive": {
3535
"nextAvailableLeafIndex": 2,
36-
"root": "0x0f24dbb7e2a507326574582c3f44c08266eb441e926f2d68ca112f358585669f"
36+
"root": "0x2e45afa261e3aac1f5afe60c9c839d54feafeb03a1fa1676265cb50fd7144202"
3737
},
3838
"stateReference": {
3939
"l1ToL2MessageTree": {
@@ -56,8 +56,8 @@
5656
}
5757
}
5858
},
59-
"header": "0x0f24dbb7e2a507326574582c3f44c08266eb441e926f2d68ca112f358585669f00000002000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3000000200b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d0000010019a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc0000018023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001800000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000350000000000000000000000000000000000000000000000000000000066cf4cc2872bd7c2a38898f9fc254b86f0fd95475f7eec202d78818b03bcaf7034fca9d658f1212c6b2aecd6839e03cc21e2846fc061202d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
60-
"publicInputsHash": "0x00de3870b035eca1a73e8adf24b738db855a034548805b300d8dbecfd2a6e66b",
59+
"header": "0x2e45afa261e3aac1f5afe60c9c839d54feafeb03a1fa1676265cb50fd714420200000002000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3000000200b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d0000010019a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc0000018023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001800000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000000000000000000000066d6fda1e18d2e77cb7d56929128e82138140e07f81237f0249d3ad6f4117aa61fb1c3f901889be704af87fc9bb1686ba21218a3b50c36bf000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
60+
"publicInputsHash": "0x00b9a5096ad3d9edef7e78a242b1402a5cd1adeb08ee654c6e738a08b3522483",
6161
"numTxs": 0
6262
}
6363
}

l1-contracts/test/fixtures/mixed_block_1.json

+7-7
Large diffs are not rendered by default.

l1-contracts/test/fixtures/mixed_block_2.json

+8-8
Large diffs are not rendered by default.

noir-projects/noir-protocol-circuits/crates/types/src/constants.nr

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ global INITIAL_L2_BLOCK_NUM: Field = 1;
135135
global BLOB_SIZE_IN_BYTES: Field = 31 * 4096;
136136
global ETHEREUM_SLOT_DURATION: u32 = 12;
137137
// AZTEC_SLOT_DURATION should be a multiple of ETHEREUM_SLOT_DURATION
138-
global AZTEC_SLOT_DURATION: u32 = ETHEREUM_SLOT_DURATION * 1;
138+
global AZTEC_SLOT_DURATION: u32 = ETHEREUM_SLOT_DURATION * 3;
139139
global AZTEC_EPOCH_DURATION: u32 = 48;
140140
global AZTEC_TARGET_COMMITTEE_SIZE: u32 = 48;
141141
// The following is taken from building a block and looking at the `lastArchive` value in it.

yarn-project/aztec.js/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@
7777
"@aztec/circuits.js": "workspace:^",
7878
"@aztec/ethereum": "workspace:^",
7979
"@aztec/foundation": "workspace:^",
80+
"@aztec/l1-artifacts": "workspace:^",
8081
"@aztec/protocol-contracts": "workspace:^",
8182
"@aztec/types": "workspace:^",
8283
"axios": "^1.7.2",
83-
"tslib": "^2.4.0"
84+
"tslib": "^2.4.0",
85+
"viem": "^2.7.15"
8486
},
8587
"devDependencies": {
8688
"@jest/globals": "^29.5.0",

yarn-project/aztec.js/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export { ContractDeployer } from './deployment/index.js';
3939

4040
export {
4141
AztecAddressLike,
42+
AnvilTestWatcher,
4243
CheatCodes,
4344
EthAddressLike,
4445
EthCheatCodes,

yarn-project/end-to-end/src/fixtures/watcher.ts yarn-project/aztec.js/src/utils/anvil_test_watcher.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import { RollupAbi } from '@aztec/l1-artifacts';
66
import { type GetContractReturnType, type HttpTransport, type PublicClient, getAddress, getContract } from 'viem';
77
import type * as chains from 'viem/chains';
88

9-
export class Watcher {
9+
/**
10+
* Represents a watcher for a rollup contract.
11+
*
12+
* It started on a network like anvil where time traveling is allowed, and auto-mine is turned on
13+
* it will periodically check if the current slot have already been filled, e.g., there was an L2
14+
* block within the slot. And if so, it will time travel into the next slot.
15+
*/
16+
export class AnvilTestWatcher {
1017
private rollup: GetContractReturnType<typeof RollupAbi, PublicClient<HttpTransport, chains.Chain>>;
1118

1219
private filledRunningPromise?: RunningPromise;
@@ -27,13 +34,24 @@ export class Watcher {
2734
this.logger.info(`Watcher created for rollup at ${rollupAddress}`);
2835
}
2936

30-
start() {
37+
async start() {
3138
if (this.filledRunningPromise) {
3239
throw new Error('Watcher already watching for filled slot');
3340
}
34-
this.filledRunningPromise = new RunningPromise(() => this.mineIfSlotFilled(), 1000);
35-
this.filledRunningPromise.start();
36-
this.logger.info(`Watcher started`);
41+
42+
// If auto mining is not supported (e.g., we are on a real network), then we
43+
// will simple do nothing. But if on an anvil or the like, this make sure that
44+
// the sandbox and tests don't break because time is frozen and we never get to
45+
// the next slot.
46+
const isAutoMining = await this.cheatcodes.isAutoMining();
47+
48+
if (isAutoMining) {
49+
this.filledRunningPromise = new RunningPromise(() => this.mineIfSlotFilled(), 1000);
50+
this.filledRunningPromise.start();
51+
this.logger.info(`Watcher started`);
52+
} else {
53+
this.logger.info(`Watcher not started because not auto mining`);
54+
}
3755
}
3856

3957
async stop() {

yarn-project/aztec.js/src/utils/cheat_codes.ts

+14
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ export class EthCheatCodes {
5454
return await (await fetch(this.rpcUrl, content)).json();
5555
}
5656

57+
/**
58+
* Get the auto mine status of the underlying chain
59+
* @returns True if automine is on, false otherwise
60+
*/
61+
public async isAutoMining(): Promise<boolean> {
62+
try {
63+
const res = await this.rpcCall('anvil_getAutomine', []);
64+
return res.result;
65+
} catch (err) {
66+
this.logger.error(`Calling "anvil_getAutomine" failed with:`, err);
67+
}
68+
return false;
69+
}
70+
5771
/**
5872
* Get the current blocknumber
5973
* @returns The current block number

yarn-project/aztec.js/src/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from './cheat_codes.js';
55
export * from './authwit.js';
66
export * from './pxe.js';
77
export * from './account.js';
8+
export * from './anvil_test_watcher.js';

yarn-project/aztec.js/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
{
1919
"path": "../foundation"
2020
},
21+
{
22+
"path": "../l1-artifacts"
23+
},
2124
{
2225
"path": "../protocol-contracts"
2326
},

yarn-project/aztec/src/cli/cli.ts

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export function injectAztecCommands(program: Command, userLog: LogFn, debugLogge
5353
const { aztecNodeConfig, node, pxe, stop } = await createSandbox({
5454
enableGas: sandboxOptions.enableGas,
5555
l1Mnemonic: options.l1Mnemonic,
56+
l1RpcUrl: options.l1RpcUrl,
5657
});
5758

5859
// Deploy test accounts by default

yarn-project/aztec/src/sandbox.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env -S node --no-warnings
22
import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node';
3-
import { SignerlessWallet } from '@aztec/aztec.js';
3+
import { AnvilTestWatcher, EthCheatCodes, SignerlessWallet } from '@aztec/aztec.js';
44
import { DefaultMultiCallEntrypoint } from '@aztec/aztec.js/entrypoint';
55
import { type AztecNode } from '@aztec/circuit-types';
66
import { deployCanonicalAuthRegistry, deployCanonicalKeyRegistry, deployCanonicalL2FeeJuice } from '@aztec/cli/misc';
@@ -166,8 +166,25 @@ export async function createSandbox(config: Partial<SandboxConfig> = {}) {
166166
aztecNodeConfig.validatorPrivateKey = `0x${Buffer.from(privKey!).toString('hex')}`;
167167
}
168168

169+
let watcher: AnvilTestWatcher | undefined = undefined;
169170
if (!aztecNodeConfig.p2pEnabled) {
170-
await deployContractsToL1(aztecNodeConfig, hdAccount);
171+
const l1ContractAddresses = await deployContractsToL1(aztecNodeConfig, hdAccount);
172+
173+
const chain = aztecNodeConfig.l1RpcUrl
174+
? createEthereumChain(aztecNodeConfig.l1RpcUrl, aztecNodeConfig.l1ChainId)
175+
: { chainInfo: localAnvil };
176+
177+
const publicClient = createPublicClient({
178+
chain: chain.chainInfo,
179+
transport: httpViemTransport(aztecNodeConfig.l1RpcUrl),
180+
});
181+
182+
watcher = new AnvilTestWatcher(
183+
new EthCheatCodes(aztecNodeConfig.l1RpcUrl),
184+
l1ContractAddresses.rollupAddress,
185+
publicClient,
186+
);
187+
await watcher.start();
171188
}
172189

173190
const client = await createAndStartTelemetryClient(getTelemetryClientConfig());
@@ -191,6 +208,7 @@ export async function createSandbox(config: Partial<SandboxConfig> = {}) {
191208
const stop = async () => {
192209
await pxe.stop();
193210
await node.stop();
211+
await watcher?.stop();
194212
};
195213

196214
return { node, pxe, aztecNodeConfig, stop };

yarn-project/circuits.js/src/constants.gen.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const INITIALIZATION_SLOT_SEPARATOR = 1000000000;
8888
export const INITIAL_L2_BLOCK_NUM = 1;
8989
export const BLOB_SIZE_IN_BYTES = 126976;
9090
export const ETHEREUM_SLOT_DURATION = 12;
91-
export const AZTEC_SLOT_DURATION = 12;
91+
export const AZTEC_SLOT_DURATION = 36;
9292
export const AZTEC_EPOCH_DURATION = 48;
9393
export const AZTEC_TARGET_COMMITTEE_SIZE = 48;
9494
export const GENESIS_ARCHIVE_ROOT = 8142738430000951296386584486068033372964809139261822027365426310856631083550n;

yarn-project/end-to-end/scripts/create_k8s_dashboard.sh

100644100755
File mode changed.

yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import {
2121
const BLOCK_SIZE = BENCHMARK_HISTORY_BLOCK_SIZE;
2222
const CHAIN_LENGTHS = BENCHMARK_HISTORY_CHAIN_LENGTHS;
2323
const MAX_CHAIN_LENGTH = CHAIN_LENGTHS[CHAIN_LENGTHS.length - 1];
24-
const SETUP_BLOCK_COUNT = 4; // deploy protocol contracts + deploy account + deploy contract
24+
25+
let setupBlockCount: number;
2526

2627
describe('benchmarks/process_history', () => {
2728
let context: EndToEndContext;
@@ -30,6 +31,7 @@ describe('benchmarks/process_history', () => {
3031

3132
beforeEach(async () => {
3233
({ context, contract, sequencer } = await benchmarkSetup({ maxTxsPerBlock: BLOCK_SIZE }));
34+
setupBlockCount = await context.aztecNode.getBlockNumber();
3335
});
3436

3537
it(
@@ -59,7 +61,7 @@ describe('benchmarks/process_history', () => {
5961
});
6062

6163
const blockNumber = await node.getBlockNumber();
62-
expect(blockNumber).toEqual(chainLength + SETUP_BLOCK_COUNT);
64+
expect(blockNumber).toEqual(chainLength + setupBlockCount);
6365

6466
context.logger.info(`Node synced chain up to block ${chainLength}`, {
6567
eventName: 'node-synced-chain-history',
@@ -74,7 +76,7 @@ describe('benchmarks/process_history', () => {
7476
// Create a new pxe and measure how much time it takes it to sync with failed and successful decryption
7577
// Skip the first two blocks used for setup (create account contract and deploy benchmarking contract)
7678
context.logger.info(`Starting new pxe`);
77-
const pxe = await waitNewPXESynced(node, contract, INITIAL_L2_BLOCK_NUM + SETUP_BLOCK_COUNT);
79+
const pxe = await waitNewPXESynced(node, contract, INITIAL_L2_BLOCK_NUM + setupBlockCount);
7880

7981
// Register the owner account and wait until it's synced so we measure how much time it took
8082
context.logger.info(`Registering owner account on new pxe`);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from './fixtures.js';
22
export * from './logging.js';
33
export * from './utils.js';
4-
export * from './watcher.js';

0 commit comments

Comments
 (0)