@aztec/aztec 0.0.1-commit.f5d02921e → 0.0.1-commit.f7ea82942

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 (48) hide show
  1. package/dest/cli/aztec_start_action.d.ts +1 -1
  2. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  3. package/dest/cli/aztec_start_action.js +12 -3
  4. package/dest/cli/aztec_start_options.d.ts +2 -2
  5. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  6. package/dest/cli/aztec_start_options.js +13 -0
  7. package/dest/cli/cmds/compile.d.ts +1 -1
  8. package/dest/cli/cmds/compile.d.ts.map +1 -1
  9. package/dest/cli/cmds/compile.js +1 -14
  10. package/dest/cli/cmds/standby.d.ts +1 -1
  11. package/dest/cli/cmds/standby.js +2 -2
  12. package/dest/cli/cmds/start_archiver.d.ts +1 -1
  13. package/dest/cli/cmds/start_archiver.d.ts.map +1 -1
  14. package/dest/cli/cmds/start_archiver.js +3 -1
  15. package/dest/cli/cmds/start_node.d.ts +1 -1
  16. package/dest/cli/cmds/start_node.d.ts.map +1 -1
  17. package/dest/cli/cmds/start_node.js +6 -20
  18. package/dest/cli/cmds/start_prover_agent.d.ts +1 -1
  19. package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
  20. package/dest/cli/cmds/start_prover_agent.js +3 -15
  21. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +2 -2
  22. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -1
  23. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +33 -12
  24. package/dest/local-network/local-network.d.ts +3 -4
  25. package/dest/local-network/local-network.d.ts.map +1 -1
  26. package/dest/local-network/local-network.js +3 -3
  27. package/dest/testing/anvil_test_watcher.d.ts +7 -3
  28. package/dest/testing/anvil_test_watcher.d.ts.map +1 -1
  29. package/dest/testing/anvil_test_watcher.js +39 -13
  30. package/dest/testing/cheat_codes.d.ts +11 -15
  31. package/dest/testing/cheat_codes.d.ts.map +1 -1
  32. package/dest/testing/cheat_codes.js +33 -31
  33. package/dest/testing/index.d.ts +2 -2
  34. package/dest/testing/index.d.ts.map +1 -1
  35. package/package.json +33 -33
  36. package/scripts/aztec.sh +5 -1
  37. package/src/cli/aztec_start_action.ts +6 -3
  38. package/src/cli/aztec_start_options.ts +19 -2
  39. package/src/cli/cmds/compile.ts +1 -17
  40. package/src/cli/cmds/standby.ts +2 -2
  41. package/src/cli/cmds/start_archiver.ts +7 -1
  42. package/src/cli/cmds/start_node.ts +9 -11
  43. package/src/cli/cmds/start_prover_agent.ts +3 -6
  44. package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +35 -12
  45. package/src/local-network/local-network.ts +5 -5
  46. package/src/testing/anvil_test_watcher.ts +43 -12
  47. package/src/testing/cheat_codes.ts +41 -35
  48. package/src/testing/index.ts +1 -1
@@ -7,7 +7,25 @@ import { join } from 'path';
7
7
 
8
8
  import { collectCrateDirs } from './collect_crate_dirs.js';
9
9
 
