@aztec/aztec 0.0.1-commit.96bb3f7 → 0.0.1-commit.993d240

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.
Files changed (154) hide show
  1. package/dest/bin/index.js +7 -3
  2. package/dest/cli/admin_api_key_store.d.ts +45 -0
  3. package/dest/cli/admin_api_key_store.d.ts.map +1 -0
  4. package/dest/cli/admin_api_key_store.js +98 -0
  5. package/dest/cli/aztec_start_action.d.ts +1 -1
  6. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  7. package/dest/cli/aztec_start_action.js +76 -23
  8. package/dest/cli/aztec_start_options.d.ts +2 -2
  9. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  10. package/dest/cli/aztec_start_options.js +43 -25
  11. package/dest/cli/cli.d.ts +1 -1
  12. package/dest/cli/cli.d.ts.map +1 -1
  13. package/dest/cli/cli.js +3 -4
  14. package/dest/cli/cmds/compile.d.ts +4 -0
  15. package/dest/cli/cmds/compile.d.ts.map +1 -0
  16. package/dest/cli/cmds/compile.js +166 -0
  17. package/dest/cli/cmds/profile.d.ts +4 -0
  18. package/dest/cli/cmds/profile.d.ts.map +1 -0
  19. package/dest/cli/cmds/profile.js +8 -0
  20. package/dest/cli/cmds/profile_flamegraph.d.ts +4 -0
  21. package/dest/cli/cmds/profile_flamegraph.d.ts.map +1 -0
  22. package/dest/cli/cmds/profile_flamegraph.js +52 -0
  23. package/dest/cli/cmds/profile_gates.d.ts +4 -0
  24. package/dest/cli/cmds/profile_gates.d.ts.map +1 -0
  25. package/dest/cli/cmds/profile_gates.js +76 -0
  26. package/dest/cli/cmds/profile_utils.d.ts +18 -0
  27. package/dest/cli/cmds/profile_utils.d.ts.map +1 -0
  28. package/dest/cli/cmds/profile_utils.js +50 -0
  29. package/dest/cli/cmds/standby.d.ts +30 -0
  30. package/dest/cli/cmds/standby.d.ts.map +1 -0
  31. package/dest/cli/cmds/standby.js +97 -0
  32. package/dest/cli/cmds/start_bot.d.ts +3 -3
  33. package/dest/cli/cmds/start_bot.d.ts.map +1 -1
  34. package/dest/cli/cmds/start_bot.js +12 -8
  35. package/dest/cli/cmds/start_node.d.ts +3 -2
  36. package/dest/cli/cmds/start_node.d.ts.map +1 -1
  37. package/dest/cli/cmds/start_node.js +75 -35
  38. package/dest/cli/cmds/start_p2p_bootstrap.d.ts +2 -2
  39. package/dest/cli/cmds/start_p2p_bootstrap.d.ts.map +1 -1
  40. package/dest/cli/cmds/start_p2p_bootstrap.js +1 -2
  41. package/dest/cli/cmds/start_prover_agent.d.ts +1 -1
  42. package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
  43. package/dest/cli/cmds/start_prover_agent.js +6 -18
  44. package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
  45. package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
  46. package/dest/cli/cmds/start_prover_broker.js +24 -15
  47. package/dest/cli/cmds/start_txe.d.ts +2 -2
  48. package/dest/cli/cmds/start_txe.d.ts.map +1 -1
  49. package/dest/cli/cmds/start_txe.js +6 -5
  50. package/dest/cli/cmds/utils/artifacts.d.ts +21 -0
  51. package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -0
  52. package/dest/cli/cmds/utils/artifacts.js +24 -0
  53. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts +21 -0
  54. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts.map +1 -0
  55. package/dest/cli/cmds/utils/collect_crate_dirs.js +114 -0
  56. package/dest/cli/cmds/utils/needs_recompile.d.ts +10 -0
  57. package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -0
  58. package/dest/cli/cmds/utils/needs_recompile.js +90 -0
  59. package/dest/cli/cmds/utils/spawn.d.ts +3 -0
  60. package/dest/cli/cmds/utils/spawn.d.ts.map +1 -0
  61. package/dest/cli/cmds/utils/spawn.js +16 -0
  62. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +4 -0
  63. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -0
  64. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +61 -0
  65. package/dest/cli/util.d.ts +7 -18
  66. package/dest/cli/util.d.ts.map +1 -1
  67. package/dest/cli/util.js +57 -91
  68. package/dest/examples/token.js +9 -9
  69. package/dest/local-network/auth_registry.d.ts +4 -0
  70. package/dest/local-network/auth_registry.d.ts.map +1 -0
  71. package/dest/local-network/auth_registry.js +15 -0
  72. package/dest/local-network/banana_fpc.d.ts +1 -1
  73. package/dest/local-network/banana_fpc.d.ts.map +1 -1
  74. package/dest/local-network/banana_fpc.js +11 -9
  75. package/dest/local-network/local-network.d.ts +7 -29
  76. package/dest/local-network/local-network.d.ts.map +1 -1
  77. package/dest/local-network/local-network.js +78 -33
  78. package/dest/testing/anvil_test_watcher.d.ts +23 -3
  79. package/dest/testing/anvil_test_watcher.d.ts.map +1 -1
  80. package/dest/testing/anvil_test_watcher.js +113 -22
  81. package/dest/testing/cheat_codes.d.ts +20 -17
  82. package/dest/testing/cheat_codes.d.ts.map +1 -1
  83. package/dest/testing/cheat_codes.js +72 -36
  84. package/dest/testing/epoch_test_settler.d.ts +4 -2
  85. package/dest/testing/epoch_test_settler.d.ts.map +1 -1
  86. package/dest/testing/epoch_test_settler.js +21 -10
  87. package/dest/testing/index.d.ts +3 -2
  88. package/dest/testing/index.d.ts.map +1 -1
  89. package/dest/testing/index.js +1 -0
  90. package/dest/testing/token_allowed_setup.d.ts +7 -0
  91. package/dest/testing/token_allowed_setup.d.ts.map +1 -0
  92. package/dest/testing/token_allowed_setup.js +20 -0
  93. package/package.json +36 -35
  94. package/scripts/add_crate.sh +53 -0
  95. package/scripts/aztec.sh +15 -5
  96. package/scripts/init.sh +23 -19
  97. package/scripts/new.sh +48 -24
  98. package/scripts/setup_workspace.sh +69 -0
  99. package/scripts/templates/blank/contract/Nargo.toml +6 -0
  100. package/scripts/templates/blank/contract/src/main.nr +10 -0
  101. package/scripts/templates/blank/test/Nargo.toml +7 -0
  102. package/scripts/templates/blank/test/src/lib.nr +11 -0
  103. package/scripts/templates/counter/contract/Nargo.toml +7 -0
  104. package/scripts/templates/counter/contract/src/main.nr +48 -0
  105. package/scripts/templates/counter/test/Nargo.toml +7 -0
  106. package/scripts/templates/counter/test/src/lib.nr +32 -0
  107. package/src/bin/index.ts +7 -3
  108. package/src/cli/admin_api_key_store.ts +128 -0
  109. package/src/cli/aztec_start_action.ts +69 -19
  110. package/src/cli/aztec_start_options.ts +51 -31
  111. package/src/cli/cli.ts +3 -4
  112. package/src/cli/cmds/compile.ts +192 -0
  113. package/src/cli/cmds/profile.ts +26 -0
  114. package/src/cli/cmds/profile_flamegraph.ts +64 -0
  115. package/src/cli/cmds/profile_gates.ts +84 -0
  116. package/src/cli/cmds/profile_utils.ts +58 -0
  117. package/src/cli/cmds/standby.ts +132 -0
  118. package/src/cli/cmds/start_bot.ts +11 -10
  119. package/src/cli/cmds/start_node.ts +86 -40
  120. package/src/cli/cmds/start_p2p_bootstrap.ts +2 -2
  121. package/src/cli/cmds/start_prover_agent.ts +7 -10
  122. package/src/cli/cmds/start_prover_broker.ts +28 -25
  123. package/src/cli/cmds/start_txe.ts +7 -5
  124. package/src/cli/cmds/utils/artifacts.ts +44 -0
  125. package/src/cli/cmds/utils/collect_crate_dirs.ts +118 -0
  126. package/src/cli/cmds/utils/needs_recompile.ts +98 -0
  127. package/src/cli/cmds/utils/spawn.ts +16 -0
  128. package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +76 -0
  129. package/src/cli/util.ts +64 -102
  130. package/src/examples/token.ts +10 -10
  131. package/src/local-network/auth_registry.ts +14 -0
  132. package/src/local-network/banana_fpc.ts +8 -7
  133. package/src/local-network/local-network.ts +92 -34
  134. package/src/testing/anvil_test_watcher.ts +127 -20
  135. package/src/testing/cheat_codes.ts +92 -39
  136. package/src/testing/epoch_test_settler.ts +19 -9
  137. package/src/testing/index.ts +2 -1
  138. package/src/testing/token_allowed_setup.ts +19 -0
  139. package/dest/cli/cmds/start_archiver.d.ts +0 -9
  140. package/dest/cli/cmds/start_archiver.d.ts.map +0 -1
  141. package/dest/cli/cmds/start_archiver.js +0 -50
  142. package/dest/cli/cmds/start_prover_node.d.ts +0 -7
  143. package/dest/cli/cmds/start_prover_node.d.ts.map +0 -1
  144. package/dest/cli/cmds/start_prover_node.js +0 -108
  145. package/dest/cli/release_version.d.ts +0 -2
  146. package/dest/cli/release_version.d.ts.map +0 -1
  147. package/dest/cli/release_version.js +0 -14
  148. package/scripts/compile.sh +0 -44
  149. package/scripts/extract_function.js +0 -47
  150. package/scripts/flamegraph.sh +0 -59
  151. package/scripts/setup_project.sh +0 -31
  152. package/src/cli/cmds/start_archiver.ts +0 -61
  153. package/src/cli/cmds/start_prover_node.ts +0 -124
  154. package/src/cli/release_version.ts +0 -21
