@aztec/aztec 0.0.1-commit.b33fc05d0 → 0.0.1-commit.b3d3157a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dest/bin/index.js +1 -1
  2. package/dest/cli/aztec_start_action.d.ts +1 -1
  3. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  4. package/dest/cli/aztec_start_action.js +28 -12
  5. package/dest/cli/aztec_start_options.d.ts +2 -2
  6. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  7. package/dest/cli/aztec_start_options.js +14 -14
  8. package/dest/cli/cmds/compile.d.ts +1 -1
  9. package/dest/cli/cmds/compile.d.ts.map +1 -1
  10. package/dest/cli/cmds/compile.js +8 -8
  11. package/dest/cli/cmds/profile.d.ts +1 -1
  12. package/dest/cli/cmds/profile.d.ts.map +1 -1
  13. package/dest/cli/cmds/profile.js +1 -1
  14. package/dest/cli/cmds/profile_gates.d.ts +2 -2
  15. package/dest/cli/cmds/profile_gates.d.ts.map +1 -1
  16. package/dest/cli/cmds/profile_gates.js +21 -3
  17. package/dest/cli/cmds/standby.d.ts +12 -9
  18. package/dest/cli/cmds/standby.d.ts.map +1 -1
  19. package/dest/cli/cmds/standby.js +36 -17
  20. package/dest/cli/cmds/start_bot.d.ts +1 -1
  21. package/dest/cli/cmds/start_bot.d.ts.map +1 -1
  22. package/dest/cli/cmds/start_bot.js +3 -3
  23. package/dest/cli/cmds/start_node.d.ts +1 -1
  24. package/dest/cli/cmds/start_node.d.ts.map +1 -1
  25. package/dest/cli/cmds/start_node.js +15 -25
  26. package/dest/cli/cmds/start_prover_agent.d.ts +1 -1
  27. package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
  28. package/dest/cli/cmds/start_prover_agent.js +5 -17
  29. package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
  30. package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
  31. package/dest/cli/cmds/start_prover_broker.js +17 -8
  32. package/dest/cli/cmds/start_txe.d.ts +2 -2
  33. package/dest/cli/cmds/start_txe.d.ts.map +1 -1
  34. package/dest/cli/cmds/start_txe.js +6 -5
  35. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts +21 -0
  36. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts.map +1 -0
  37. package/dest/cli/cmds/utils/collect_crate_dirs.js +114 -0
  38. package/dest/cli/cmds/utils/needs_recompile.d.ts +1 -1
  39. package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -1
  40. package/dest/cli/cmds/utils/needs_recompile.js +9 -53
  41. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +4 -0
  42. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -0
  43. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +61 -0
  44. package/dest/cli/util.js +7 -5
  45. package/dest/local-network/auth_registry.d.ts +5 -0
  46. package/dest/local-network/auth_registry.d.ts.map +1 -0
  47. package/dest/local-network/auth_registry.js +17 -0
  48. package/dest/local-network/banana_fpc.d.ts +3 -2
  49. package/dest/local-network/banana_fpc.d.ts.map +1 -1
  50. package/dest/local-network/banana_fpc.js +11 -7
  51. package/dest/local-network/local-network.d.ts +5 -28
  52. package/dest/local-network/local-network.d.ts.map +1 -1
  53. package/dest/local-network/local-network.js +36 -14
  54. package/dest/testing/anvil_test_watcher.d.ts +15 -3
  55. package/dest/testing/anvil_test_watcher.d.ts.map +1 -1
  56. package/dest/testing/anvil_test_watcher.js +68 -14
  57. package/dest/testing/cheat_codes.d.ts +18 -17
  58. package/dest/testing/cheat_codes.d.ts.map +1 -1
  59. package/dest/testing/cheat_codes.js +72 -36
  60. package/dest/testing/epoch_test_settler.d.ts +1 -1
  61. package/dest/testing/epoch_test_settler.d.ts.map +1 -1
  62. package/dest/testing/epoch_test_settler.js +6 -4
  63. package/dest/testing/index.d.ts +2 -2
  64. package/dest/testing/index.d.ts.map +1 -1
  65. package/package.json +34 -34
  66. package/scripts/add_crate.sh +11 -60
  67. package/scripts/aztec.sh +6 -2
  68. package/scripts/init.sh +5 -5
  69. package/scripts/new.sh +2 -2
  70. package/scripts/setup_workspace.sh +3 -2
  71. package/scripts/templates/blank/contract/Nargo.toml +6 -0
  72. package/scripts/templates/blank/contract/src/main.nr +10 -0
  73. package/scripts/templates/blank/test/Nargo.toml +7 -0
  74. package/scripts/templates/blank/test/src/lib.nr +11 -0
  75. package/scripts/templates/counter/contract/Nargo.toml +7 -0
  76. package/scripts/templates/counter/contract/src/main.nr +48 -0
  77. package/scripts/templates/counter/test/Nargo.toml +7 -0
  78. package/scripts/templates/counter/test/src/lib.nr +32 -0
  79. package/src/bin/index.ts +1 -1
  80. package/src/cli/aztec_start_action.ts +21 -12
  81. package/src/cli/aztec_start_options.ts +21 -22
  82. package/src/cli/cmds/compile.ts +10 -9
  83. package/src/cli/cmds/profile.ts +2 -1
  84. package/src/cli/cmds/profile_gates.ts +20 -4
  85. package/src/cli/cmds/standby.ts +41 -20
  86. package/src/cli/cmds/start_bot.ts +3 -5
  87. package/src/cli/cmds/start_node.ts +20 -17
  88. package/src/cli/cmds/start_prover_agent.ts +5 -8
  89. package/src/cli/cmds/start_prover_broker.ts +17 -11
  90. package/src/cli/cmds/start_txe.ts +7 -5
  91. package/src/cli/cmds/utils/collect_crate_dirs.ts +118 -0
  92. package/src/cli/cmds/utils/needs_recompile.ts +8 -61
  93. package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +76 -0
  94. package/src/cli/util.ts +7 -7
  95. package/src/local-network/auth_registry.ts +19 -0
  96. package/src/local-network/banana_fpc.ts +12 -8
  97. package/src/local-network/local-network.ts +39 -13
  98. package/src/testing/anvil_test_watcher.ts +76 -13
  99. package/src/testing/cheat_codes.ts +92 -39
  100. package/src/testing/epoch_test_settler.ts +3 -4
  101. package/src/testing/index.ts +1 -1
  102. package/dest/cli/cmds/start_archiver.d.ts +0 -9
  103. package/dest/cli/cmds/start_archiver.d.ts.map +0 -1
  104. package/dest/cli/cmds/start_archiver.js +0 -48
  105. package/src/cli/cmds/start_archiver.ts +0 -50
