@aztec-labs/aztec 6.0.0-nightly.20260829

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +57 -0
  2. package/dest/bin/index.d.ts +3 -0
  3. package/dest/bin/index.d.ts.map +1 -0
  4. package/dest/bin/index.js +61 -0
  5. package/dest/cli/admin_api_key_store.d.ts +45 -0
  6. package/dest/cli/admin_api_key_store.d.ts.map +1 -0
  7. package/dest/cli/admin_api_key_store.js +98 -0
  8. package/dest/cli/aztec_start_action.d.ts +3 -0
  9. package/dest/cli/aztec_start_action.d.ts.map +1 -0
  10. package/dest/cli/aztec_start_action.js +153 -0
  11. package/dest/cli/aztec_start_options.d.ts +17 -0
  12. package/dest/cli/aztec_start_options.d.ts.map +1 -0
  13. package/dest/cli/aztec_start_options.js +290 -0
  14. package/dest/cli/cli.d.ts +9 -0
  15. package/dest/cli/cli.d.ts.map +1 -0
  16. package/dest/cli/cli.js +37 -0
  17. package/dest/cli/cmds/compile.d.ts +4 -0
  18. package/dest/cli/cmds/compile.d.ts.map +1 -0
  19. package/dest/cli/cmds/compile.js +174 -0
  20. package/dest/cli/cmds/migrate_ha_db.d.ts +3 -0
  21. package/dest/cli/cmds/migrate_ha_db.d.ts.map +1 -0
  22. package/dest/cli/cmds/migrate_ha_db.js +27 -0
  23. package/dest/cli/cmds/profile.d.ts +4 -0
  24. package/dest/cli/cmds/profile.d.ts.map +1 -0
  25. package/dest/cli/cmds/profile.js +8 -0
  26. package/dest/cli/cmds/profile_flamegraph.d.ts +4 -0
  27. package/dest/cli/cmds/profile_flamegraph.d.ts.map +1 -0
  28. package/dest/cli/cmds/profile_flamegraph.js +52 -0
  29. package/dest/cli/cmds/profile_gates.d.ts +4 -0
  30. package/dest/cli/cmds/profile_gates.d.ts.map +1 -0
  31. package/dest/cli/cmds/profile_gates.js +76 -0
  32. package/dest/cli/cmds/profile_utils.d.ts +18 -0
  33. package/dest/cli/cmds/profile_utils.d.ts.map +1 -0
  34. package/dest/cli/cmds/profile_utils.js +50 -0
  35. package/dest/cli/cmds/prover.d.ts +4 -0
  36. package/dest/cli/cmds/prover.d.ts.map +1 -0
  37. package/dest/cli/cmds/prover.js +24 -0
  38. package/dest/cli/cmds/standby.d.ts +56 -0
  39. package/dest/cli/cmds/standby.d.ts.map +1 -0
  40. package/dest/cli/cmds/standby.js +140 -0
  41. package/dest/cli/cmds/start_bot.d.ts +8 -0
  42. package/dest/cli/cmds/start_bot.d.ts.map +1 -0
  43. package/dest/cli/cmds/start_bot.js +53 -0
  44. package/dest/cli/cmds/start_node.d.ts +8 -0
  45. package/dest/cli/cmds/start_node.d.ts.map +1 -0
  46. package/dest/cli/cmds/start_node.js +150 -0
  47. package/dest/cli/cmds/start_p2p_bootstrap.d.ts +6 -0
  48. package/dest/cli/cmds/start_p2p_bootstrap.d.ts.map +1 -0
  49. package/dest/cli/cmds/start_p2p_bootstrap.js +30 -0
  50. package/dest/cli/cmds/start_prover_agent.d.ts +4 -0
  51. package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -0
  52. package/dest/cli/cmds/start_prover_agent.js +58 -0
  53. package/dest/cli/cmds/start_prover_broker.d.ts +9 -0
  54. package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -0
  55. package/dest/cli/cmds/start_prover_broker.js +46 -0
  56. package/dest/cli/cmds/start_txe.d.ts +3 -0
  57. package/dest/cli/cmds/start_txe.d.ts.map +1 -0
  58. package/dest/cli/cmds/start_txe.js +12 -0
  59. package/dest/cli/cmds/utils/artifacts.d.ts +26 -0
  60. package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -0
  61. package/dest/cli/cmds/utils/artifacts.js +24 -0
  62. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts +21 -0
  63. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts.map +1 -0
  64. package/dest/cli/cmds/utils/collect_crate_dirs.js +114 -0
  65. package/dest/cli/cmds/utils/needs_recompile.d.ts +10 -0
  66. package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -0
  67. package/dest/cli/cmds/utils/needs_recompile.js +90 -0
  68. package/dest/cli/cmds/utils/spawn.d.ts +3 -0
  69. package/dest/cli/cmds/utils/spawn.d.ts.map +1 -0
  70. package/dest/cli/cmds/utils/spawn.js +16 -0
  71. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +4 -0
  72. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -0
  73. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +61 -0
  74. package/dest/cli/index.d.ts +2 -0
  75. package/dest/cli/index.d.ts.map +1 -0
  76. package/dest/cli/index.js +1 -0
  77. package/dest/cli/preload_crs.d.ts +3 -0
  78. package/dest/cli/preload_crs.d.ts.map +1 -0
  79. package/dest/cli/preload_crs.js +6 -0
  80. package/dest/cli/util.d.ts +71 -0
  81. package/dest/cli/util.d.ts.map +1 -0
  82. package/dest/cli/util.js +261 -0
  83. package/dest/cli/versioning.d.ts +4 -0
  84. package/dest/cli/versioning.d.ts.map +1 -0
  85. package/dest/cli/versioning.js +9 -0
  86. package/dest/examples/token.d.ts +2 -0
  87. package/dest/examples/token.d.ts.map +1 -0
  88. package/dest/examples/token.js +59 -0
  89. package/dest/examples/util.d.ts +19 -0
  90. package/dest/examples/util.d.ts.map +1 -0
  91. package/dest/examples/util.js +30 -0
  92. package/dest/index.d.ts +2 -0
  93. package/dest/index.d.ts.map +1 -0
  94. package/dest/index.js +1 -0
  95. package/dest/local-network/auth_registry.d.ts +5 -0
  96. package/dest/local-network/auth_registry.d.ts.map +1 -0
  97. package/dest/local-network/auth_registry.js +17 -0
  98. package/dest/local-network/banana_fpc.d.ts +11 -0
  99. package/dest/local-network/banana_fpc.d.ts.map +1 -0
  100. package/dest/local-network/banana_fpc.js +81 -0
  101. package/dest/local-network/index.d.ts +4 -0
  102. package/dest/local-network/index.d.ts.map +1 -0
  103. package/dest/local-network/index.js +3 -0
  104. package/dest/local-network/local-network.d.ts +51 -0
  105. package/dest/local-network/local-network.d.ts.map +1 -0
  106. package/dest/local-network/local-network.js +205 -0
  107. package/dest/local-network/sponsored_fpc.d.ts +5 -0
  108. package/dest/local-network/sponsored_fpc.d.ts.map +1 -0
  109. package/dest/local-network/sponsored_fpc.js +18 -0
  110. package/dest/mnemonic.d.ts +2 -0
  111. package/dest/mnemonic.d.ts.map +1 -0
  112. package/dest/mnemonic.js +1 -0
  113. package/dest/splash.d.ts +3 -0
  114. package/dest/splash.d.ts.map +1 -0
  115. package/dest/splash.js +2 -0
  116. package/dest/testing/cheat_codes.d.ts +37 -0
  117. package/dest/testing/cheat_codes.d.ts.map +1 -0
  118. package/dest/testing/cheat_codes.js +36 -0
  119. package/dest/testing/epoch_test_settler.d.ts +19 -0
  120. package/dest/testing/epoch_test_settler.d.ts.map +1 -0
  121. package/dest/testing/epoch_test_settler.js +42 -0
  122. package/dest/testing/index.d.ts +6 -0
  123. package/dest/testing/index.d.ts.map +1 -0
  124. package/dest/testing/index.js +5 -0
  125. package/dest/testing/local-network.d.ts +51 -0
  126. package/dest/testing/local-network.d.ts.map +1 -0
  127. package/dest/testing/local-network.js +60 -0
  128. package/dest/testing/token_allowed_setup.d.ts +12 -0
  129. package/dest/testing/token_allowed_setup.d.ts.map +1 -0
  130. package/dest/testing/token_allowed_setup.js +24 -0
  131. package/package.json +125 -0
  132. package/scripts/add_crate.sh +53 -0
  133. package/scripts/aztec.sh +73 -0
  134. package/scripts/init.sh +39 -0
  135. package/scripts/new.sh +83 -0
  136. package/scripts/setup_workspace.sh +69 -0
  137. package/scripts/templates/blank/contract/Nargo.toml +6 -0
  138. package/scripts/templates/blank/contract/src/main.nr +10 -0
  139. package/scripts/templates/blank/test/Nargo.toml +7 -0
  140. package/scripts/templates/blank/test/src/lib.nr +11 -0
  141. package/scripts/templates/counter/contract/Nargo.toml +7 -0
  142. package/scripts/templates/counter/contract/src/main.nr +48 -0
  143. package/scripts/templates/counter/test/Nargo.toml +7 -0
  144. package/scripts/templates/counter/test/src/lib.nr +32 -0
  145. package/src/bin/index.ts +73 -0
  146. package/src/cli/admin_api_key_store.ts +127 -0
  147. package/src/cli/aztec_start_action.ts +173 -0
  148. package/src/cli/aztec_start_options.ts +333 -0
  149. package/src/cli/cli.ts +55 -0
  150. package/src/cli/cmds/compile.ts +205 -0
  151. package/src/cli/cmds/migrate_ha_db.ts +42 -0
  152. package/src/cli/cmds/profile.ts +25 -0
  153. package/src/cli/cmds/profile_flamegraph.ts +64 -0
  154. package/src/cli/cmds/profile_gates.ts +84 -0
  155. package/src/cli/cmds/profile_utils.ts +58 -0
  156. package/src/cli/cmds/prover.ts +41 -0
  157. package/src/cli/cmds/standby.ts +183 -0
  158. package/src/cli/cmds/start_bot.ts +78 -0
  159. package/src/cli/cmds/start_node.ts +199 -0
  160. package/src/cli/cmds/start_p2p_bootstrap.ts +37 -0
  161. package/src/cli/cmds/start_prover_agent.ts +77 -0
  162. package/src/cli/cmds/start_prover_broker.ts +69 -0
  163. package/src/cli/cmds/start_txe.ts +17 -0
  164. package/src/cli/cmds/utils/artifacts.ts +49 -0
  165. package/src/cli/cmds/utils/collect_crate_dirs.ts +118 -0
  166. package/src/cli/cmds/utils/needs_recompile.ts +98 -0
  167. package/src/cli/cmds/utils/spawn.ts +16 -0
  168. package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +75 -0
  169. package/src/cli/index.ts +1 -0
  170. package/src/cli/preload_crs.ts +7 -0
  171. package/src/cli/util.ts +310 -0
  172. package/src/cli/versioning.ts +13 -0
  173. package/src/examples/token.ts +77 -0
  174. package/src/examples/util.ts +42 -0
  175. package/src/index.ts +6 -0
  176. package/src/local-network/auth_registry.ts +19 -0
  177. package/src/local-network/banana_fpc.ts +89 -0
  178. package/src/local-network/index.ts +7 -0
  179. package/src/local-network/local-network.ts +254 -0
  180. package/src/local-network/sponsored_fpc.ts +26 -0
  181. package/src/mnemonic.ts +1 -0
  182. package/src/splash.ts +10 -0
  183. package/src/testing/cheat_codes.ts +48 -0
  184. package/src/testing/epoch_test_settler.ts +47 -0
  185. package/src/testing/index.ts +5 -0
  186. package/src/testing/local-network.ts +96 -0
  187. package/src/testing/token_allowed_setup.ts +26 -0