@@ -11,6 +11,7 @@ import { waitForPublicClient } from '@aztec/ethereum/client';
11
11
  import { getL1ContractsConfigEnvVars } from '@aztec/ethereum/config';
12
12
  import { NULL_KEY } from '@aztec/ethereum/constants';
13
13
  import { deployAztecL1Contracts } from '@aztec/ethereum/deploy-aztec-l1-contracts';
14
+ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
14
15
  import { EthCheatCodes } from '@aztec/ethereum/test';
15
16
  import { SecretValue } from '@aztec/foundation/config';
16
17
  import { EthAddress } from '@aztec/foundation/eth-address';
@@ -18,13 +19,17 @@ import type { LogFn } from '@aztec/foundation/log';
18
19
  import { DateProvider, TestDateProvider } from '@aztec/foundation/timer';
19
20
  import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
20
21
  import { protocolContractsHash } from '@aztec/protocol-contracts';
21
- import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
22
+ import { SequencerState } from '@aztec/sequencer-client';
23
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
24
+ import type { ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
25
+ import type { GenesisData } from '@aztec/stdlib/world-state';
22
26
  import {
23
27
  type TelemetryClient,
24
28
  getConfigEnvVars as getTelemetryClientConfig,
25
29
  initTelemetryClient,
26
30
  } from '@aztec/telemetry-client';
27
- import { TestWallet, deployFundedSchnorrAccounts } from '@aztec/test-wallet/server';
31
+ import { EmbeddedWallet } from '@aztec/wallets/embedded';
32
+ import { deployFundedSchnorrAccounts } from '@aztec/wallets/testing';
28
33
  import { getGenesisValues } from '@aztec/world-state/testing';
29
34
 
30
35
  import { type Hex, createPublicClient, fallback, http as httpViemTransport } from 'viem';
@@ -35,6 +40,8 @@ import { createAccountLogs } from '../cli/util.js';
35
40
  import { DefaultMnemonic } from '../mnemonic.js';
36
41
  import { AnvilTestWatcher } from '../testing/anvil_test_watcher.js';
37
42
  import { EpochTestSettler } from '../testing/epoch_test_settler.js';
43
+ import { getTokenAllowedSetupFunctions } from '../testing/token_allowed_setup.js';
44
+ import { publishStandardAuthRegistry } from './auth_registry.js';
38
45
  import { getBananaFPCAddress, setupBananaFPC } from './banana_fpc.js';
39
46
  import { getSponsoredFPCAddress } from './sponsored_fpc.js';
40
47
 
@@ -51,11 +58,10 @@ export async function deployContractsToL1(
51
58
  aztecNodeConfig: AztecNodeConfig,
52
59
  privateKey: Hex,
53
60
  opts: {
54
- assumeProvenThroughBlockNumber?: number;
55
61
  genesisArchiveRoot?: Fr;
56
62
  feeJuicePortalInitialBalance?: bigint;
57
63
  } = {},
58
- ) {
64
+ ): Promise<L1ContractAddresses> {
59
65
  await waitForPublicClient(aztecNodeConfig);
60
66
 
61
67
  const l1Contracts = await deployAztecL1Contracts(aztecNodeConfig.l1RpcUrls[0], privateKey, foundry.id, {
@@ -66,14 +72,14 @@ export async function deployContractsToL1(
66
72
  genesisArchiveRoot: opts.genesisArchiveRoot ?? new Fr(GENESIS_ARCHIVE_ROOT),
67
73
  feeJuicePortalInitialBalance: opts.feeJuicePortalInitialBalance,
68
74
  aztecTargetCommitteeSize: 0, // no committee in local network
69
- slasherFlavor: 'none', // no slashing in local network
75
+ slasherEnabled: false, // no slashing in local network
70
76
  realVerifier: false,
71
77
  });
72
78
 
73
- aztecNodeConfig.l1Contracts = l1Contracts.l1ContractAddresses;
79
+ Object.assign(aztecNodeConfig, l1Contracts.l1ContractAddresses);
74
80
  aztecNodeConfig.rollupVersion = l1Contracts.rollupVersion;
75
81
 
76
- return aztecNodeConfig.l1Contracts;
82
+ return l1Contracts.l1ContractAddresses;
77
83
  }
78
84
 
79
85
  /** Local network settings. */
@@ -99,18 +105,25 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
99
105
  logger.warn(`Multiple L1 RPC URLs provided. Local networks will only use the first one: ${l1RpcUrl}`);
100
106
  }
101
107
 
108
+ // The local network deploys a banana FPC with Token contracts, so include Token entries
109
+ // in the setup allowlist so FPC-based fee payments work out of the box.
110
+ const tokenAllowList = await getTokenAllowedSetupFunctions();
111
+
102
112
  const aztecNodeConfig: AztecNodeConfig = {
103
113
  ...getConfigEnvVars(),
104
114
  ...config,
115
+ txPublicSetupAllowListExtend: [...tokenAllowList, ...(config.txPublicSetupAllowListExtend ?? [])],
105
116
  };
106
117
  const hdAccount = mnemonicToAccount(config.l1Mnemonic || DefaultMnemonic);
107
118
  if (
108
- aztecNodeConfig.publisherPrivateKeys == undefined ||
109
- !aztecNodeConfig.publisherPrivateKeys.length ||
110
- aztecNodeConfig.publisherPrivateKeys[0].getValue() === NULL_KEY
119
+ aztecNodeConfig.sequencerPublisherPrivateKeys == undefined ||
120
+ !aztecNodeConfig.sequencerPublisherPrivateKeys.length ||
121
+ aztecNodeConfig.sequencerPublisherPrivateKeys[0].getValue() === NULL_KEY
111
122
  ) {
112
123
  const privKey = hdAccount.getHdKey().privateKey;
113
- aztecNodeConfig.publisherPrivateKeys = [new SecretValue(`0x${Buffer.from(privKey!).toString('hex')}` as const)];
124
+ aztecNodeConfig.sequencerPublisherPrivateKeys = [
125
+ new SecretValue(`0x${Buffer.from(privKey!).toString('hex')}` as const),
126
+ ];
114
127
  }
115
128
  if (!aztecNodeConfig.validatorPrivateKeys?.getValue().length) {
116
129
  const privKey = hdAccount.getHdKey().privateKey;
@@ -134,10 +147,13 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
134
147
 
135
148
  const bananaFPC = await getBananaFPCAddress(initialAccounts);
136
149
  const sponsoredFPC = await getSponsoredFPCAddress();
137
- const fundedAddresses = initialAccounts.length
138
- ? [...initialAccounts.map(a => a.address), bananaFPC, sponsoredFPC]
139
- : [];
140
- const { genesisArchiveRoot, prefilledPublicData, fundingNeeded } = await getGenesisValues(fundedAddresses);
150
+ const prefundAddresses = (aztecNodeConfig.prefundAddresses ?? []).map(a => AztecAddress.fromString(a));
151
+ const fundedAddresses = [
152
+ ...initialAccounts.map(a => a.address),
153
+ ...(initialAccounts.length ? [bananaFPC, sponsoredFPC] : []),
154
+ ...prefundAddresses,
155
+ ];
156
+ const { genesisArchiveRoot, genesis, fundingNeeded } = await getGenesisValues(fundedAddresses);
141
157
 
142
158
  const dateProvider = new TestDateProvider();
143
159
 
@@ -149,7 +165,6 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
149
165
  aztecNodeConfig,
150
166
  aztecNodeConfig.validatorPrivateKeys.getValue()[0],
151
167
  {
152
- assumeProvenThroughBlockNumber: Number.MAX_SAFE_INTEGER,
153
168
  genesisArchiveRoot,
154
169
  feeJuicePortalInitialBalance: fundingNeeded,
155
170
  },
@@ -177,29 +192,64 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
177
192
  const telemetry = await initTelemetryClient(getTelemetryClientConfig());
178
193
  // Create a local blob client client inside the local network, no http connectivity
179
194
  const blobClient = createBlobClient();
180
- const node = await createAztecNode(aztecNodeConfig, { telemetry, blobClient, dateProvider }, { prefilledPublicData });
195
+ const node = await createAztecNode(aztecNodeConfig, { telemetry, blobClient, dateProvider }, { genesis });
196
+
197
+ // Now that the node is up, let the watcher check for pending txs so it can skip unfilled slots faster when
198
+ // transactions are waiting in the mempool. Also let it check if the sequencer is actively building, to avoid
199
+ // warping time out from under an in-progress block.
200
+ watcher?.setGetPendingTxCount(() => node.getPendingTxCount());
201
+ const sequencer = node.getSequencer()?.getSequencer();
202
+ if (sequencer) {
203
+ const idleStates: Set<string> = new Set([
204
+ SequencerState.STOPPED,
205
+ SequencerState.STOPPING,
206
+ SequencerState.IDLE,
207
+ SequencerState.SYNCHRONIZING,
208
+ ]);
209
+ watcher?.setIsSequencerBuilding(() => !idleStates.has(sequencer.getState()));
210
+ // Under proposer pipelining the L1 publish for slot N happens during wall-clock slot N,
211
+ // but the proposer for slot N has already built the checkpoint during slot N-1 and is
212
+ // waiting for L1 to advance. We need to fast-forward L1 to wake that wait — and the wait
213
+ // we have to break first is `waitForValidParentCheckpointOnL1`, which blocks the
214
+ // checkpoint_proposal_job's background submission task until the archiver has synced past
215
+ // the build slot. That wait happens *before* `PUBLISHING_CHECKPOINT` is set, so a hook on
216
+ // that state transition would be circular (L1 has to advance before the state we'd use to
217
+ // advance L1 fires). The earliest pre-wait signal is `block-proposed`, which the sequencer
218
+ // emits once each block is built. In sandbox single-block-per-slot mode this is
219
+ // effectively "checkpoint built", and the watcher warp is harmless if a subsequent
220
+ // assembly/validation/parent-wait step aborts: L1 just sits one slot ahead, which the
221
+ // cascade absorbs.
222
+ if (watcher) {
223
+ sequencer.on('block-proposed', ({ slot }) => watcher!.setProposedTargetSlot(Number(slot)));
224
+ }
225
+ }
181
226
 
182
227
  let epochTestSettler: EpochTestSettler | undefined;
183
228
  if (!aztecNodeConfig.p2pEnabled) {
184
- epochTestSettler = new EpochTestSettler(cheatcodes!, rollupAddress!, node.getBlockSource(), {
185
- pollingIntervalMs: 200,
186
- });
229
+ epochTestSettler = new EpochTestSettler(
230
+ cheatcodes!,
231
+ rollupAddress!,
232
+ node.getBlockSource(),
233
+ logger.createChild('epoch-settler'),
234
+ { pollingIntervalMs: 200 },
235
+ );
187
236
  await epochTestSettler.start();
188
237
  }
189
238
 
190
239
  if (initialAccounts.length) {
191
- const PXEConfig = { proverEnabled: aztecNodeConfig.realProofs };
192
- const wallet = await TestWallet.create(node, PXEConfig);
240
+ const wallet = await EmbeddedWallet.create(node, {
241
+ pxeConfig: { proverEnabled: aztecNodeConfig.realProofs },
242
+ ephemeral: true,
243
+ });
193
244
 
194
245
  userLog('Setting up funded test accounts...');
195
- const accountManagers = await deployFundedSchnorrAccounts(wallet, node, initialAccounts);
196
- const accountsWithSecrets = accountManagers.map((manager, i) => ({
197
- account: manager,
198
- secretKey: initialAccounts[i].secret,
199
- }));
200
- const accLogs = await createAccountLogs(accountsWithSecrets, wallet);
246
+ const accountManagers = await deployFundedSchnorrAccounts(wallet, initialAccounts);
247
+ const accLogs = await createAccountLogs(accountManagers, wallet);
201
248
  userLog(accLogs.join(''));
202
249
 
250
+ userLog('Publishing standard AuthRegistry contract...');
251
+ await publishStandardAuthRegistry(wallet, initialAccounts[0].address);
252
+
203
253
  await setupBananaFPC(initialAccounts, wallet, userLog);
204
254
 
205
255
  userLog(`SponsoredFPC: ${await getSponsoredFPCAddress()}`);
@@ -223,16 +273,24 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
223
273
  */
224
274
  export async function createAztecNode(
225
275
  config: Partial<AztecNodeConfig> = {},
226
- deps: { telemetry?: TelemetryClient; blobClient?: BlobClientInterface; dateProvider?: DateProvider } = {},
227
- options: { prefilledPublicData?: PublicDataTreeLeaf[] } = {},
276
+ deps: {
277
+ telemetry?: TelemetryClient;
278
+ blobClient?: BlobClientInterface;
279
+ dateProvider?: DateProvider;
280
+ proverBroker?: ProvingJobBroker;
281
+ } = {},
282
+ options: { genesis?: GenesisData } = {},
228
283
  ) {
229
284
  // TODO(#12272): will clean this up. This is criminal.
230
- const { l1Contracts, ...rest } = getConfigEnvVars();
285
+ // Not sure why this was ever done. Will be fixed in A-989, A-991, A-990.
231
286
  const aztecNodeConfig: AztecNodeConfig = {
232
- ...rest,
287
+ ...getConfigEnvVars(),
233
288
  ...config,
234
- l1Contracts: { ...l1Contracts, ...config.l1Contracts },
235
289
  };
236
- const node = await AztecNodeService.createAndSync(aztecNodeConfig, deps, options);
290
+ const node = await AztecNodeService.createAndSync(
291
+ aztecNodeConfig,
292
+ { ...deps, proverNodeDeps: { broker: deps.proverBroker } },
293
+ options,
294
+ );
237
295
  return node;
238
296
  }
@@ -9,6 +9,11 @@ import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
9
9
 
10
10
  import { type GetContractReturnType, getAddress, getContract } from 'viem';
11
11
 
12
+ export type AnvilTestWatcherOpts = {
13
+ isLocalNetwork?: boolean;
14
+ isMarkingAsProven?: boolean;
15
+ };
16
+
12
17
  /**
13
18
  * Represents a watcher for a rollup contract.
14
19
  *
@@ -17,7 +22,8 @@ import { type GetContractReturnType, getAddress, getContract } from 'viem';
17
22
  * block within the slot. And if so, it will time travel into the next slot.
18
23
  */
19
24
  export class AnvilTestWatcher {
20
- private isLocalNetwork: boolean = false;
25
+ private isLocalNetwork;
26
+ private isMarkingAsProven;
21
27
 
22
28
  private rollup: GetContractReturnType<typeof RollupAbi, ViemClient>;
23
29
  private rollupCheatCodes: RollupCheatCodes;
@@ -29,13 +35,27 @@ export class AnvilTestWatcher {
29
35
 
30
36
  private logger: Logger = createLogger(`aztecjs:utils:watcher`);
31
37
 
32
- private isMarkingAsProven = true;
38
+ // Optional callback to check if there are pending txs in the mempool.
39
+ private getPendingTxCount?: () => Promise<number>;
40
+
41
+ // Optional callback to check if the sequencer is actively building a block.
42
+ private isSequencerBuilding?: () => boolean;
43
+
44
+ // Tracks when we first observed the current unfilled slot with pending txs (real wall time).
45
+ private unfilledSlotFirstSeen?: { slot: number; realTime: number };
46
+
47
+ // Latest target slot for which the proposer has built a block destined for L1 but which has
48
+ // not yet been committed. Set by the proposer-pipelining hook from `block-proposed` events so
49
+ // the watcher can advance L1 (and the injected date provider) to the target slot ahead of the
50
+ // publisher's `sendRequestsAt` sleep, instead of waiting a full wall-clock slot.
51
+ private proposedTargetSlot?: number;
33
52
 
34
53
  constructor(
35
54
  private cheatcodes: EthCheatCodes,
36
55
  rollupAddress: EthAddress,
37
56
  l1Client: ViemClient,
38
57
  private dateProvider?: TestDateProvider,
58
+ opts: AnvilTestWatcherOpts = {},
39
59
  ) {
40
60
  this.rollup = getContract({
41
61
  address: getAddress(rollupAddress.toString()),
@@ -47,6 +67,9 @@ export class AnvilTestWatcher {
47
67
  rollupAddress,
48
68
  });
49
69
 
70
+ this.isLocalNetwork = opts.isLocalNetwork ?? false;
71
+ this.isMarkingAsProven = opts.isMarkingAsProven ?? true;
72
+
50
73
  this.logger.debug(`Watcher created for rollup at ${rollupAddress}`);
51
74
  }
52
75
 
@@ -59,6 +82,28 @@ export class AnvilTestWatcher {
59
82
  this.isLocalNetwork = isLocalNetwork;
60
83
  }
61
84
 
85
+ /** Sets a callback to check for pending txs, used to skip unfilled slots faster when txs are waiting. */
86
+ setGetPendingTxCount(fn: () => Promise<number>) {
87
+ this.getPendingTxCount = fn;
88
+ }
89
+
90
+ /** Sets a callback to check if the sequencer is actively building, to avoid warping while it works. */
91
+ setIsSequencerBuilding(fn: () => boolean) {
92
+ this.isSequencerBuilding = fn;
93
+ }
94
+
95
+ /**
96
+ * Records the target slot for which the proposer has built a block destined for L1. Used by
97
+ * the local-network watcher to fast-forward L1 (and the injected date provider) ahead of the
98
+ * pipelined publisher's `sendRequestsAt` sleep so it ends promptly instead of waiting a full
99
+ * wall-clock slot. Only ratchets up — late warps for stale slots are no-ops.
100
+ */
101
+ setProposedTargetSlot(slot: number) {
102
+ if (this.proposedTargetSlot === undefined || slot > this.proposedTargetSlot) {
103
+ this.proposedTargetSlot = slot;
104
+ }
105
+ }
106
+
62
107
  async start() {
63
108
  if (this.filledRunningPromise) {
64
109
  throw new Error('Watcher already watching for filled slot');
@@ -111,14 +156,21 @@ export class AnvilTestWatcher {
111
156
  return;
112
157
  }
113
158
 
114
- const l1Time = (await this.cheatcodes.timestamp()) * 1000;
159
+ const l1Time = (await this.cheatcodes.lastBlockTimestamp()) * 1000;
115
160
  const wallTime = this.dateProvider.now();
116
161
  if (l1Time > wallTime) {
117
162
  this.logger.warn(`L1 is ahead of wall time. Syncing wall time to L1 time`);
118
163
  this.dateProvider.setTime(l1Time);
119
164
  } else if (l1Time + Number(this.l2SlotDuration) * 1000 < wallTime) {
120
- this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to wall time`);
121
- await this.cheatcodes.warp(Math.ceil(wallTime / 1000));
165
+ // Warp L1 to the slot boundary at-or-before wall time. Rounding to a slot boundary (rather than
166
+ // `ceil(wallTime / 1000)`) keeps this loop's target aligned with `warpTimeIfNeeded`'s
167
+ // `nextSlotTimestamp` target, avoiding a race where the two loops pick timestamps a fraction of
168
+ // a second apart and one of them is then rejected by anvil as non-monotonic.
169
+ const wallSec = Math.floor(wallTime / 1000);
170
+ const targetSlot = await this.rollup.read.getSlotAt([BigInt(wallSec)]);
171
+ const targetTimestamp = Number(await this.rollup.read.getTimestampForSlot([targetSlot]));
172
+ this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to slot ${targetSlot} boundary`);
173
+ await this.warpToTimestamp(targetTimestamp);
122
174
  }
123
175
  }
124
176
 
@@ -131,16 +183,10 @@ export class AnvilTestWatcher {
131
183
  const nextSlotTimestamp = Number(await this.rollup.read.getTimestampForSlot([BigInt(nextSlot)]));
132
184
 
133
185
  if (BigInt(currentSlot) === checkpointLog.slotNumber) {
134
- // We should jump to the next slot
135
- try {
136
- await this.cheatcodes.warp(nextSlotTimestamp, {
137
- resetBlockInterval: true,
138
- });
139
- } catch (e) {
140
- this.logger.error(`Failed to warp to timestamp ${nextSlotTimestamp}: ${e}`);
186
+ // The current slot has been filled, we should jump to the next slot.
187
+ if (await this.warpToTimestamp(nextSlotTimestamp)) {
188
+ this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
141
189
  }
142
-
143
- this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
144
190
  return;
145
191
  }
146
192
 
@@ -149,18 +195,79 @@ export class AnvilTestWatcher {
149
195
  return;
150
196
  }
151
197
 
198
+ // Pipelined-publish shortcut: if the proposer has built a block destined for a slot
199
+ // beyond the current L1 slot, fast-forward L1 to that slot's timestamp so the publisher's
200
+ // `sendRequestsAt(targetSlot)` sleep ends and the multicall mines inside the target slot.
201
+ // Without this, the publisher waits up to a full real-time slot for wall clock to catch up.
202
+ if (this.proposedTargetSlot !== undefined && this.proposedTargetSlot > currentSlot) {
203
+ const targetSlotTimestamp = Number(
204
+ await this.rollup.read.getTimestampForSlot([BigInt(this.proposedTargetSlot)]),
205
+ );
206
+ if (await this.warpToTimestamp(targetSlotTimestamp)) {
207
+ this.logger.info(`Warped L1 to target slot ${this.proposedTargetSlot} for pipelined publish`);
208
+ }
209
+ return;
210
+ }
211
+
212
+ // If there are pending txs and the sequencer missed them, warp quickly (after a 2s real-time debounce) so the
213
+ // sequencer can retry in the next slot. Without this, we'd have to wait a full real-time slot duration (~36s) for
214
+ // the dateProvider to catch up to the next slot timestamp. We skip the warp if the sequencer is actively building
215
+ // to avoid invalidating its in-progress work.
216
+ if (this.getPendingTxCount) {
217
+ const pendingTxs = await this.getPendingTxCount();
218
+ if (pendingTxs > 0) {
219
+ if (this.isSequencerBuilding?.()) {
220
+ this.unfilledSlotFirstSeen = undefined;
221
+ return;
222
+ }
223
+
224
+ const realNow = Date.now();
225
+ if (!this.unfilledSlotFirstSeen || this.unfilledSlotFirstSeen.slot !== currentSlot) {
226
+ this.unfilledSlotFirstSeen = { slot: currentSlot, realTime: realNow };
227
+ return;
228
+ }
229
+
230
+ if (realNow - this.unfilledSlotFirstSeen.realTime > 2000) {
231
+ if (await this.warpToTimestamp(nextSlotTimestamp)) {
232
+ this.logger.info(`Slot ${currentSlot} was missed with pending txs, jumped to next slot`);
233
+ }
234
+ this.unfilledSlotFirstSeen = undefined;
235
+ }
236
+
237
+ return;
238
+ }
239
+ }
240
+
241
+ // Fallback: warp when the dateProvider time has passed the next slot timestamp.
152
242
  const currentTimestamp = this.dateProvider?.now() ?? Date.now();
153
243
  if (currentTimestamp > nextSlotTimestamp * 1000) {
154
- try {
155
- await this.cheatcodes.warp(nextSlotTimestamp, { resetBlockInterval: true });
156
- } catch (e) {
157
- this.logger.error(`Failed to warp to timestamp ${nextSlotTimestamp}: ${e}`);
244
+ if (await this.warpToTimestamp(nextSlotTimestamp)) {
245
+ this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
158
246
  }
159
-
160
- this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
161
247
  }
162
248
  } catch {
163
249
  this.logger.error('mineIfSlotFilled failed');
164
250
  }
165
251
  }
252
+
253
+ /**
254
+ * Warps L1 to `timestamp`, unless L1 is already at or past it. Returns true when a warp actually
255
+ * happened, false when skipped or on error. Callers use the return value to gate success logs.
256
+ */
257
+ private async warpToTimestamp(timestamp: number): Promise<boolean> {
258
+ try {
259
+ // Anvil rejects evm_setNextBlockTimestamp values <= the current block's timestamp. The two
260
+ // watcher loops can race and pick targets a fraction of a second apart; skip here rather than
261
+ // letting the second one error out noisily.
262
+ const lastTimestamp = await this.cheatcodes.lastBlockTimestamp();
263
+ if (timestamp <= lastTimestamp) {
264
+ return false;
265
+ }
266
+ await this.cheatcodes.warp(timestamp, { resetBlockInterval: true });
267
+ return true;
268
+ } catch (e) {
269
+ this.logger.error(`Failed to warp to timestamp ${timestamp}: ${e}`);
270
+ return false;
271
+ }
272
+ }
166
273
  }
@@ -1,9 +1,9 @@
1
1
  import { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
2
- import { BlockNumber } from '@aztec/foundation/branded-types';
3
- import { retryUntil } from '@aztec/foundation/retry';
2
+ import { SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { createLogger } from '@aztec/foundation/log';
4
4
  import type { DateProvider } from '@aztec/foundation/timer';
5
- import type { SequencerClient } from '@aztec/sequencer-client';
6
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
5
+ import type { AutomineSequencer } from '@aztec/sequencer-client';
6
+ import type { AztecNode, AztecNodeDebug } from '@aztec/stdlib/interfaces/client';
7
7
 
8
8
  /**
9
9
  * A class that provides utility functions for interacting with the chain.
@@ -12,68 +12,121 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
12
12
  * codes, please consider whether it makes sense to just introduce new utils in your tests instead.
13
13
  */
14
14
  export class CheatCodes {
15
+ private logger = createLogger('aztecjs:cheat_codes');
16
+
15
17
  constructor(
16
18
  /** Cheat codes for L1.*/
17
19
  public eth: EthCheatCodes,
18
20
  /** Cheat codes for the Aztec Rollup contract on L1. */
19
21
  public rollup: RollupCheatCodes,
22
+ /** When wired, redirects time-warps through the AutomineSequencer queue (test-only). */
23
+ private automine?: AutomineSequencer,
20
24
  ) {}
21
25
 
22
- static async create(rpcUrls: string[], node: AztecNode, dateProvider: DateProvider): Promise<CheatCodes> {
26
+ static async create(
27
+ rpcUrls: string[],
28
+ node: AztecNode,
29
+ dateProvider: DateProvider,
30
+ automine?: AutomineSequencer,
31
+ ): Promise<CheatCodes> {
23
32
  const ethCheatCodes = new EthCheatCodes(rpcUrls, dateProvider);
24
33
  const rollupCheatCodes = new RollupCheatCodes(
25
34
  ethCheatCodes,
26
35
  await node.getNodeInfo().then(n => n.l1ContractAddresses),
27
36
  );
28
- return new CheatCodes(ethCheatCodes, rollupCheatCodes);
37
+ return new CheatCodes(ethCheatCodes, rollupCheatCodes, automine);
29
38
  }
30
39
 
31
40
  /**
32
41
  * Warps the L1 timestamp to a target timestamp and mines an L2 block that advances the L2 timestamp to at least
33
- * the target timestamp. L2 timestamp is not advanced exactly to the target timestamp because it is determined
34
- * by the slot number, which advances in fixed intervals.
35
- * This is useful for testing time-dependent contract behavior.
36
- * @param sequencerClient - The sequencer client to use to force an empty block to be mined.
37
- * @param node - The Aztec node used to query if a new block has been mined.
42
+ * the target timestamp. If the target timestamp falls within the current L2 slot (which already has a block),
43
+ * the timestamp is automatically adjusted forward to the start of the next slot so that `mineBlock()` succeeds.
44
+ * @param node - The Aztec node used to force an empty block to be mined.
38
45
  * @param targetTimestamp - The target timestamp to warp to (in seconds)
39
46
  */
40
- async warpL2TimeAtLeastTo(sequencerClient: SequencerClient, node: AztecNode, targetTimestamp: bigint | number) {
41
- const currentL2BlockNumber: BlockNumber = await node.getBlockNumber();
47
+ async warpL2TimeAtLeastTo(node: AztecNode & AztecNodeDebug, targetTimestamp: bigint | number) {
48
+ const targetBigInt = BigInt(targetTimestamp);
49
+ const currentTimestamp = BigInt(await this.eth.lastBlockTimestamp());
42
50
 
43
- // We warp the L1 timestamp
44
- await this.eth.warp(targetTimestamp, { resetBlockInterval: true });
51
+ if (targetBigInt <= currentTimestamp) {
52
+ throw new Error(
53
+ `warpL2TimeAtLeastTo: target timestamp ${targetBigInt} is not in the future (current L1 timestamp is ${currentTimestamp}).`,
54
+ );
55
+ }
45
56
 
46
- // Wait until an L2 block is mined
47
- const sequencer = sequencerClient.getSequencer();
48
- const minTxsPerBlock = sequencer.getConfig().minTxsPerBlock;
49
- sequencer.updateConfig({ minTxsPerBlock: 0 });
57
+ // AutomineSequencer owns time control through its serial queue — delegate to keep warps atomic
58
+ // with respect to any in-flight build, and avoid the mineBlock-loop hack below.
59
+ // `warpTo` internally builds an empty L2 checkpoint, which auto-mines exactly one L1 block at
60
+ // the target slot boundary, so no separate `node.mineBlock()` is needed here.
61
+ if (this.automine) {
62
+ await this.automine.warpTo(Number(targetBigInt));
63
+ return;
64
+ }
50
65
 
51
- await retryUntil(
52
- async () => {
53
- const newL2BlockNumber: BlockNumber = await node.getBlockNumber();
54
- return newL2BlockNumber > currentL2BlockNumber;
55
- },
56
- 'new block after warping L2 time',
57
- 36,
58
- 1,
59
- );
66
+ const currentSlot = await this.rollup.getSlot();
67
+ const targetSlot = await this.rollup.getSlotAt(targetBigInt);
68
+
69
+ let effectiveTimestamp = targetBigInt;
70
+ let effectiveTargetSlot = targetSlot;
71
+
72
+ if (targetSlot <= currentSlot) {
73
+ // Target lands in the same (or earlier) slot — auto-adjust to the next slot's start.
74
+ const nextSlot = SlotNumber(currentSlot + 1);
75
+ const nextSlotTimestamp = await this.rollup.getTimestampForSlot(nextSlot);
76
+ this.logger.warn(
77
+ `warpL2TimeAtLeastTo: target timestamp ${targetBigInt} falls in current slot ${currentSlot}. ` +
78
+ `Auto-adjusting to start of slot ${nextSlot} at timestamp ${nextSlotTimestamp}.`,
79
+ );
80
+ effectiveTimestamp = nextSlotTimestamp;
81
+ effectiveTargetSlot = nextSlot;
82
+ }
60
83
 
61
- // Restore original minTxsPerBlock
62
- sequencer.updateConfig({ minTxsPerBlock });
84
+ await this.eth.warp(effectiveTimestamp, { resetBlockInterval: true });
85
+
86
+ // The sequencer's polling loop may have a `work()` cycle in flight that captured pre-warp slot/timestamp values
87
+ // just before our warp landed. That cycle would mine an L2 block at the stale slot — the L1 sync prunes such a
88
+ // block from the canonical chain, but it lingers in local world state and the PXE will use it as the anchor for
89
+ // subsequent txs, leading to `expiration_timestamp` values that are already in the past relative to L1. Mine
90
+ // until we observe an L2 block at (or past) the post-warp slot, ensuring the next tx anchors to a fresh block.
91
+ const maxAttempts = 5;
92
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
93
+ await node.mineBlock();
94
+ const blockData = await node.getBlockData('latest');
95
+ const blockSlot = blockData?.header.globalVariables.slotNumber;
96
+ if (blockSlot !== undefined && BigInt(blockSlot) >= BigInt(effectiveTargetSlot)) {
97
+ return;
98
+ }
99
+ this.logger.warn(
100
+ `warpL2TimeAtLeastTo: mined L2 block at slot ${blockSlot}, expected at least ${effectiveTargetSlot}. ` +
101
+ `Retrying mineBlock (attempt ${attempt}/${maxAttempts}).`,
102
+ );
103
+ }
104
+ throw new Error(
105
+ `warpL2TimeAtLeastTo: failed to mine an L2 block at or past slot ${effectiveTargetSlot} after ${maxAttempts} attempts.`,
106
+ );
63
107
  }
64
108
 
65
109
  /**
66
110
  * Warps the L1 timestamp forward by a specified duration and mines an L2 block that advances the L2 timestamp at
67
- * least by the duration. L2 timestamp is not advanced exactly by the duration because it is determined by the slot
68
- * number, which advances in fixed intervals.
69
- * This is useful for testing time-dependent contract behavior.
70
- * @param sequencerClient - The sequencer client to use to force an empty block to be mined.
71
- * @param node - The Aztec node used to query if a new block has been mined.
111
+ * least by the duration. If the duration is too short to cross an L2 slot boundary, the warp is automatically
112
+ * extended to the start of the next slot so that `mineBlock()` succeeds.
113
+ * @param node - The Aztec node used to force an empty block to be mined.
72
114
  * @param duration - The duration to advance time by (in seconds)
73
115
  */
74
- async warpL2TimeAtLeastBy(sequencerClient: SequencerClient, node: AztecNode, duration: bigint | number) {
75
- const currentTimestamp = await this.eth.timestamp();
76
- const targetTimestamp = BigInt(currentTimestamp) + BigInt(duration);
77
- await this.warpL2TimeAtLeastTo(sequencerClient, node, targetTimestamp);
116
+ async warpL2TimeAtLeastBy(node: AztecNode & AztecNodeDebug, duration: bigint | number) {
117
+ if (BigInt(duration) <= 0n) {
118
+ throw new Error(`warpL2TimeAtLeastBy: duration must be positive, got ${duration} seconds.`);
119
+ }
120
+
121
+ // Advance relative to whichever clock leads. A live sequencer mines L2 blocks at slot boundaries that can run
122
+ // ahead of anvil's L1 timestamp, so basing the target on L1 alone would advance the L2 timestamp by less than
123
+ // `duration`. Anchoring to the latest L2 block timestamp when it leads guarantees the post-warp L2 block is at
124
+ // least `duration` ahead of the current one.
125
+ const currentL1Timestamp = BigInt(await this.eth.lastBlockTimestamp());
126
+ const latestBlockData = await node.getBlockData('latest');
127
+ const latestL2Timestamp = latestBlockData ? BigInt(latestBlockData.header.globalVariables.timestamp) : 0n;
128
+ const baseTimestamp = latestL2Timestamp > currentL1Timestamp ? latestL2Timestamp : currentL1Timestamp;
129
+ const targetTimestamp = baseTimestamp + BigInt(duration);
130
+ await this.warpL2TimeAtLeastTo(node, targetTimestamp);
78
131
  }
79
132
  }