@@ -1,5 +1,6 @@
1
1
  import { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
2
- import { retryUntil } from '@aztec/foundation/retry';
2
+ import { SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { createLogger } from '@aztec/foundation/log';
3
4
  /**
4
5
  * A class that provides utility functions for interacting with the chain.
5
6
  * @deprecated There used to be 3 kinds of cheat codes: eth, rollup and aztec. We have nuked the Aztec ones because
@@ -8,55 +9,90 @@ import { retryUntil } from '@aztec/foundation/retry';
8
9
  */ export class CheatCodes {
9
10
  eth;
10
11
  rollup;
11
- constructor(/** Cheat codes for L1.*/ eth, /** Cheat codes for the Aztec Rollup contract on L1. */ rollup){
12
+ automine;
13
+ logger;
14
+ constructor(/** Cheat codes for L1.*/ eth, /** Cheat codes for the Aztec Rollup contract on L1. */ rollup, /** When wired, redirects time-warps through the AutomineSequencer queue (test-only). */ automine){
12
15
  this.eth = eth;
13
16
  this.rollup = rollup;
17
+ this.automine = automine;
18
+ this.logger = createLogger('aztecjs:cheat_codes');
14
19
  }
15
- static async create(rpcUrls, node, dateProvider) {
20
+ static async create(rpcUrls, node, dateProvider, automine) {
16
21
  const ethCheatCodes = new EthCheatCodes(rpcUrls, dateProvider);
17
22
  const rollupCheatCodes = new RollupCheatCodes(ethCheatCodes, await node.getNodeInfo().then((n)=>n.l1ContractAddresses));
18
- return new CheatCodes(ethCheatCodes, rollupCheatCodes);
23
+ return new CheatCodes(ethCheatCodes, rollupCheatCodes, automine);
19
24
  }
20
25
  /**
21
26
  * Warps the L1 timestamp to a target timestamp and mines an L2 block that advances the L2 timestamp to at least
22
- * the target timestamp. L2 timestamp is not advanced exactly to the target timestamp because it is determined
23
- * by the slot number, which advances in fixed intervals.
24
- * This is useful for testing time-dependent contract behavior.
25
- * @param sequencerClient - The sequencer client to use to force an empty block to be mined.
26
- * @param node - The Aztec node used to query if a new block has been mined.
27
+ * the target timestamp. If the target timestamp falls within the current L2 slot (which already has a block),
28
+ * the timestamp is automatically adjusted forward to the start of the next slot so that `mineBlock()` succeeds.
29
+ * @param node - The Aztec node used to force an empty block to be mined.
27
30
  * @param targetTimestamp - The target timestamp to warp to (in seconds)
28
- */ async warpL2TimeAtLeastTo(sequencerClient, node, targetTimestamp) {
29
- const currentL2BlockNumber = await node.getBlockNumber();
30
- // We warp the L1 timestamp
31
- await this.eth.warp(targetTimestamp, {
31
+ */ async warpL2TimeAtLeastTo(node, targetTimestamp) {
32
+ const targetBigInt = BigInt(targetTimestamp);
33
+ const currentTimestamp = BigInt(await this.eth.lastBlockTimestamp());
34
+ if (targetBigInt <= currentTimestamp) {
35
+ throw new Error(`warpL2TimeAtLeastTo: target timestamp ${targetBigInt} is not in the future (current L1 timestamp is ${currentTimestamp}).`);
36
+ }
37
+ // AutomineSequencer owns time control through its serial queue — delegate to keep warps atomic
38
+ // with respect to any in-flight build, and avoid the mineBlock-loop hack below.
39
+ // `warpTo` internally builds an empty L2 checkpoint, which auto-mines exactly one L1 block at
40
+ // the target slot boundary, so no separate `node.mineBlock()` is needed here.
41
+ if (this.automine) {
42
+ await this.automine.warpTo(Number(targetBigInt));
43
+ return;
44
+ }
45
+ const currentSlot = await this.rollup.getSlot();
46
+ const targetSlot = await this.rollup.getSlotAt(targetBigInt);
47
+ let effectiveTimestamp = targetBigInt;
48
+ let effectiveTargetSlot = targetSlot;
49
+ if (targetSlot <= currentSlot) {
50
+ // Target lands in the same (or earlier) slot — auto-adjust to the next slot's start.
51
+ const nextSlot = SlotNumber(currentSlot + 1);
52
+ const nextSlotTimestamp = await this.rollup.getTimestampForSlot(nextSlot);
53
+ this.logger.warn(`warpL2TimeAtLeastTo: target timestamp ${targetBigInt} falls in current slot ${currentSlot}. ` + `Auto-adjusting to start of slot ${nextSlot} at timestamp ${nextSlotTimestamp}.`);
54
+ effectiveTimestamp = nextSlotTimestamp;
55
+ effectiveTargetSlot = nextSlot;
56
+ }
57
+ await this.eth.warp(effectiveTimestamp, {
32
58
  resetBlockInterval: true
33
59
  });
34
- // Wait until an L2 block is mined
35
- const sequencer = sequencerClient.getSequencer();
36
- const minTxsPerBlock = sequencer.getConfig().minTxsPerBlock;
37
- sequencer.updateConfig({
38
- minTxsPerBlock: 0
39
- });
40
- await retryUntil(async ()=>{
41
- const newL2BlockNumber = await node.getBlockNumber();
42
- return newL2BlockNumber > currentL2BlockNumber;
43
- }, 'new block after warping L2 time', 36, 1);
44
- // Restore original minTxsPerBlock
45
- sequencer.updateConfig({
46
- minTxsPerBlock
47
- });
60
+ // The sequencer's polling loop may have a `work()` cycle in flight that captured pre-warp slot/timestamp values
61
+ // just before our warp landed. That cycle would mine an L2 block at the stale slot — the L1 sync prunes such a
62
+ // block from the canonical chain, but it lingers in local world state and the PXE will use it as the anchor for
63
+ // subsequent txs, leading to `expiration_timestamp` values that are already in the past relative to L1. Mine
64
+ // until we observe an L2 block at (or past) the post-warp slot, ensuring the next tx anchors to a fresh block.
65
+ const maxAttempts = 5;
66
+ for(let attempt = 1; attempt <= maxAttempts; attempt++){
67
+ await node.mineBlock();
68
+ const blockData = await node.getBlockData('latest');
69
+ const blockSlot = blockData?.header.globalVariables.slotNumber;
70
+ if (blockSlot !== undefined && BigInt(blockSlot) >= BigInt(effectiveTargetSlot)) {
71
+ return;
72
+ }
73
+ this.logger.warn(`warpL2TimeAtLeastTo: mined L2 block at slot ${blockSlot}, expected at least ${effectiveTargetSlot}. ` + `Retrying mineBlock (attempt ${attempt}/${maxAttempts}).`);
74
+ }
75
+ throw new Error(`warpL2TimeAtLeastTo: failed to mine an L2 block at or past slot ${effectiveTargetSlot} after ${maxAttempts} attempts.`);
48
76
  }
49
77
  /**
50
78
  * Warps the L1 timestamp forward by a specified duration and mines an L2 block that advances the L2 timestamp at
51
- * least by the duration. L2 timestamp is not advanced exactly by the duration because it is determined by the slot
52
- * number, which advances in fixed intervals.
53
- * This is useful for testing time-dependent contract behavior.
54
- * @param sequencerClient - The sequencer client to use to force an empty block to be mined.
55
- * @param node - The Aztec node used to query if a new block has been mined.
79
+ * least by the duration. If the duration is too short to cross an L2 slot boundary, the warp is automatically
80
+ * extended to the start of the next slot so that `mineBlock()` succeeds.
81
+ * @param node - The Aztec node used to force an empty block to be mined.
56
82
  * @param duration - The duration to advance time by (in seconds)
57
- */ async warpL2TimeAtLeastBy(sequencerClient, node, duration) {
58
- const currentTimestamp = await this.eth.timestamp();
59
- const targetTimestamp = BigInt(currentTimestamp) + BigInt(duration);
60
- await this.warpL2TimeAtLeastTo(sequencerClient, node, targetTimestamp);
83
+ */ async warpL2TimeAtLeastBy(node, duration) {
84
+ if (BigInt(duration) <= 0n) {
85
+ throw new Error(`warpL2TimeAtLeastBy: duration must be positive, got ${duration} seconds.`);
86
+ }
87
+ // Advance relative to whichever clock leads. A live sequencer mines L2 blocks at slot boundaries that can run
88
+ // ahead of anvil's L1 timestamp, so basing the target on L1 alone would advance the L2 timestamp by less than
89
+ // `duration`. Anchoring to the latest L2 block timestamp when it leads guarantees the post-warp L2 block is at
90
+ // least `duration` ahead of the current one.
91
+ const currentL1Timestamp = BigInt(await this.eth.lastBlockTimestamp());
92
+ const latestBlockData = await node.getBlockData('latest');
93
+ const latestL2Timestamp = latestBlockData ? BigInt(latestBlockData.header.globalVariables.timestamp) : 0n;
94
+ const baseTimestamp = latestL2Timestamp > currentL1Timestamp ? latestL2Timestamp : currentL1Timestamp;
95
+ const targetTimestamp = baseTimestamp + BigInt(duration);
96
+ await this.warpL2TimeAtLeastTo(node, targetTimestamp);
61
97
  }
62
98
  }
@@ -16,4 +16,4 @@ export declare class EpochTestSettler {
16
16
  stop(): Promise<void>;
17
17
  handleEpochReadyToProve(epoch: EpochNumber): Promise<boolean>;
18
18
  }
19
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXBvY2hfdGVzdF9zZXR0bGVyLmQudHMiLCJzb3VyY2VSb290I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,EAAE,UAAU,EACjB,aAAa,EAAE,aAAa,EAC5B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;QAAE,iBAAiB,EAAE,MAAM,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,EAGxE;IAEK,KAAK,kBAIV;IAEK,IAAI,kBAET;IAEK,uBAAuB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAmClE;CACF"}
@@ -27,8 +27,10 @@ export class EpochTestSettler {
27
27
  await this.epochMonitor?.stop();
28
28
  }
29
29
  async handleEpochReadyToProve(epoch) {
30
- const checkpointedBlocks = await this.l2BlockSource.getCheckpointedBlocksForEpoch(epoch);
31
- const blocks = checkpointedBlocks.map((b)=>b.block);
30
+ const blocks = await this.l2BlockSource.getBlocks({
31
+ epoch,
32
+ onlyCheckpointed: true
33
+ });
32
34
  this.log.info(`Settling epoch ${epoch} with blocks ${blocks[0]?.header.getBlockNumber()} to ${blocks.at(-1)?.header.getBlockNumber()}`, {
33
35
  blocks: blocks.map((b)=>b.toBlockInfo())
34
36
  });
@@ -46,11 +48,11 @@ export class EpochTestSettler {
46
48
  }
47
49
  const outHash = computeEpochOutHash(messagesInEpoch);
48
50
  if (!outHash.isZero()) {
49
- await this.rollupCheatCodes.insertOutbox(epoch, outHash.toBigInt());
51
+ await this.rollupCheatCodes.insertOutbox(epoch, messagesInEpoch.length, outHash.toBigInt());
50
52
  } else {
51
53
  this.log.info(`No L2 to L1 messages in epoch ${epoch}`);
52
54
  }
53
- const lastCheckpoint = checkpointedBlocks.at(-1)?.checkpointNumber;
55
+ const lastCheckpoint = blocks.at(-1)?.checkpointNumber;
54
56
  if (lastCheckpoint !== undefined) {
55
57
  await this.rollupCheatCodes.markAsProven(lastCheckpoint);
56
58
  } else {
@@ -1,6 +1,6 @@
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';
5
5
  export { getTokenAllowedSetupFunctions } from './token_allowed_setup.js';
6
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0aW5nL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQzNELE9BQU8sRUFBRSxhQUFhLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUN2RSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFDOUMsT0FBTyxFQUFFLGdCQUFnQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDM0QsT0FBTyxFQUFFLDZCQUE2QixFQUFFLE1BQU0sMEJBQTBCLENBQUMifQ==
6
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0aW5nL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxnQkFBZ0IsRUFBRSxLQUFLLG9CQUFvQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDdEYsT0FBTyxFQUFFLGFBQWEsRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ3ZFLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUM5QyxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUMzRCxPQUFPLEVBQUUsNkJBQTZCLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQyJ9
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/aztec",
3
- "version": "0.0.1-commit.b33fc05d0",
3
+ "version": "0.0.1-commit.b3d3157a",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -28,39 +28,39 @@
28
28
  "../package.common.json"
29
29
  ],
30
30
  "dependencies": {
31
- "@aztec/accounts": "0.0.1-commit.b33fc05d0",
32
- "@aztec/archiver": "0.0.1-commit.b33fc05d0",
33
- "@aztec/aztec-faucet": "0.0.1-commit.b33fc05d0",
34
- "@aztec/aztec-node": "0.0.1-commit.b33fc05d0",
35
- "@aztec/aztec.js": "0.0.1-commit.b33fc05d0",
36
- "@aztec/bb-prover": "0.0.1-commit.b33fc05d0",
37
- "@aztec/bb.js": "0.0.1-commit.b33fc05d0",
38
- "@aztec/blob-client": "0.0.1-commit.b33fc05d0",
39
- "@aztec/bot": "0.0.1-commit.b33fc05d0",
40
- "@aztec/builder": "0.0.1-commit.b33fc05d0",
41
- "@aztec/cli": "0.0.1-commit.b33fc05d0",
42
- "@aztec/constants": "0.0.1-commit.b33fc05d0",
43
- "@aztec/entrypoints": "0.0.1-commit.b33fc05d0",
44
- "@aztec/ethereum": "0.0.1-commit.b33fc05d0",
45
- "@aztec/foundation": "0.0.1-commit.b33fc05d0",
46
- "@aztec/kv-store": "0.0.1-commit.b33fc05d0",
47
- "@aztec/l1-artifacts": "0.0.1-commit.b33fc05d0",
48
- "@aztec/node-lib": "0.0.1-commit.b33fc05d0",
49
- "@aztec/noir-contracts.js": "0.0.1-commit.b33fc05d0",
50
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.b33fc05d0",
51
- "@aztec/p2p": "0.0.1-commit.b33fc05d0",
52
- "@aztec/p2p-bootstrap": "0.0.1-commit.b33fc05d0",
53
- "@aztec/protocol-contracts": "0.0.1-commit.b33fc05d0",
54
- "@aztec/prover-client": "0.0.1-commit.b33fc05d0",
55
- "@aztec/prover-node": "0.0.1-commit.b33fc05d0",
56
- "@aztec/pxe": "0.0.1-commit.b33fc05d0",
57
- "@aztec/sequencer-client": "0.0.1-commit.b33fc05d0",
58
- "@aztec/stdlib": "0.0.1-commit.b33fc05d0",
59
- "@aztec/telemetry-client": "0.0.1-commit.b33fc05d0",
60
- "@aztec/txe": "0.0.1-commit.b33fc05d0",
61
- "@aztec/validator-ha-signer": "0.0.1-commit.b33fc05d0",
62
- "@aztec/wallets": "0.0.1-commit.b33fc05d0",
63
- "@aztec/world-state": "0.0.1-commit.b33fc05d0",
31
+ "@aztec/accounts": "0.0.1-commit.b3d3157a",
32
+ "@aztec/archiver": "0.0.1-commit.b3d3157a",
33
+ "@aztec/aztec-node": "0.0.1-commit.b3d3157a",
34
+ "@aztec/aztec.js": "0.0.1-commit.b3d3157a",
35
+ "@aztec/bb-prover": "0.0.1-commit.b3d3157a",
36
+ "@aztec/bb.js": "0.0.1-commit.b3d3157a",
37
+ "@aztec/blob-client": "0.0.1-commit.b3d3157a",
38
+ "@aztec/bot": "0.0.1-commit.b3d3157a",
39
+ "@aztec/builder": "0.0.1-commit.b3d3157a",
40
+ "@aztec/cli": "0.0.1-commit.b3d3157a",
41
+ "@aztec/constants": "0.0.1-commit.b3d3157a",
42
+ "@aztec/entrypoints": "0.0.1-commit.b3d3157a",
43
+ "@aztec/ethereum": "0.0.1-commit.b3d3157a",
44
+ "@aztec/foundation": "0.0.1-commit.b3d3157a",
45
+ "@aztec/kv-store": "0.0.1-commit.b3d3157a",
46
+ "@aztec/l1-artifacts": "0.0.1-commit.b3d3157a",
47
+ "@aztec/node-lib": "0.0.1-commit.b3d3157a",
48
+ "@aztec/noir-contracts.js": "0.0.1-commit.b3d3157a",
49
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.b3d3157a",
50
+ "@aztec/p2p": "0.0.1-commit.b3d3157a",
51
+ "@aztec/p2p-bootstrap": "0.0.1-commit.b3d3157a",
52
+ "@aztec/protocol-contracts": "0.0.1-commit.b3d3157a",
53
+ "@aztec/prover-client": "0.0.1-commit.b3d3157a",
54
+ "@aztec/prover-node": "0.0.1-commit.b3d3157a",
55
+ "@aztec/pxe": "0.0.1-commit.b3d3157a",
56
+ "@aztec/sequencer-client": "0.0.1-commit.b3d3157a",
57
+ "@aztec/standard-contracts": "0.0.1-commit.b3d3157a",
58
+ "@aztec/stdlib": "0.0.1-commit.b3d3157a",
59
+ "@aztec/telemetry-client": "0.0.1-commit.b3d3157a",
60
+ "@aztec/txe": "0.0.1-commit.b3d3157a",
61
+ "@aztec/validator-ha-signer": "0.0.1-commit.b3d3157a",
62
+ "@aztec/wallets": "0.0.1-commit.b3d3157a",
63
+ "@aztec/world-state": "0.0.1-commit.b3d3157a",
64
64
  "@iarna/toml": "^2.2.5",
65
65
  "@types/chalk": "^2.2.0",
66
66
  "abitype": "^0.8.11",
@@ -2,10 +2,11 @@
2
2
  set -euo pipefail
3
3
 
4
4
  # Creates a contract+test crate pair and adds them to an existing workspace.
5
- # Usage: add_crate.sh <crate_name>
5
+ # Usage: add_crate.sh <crate_name> <template>
6
6
  # Must be called from a workspace root that already has Nargo.toml with [workspace].
7
7
 
8
8
  crate_name=$1
9
+ template=$2
9
10
 
10
11
  if [ -z "$crate_name" ]; then
11
12
  echo "Error: crate name is required"
@@ -31,72 +32,22 @@ fi
31
32
 
32
33
  # Get the actual aztec version for the git tag.
33
34
  AZTEC_VERSION=$(jq -r '.version' $(dirname $0)/../package.json)
35
+ TEMPLATE_DIR="$(dirname $0)/templates/$template"
34
36
 
35
- # Create contract crate
36
- mkdir -p "$contract_dir/src"
37
- cat > "$contract_dir/Nargo.toml" << CEOF
38
- [package]
39
- name = "${crate_name}_contract"
40
- type = "contract"
41
-
42
- [dependencies]
43
- aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v${AZTEC_VERSION}", directory="aztec" }
44
- CEOF
45
-
46
- cat > "$contract_dir/src/main.nr" << 'EOF'
47
- use aztec::macros::aztec;
48
-
49
- #[aztec]
50
- pub contract Main {
51
- use aztec::macros::functions::{external, initializer};
52
-
53
- #[initializer]
54
- #[external("private")]
55
- fn constructor() {}
56
- }
57
- EOF
58
-
59
- # Create test crate
60
- mkdir -p "$test_dir/src"
61
- cat > "$test_dir/Nargo.toml" << TEOF
62
- [package]
63
- name = "${crate_name}_test"
64
- type = "lib"
65
-
66
- [dependencies]
67
- aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v${AZTEC_VERSION}", directory="aztec" }
68
- ${crate_name}_contract = { path = "../${contract_dir}" }
69
- TEOF
70
-
71
- cat > "$test_dir/src/lib.nr" << 'NOIR'
72
- use aztec::test::helpers::test_environment::TestEnvironment;
73
- use __CRATE_NAME___contract::Main;
74
-
75
- #[test]
76
- unconstrained fn test_constructor() {
77
- let mut env = TestEnvironment::new();
78
- let deployer = env.create_light_account();
79
-
80
- // Deploy the contract with the default constructor:
81
- let contract_address = env.deploy("@__CRATE_NAME___contract/Main").with_private_initializer(
82
- deployer,
83
- Main::interface().constructor(),
84
- );
85
-
86
- // Deploy without an initializer:
87
- let contract_address = env.deploy("@__CRATE_NAME___contract/Main").without_initializer();
88
- }
89
- NOIR
90
-
91
- sed -i "s/__CRATE_NAME__/${crate_name}/g" "$test_dir/src/lib.nr"
37
+ # Copy template crates and substitute placeholders
38
+ cp -r "$TEMPLATE_DIR/contract" "$contract_dir"
39
+ cp -r "$TEMPLATE_DIR/test" "$test_dir"
40
+ # Use perl -i for portability across os.
41
+ find "$contract_dir" "$test_dir" -type f -exec \
42
+ perl -i -pe "s/__CRATE_NAME__/${crate_name}/g; s/__AZTEC_VERSION__/${AZTEC_VERSION}/g" {} +
92
43
 
93
44
  # Add members to workspace Nargo.toml
94
45
  if grep -q 'members\s*=\s*\[\s*\]' Nargo.toml; then
95
46
  # Empty array: members = []
96
- sed -i "s|members\s*=\s*\[\s*\]|members = [\"${contract_dir}\", \"${test_dir}\"]|" Nargo.toml
47
+ perl -i -pe "s|members\s*=\s*\[\s*\]|members = [\"${contract_dir}\", \"${test_dir}\"]|" Nargo.toml
97
48
  else
98
49
  # Non-empty array: add before closing ]
99
- sed -i "s|\(members\s*=\s*\[.*\)\]|\1, \"${contract_dir}\", \"${test_dir}\"]|" Nargo.toml
50
+ perl -i -pe "s|(members\s*=\s*\[.*)\]|\1, \"${contract_dir}\", \"${test_dir}\"]|" Nargo.toml
100
51
  fi
101
52
 
102
53
  echo "Created crates '${contract_dir}' and '${test_dir}'"
package/scripts/aztec.sh CHANGED
@@ -23,13 +23,17 @@ case $cmd in
23
23
  # Attempt to compile, no-op if there are no changes
24
24
  node --no-warnings "$script_dir/../dest/bin/index.js" compile
25
25
 
26
- export LOG_LEVEL="${LOG_LEVEL:-"error;trace:contract_log"}"
26
+ export LOG_LEVEL="${LOG_LEVEL:-"error;trace:^contract:"}"
27
27
  aztec start --txe --port 8081 &
28
28
  server_pid=$!
29
29
  trap 'kill $server_pid &>/dev/null || true' EXIT
30
+ if ! command -v nc &>/dev/null; then
31
+ echo "Error: 'nc' (netcat) is required but not installed." >&2
32
+ exit 1
33
+ fi
30
34
  while ! nc -z 127.0.0.1 8081 &>/dev/null; do sleep 0.2; done
31
35
  export NARGO_FOREIGN_CALL_TIMEOUT=300000
32
- nargo test --silence-warnings --oracle-resolver http://127.0.0.1:8081 --test-threads 16 "$@"
36
+ nargo test --silence-warnings --oracle-resolver http://127.0.0.1:8081 "$@"
33
37
  ;;
34
38
  start)
35
39
  if [ "${1:-}" == "--local-network" ]; then
package/scripts/init.sh CHANGED
@@ -16,11 +16,11 @@ Options:
16
16
  -h, --help Print help
17
17
 
18
18
  This command creates a new Aztec Noir project in the current directory with
19
- a workspace containing a contract crate and a test crate, and automatically
20
- adds the Aztec.nr dependency to both.
19
+ a workspace containing a Counter contract example with tests. The Counter
20
+ demonstrates private state, private functions, and utility reads.
21
21
 
22
- If a workspace already exists in the current directory, use
23
- 'aztec new <name>' instead to add another contract.
22
+ Use 'aztec new <name>' to create a blank contract project, or to add another
23
+ contract to an existing workspace.
24
24
  EOF
25
25
  exit 0
26
26
  ;;
@@ -36,4 +36,4 @@ done
36
36
  package_name="$(basename $(pwd))"
37
37
 
38
38
  echo "Initializing Aztec contract project..."
39
- $script_path/setup_workspace.sh "$package_name"
39
+ $script_path/setup_workspace.sh "$package_name" counter
package/scripts/new.sh CHANGED
@@ -68,7 +68,7 @@ fi
68
68
  if [ -f "Nargo.toml" ] && grep -q '\[workspace\]' Nargo.toml; then
69
69
  # Add crate pair to existing workspace
70
70
  echo "Adding contract '$package_name' to existing workspace..."
71
- $script_path/add_crate.sh "$package_name"
71
+ $script_path/add_crate.sh "$package_name" blank
72
72
  else
73
73
  # Create new workspace
74
74
  if [ -d "$project_path" ] && [ "$(ls -A $project_path 2>/dev/null)" ]; then
@@ -79,5 +79,5 @@ else
79
79
  echo "Creating new Aztec contract project at $project_path..."
80
80
  mkdir -p "$project_path"
81
81
  cd "$project_path"
82
- $script_path/setup_workspace.sh "$package_name"
82
+ $script_path/setup_workspace.sh "$package_name" blank
83
83
  fi
@@ -2,10 +2,11 @@
2
2
  set -euo pipefail
3
3
 
4
4
  # Creates an Aztec contract workspace with a contract crate and a test crate.
5
- # Usage: setup_workspace.sh <package_name>
5
+ # Usage: setup_workspace.sh <package_name> <template>
6
6
  # Must be called from the workspace root directory.
7
7
 
8
8
  package_name=$1
9
+ template=$2
9
10
  script_path=$(realpath $(dirname "$0"))
10
11
 
11
12
  if [ -z "$package_name" ]; then
@@ -26,7 +27,7 @@ members = []
26
27
  EOF
27
28
 
28
29
  # Create the first crate pair
29
- $script_path/add_crate.sh "$package_name"
30
+ $script_path/add_crate.sh "$package_name" "$template"
30
31
 
31
32
  # Create README
32
33
  cat > README.md << REOF
@@ -0,0 +1,6 @@
1
+ [package]
2
+ name = "__CRATE_NAME___contract"
3
+ type = "contract"
4
+
5
+ [dependencies]
6
+ aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v__AZTEC_VERSION__", directory="aztec" }
@@ -0,0 +1,10 @@
1
+ use aztec::macros::aztec;
2
+
3
+ #[aztec]
4
+ pub contract Main {
5
+ use aztec::macros::functions::{external, initializer};
6
+
7
+ #[initializer]
8
+ #[external("private")]
9
+ fn constructor() {}
10
+ }
@@ -0,0 +1,7 @@
1
+ [package]
2
+ name = "__CRATE_NAME___test"
3
+ type = "lib"
4
+
5
+ [dependencies]
6
+ aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v__AZTEC_VERSION__", directory="aztec" }
7
+ __CRATE_NAME___contract = { path = "../__CRATE_NAME___contract" }
@@ -0,0 +1,11 @@
1
+ use aztec::test::helpers::test_environment::TestEnvironment;
2
+ use __CRATE_NAME___contract::Main;
3
+
4
+ #[test]
5
+ unconstrained fn test_constructor() {
6
+ let mut env = TestEnvironment::new();
7
+ let deployer = env.create_light_account();
8
+
9
+ let _contract_address = env.deploy("@__CRATE_NAME___contract/Main")
10
+ .with_private_initializer(deployer, Main::interface().constructor());
11
+ }
@@ -0,0 +1,7 @@
1
+ [package]
2
+ name = "__CRATE_NAME___contract"
3
+ type = "contract"
4
+
5
+ [dependencies]
6
+ aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v__AZTEC_VERSION__", directory="aztec" }
7
+ balance_set = { git="https://github.com/AztecProtocol/aztec-nr", tag="v__AZTEC_VERSION__", directory="balance-set" }
@@ -0,0 +1,48 @@
1
+ use aztec::macros::aztec;
2
+
3
+ #[aztec]
4
+ pub contract Counter {
5
+ use aztec::{
6
+ macros::{functions::{external, initializer}, storage::storage},
7
+ messages::message_delivery::MessageDelivery,
8
+ protocol::address::AztecAddress,
9
+ state_vars::Owned,
10
+ };
11
+ use balance_set::BalanceSet;
12
+
13
+ #[storage]
14
+ struct Storage<Context> {
15
+ // Each owner has their own counter, stored as private encrypted notes.
16
+ // Owned: dictates who will receive the encrypted notes.
17
+ // BalanceSet: manages the underlying notes, providing add/sub/balance_of.
18
+ counters: Owned<BalanceSet<Context>, Context>,
19
+ }
20
+
21
+ // Sets the owner's counter to an initial value.
22
+ //
23
+ // #[external("private")]: executes on the user's device, inputs are hidden from everyone.
24
+ #[initializer]
25
+ #[external("private")]
26
+ fn constructor(initial_value: u128, owner: AztecAddress) {
27
+ // Delivers the note to the recipient onchain with provable correctness.
28
+ // Without delivery, the recipient can't find or decrypt the note.
29
+ self.storage.counters.at(owner).add(initial_value).deliver(
30
+ MessageDelivery::onchain_constrained(),
31
+ );
32
+ }
33
+
34
+ // Adds 1 to the owner's counter.
35
+ #[external("private")]
36
+ fn increment(owner: AztecAddress) {
37
+ self.storage.counters.at(owner).add(1).deliver(MessageDelivery::onchain_constrained());
38
+ }
39
+
40
+ // Returns the current value of the owner's counter.
41
+ //
42
+ // #[external("utility")]: runs off-chain, no transaction created, no cost.
43
+ // Only the owner can decrypt and read their own counter.
44
+ #[external("utility")]
45
+ unconstrained fn get_counter(owner: AztecAddress) -> u128 {
46
+ self.storage.counters.at(owner).balance_of()
47
+ }
48
+ }
@@ -0,0 +1,7 @@
1
+ [package]
2
+ name = "__CRATE_NAME___test"
3
+ type = "lib"
4
+
5
+ [dependencies]
6
+ aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v__AZTEC_VERSION__", directory="aztec" }
7
+ __CRATE_NAME___contract = { path = "../__CRATE_NAME___contract" }
@@ -0,0 +1,32 @@
1
+ use aztec::{protocol::address::AztecAddress, test::helpers::test_environment::TestEnvironment};
2
+ use __CRATE_NAME___contract::Counter;
3
+
4
+ unconstrained fn setup(initial_value: u128) -> (TestEnvironment, AztecAddress, AztecAddress) {
5
+ let mut env = TestEnvironment::new();
6
+ let owner = env.create_light_account();
7
+
8
+ let contract_address = env.deploy("@__CRATE_NAME___contract/Counter")
9
+ .with_private_initializer(owner, Counter::interface().constructor(initial_value, owner));
10
+
11
+ (env, contract_address, owner)
12
+ }
13
+
14
+ #[test]
15
+ unconstrained fn test_constructor() {
16
+ let initial_value = 5;
17
+ let (env, contract_address, owner) = setup(initial_value);
18
+
19
+ let counter = env.execute_utility(Counter::at(contract_address).get_counter(owner));
20
+ assert_eq(counter, initial_value);
21
+ }
22
+
23
+ #[test]
24
+ unconstrained fn test_increment() {
25
+ let initial_value = 5;
26
+ let (mut env, contract_address, owner) = setup(initial_value);
27
+
28
+ env.call_private(owner, Counter::at(contract_address).increment(owner));
29
+
30
+ let counter = env.execute_utility(Counter::at(contract_address).get_counter(owner));
31
+ assert_eq(counter, initial_value + 1);
32
+ }
package/src/bin/index.ts CHANGED
@@ -47,7 +47,7 @@ async function main() {
47
47
  await enrichEnvironmentWithNetworkConfig(networkName);
48
48
  enrichEnvironmentWithChainName(networkName);
49
49
 
50
- const cliVersion = getPackageVersion() ?? 'unknown';
50
+ const cliVersion = getPackageVersion();
51
51
  let program = new Command('aztec');
52
52
  program.description('Aztec command line interface').version(cliVersion).enablePositionalOptions();
53
53
  program = injectAztecCommands(program, userLog, debugLogger);