10
- /** Warns if the `aztec` dependency tag in any crate's Nargo.toml doesn't match the CLI version. */
10
+ /** Returns true if the given git URL points to the AztecProtocol/aztec-nr repository. */
11
+ function isAztecNrGitUrl(gitUrl: string): boolean {
12
+ let url: URL;
13
+ try {
14
+ url = new URL(gitUrl);
15
+ } catch {
16
+ return false;
17
+ }
18
+ if (url.hostname !== 'github.com') {
19
+ return false;
20
+ }
21
+ const repoPath = url.pathname
22
+ .replace(/^\//, '')
23
+ .replace(/\.git$/, '')
24
+ .replace(/\/$/, '');
25
+ return repoPath === 'AztecProtocol/aztec-nr';
26
+ }
27
+
28
+ /** Warns if any aztec-nr git dependency in a crate's Nargo.toml has a tag that doesn't match the CLI version. */
11
29
  export async function warnIfAztecVersionMismatch(log: LogFn, cliVersion?: string): Promise<void> {
12
30
  const version = cliVersion ?? getPackageVersion();
13
31
  if (!version) {
@@ -16,7 +34,7 @@ export async function warnIfAztecVersionMismatch(log: LogFn, cliVersion?: string
16
34
  }
17
35
 
18
36
  const expectedTag = `v${version}`;
19
- const mismatches: { file: string; tag: string }[] = [];
37
+ const mismatches: { file: string; depName: string; tag: string }[] = [];
20
38
 
21
39
  const crateDirs = await collectCrateDirs('.', { skipGitDeps: true });
22
40
 
@@ -30,23 +48,28 @@ export async function warnIfAztecVersionMismatch(log: LogFn, cliVersion?: string
30
48
  }
31
49
 
32
50
  const parsed = TOML.parse(content) as Record<string, any>;
33
- const aztecDep = (parsed.dependencies as Record<string, any>)?.aztec;
34
- if (!aztecDep || typeof aztecDep !== 'object' || typeof aztecDep.tag !== 'string') {
35
- // If a dep called "aztec" doesn't exist or it does not get parsed to an object or it doesn't have a tag defined
36
- // we skip the check.
37
- continue;
38
- }
51
+ const deps = (parsed.dependencies as Record<string, any>) ?? {};
39
52
 
40
- if (aztecDep.tag !== expectedTag) {
41
- mismatches.push({ file: tomlPath, tag: aztecDep.tag });
53
+ for (const [depName, dep] of Object.entries(deps)) {
54
+ // Skip non-object deps (e.g. malformed entries) and anything that isn't a tagged git dep.
55
+ if (!dep || typeof dep !== 'object' || typeof dep.git !== 'string' || typeof dep.tag !== 'string') {
56
+ continue;
57
+ }
58
+ // Only flag deps that are sourced from the aztec-nr repo.
59
+ if (!isAztecNrGitUrl(dep.git)) {
60
+ continue;
61
+ }
62
+ if (dep.tag !== expectedTag) {
63
+ mismatches.push({ file: tomlPath, depName, tag: dep.tag });
64
+ }
42
65
  }
43
66
  }
44
67
 
45
68
  if (mismatches.length > 0) {
46
- const details = mismatches.map(m => ` ${m.file} (${m.tag})`).join('\n');
69
+ const details = mismatches.map(m => ` ${m.file} — ${m.depName} (${m.tag})`).join('\n');
47
70
  log(
48
71
  `WARNING: Aztec dependency version mismatch detected.\n` +
49
- `The following crates have an aztec dependency that does not match the CLI version (${expectedTag}):\n` +
72
+ `The following aztec-nr dependencies do not match the CLI version (${expectedTag}):\n` +
50
73
  `${details}\n\n` +
51
74
  `See https://docs.aztec.network/errors/9 for how to update your dependencies.`,
52
75
  );
@@ -21,7 +21,7 @@ import { protocolContractsHash } from '@aztec/protocol-contracts';
21
21
  import { SequencerState } from '@aztec/sequencer-client';
22
22
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
23
23
  import type { ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
24
- import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
24
+ import type { GenesisData } from '@aztec/stdlib/world-state';
25
25
  import {
26
26
  type TelemetryClient,
27
27
  getConfigEnvVars as getTelemetryClientConfig,
@@ -70,7 +70,7 @@ export async function deployContractsToL1(
70
70
  genesisArchiveRoot: opts.genesisArchiveRoot ?? new Fr(GENESIS_ARCHIVE_ROOT),
71
71
  feeJuicePortalInitialBalance: opts.feeJuicePortalInitialBalance,
72
72
  aztecTargetCommitteeSize: 0, // no committee in local network
73
- slasherFlavor: 'none', // no slashing in local network
73
+ slasherEnabled: false, // no slashing in local network
74
74
  realVerifier: false,
75
75
  });
76
76
 
@@ -151,7 +151,7 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
151
151
  ...(initialAccounts.length ? [bananaFPC, sponsoredFPC] : []),
152
152
  ...prefundAddresses,
153
153
  ];
154
- const { genesisArchiveRoot, prefilledPublicData, fundingNeeded } = await getGenesisValues(fundedAddresses);
154
+ const { genesisArchiveRoot, genesis, fundingNeeded } = await getGenesisValues(fundedAddresses);
155
155
 
156
156
  const dateProvider = new TestDateProvider();
157
157
 
@@ -190,7 +190,7 @@ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {
190
190
  const telemetry = await initTelemetryClient(getTelemetryClientConfig());
191
191
  // Create a local blob client client inside the local network, no http connectivity
192
192
  const blobClient = createBlobClient();
193
- const node = await createAztecNode(aztecNodeConfig, { telemetry, blobClient, dateProvider }, { prefilledPublicData });
193
+ const node = await createAztecNode(aztecNodeConfig, { telemetry, blobClient, dateProvider }, { genesis });
194
194
 
195
195
  // Now that the node is up, let the watcher check for pending txs so it can skip unfilled slots faster when
196
196
  // transactions are waiting in the mempool. Also let it check if the sequencer is actively building, to avoid
@@ -259,7 +259,7 @@ export async function createAztecNode(
259
259
  dateProvider?: DateProvider;
260
260
  proverBroker?: ProvingJobBroker;
261
261
  } = {},
262
- options: { prefilledPublicData?: PublicDataTreeLeaf[] } = {},
262
+ options: { genesis?: GenesisData } = {},
263
263
  ) {
264
264
  // TODO(#12272): will clean this up. This is criminal.
265
265
  const { l1Contracts, ...rest } = getConfigEnvVars();
@@ -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,8 +35,6 @@ export class AnvilTestWatcher {
29
35
 
30
36
  private logger: Logger = createLogger(`aztecjs:utils:watcher`);
31
37
 
32
- private isMarkingAsProven = true;
33
-
34
38
  // Optional callback to check if there are pending txs in the mempool.
35
39
  private getPendingTxCount?: () => Promise<number>;
36
40
 
@@ -45,6 +49,7 @@ export class AnvilTestWatcher {
45
49
  rollupAddress: EthAddress,
46
50
  l1Client: ViemClient,
47
51
  private dateProvider?: TestDateProvider,
52
+ opts: AnvilTestWatcherOpts = {},
48
53
  ) {
49
54
  this.rollup = getContract({
50
55
  address: getAddress(rollupAddress.toString()),
@@ -56,6 +61,9 @@ export class AnvilTestWatcher {
56
61
  rollupAddress,
57
62
  });
58
63
 
64
+ this.isLocalNetwork = opts.isLocalNetwork ?? false;
65
+ this.isMarkingAsProven = opts.isMarkingAsProven ?? true;
66
+
59
67
  this.logger.debug(`Watcher created for rollup at ${rollupAddress}`);
60
68
  }
61
69
 
@@ -136,8 +144,15 @@ export class AnvilTestWatcher {
136
144
  this.logger.warn(`L1 is ahead of wall time. Syncing wall time to L1 time`);
137
145
  this.dateProvider.setTime(l1Time);
138
146
  } else if (l1Time + Number(this.l2SlotDuration) * 1000 < wallTime) {
139
- this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to wall time`);
140
- await this.cheatcodes.warp(Math.ceil(wallTime / 1000));
147
+ // Warp L1 to the slot boundary at-or-before wall time. Rounding to a slot boundary (rather than
148
+ // `ceil(wallTime / 1000)`) keeps this loop's target aligned with `warpTimeIfNeeded`'s
149
+ // `nextSlotTimestamp` target, avoiding a race where the two loops pick timestamps a fraction of
150
+ // a second apart and one of them is then rejected by anvil as non-monotonic.
151
+ const wallSec = Math.floor(wallTime / 1000);
152
+ const targetSlot = await this.rollup.read.getSlotAt([BigInt(wallSec)]);
153
+ const targetTimestamp = Number(await this.rollup.read.getTimestampForSlot([targetSlot]));
154
+ this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to slot ${targetSlot} boundary`);
155
+ await this.warpToTimestamp(targetTimestamp);
141
156
  }
142
157
  }
143
158
 
@@ -151,8 +166,9 @@ export class AnvilTestWatcher {
151
166
 
152
167
  if (BigInt(currentSlot) === checkpointLog.slotNumber) {
153
168
  // The current slot has been filled, we should jump to the next slot.
154
- await this.warpToTimestamp(nextSlotTimestamp);
155
- this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
169
+ if (await this.warpToTimestamp(nextSlotTimestamp)) {
170
+ this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
171
+ }
156
172
  return;
157
173
  }
158
174
 
@@ -180,9 +196,10 @@ export class AnvilTestWatcher {
180
196
  }
181
197
 
182
198
  if (realNow - this.unfilledSlotFirstSeen.realTime > 2000) {
183
- await this.warpToTimestamp(nextSlotTimestamp);
199
+ if (await this.warpToTimestamp(nextSlotTimestamp)) {
200
+ this.logger.info(`Slot ${currentSlot} was missed with pending txs, jumped to next slot`);
201
+ }
184
202
  this.unfilledSlotFirstSeen = undefined;
185
- this.logger.info(`Slot ${currentSlot} was missed with pending txs, jumped to next slot`);
186
203
  }
187
204
 
188
205
  return;
@@ -192,19 +209,33 @@ export class AnvilTestWatcher {
192
209
  // Fallback: warp when the dateProvider time has passed the next slot timestamp.
193
210
  const currentTimestamp = this.dateProvider?.now() ?? Date.now();
194
211
  if (currentTimestamp > nextSlotTimestamp * 1000) {
195
- await this.warpToTimestamp(nextSlotTimestamp);
196
- this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
212
+ if (await this.warpToTimestamp(nextSlotTimestamp)) {
213
+ this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
214
+ }
197
215
  }
198
216
  } catch {
199
217
  this.logger.error('mineIfSlotFilled failed');
200
218
  }
201
219
  }
202
220
 
203
- private async warpToTimestamp(timestamp: number) {
221
+ /**
222
+ * Warps L1 to `timestamp`, unless L1 is already at or past it. Returns true when a warp actually
223
+ * happened, false when skipped or on error. Callers use the return value to gate success logs.
224
+ */
225
+ private async warpToTimestamp(timestamp: number): Promise<boolean> {
204
226
  try {
227
+ // Anvil rejects evm_setNextBlockTimestamp values <= the current block's timestamp. The two
228
+ // watcher loops can race and pick targets a fraction of a second apart; skip here rather than
229
+ // letting the second one error out noisily.
230
+ const lastTimestamp = await this.cheatcodes.lastBlockTimestamp();
231
+ if (timestamp <= lastTimestamp) {
232
+ return false;
233
+ }
205
234
  await this.cheatcodes.warp(timestamp, { resetBlockInterval: true });
235
+ return true;
206
236
  } catch (e) {
207
237
  this.logger.error(`Failed to warp to timestamp ${timestamp}: ${e}`);
238
+ return false;
208
239
  }
209
240
  }
210
241
  }
@@ -1,9 +1,8 @@
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 { AztecNode, AztecNodeDebug } from '@aztec/stdlib/interfaces/client';
7
6
 
8
7
  /**
9
8
  * A class that provides utility functions for interacting with the chain.
@@ -12,6 +11,8 @@ import type { AztecNode } from '@aztec/stdlib/interfaces/client';
12
11
  * codes, please consider whether it makes sense to just introduce new utils in your tests instead.
13
12
  */
14
13
  export class CheatCodes {
14
+ private logger = createLogger('aztecjs:cheat_codes');
15
+
15
16
  constructor(
16
17
  /** Cheat codes for L1.*/
17
18
  public eth: EthCheatCodes,
@@ -30,50 +31,55 @@ export class CheatCodes {
30
31
 
31
32
  /**
32
33
  * 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.
34
+ * the target timestamp. If the target timestamp falls within the current L2 slot (which already has a block),
35
+ * the timestamp is automatically adjusted forward to the start of the next slot so that `mineBlock()` succeeds.
36
+ * @param node - The Aztec node used to force an empty block to be mined.
38
37
  * @param targetTimestamp - The target timestamp to warp to (in seconds)
39
38
  */
40
- async warpL2TimeAtLeastTo(sequencerClient: SequencerClient, node: AztecNode, targetTimestamp: bigint | number) {
41
- const currentL2BlockNumber: BlockNumber = await node.getBlockNumber();
39
+ async warpL2TimeAtLeastTo(node: AztecNodeDebug, targetTimestamp: bigint | number) {
40
+ const targetBigInt = BigInt(targetTimestamp);
41
+ const currentTimestamp = BigInt(await this.eth.lastBlockTimestamp());
42
42
 
43
- // We warp the L1 timestamp
44
- await this.eth.warp(targetTimestamp, { resetBlockInterval: true });
43
+ if (targetBigInt <= currentTimestamp) {
44
+ throw new Error(
45
+ `warpL2TimeAtLeastTo: target timestamp ${targetBigInt} is not in the future (current L1 timestamp is ${currentTimestamp}).`,
46
+ );
47
+ }
45
48
 
46
- // Wait until an L2 block is mined
47
- const sequencer = sequencerClient.getSequencer();
48
- const minTxsPerBlock = sequencer.getConfig().minTxsPerBlock;
49
- sequencer.updateConfig({ minTxsPerBlock: 0 });
49
+ const currentSlot = await this.rollup.getSlot();
50
+ const targetSlot = await this.rollup.getSlotAt(targetBigInt);
50
51
 
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
- );
52
+ let effectiveTimestamp = targetBigInt;
60
53
 
61
- // Restore original minTxsPerBlock
62
- sequencer.updateConfig({ minTxsPerBlock });
54
+ if (targetSlot <= currentSlot) {
55
+ // Target lands in the same (or earlier) slot — auto-adjust to the next slot's start.
56
+ const nextSlot = SlotNumber(currentSlot + 1);
57
+ const nextSlotTimestamp = await this.rollup.getTimestampForSlot(nextSlot);
58
+ this.logger.warn(
59
+ `warpL2TimeAtLeastTo: target timestamp ${targetBigInt} falls in current slot ${currentSlot}. ` +
60
+ `Auto-adjusting to start of slot ${nextSlot} at timestamp ${nextSlotTimestamp}.`,
61
+ );
62
+ effectiveTimestamp = nextSlotTimestamp;
63
+ }
64
+
65
+ await this.eth.warp(effectiveTimestamp, { resetBlockInterval: true });
66
+ await node.mineBlock();
63
67
  }
64
68
 
65
69
  /**
66
70
  * 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.
71
+ * least by the duration. If the duration is too short to cross an L2 slot boundary, the warp is automatically
72
+ * extended to the start of the next slot so that `mineBlock()` succeeds.
73
+ * @param node - The Aztec node used to force an empty block to be mined.
72
74
  * @param duration - The duration to advance time by (in seconds)
73
75
  */
74
- async warpL2TimeAtLeastBy(sequencerClient: SequencerClient, node: AztecNode, duration: bigint | number) {
76
+ async warpL2TimeAtLeastBy(node: AztecNodeDebug, duration: bigint | number) {
77
+ if (BigInt(duration) <= 0n) {
78
+ throw new Error(`warpL2TimeAtLeastBy: duration must be positive, got ${duration} seconds.`);
79
+ }
80
+
75
81
  const currentTimestamp = await this.eth.lastBlockTimestamp();
76
82
  const targetTimestamp = BigInt(currentTimestamp) + BigInt(duration);
77
- await this.warpL2TimeAtLeastTo(sequencerClient, node, targetTimestamp);
83
+ await this.warpL2TimeAtLeastTo(node, targetTimestamp);
78
84
  }
79
85
  }
@@ -1,4 +1,4 @@
1
- export { AnvilTestWatcher } from './anvil_test_watcher.js';
1
+ export { AnvilTestWatcher, type AnvilTestWatcherOpts } from './anvil_test_watcher.js';
2
2
  export { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
3
3
  export { CheatCodes } from './cheat_codes.js';
4
4
  export { EpochTestSettler } from './epoch_test_settler.js';