@@ -0,0 +1,254 @@
1
+ #!/usr/bin/env -S node --no-warnings
2
+ import { getInitialTestAccountsData } from '@aztec-labs/accounts/testing';
3
+ import { createAztecNodeService } from '@aztec-labs/aztec-node';
4
+ import { type AztecNodeConfig, getConfigEnvVars } from '@aztec-labs/aztec-node/config';
5
+ import { Fr } from '@aztec-labs/aztec.js/fields';
6
+ import { createLogger } from '@aztec-labs/aztec.js/log';
7
+ import { type BlobClientInterface, createBlobClient } from '@aztec-labs/blob-client/client';
8
+ import { GENESIS_ARCHIVE_ROOT } from '@aztec-labs/constants';
9
+ import { waitForPublicClient } from '@aztec-labs/ethereum/client';
10
+ import { getL1ContractsConfigEnvVars } from '@aztec-labs/ethereum/config';
11
+ import { NULL_KEY } from '@aztec-labs/ethereum/constants';
12
+ import { deployAztecL1Contracts } from '@aztec-labs/ethereum/deploy-aztec-l1-contracts';
13
+ import type { L1ContractAddresses } from '@aztec-labs/ethereum/l1-contract-addresses';
14
+ import { SecretValue } from '@aztec-labs/foundation/config';
15
+ import { EthAddress } from '@aztec-labs/foundation/eth-address';
16
+ import type { LogFn } from '@aztec-labs/foundation/log';
17
+ import { DateProvider, TestDateProvider } from '@aztec-labs/foundation/timer';
18
+ import { getVKTreeRoot } from '@aztec-labs/noir-protocol-circuits-types/vk-tree';
19
+ import { protocolContractsHash } from '@aztec-labs/protocol-contracts';
20
+ import { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
21
+ import type { ProvingJobBroker } from '@aztec-labs/stdlib/interfaces/server';
22
+ import { TxStatus } from '@aztec-labs/stdlib/tx';
23
+ import type { GenesisData } from '@aztec-labs/stdlib/world-state';
24
+ import {
25
+ type TelemetryClient,
26
+ getConfigEnvVars as getTelemetryClientConfig,
27
+ initTelemetryClient,
28
+ } from '@aztec-labs/telemetry-client';
29
+ import { EmbeddedWallet } from '@aztec-labs/wallets/embedded';
30
+ import { createFundedInitializerlessAccounts } from '@aztec-labs/wallets/testing';
31
+ import { getGenesisValues } from '@aztec-labs/world-state/testing';
32
+ import type { Hex } from 'viem';
33
+ import { mnemonicToAccount, privateKeyToAddress } from 'viem/accounts';
34
+ import { foundry } from 'viem/chains';
35
+
36
+ import { createAccountLogs } from '../cli/util.js';
37
+ import { DefaultMnemonic } from '../mnemonic.js';
38
+ import { getTokenAllowedSetupFunctions } from '../testing/token_allowed_setup.js';
39
+ import { publishStandardAuthRegistry } from './auth_registry.js';
40
+ import { getBananaFPCAddress, setupBananaFPC } from './banana_fpc.js';
41
+ import { getSponsoredFPCAddress } from './sponsored_fpc.js';
42
+
43
+ const logger = createLogger('local-network');
44
+
45
+ // The embedded wallet defaults to waiting for PROPOSED, which returns as soon as a tx lands in a
46
+ // proposed L2 block. That is flaky for the serial sandbox setup below: a proposed block can be
47
+ // pruned before its checkpoint is published, dropping a tx we already moved on from ("Tx dropped by
48
+ // P2P node"). Wait for the checkpoint so each setup tx is durably included before the next is sent.
49
+ const setupWaitOpts = { waitForStatus: TxStatus.CHECKPOINTED };
50
+
51
+ /**
52
+ * Function to deploy our L1 contracts to the local network L1
53
+ * @param aztecNodeConfig - The Aztec Node Config
54
+ * @param hdAccount - Account for publishing L1 contracts
55
+ */
56
+ export async function deployContractsToL1(
57
+ aztecNodeConfig: AztecNodeConfig,
58
+ privateKey: Hex,
59
+ opts: {
60
+ genesisArchiveRoot?: Fr;
61
+ feeJuicePortalInitialBalance?: bigint;
62
+ } = {},
63
+ ): Promise<L1ContractAddresses> {
64
+ await waitForPublicClient(aztecNodeConfig);
65
+
66
+ const l1Contracts = await deployAztecL1Contracts(aztecNodeConfig.l1RpcUrls[0], privateKey, foundry.id, {
67
+ ...getL1ContractsConfigEnvVars(), // TODO: We should not need to be loading config from env again, caller should handle this
68
+ ...aztecNodeConfig,
69
+ vkTreeRoot: getVKTreeRoot(),
70
+ protocolContractsHash,
71
+ genesisArchiveRoot: opts.genesisArchiveRoot ?? new Fr(GENESIS_ARCHIVE_ROOT),
72
+ feeJuicePortalInitialBalance: opts.feeJuicePortalInitialBalance,
73
+ aztecTargetCommitteeSize: 0, // no committee in local network
74
+ slasherEnabled: false, // no slashing in local network
75
+ realVerifier: false,
76
+ });
77
+
78
+ Object.assign(aztecNodeConfig, l1Contracts.l1ContractAddresses);
79
+ aztecNodeConfig.rollupVersion = l1Contracts.rollupVersion;
80
+
81
+ return l1Contracts.l1ContractAddresses;
82
+ }
83
+
84
+ /** Local network settings. */
85
+ export type LocalNetworkConfig = AztecNodeConfig & {
86
+ /** Mnemonic used to derive the L1 deployer private key.*/
87
+ l1Mnemonic: string;
88
+ /** Whether to deploy test accounts on local network start.*/
89
+ testAccounts: boolean;
90
+ /** Override the default per-address fee juice granted at genesis to funded addresses. */
91
+ initialAccountFeeJuice?: Fr;
92
+ };
93
+
94
+ /**
95
+ * Create and start a new Aztec Node and PXE. Deploys L1 contracts.
96
+ * Does not start any HTTP services nor populate any initial accounts.
97
+ * @param config - Optional local network settings.
98
+ */
99
+ export async function createLocalNetwork(config: Partial<LocalNetworkConfig> = {}, userLog: LogFn) {
100
+ // local network is meant for test envs. We should only need one l1RpcUrl
101
+ const l1RpcUrl = config.l1RpcUrls?.[0];
102
+ if (!l1RpcUrl) {
103
+ throw new Error('An L1 RPC URL is required');
104
+ }
105
+ if ((config.l1RpcUrls?.length || 0) > 1) {
106
+ logger.warn(`Multiple L1 RPC URLs provided. Local networks will only use the first one: ${l1RpcUrl}`);
107
+ }
108
+
109
+ // The local network deploys a banana FPC with Token contracts, so include Token entries
110
+ // in the setup allowlist so FPC-based fee payments work out of the box.
111
+ const tokenAllowList = await getTokenAllowedSetupFunctions();
112
+
113
+ const envConfig = getConfigEnvVars();
114
+ const aztecNodeConfig: AztecNodeConfig = {
115
+ ...envConfig,
116
+ ...config,
117
+ skipOrphanProposedBlockPruning: true,
118
+ // The local network builds node config from env without a DATA_DIRECTORY, so the validator's
119
+ // local signing protection runs against an ephemeral store. That is acceptable for this dev
120
+ // network; production validators must persist it and fail-fast when the data directory is unset.
121
+ allowEphemeralSigningProtection: config.allowEphemeralSigningProtection ?? true,
122
+ txPublicSetupAllowListExtend: [...tokenAllowList, ...(config.txPublicSetupAllowListExtend ?? [])],
123
+ // The local network runs against anvil with no committee, so it defaults to the deterministic
124
+ // AutomineSequencer, which owns L1 time control (warps the dateProvider and L1 timestamps to slot
125
+ // boundaries as it builds), replacing the deleted AnvilTestWatcher. This remains true when p2p is
126
+ // enabled for local peer testing; local-network is not a mode for connecting to an existing network.
127
+ useAutomineSequencer: config.useAutomineSequencer ?? true,
128
+ // The AutomineSequencer owns epoch proving in the local network — it writes epoch out hashes to
129
+ // the L1 Outbox and advances the proven tip as checkpoints land, through the same serial queue as
130
+ // its builds — replacing the standalone EpochTestSettler that used to race the build loop.
131
+ automineEnableProveEpoch: config.automineEnableProveEpoch ?? true,
132
+ // Defaults for the local network / sandbox; callers (e.g. the CLI) may override. No real proving
133
+ // happens here — the AutomineSequencer synthetically settles epochs. Short epochs let it write out
134
+ // hashes quickly (so users can consume L2-to-L1 messages without a long wait), with a wider
135
+ // proof-submission window so the synthetic settler has headroom before the rollup would prune an
136
+ // unproven checkpoint.
137
+ realProofs: config.realProofs ?? false,
138
+ aztecEpochDuration: config.aztecEpochDuration ?? 4,
139
+ aztecProofSubmissionEpochs: config.aztecProofSubmissionEpochs ?? 2,
140
+ };
141
+ const hdAccount = mnemonicToAccount(config.l1Mnemonic || DefaultMnemonic);
142
+ if (
143
+ aztecNodeConfig.sequencerPublisherPrivateKeys == undefined ||
144
+ !aztecNodeConfig.sequencerPublisherPrivateKeys.length ||
145
+ aztecNodeConfig.sequencerPublisherPrivateKeys[0].getValue() === NULL_KEY
146
+ ) {
147
+ const privKey = hdAccount.getHdKey().privateKey;
148
+ aztecNodeConfig.sequencerPublisherPrivateKeys = [
149
+ new SecretValue(`0x${Buffer.from(privKey!).toString('hex')}` as const),
150
+ ];
151
+ }
152
+ if (!aztecNodeConfig.validatorPrivateKeys?.getValue().length) {
153
+ const privKey = hdAccount.getHdKey().privateKey;
154
+ aztecNodeConfig.validatorPrivateKeys = new SecretValue([`0x${Buffer.from(privKey!).toString('hex')}`]);
155
+ }
156
+ aztecNodeConfig.coinbase = EthAddress.fromString(
157
+ privateKeyToAddress(aztecNodeConfig.validatorPrivateKeys.getValue()[0]),
158
+ );
159
+
160
+ const initialAccounts = await (async () => {
161
+ if (config.testAccounts === true || config.testAccounts === undefined) {
162
+ if (aztecNodeConfig.p2pEnabled) {
163
+ userLog(`Not setting up test accounts when p2p is enabled`);
164
+ } else {
165
+ userLog(`Setting up test accounts`);
166
+ return await getInitialTestAccountsData();
167
+ }
168
+ }
169
+ return [];
170
+ })();
171
+
172
+ const bananaFPC = await getBananaFPCAddress(initialAccounts);
173
+ const sponsoredFPC = await getSponsoredFPCAddress();
174
+ const prefundAddresses = (aztecNodeConfig.prefundAddresses ?? []).map(a => AztecAddress.fromStringUnsafe(a));
175
+ const fundedAddresses = [
176
+ ...initialAccounts.map(a => a.address),
177
+ ...(initialAccounts.length ? [bananaFPC, sponsoredFPC] : []),
178
+ ...prefundAddresses,
179
+ ];
180
+ const { genesisArchiveRoot, genesis, fundingNeeded } = await getGenesisValues(
181
+ fundedAddresses,
182
+ config.initialAccountFeeJuice,
183
+ );
184
+
185
+ const dateProvider = new TestDateProvider();
186
+
187
+ if (!aztecNodeConfig.p2pEnabled) {
188
+ await deployContractsToL1(aztecNodeConfig, aztecNodeConfig.validatorPrivateKeys.getValue()[0], {
189
+ genesisArchiveRoot,
190
+ feeJuicePortalInitialBalance: fundingNeeded,
191
+ });
192
+ }
193
+
194
+ const telemetry = await initTelemetryClient(getTelemetryClientConfig());
195
+ // Create a local blob client client inside the local network, no http connectivity
196
+ const blobClient = createBlobClient();
197
+ const node = await createAztecNode(aztecNodeConfig, { telemetry, blobClient, dateProvider }, { genesis });
198
+
199
+ if (initialAccounts.length) {
200
+ const wallet = await EmbeddedWallet.create(node, {
201
+ pxeConfig: { proverEnabled: aztecNodeConfig.realProofs },
202
+ ephemeral: true,
203
+ });
204
+
205
+ userLog('Setting up funded test accounts...');
206
+ const accountManagers = await createFundedInitializerlessAccounts(wallet, initialAccounts);
207
+ const accLogs = await createAccountLogs(accountManagers, wallet);
208
+ userLog(accLogs.join(''));
209
+
210
+ userLog('Publishing standard AuthRegistry contract...');
211
+ await publishStandardAuthRegistry(wallet, initialAccounts[0].address, setupWaitOpts);
212
+
213
+ await setupBananaFPC(initialAccounts, wallet, userLog, setupWaitOpts);
214
+
215
+ userLog(`SponsoredFPC: ${await getSponsoredFPCAddress()}`);
216
+
217
+ // We no longer need the wallet once we've setup the accounts so we stop the underlying PXE job queue
218
+ await wallet.stop();
219
+ }
220
+
221
+ const stop = async () => {
222
+ await node.stop();
223
+ };
224
+
225
+ return { node, stop };
226
+ }
227
+
228
+ /**
229
+ * Create and start a new Aztec RPC HTTP Server
230
+ * @param config - Optional Aztec node settings.
231
+ */
232
+ export async function createAztecNode(
233
+ config: Partial<AztecNodeConfig> = {},
234
+ deps: {
235
+ telemetry?: TelemetryClient;
236
+ blobClient?: BlobClientInterface;
237
+ dateProvider?: DateProvider;
238
+ proverBroker?: ProvingJobBroker;
239
+ } = {},
240
+ options: { genesis?: GenesisData } = {},
241
+ ) {
242
+ // TODO(#12272): will clean this up. This is criminal.
243
+ // Not sure why this was ever done. Will be fixed in A-989, A-991, A-990.
244
+ const aztecNodeConfig: AztecNodeConfig = {
245
+ ...getConfigEnvVars(),
246
+ ...config,
247
+ };
248
+ const node = await createAztecNodeService(
249
+ aztecNodeConfig,
250
+ { ...deps, proverNodeDeps: { broker: deps.proverBroker } },
251
+ options,
252
+ );
253
+ return node;
254
+ }
@@ -0,0 +1,26 @@
1
+ import type { AztecAddress } from '@aztec-labs/aztec.js/addresses';
2
+ import {
3
+ type ContractInstanceWithAddress,
4
+ getContractInstanceFromInstantiationParams,
5
+ } from '@aztec-labs/aztec.js/contracts';
6
+ import { Fr } from '@aztec-labs/aztec.js/fields';
7
+ import type { Wallet } from '@aztec-labs/aztec.js/wallet';
8
+ import { SPONSORED_FPC_SALT } from '@aztec-labs/constants';
9
+ import { SponsoredFPCContract } from '@aztec-labs/noir-contracts.js/SponsoredFPC';
10
+
11
+ async function getSponsoredFPCInstance(): Promise<ContractInstanceWithAddress> {
12
+ return await getContractInstanceFromInstantiationParams(SponsoredFPCContract.artifact, {
13
+ salt: new Fr(SPONSORED_FPC_SALT),
14
+ });
15
+ }
16
+
17
+ export async function getSponsoredFPCAddress(): Promise<AztecAddress> {
18
+ return (await getSponsoredFPCInstance()).address;
19
+ }
20
+
21
+ export async function registerDeployedSponsoredFPCInWalletAndGetAddress(wallet: Wallet): Promise<AztecAddress> {
22
+ const fpc = await getSponsoredFPCInstance();
23
+ // The following is no-op if the contract is already registered
24
+ await wallet.registerContract(fpc, SponsoredFPCContract.artifact);
25
+ return fpc.address;
26
+ }
@@ -0,0 +1 @@
1
+ export const DefaultMnemonic = 'test test test test test test test test test test test junk';
package/src/splash.ts ADDED
@@ -0,0 +1,10 @@
1
+ export const splash: string =
2
+ '\n' +
3
+ ' _\n' +
4
+ ' /\\ | |\n' +
5
+ ' / \\ ___| |_ ___ ___ \n' +
6
+ ' / /\\ \\ |_ / __/ _ \\/ __|\n' +
7
+ ' / ____ \\ / /| || __/ (__ \n' +
8
+ '/_/___ \\_\\/___|\\__\\___|\\___|\n';
9
+
10
+ export const github = 'https://github.com/AztecProtocol';
@@ -0,0 +1,48 @@
1
+ import { EthCheatCodes, RollupCheatCodes } from '@aztec-labs/ethereum/test';
2
+ import type { DateProvider } from '@aztec-labs/foundation/timer';
3
+ import type { AztecNode, AztecNodeDebug } from '@aztec-labs/stdlib/interfaces/client';
4
+
5
+ /**
6
+ * Wrapper for Aztec Debug API.
7
+ * @deprecated use the AztecNode debug API directly.
8
+ */
9
+ export class CheatCodes {
10
+ constructor(
11
+ /** Cheat codes for L1.*/
12
+ public eth: EthCheatCodes,
13
+ /** Cheat codes for the Aztec Rollup contract on L1. */
14
+ public rollup: RollupCheatCodes,
15
+ ) {}
16
+
17
+ static async create(rpcUrls: string[], node: AztecNode, dateProvider: DateProvider): Promise<CheatCodes> {
18
+ const ethCheatCodes = new EthCheatCodes(rpcUrls, dateProvider);
19
+ const rollupCheatCodes = new RollupCheatCodes(
20
+ ethCheatCodes,
21
+ await node.getNodeInfo().then(n => n.l1ContractAddresses),
22
+ );
23
+ return new CheatCodes(ethCheatCodes, rollupCheatCodes);
24
+ }
25
+
26
+ /**
27
+ * Warps the L1 timestamp to at least `targetTimestamp` and mines an L2 block advancing the L2 timestamp to at least
28
+ * the target. Forwards to the node's debug API, which serializes the warp through the automine sequencer queue.
29
+ * @param node - The Aztec node whose debug API performs the warp. Must run an automine sequencer.
30
+ * @param targetTimestamp - The target timestamp to warp to (in seconds).
31
+ * @deprecated Call `node.warpL2TimeAtLeastTo(targetTimestamp)` on the node debug API directly.
32
+ */
33
+ warpL2TimeAtLeastTo(node: AztecNode & AztecNodeDebug, targetTimestamp: bigint | number): Promise<void> {
34
+ return node.warpL2TimeAtLeastTo(Number(targetTimestamp));
35
+ }
36
+
37
+ /**
38
+ * Warps the L1 timestamp forward by at least `duration` seconds and mines an L2 block advancing the L2 timestamp at
39
+ * least by the duration. Forwards to the node's debug API, which serializes the warp through the automine sequencer
40
+ * queue.
41
+ * @param node - The Aztec node whose debug API performs the warp. Must run an automine sequencer.
42
+ * @param duration - The duration to advance time by (in seconds).
43
+ * @deprecated Call `node.warpL2TimeAtLeastBy(duration)` on the node debug API directly.
44
+ */
45
+ warpL2TimeAtLeastBy(node: AztecNode & AztecNodeDebug, duration: bigint | number): Promise<void> {
46
+ return node.warpL2TimeAtLeastBy(Number(duration));
47
+ }
48
+ }
@@ -0,0 +1,47 @@
1
+ import { type EthCheatCodes, RollupCheatCodes } from '@aztec-labs/ethereum/test';
2
+ import type { EpochNumber } from '@aztec-labs/foundation/branded-types';
3
+ import type { Logger } from '@aztec-labs/foundation/log';
4
+ import { settleEpochOutbox } from '@aztec-labs/prover-client/test';
5
+ import { EpochMonitor } from '@aztec-labs/prover-node';
6
+ import type { EthAddress, L2BlockSource } from '@aztec-labs/stdlib/block';
7
+
8
+ export class EpochTestSettler {
9
+ private rollupCheatCodes: RollupCheatCodes;
10
+ private epochMonitor?: EpochMonitor;
11
+
12
+ constructor(
13
+ cheatcodes: EthCheatCodes,
14
+ rollupAddress: EthAddress,
15
+ private l2BlockSource: L2BlockSource,
16
+ private log: Logger,
17
+ private options: { pollingIntervalMs: number; provingDelayMs?: number },
18
+ ) {
19
+ this.rollupCheatCodes = new RollupCheatCodes(cheatcodes, { rollupAddress });
20
+ }
21
+
22
+ async start() {
23
+ const { epochDuration } = await this.rollupCheatCodes.getConfig();
24
+ this.epochMonitor = new EpochMonitor(this.l2BlockSource, { epochDuration: Number(epochDuration) }, this.options);
25
+ this.epochMonitor.start(this);
26
+ }
27
+
28
+ async stop() {
29
+ await this.epochMonitor?.stop();
30
+ }
31
+
32
+ async handleEpochReadyToProve(epoch: EpochNumber): Promise<boolean> {
33
+ const lastCheckpoint = await settleEpochOutbox({
34
+ rollupCheatCodes: this.rollupCheatCodes,
35
+ l2BlockSource: this.l2BlockSource,
36
+ epoch,
37
+ log: this.log,
38
+ });
39
+ if (lastCheckpoint !== undefined) {
40
+ await this.rollupCheatCodes.markAsProven(lastCheckpoint);
41
+ } else {
42
+ this.log.warn(`No checkpoint found for epoch ${epoch}`);
43
+ }
44
+
45
+ return true;
46
+ }
47
+ }
@@ -0,0 +1,5 @@
1
+ export { EthCheatCodes, RollupCheatCodes } from '@aztec-labs/ethereum/test';
2
+ export { CheatCodes } from './cheat_codes.js';
3
+ export { EpochTestSettler } from './epoch_test_settler.js';
4
+ export { setupLocalNetwork, TEST_FEE_PADDING, type LocalNetwork, type LocalNetworkOptions } from './local-network.js';
5
+ export { getTokenAllowedSetupFunctions } from './token_allowed_setup.js';
@@ -0,0 +1,96 @@
1
+ import type { AztecNodeService } from '@aztec-labs/aztec-node';
2
+ import type { AztecNodeConfig } from '@aztec-labs/aztec-node/config';
3
+ import type { Fr } from '@aztec-labs/aztec.js/fields';
4
+ import { startAnvil } from '@aztec-labs/ethereum/test';
5
+ import type { AztecAddress } from '@aztec-labs/stdlib/aztec-address';
6
+ import { foundry } from 'viem/chains';
7
+
8
+ import { createLocalNetwork } from '../local-network/local-network.js';
9
+
10
+ /** A running in-process local network: an inline Aztec node backed by its own anvil L1. */
11
+ export interface LocalNetwork extends AsyncDisposable {
12
+ /** Fully-synced Aztec node, ready to serve client requests. */
13
+ node: AztecNodeService;
14
+ /** RPC URL of the spawned anvil instance. */
15
+ l1RpcUrl: string;
16
+ /** Chain id used on L1 (foundry's default 31337). */
17
+ l1ChainId: number;
18
+ /** Stops every process started by the fixture: node and anvil. Also invoked by `await using`. */
19
+ stop: () => Promise<void>;
20
+ }
21
+
22
+ /** Options for {@link setupLocalNetwork}. */
23
+ export interface LocalNetworkOptions {
24
+ /**
25
+ * Addresses that should hold fee juice at genesis. Saves each of these the round-trip of bridging
26
+ * + claiming fee juice before they can pay for gas.
27
+ */
28
+ fundedAddresses?: AztecAddress[];
29
+ /** Override the default per-address genesis fee juice granted to {@link fundedAddresses}. */
30
+ initialAccountFeeJuice?: Fr;
31
+ /** Node config overrides, e.g. `realProofs`, `aztecEpochDuration`, `p2pEnabled`. */
32
+ config?: Partial<AztecNodeConfig>;
33
+ }
34
+
35
+ /**
36
+ * Spin up an in-process local network with the given addresses pre-funded.
37
+ *
38
+ * Each call spawns its own anvil on an OS-assigned random port and runs the Aztec node inline via
39
+ * the same {@link createLocalNetwork} codepath that backs `aztec start --local-network` (with the
40
+ * sandbox account/FPC/token setup skipped). Distinct ports let independent suites run in parallel.
41
+ * The caller must `await result.stop()` in its teardown (or hold the result with `await using`).
42
+ *
43
+ * Requires a Foundry toolchain (`anvil`/`forge`), installed via `aztec-up` or `foundryup`. Binaries
44
+ * are located in the standard install directories or on `PATH`; set `$ANVIL_BIN` / `$FORGE_BIN` to
45
+ * pin specific ones.
46
+ */
47
+ export async function setupLocalNetwork(opts: LocalNetworkOptions = {}): Promise<LocalNetwork> {
48
+ // `--port 0` → anvil binds an ephemeral port that `startAnvil` reads back, so parallel suites
49
+ // never collide on a fixed port.
50
+ const { rpcUrl, stop: stopAnvil } = await startAnvil({ port: 0 });
51
+
52
+ try {
53
+ const { node, stop: stopNode } = await createLocalNetwork(
54
+ {
55
+ ...opts.config,
56
+ l1RpcUrls: [rpcUrl],
57
+ testAccounts: false,
58
+ prefundAddresses: (opts.fundedAddresses ?? []).map(a => a.toString()),
59
+ initialAccountFeeJuice: opts.initialAccountFeeJuice,
60
+ },
61
+ () => {},
62
+ );
63
+
64
+ // Stop the node before anvil (its teardown still talks to L1); the finally guarantees anvil is
65
+ // reaped even if node shutdown throws.
66
+ const stop = async () => {
67
+ try {
68
+ await stopNode();
69
+ } finally {
70
+ await stopAnvil();
71
+ }
72
+ };
73
+
74
+ return {
75
+ node,
76
+ l1RpcUrl: rpcUrl,
77
+ l1ChainId: foundry.id,
78
+ stop,
79
+ [Symbol.asyncDispose]: stop,
80
+ };
81
+ } catch (err) {
82
+ await stopAnvil();
83
+ throw err;
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Min-fee padding multiplier for test wallets whose txs may mine well after their fee estimate.
89
+ * The automine sequencer builds one block per tx and advances L1 time in big jumps, and proposer
90
+ * pipelining evolves the fee-asset price across the build/publish gap (~20x observed in CI), so the
91
+ * network's congestion base fee can swing sharply between the wallet's fee estimate and the block
92
+ * the tx actually lands in. The default wallet padding isn't enough and trips
93
+ * `maxFeesPerGas.feePerL2Gas must be >= gasFees.feePerL2Gas`. Apply via
94
+ * `wallet.setMinFeePadding(TEST_FEE_PADDING)` on every test wallet that sends txs.
95
+ */
96
+ export const TEST_FEE_PADDING = 30;
@@ -0,0 +1,26 @@
1
+ import { TokenContractArtifact } from '@aztec-labs/noir-contracts.js/Token';
2
+ import { buildAllowedElement } from '@aztec-labs/p2p/msg_validators';
3
+ import type { ContractArtifact } from '@aztec-labs/stdlib/abi';
4
+ import { getContractClassFromArtifact } from '@aztec-labs/stdlib/contract';
5
+ import type { AllowedElement } from '@aztec-labs/stdlib/interfaces/server';
6
+
7
+ /**
8
+ * Returns the allowlist entries needed for FPC-based fee payments, keyed by the contract class of
9
+ * the `artifact` actually deployed as the fee token (defaults to canonical Token). The setup-phase
10
+ * validator matches these entries by class id, so a test deploying the codegen'd TestToken as its
11
+ * fee vehicle must pass `TestTokenContract.artifact` here -- otherwise the FPC fee calls are matched
12
+ * against the wrong class and rejected. Test-only: FPC fee payment with custom tokens won't work on
13
+ * mainnet alpha.
14
+ */
15
+ export async function getTokenAllowedSetupFunctions(
16
+ artifact: ContractArtifact = TokenContractArtifact,
17
+ ): Promise<AllowedElement[]> {
18
+ const tokenClassId = (await getContractClassFromArtifact(artifact)).id;
19
+ const target = { classId: tokenClassId };
20
+ return Promise.all([
21
+ // needed for private transfers via FPC (transfer_to_public enqueues this)
22
+ buildAllowedElement(artifact, target, '_increase_public_balance', { onlySelf: true }),
23
+ // needed for public transfers via FPC (fee_entrypoint_public enqueues this)
24
+ buildAllowedElement(artifact, target, 'transfer_in_public'),
25
+ ]);
26
+ }