@aztec/aztec 0.0.1-commit.c2eed6949 → 0.0.1-commit.c52d6e7

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 (125) hide show
  1. package/dest/bin/index.js +3 -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 +16 -24
  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 +15 -15
  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 +32 -24
  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/prover.d.ts +4 -0
  18. package/dest/cli/cmds/prover.d.ts.map +1 -0
  19. package/dest/cli/cmds/prover.js +24 -0
  20. package/dest/cli/cmds/standby.d.ts +30 -6
  21. package/dest/cli/cmds/standby.d.ts.map +1 -1
  22. package/dest/cli/cmds/standby.js +48 -5
  23. package/dest/cli/cmds/start_bot.d.ts +1 -1
  24. package/dest/cli/cmds/start_bot.d.ts.map +1 -1
  25. package/dest/cli/cmds/start_bot.js +8 -4
  26. package/dest/cli/cmds/start_node.d.ts +1 -1
  27. package/dest/cli/cmds/start_node.d.ts.map +1 -1
  28. package/dest/cli/cmds/start_node.js +22 -47
  29. package/dest/cli/cmds/start_prover_agent.d.ts +1 -1
  30. package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
  31. package/dest/cli/cmds/start_prover_agent.js +5 -17
  32. package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
  33. package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
  34. package/dest/cli/cmds/start_prover_broker.js +11 -8
  35. package/dest/cli/cmds/start_txe.d.ts +2 -2
  36. package/dest/cli/cmds/start_txe.d.ts.map +1 -1
  37. package/dest/cli/cmds/start_txe.js +6 -5
  38. package/dest/cli/cmds/utils/artifacts.d.ts +6 -1
  39. package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -1
  40. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts +21 -0
  41. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts.map +1 -0
  42. package/dest/cli/cmds/utils/collect_crate_dirs.js +114 -0
  43. package/dest/cli/cmds/utils/needs_recompile.d.ts +1 -1
  44. package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -1
  45. package/dest/cli/cmds/utils/needs_recompile.js +9 -53
  46. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +4 -0
  47. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -0
  48. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +61 -0
  49. package/dest/cli/util.d.ts +10 -5
  50. package/dest/cli/util.d.ts.map +1 -1
  51. package/dest/cli/util.js +26 -53
  52. package/dest/examples/token.js +3 -3
  53. package/dest/local-network/auth_registry.d.ts +5 -0
  54. package/dest/local-network/auth_registry.d.ts.map +1 -0
  55. package/dest/local-network/auth_registry.js +17 -0
  56. package/dest/local-network/banana_fpc.d.ts +3 -2
  57. package/dest/local-network/banana_fpc.d.ts.map +1 -1
  58. package/dest/local-network/banana_fpc.js +11 -7
  59. package/dest/local-network/local-network.d.ts +10 -32
  60. package/dest/local-network/local-network.d.ts.map +1 -1
  61. package/dest/local-network/local-network.js +52 -73
  62. package/dest/testing/cheat_codes.d.ts +17 -23
  63. package/dest/testing/cheat_codes.d.ts.map +1 -1
  64. package/dest/testing/cheat_codes.js +17 -43
  65. package/dest/testing/epoch_test_settler.d.ts +2 -2
  66. package/dest/testing/epoch_test_settler.d.ts.map +1 -1
  67. package/dest/testing/epoch_test_settler.js +6 -25
  68. package/dest/testing/index.d.ts +2 -2
  69. package/dest/testing/index.d.ts.map +1 -1
  70. package/dest/testing/index.js +1 -1
  71. package/dest/testing/local-network.d.ts +51 -0
  72. package/dest/testing/local-network.d.ts.map +1 -0
  73. package/dest/testing/local-network.js +60 -0
  74. package/dest/testing/token_allowed_setup.d.ts +9 -4
  75. package/dest/testing/token_allowed_setup.d.ts.map +1 -1
  76. package/dest/testing/token_allowed_setup.js +12 -8
  77. package/package.json +34 -33
  78. package/scripts/add_crate.sh +11 -60
  79. package/scripts/aztec.sh +6 -2
  80. package/scripts/init.sh +5 -5
  81. package/scripts/new.sh +2 -2
  82. package/scripts/setup_workspace.sh +3 -2
  83. package/scripts/templates/blank/contract/Nargo.toml +6 -0
  84. package/scripts/templates/blank/contract/src/main.nr +10 -0
  85. package/scripts/templates/blank/test/Nargo.toml +7 -0
  86. package/scripts/templates/blank/test/src/lib.nr +11 -0
  87. package/scripts/templates/counter/contract/Nargo.toml +7 -0
  88. package/scripts/templates/counter/contract/src/main.nr +48 -0
  89. package/scripts/templates/counter/test/Nargo.toml +7 -0
  90. package/scripts/templates/counter/test/src/lib.nr +32 -0
  91. package/src/bin/index.ts +3 -1
  92. package/src/cli/aztec_start_action.ts +14 -17
  93. package/src/cli/aztec_start_options.ts +22 -23
  94. package/src/cli/cmds/compile.ts +37 -23
  95. package/src/cli/cmds/profile.ts +2 -1
  96. package/src/cli/cmds/profile_gates.ts +20 -4
  97. package/src/cli/cmds/prover.ts +42 -0
  98. package/src/cli/cmds/standby.ts +59 -7
  99. package/src/cli/cmds/start_bot.ts +9 -6
  100. package/src/cli/cmds/start_node.ts +29 -39
  101. package/src/cli/cmds/start_prover_agent.ts +5 -8
  102. package/src/cli/cmds/start_prover_broker.ts +10 -11
  103. package/src/cli/cmds/start_txe.ts +7 -5
  104. package/src/cli/cmds/utils/artifacts.ts +5 -0
  105. package/src/cli/cmds/utils/collect_crate_dirs.ts +118 -0
  106. package/src/cli/cmds/utils/needs_recompile.ts +8 -61
  107. package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +76 -0
  108. package/src/cli/util.ts +27 -68
  109. package/src/examples/token.ts +11 -3
  110. package/src/local-network/auth_registry.ts +19 -0
  111. package/src/local-network/banana_fpc.ts +12 -8
  112. package/src/local-network/local-network.ts +61 -83
  113. package/src/testing/cheat_codes.ts +18 -49
  114. package/src/testing/epoch_test_settler.ts +8 -31
  115. package/src/testing/index.ts +1 -1
  116. package/src/testing/local-network.ts +97 -0
  117. package/src/testing/token_allowed_setup.ts +15 -8
  118. package/dest/cli/cmds/start_archiver.d.ts +0 -9
  119. package/dest/cli/cmds/start_archiver.d.ts.map +0 -1
  120. package/dest/cli/cmds/start_archiver.js +0 -48
  121. package/dest/testing/anvil_test_watcher.d.ts +0 -42
  122. package/dest/testing/anvil_test_watcher.d.ts.map +0 -1
  123. package/dest/testing/anvil_test_watcher.js +0 -181
  124. package/src/cli/cmds/start_archiver.ts +0 -50
  125. package/src/testing/anvil_test_watcher.ts +0 -210
@@ -1,5 +1,6 @@
1
1
  import { findBbBinary } from '@aztec/bb.js';
2
2
  import type { LogFn } from '@aztec/foundation/log';
3
+ import { getPackageVersion } from '@aztec/stdlib/update-checker';
3
4
 
4
5
  import { execFileSync } from 'child_process';
5
6
  import type { Command } from 'commander';
@@ -9,9 +10,10 @@ import { join } from 'path';
9
10
  import { readArtifactFiles } from './utils/artifacts.js';
10
11
  import { needsRecompile } from './utils/needs_recompile.js';
11
12
  import { run } from './utils/spawn.js';
13
+ import { warnIfAztecVersionMismatch } from './utils/warn_if_aztec_version_mismatch.js';
12
14
 
13
- /** Returns paths to contract artifacts in the target directory. */
14
- async function collectContractArtifacts(): Promise<string[]> {
15
+ /** Returns contract artifacts in the target directory along with whether each has already been postprocessed. */
16
+ async function collectContractArtifacts(): Promise<ContractArtifactInfo[]> {
15
17
  let files;
16
18
  try {
17
19
  files = await readArtifactFiles('target');
@@ -21,18 +23,18 @@ async function collectContractArtifacts(): Promise<string[]> {
21
23
  }
22
24
  throw err;
23
25
  }
24
- return files.filter(f => Array.isArray(f.content.functions)).map(f => f.filePath);
26
+ return files
27
+ .filter(f => Array.isArray(f.content.functions))
28
+ .map(f => ({ filePath: f.filePath, transpiled: f.content.transpiled === true }));
25
29
  }
26
30
 
27
- /** Strips the `__aztec_nr_internals__` prefix from function names in contract artifacts. */
28
- async function stripInternalPrefixes(artifactPaths: string[]): Promise<void> {
31
+ /** Stamps the Aztec stack version into the contract artifacts. */
32
+ async function stampAztecVersion(artifactPaths: string[]): Promise<void> {
33
+ const version = getPackageVersion();
29
34
  for (const path of artifactPaths) {
30
35
  const artifact = JSON.parse(await readFile(path, 'utf-8'));
31
- for (const fn of artifact.functions) {
32
- if (typeof fn.name === 'string') {
33
- fn.name = fn.name.replace(/^__aztec_nr_internals__/, '');
34
- }
35
- }
36
+ // eslint-disable-next-line camelcase
37
+ artifact.aztec_version = version;
36
38
  await writeFile(path, JSON.stringify(artifact, null, 2) + '\n');
37
39
  }
38
40
  }
@@ -139,31 +141,36 @@ async function checkNoTestsInContracts(nargo: string, log: LogFn): Promise<void>
139
141
 
140
142
  /** Compiles Aztec Noir contracts and postprocesses artifacts. */
141
143
  async function compileAztecContract(nargoArgs: string[], log: LogFn): Promise<void> {
142
- if (!(await needsRecompile())) {
143
- log('No source changes detected, skipping compilation.');
144
- return;
145
- }
144
+ await warnIfAztecVersionMismatch(log);
146
145
 
147
146
  const nargo = process.env.NARGO ?? 'nargo';
148
147
  const bb = process.env.BB ?? findBbBinary() ?? 'bb';
149
148
 
150
- await run(nargo, ['compile', ...nargoArgs]);
149
+ const shouldRecompile = await needsRecompile();
150
+ if (shouldRecompile) {
151
+ await run(nargo, ['compile', ...nargoArgs]);
151
152
 
152
- // Ensure contract crates contain no tests (tests belong in the test crate).
153
- await checkNoTestsInContracts(nargo, log);
153
+ // Ensure contract crates contain no tests (tests belong in the test crate).
154
+ await checkNoTestsInContracts(nargo, log);
155
+ }
154
156
 
155
- const artifacts = await collectContractArtifacts();
157
+ // Postprocess any untranspiled artifacts: those just produced by nargo above, and any left behind by a bare
158
+ // `nargo compile` run outside `aztec compile`.
159
+ const unprocessed = (await collectContractArtifacts()).filter(a => !a.transpiled).map(a => a.filePath);
156
160
 
157
- if (artifacts.length > 0) {
161
+ if (unprocessed.length > 0) {
158
162
  log('Postprocessing contracts...');
159
- const bbArgs = artifacts.flatMap(a => ['-i', a]);
163
+ const bbArgs = unprocessed.flatMap(a => ['-i', a]);
160
164
  await run(bb, ['aztec_process', ...bbArgs]);
161
165
 
162
- // TODO: This should be part of bb aztec_process!
163
- await stripInternalPrefixes(artifacts);
166
+ await stampAztecVersion(unprocessed);
164
167
  }
165
168
 
166
- log('Compilation complete!');
169
+ if (shouldRecompile || unprocessed.length > 0) {
170
+ log('Compilation complete!');
171
+ } else {
172
+ log('No source changes detected, skipping compilation.');
173
+ }
167
174
  }
168
175
 
169
176
  export function injectCompileCommand(program: Command, log: LogFn): Command {
@@ -189,3 +196,10 @@ export function injectCompileCommand(program: Command, log: LogFn): Command {
189
196
 
190
197
  return program;
191
198
  }
199
+
200
+ interface ContractArtifactInfo {
201
+ /** Path to the artifact JSON in the target directory. */
202
+ filePath: string;
203
+ /** Whether the artifact has already been transpiled and had its verification keys generated. */
204
+ transpiled: boolean;
205
+ }
@@ -11,8 +11,9 @@ export function injectProfileCommand(program: Command, log: LogFn): Command {
11
11
  profile
12
12
  .command('gates')
13
13
  .argument('[target-dir]', 'Path to the compiled artifacts directory', './target')
14
+ .option('--json', 'Output gate counts as JSON instead of a table', false)
14
15
  .description('Display gate counts for all compiled Aztec artifacts in a target directory.')
15
- .action((targetDir: string) => profileGates(targetDir, log));
16
+ .action((targetDir: string, options: { json: boolean }) => profileGates(targetDir, options.json, log));
16
17
 
17
18
  profile
18
19
  .command('flamegraph')
@@ -6,12 +6,13 @@ import { execFile as execFileCb } from 'child_process';
6
6
  import { rm } from 'fs/promises';
7
7
  import { promisify } from 'util';
8
8
 
9
- import { MAX_CONCURRENT, discoverArtifacts } from './profile_utils.js';
9
+ import { type DiscoveredArtifact, MAX_CONCURRENT, discoverArtifacts } from './profile_utils.js';
10
10
 
11
11
  const execFile = promisify(execFileCb);
12
12
 
13
13
  interface GateCountResult {
14
14
  name: string;
15
+ type: DiscoveredArtifact['type'];
15
16
  gateCount: number;
16
17
  }
17
18
 
@@ -32,24 +33,39 @@ async function getGateCount(bb: string, artifactPath: string): Promise<number> {
32
33
  }
33
34
 
34
35
  /** Profiles all compiled artifacts in a target directory and prints gate counts. */
35
- export async function profileGates(targetDir: string, log: LogFn): Promise<void> {
36
+ export async function profileGates(targetDir: string, json: boolean, log: LogFn): Promise<void> {
36
37
  const bb = process.env.BB ?? findBbBinary() ?? 'bb';
37
38
  const { artifacts, tmpDir } = await discoverArtifacts(targetDir);
38
39
 
39
40
  if (artifacts.length === 0) {
40
- log('No artifacts found in target directory.');
41
+ if (json) {
42
+ log('[]');
43
+ } else {
44
+ log('No artifacts found in target directory.');
45
+ }
41
46
  return;
42
47
  }
43
48
 
44
49
  try {
45
50
  const results: GateCountResult[] = await asyncPool(MAX_CONCURRENT, artifacts, async artifact => ({
46
51
  name: artifact.name,
52
+ type: artifact.type,
47
53
  gateCount: await getGateCount(bb, artifact.filePath),
48
54
  }));
49
55
  results.sort((a, b) => a.name.localeCompare(b.name));
50
56
 
51
57
  if (results.length === 0) {
52
- log('No constrained circuits found.');
58
+ if (json) {
59
+ log('[]');
60
+ } else {
61
+ log('No constrained circuits found.');
62
+ }
63
+ return;
64
+ }
65
+
66
+ if (json) {
67
+ const entries = results.map(r => ({ name: r.name, type: r.type, gates: r.gateCount }));
68
+ log(JSON.stringify(entries, null, 2));
53
69
  return;
54
70
  }
55
71
 
@@ -0,0 +1,42 @@
1
+ import { jsonStringify } from '@aztec/foundation/json-rpc';
2
+ import type { LogFn } from '@aztec/foundation/log';
3
+ import { createProverNodeAdminClient } from '@aztec/stdlib/interfaces/server';
4
+
5
+ import { type Command, InvalidArgumentError } from 'commander';
6
+
7
+ function parseEpoch(value: string): number {
8
+ const parsed = Number(value);
9
+ if (!Number.isInteger(parsed) || parsed < 0) {
10
+ throw new InvalidArgumentError('Epoch must be a non-negative integer.');
11
+ }
12
+ return parsed;
13
+ }
14
+
15
+ export function injectProverCommand(program: Command, log: LogFn): Command {
16
+ const proverCommand = program.command('prover').description('Operate a prover node via its admin JSON-RPC endpoint');
17
+
18
+ proverCommand
19
+ .command('start-proof')
20
+ .description('Schedules proving for the given epoch')
21
+ .requiredOption('--epoch <n>', 'Epoch number to prove', parseEpoch)
22
+ .requiredOption('--admin-url <url>', 'URL of the prover node admin JSON-RPC endpoint')
23
+ .option('--api-key <key>', 'Admin API key', process.env.AZTEC_ADMIN_API_KEY)
24
+ .action(async options => {
25
+ const client = createProverNodeAdminClient(options.adminUrl, {}, undefined, options.apiKey);
26
+ const jobId = await client.startProof(options.epoch);
27
+ log(`Started proving job ${jobId} for epoch ${options.epoch}`);
28
+ });
29
+
30
+ proverCommand
31
+ .command('get-jobs')
32
+ .description('Lists the prover node proving jobs')
33
+ .requiredOption('--admin-url <url>', 'URL of the prover node admin JSON-RPC endpoint')
34
+ .option('--api-key <key>', 'Admin API key', process.env.AZTEC_ADMIN_API_KEY)
35
+ .action(async options => {
36
+ const client = createProverNodeAdminClient(options.adminUrl, {}, undefined, options.apiKey);
37
+ const jobs = await client.getJobs();
38
+ log(jsonStringify(jobs, true));
39
+ });
40
+
41
+ return program;
42
+ }
@@ -6,13 +6,16 @@ import type { GenesisStateConfig } from '@aztec/ethereum/config';
6
6
  import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
7
7
  import type { EthAddress } from '@aztec/foundation/eth-address';
8
8
  import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server';
9
- import type { LogFn } from '@aztec/foundation/log';
9
+ import { type LogFn, createLogger } from '@aztec/foundation/log';
10
10
  import { retryUntil } from '@aztec/foundation/retry';
11
11
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
12
+ import type { VersionCheck } from '@aztec/stdlib/update-checker';
12
13
  import { getGenesisValues } from '@aztec/world-state/testing';
13
14
 
14
15
  import Koa from 'koa';
15
16
 
17
+ import { isShuttingDown, softShutdown } from '../util.js';
18
+
16
19
  const ROLLUP_POLL_INTERVAL_S = 60;
17
20
 
18
21
  /**
@@ -23,19 +26,24 @@ const ROLLUP_POLL_INTERVAL_S = 60;
23
26
  export async function computeExpectedGenesisRoot(config: GenesisStateConfig, userLog: LogFn) {
24
27
  const testAccounts = config.testAccounts ? (await getInitialTestAccountsData()).map(a => a.address) : [];
25
28
  const sponsoredFPCAccounts = config.sponsoredFPC ? [await getSponsoredFPCAddress()] : [];
26
- const prefundAddresses = (config.prefundAddresses ?? []).map(a => AztecAddress.fromString(a));
29
+ const prefundAddresses = (config.prefundAddresses ?? []).map(a => AztecAddress.fromStringUnsafe(a));
27
30
  const initialFundedAccounts = testAccounts.concat(sponsoredFPCAccounts).concat(prefundAddresses);
28
31
 
29
32
  userLog(`Initial funded accounts: ${initialFundedAccounts.map(a => a.toString()).join(', ')}`);
30
33
 
31
- const { genesisArchiveRoot, prefilledPublicData } = await getGenesisValues(initialFundedAccounts);
34
+ const { genesisArchiveRoot, genesis } = await getGenesisValues(initialFundedAccounts);
32
35
 
33
36
  userLog(`Genesis archive root: ${genesisArchiveRoot.toString()}`);
34
37
 
35
- return { genesisArchiveRoot, prefilledPublicData };
38
+ return { genesisArchiveRoot, genesis };
36
39
  }
37
40
 
38
- async function checkRollupCompatibility(
41
+ /**
42
+ * Compares the rollup's on-chain protocol constants (genesis archive root, VK tree root, protocol
43
+ * contracts hash) against the node's expected local values. Returns a list of human-readable mismatch
44
+ * descriptions, empty if the rollup is compatible.
45
+ */
46
+ export async function checkRollupCompatibility(
39
47
  rollup: RollupContract,
40
48
  expected: { genesisArchiveRoot: Fr; vkTreeRoot: Fr; protocolContractsHash: Fr },
41
49
  ): Promise<string[]> {
@@ -67,7 +75,7 @@ export async function waitForCompatibleRollup(
67
75
  config: {
68
76
  l1RpcUrls: string[];
69
77
  l1ChainId: number;
70
- l1Contracts: { registryAddress: EthAddress };
78
+ registryAddress: EthAddress;
71
79
  rollupVersion?: number;
72
80
  },
73
81
  expected: { genesisArchiveRoot: Fr; vkTreeRoot: Fr; protocolContractsHash: Fr },
@@ -77,7 +85,7 @@ export async function waitForCompatibleRollup(
77
85
  const publicClient = getPublicClient(config);
78
86
  const rollupVersion: number | 'canonical' = config.rollupVersion ?? 'canonical';
79
87
 
80
- const registry = new RegistryContract(publicClient, config.l1Contracts.registryAddress);
88
+ const registry = new RegistryContract(publicClient, config.registryAddress);
81
89
  const rollupAddress = await registry.getRollupAddress(rollupVersion);
82
90
  const rollup = new RollupContract(publicClient, rollupAddress.toString());
83
91
 
@@ -130,3 +138,47 @@ export async function waitForCompatibleRollup(
130
138
  await new Promise<void>((resolve, reject) => standbyServer.close(err => (err ? reject(err) : resolve())));
131
139
  }
132
140
  }
141
+
142
+ /**
143
+ * Polls the canonical rollup's protocol constants every 10 minutes and soft-shuts-down the node once they
144
+ * diverge from the node's expected local values (i.e. an incompatible rollup has become canonical on L1).
145
+ * The HTTP health server is left running so K8s probes keep passing on the wound-down pod. This is the
146
+ * inverse of {@link waitForCompatibleRollup}; it should only be set up for nodes following the canonical
147
+ * rollup. Reuses the {@link checkRollupCompatibility} diff and the generic VersionChecker poll primitive.
148
+ */
149
+ export async function setupAutoShutdown(
150
+ config: { l1RpcUrls: string[]; l1ChainId: number },
151
+ registryAddress: EthAddress,
152
+ rollupVersion: number | 'canonical',
153
+ expected: { genesisArchiveRoot: Fr; vkTreeRoot: Fr; protocolContractsHash: Fr },
154
+ signalHandlers: Array<() => Promise<void>>,
155
+ ): Promise<void> {
156
+ const { VersionChecker } = await import('@aztec/stdlib/update-checker');
157
+
158
+ const logger = createLogger('auto_shutdown');
159
+ const publicClient = getPublicClient(config);
160
+ const registry = new RegistryContract(publicClient, registryAddress);
161
+
162
+ const check: VersionCheck = {
163
+ name: 'rollup',
164
+ currentVersion: 'compatible',
165
+ getLatestVersion: async () => {
166
+ const rollupAddress = await registry.getRollupAddress(rollupVersion);
167
+ const rollup = new RollupContract(publicClient, rollupAddress.toString());
168
+ const mismatches = await checkRollupCompatibility(rollup, expected);
169
+ return mismatches.length === 0 ? 'compatible' : `incompatible: ${mismatches.join('; ')}`;
170
+ },
171
+ };
172
+
173
+ const checker = new VersionChecker([check], 600_000, logger);
174
+ checker.on('newVersion', ({ latestVersion }) => {
175
+ if (isShuttingDown()) {
176
+ return;
177
+ }
178
+ logger.warn('Canonical rollup is no longer compatible; auto-shutting down node', { latestVersion });
179
+ // softShutdown never rejects (it awaits handlers via allSettled); fire-and-forget from the listener.
180
+ void softShutdown(logger.info.bind(logger), signalHandlers);
181
+ });
182
+ checker.start();
183
+ signalHandlers.push(() => checker.stop());
184
+ }
@@ -21,11 +21,9 @@ export async function startBot(
21
21
  services: NamespacedApiHandlers,
22
22
  userLog: LogFn,
23
23
  ) {
24
- const { proverNode, archiver, sequencer, p2pBootstrap, txe, prover } = options;
25
- if (proverNode || archiver || sequencer || p2pBootstrap || txe || prover) {
26
- userLog(
27
- `Starting a bot with --prover-node, --prover, --archiver, --sequencer, --p2p-bootstrap, or --txe is not supported.`,
28
- );
24
+ const { proverNode, sequencer, p2pBootstrap, txe, prover } = options;
25
+ if (proverNode || sequencer || p2pBootstrap || txe || prover) {
26
+ userLog(`Starting a bot with --prover-node, --prover, --sequencer, --p2p-bootstrap, or --txe is not supported.`);
29
27
  process.exit(1);
30
28
  }
31
29
 
@@ -58,6 +56,11 @@ export async function addBot(
58
56
  const config = extractRelevantOptions<BotConfig>(options, botConfigMappings, 'bot');
59
57
  userLog?.(`Starting bot with config ${stringifyConfig(config)}`);
60
58
 
59
+ // The bot wallet's embedded PXE syncs to this tip (see start_bot.ts/start_node.ts which build the wallet from the
60
+ // same options). L1-to-L2 readiness checks must be evaluated at this tip rather than at 'latest', or the bot can
61
+ // consider a message ready while the PXE simulation anchors to an older block that cannot prove its membership yet.
62
+ const { syncChainTip } = extractRelevantOptions<PXEConfig & CliPXEOptions>(options, allPxeConfigMappings, 'pxe');
63
+
61
64
  const db = await (config.dataDirectory
62
65
  ? createStore('bot', BotStore.SCHEMA_VERSION, config)
63
66
  : openTmpStore('bot', true, config.dataStoreMapSizeKb));
@@ -65,7 +68,7 @@ export async function addBot(
65
68
  const store = new BotStore(db);
66
69
  await store.cleanupOldClaims();
67
70
 
68
- const botRunner = new BotRunner(config, wallet, aztecNode, telemetry, aztecNodeAdmin, store);
71
+ const botRunner = new BotRunner(config, wallet, aztecNode, telemetry, aztecNodeAdmin, store, syncChainTip);
69
72
  if (!config.noStart) {
70
73
  void botRunner.start(); // Do not block since bot setup takes time
71
74
  }
@@ -1,7 +1,11 @@
1
- import { type AztecNodeConfig, aztecNodeConfigMappings, getConfigEnvVars } from '@aztec/aztec-node';
1
+ import {
2
+ type AztecNodeConfig,
3
+ aztecNodeConfigMappings,
4
+ getConfigEnvVars,
5
+ registerAztecNodeRpcHandlers,
6
+ } from '@aztec/aztec-node';
2
7
  import { Fr } from '@aztec/aztec.js/fields';
3
8
  import { getL1Config } from '@aztec/cli/config';
4
- import { getPublicClient } from '@aztec/ethereum/client';
5
9
  import { getGenesisStateConfigEnvVars } from '@aztec/ethereum/config';
6
10
  import { type NetworkNames, SecretValue } from '@aztec/foundation/config';
7
11
  import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
@@ -9,10 +13,13 @@ import { Agent, makeUndiciFetch } from '@aztec/foundation/json-rpc/undici';
9
13
  import type { LogFn } from '@aztec/foundation/log';
10
14
  import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
11
15
  import { protocolContractsHash } from '@aztec/protocol-contracts';
12
- import { ProvingJobConsumerSchema, createProvingJobBrokerClient } from '@aztec/prover-client/broker';
16
+ import {
17
+ ProvingJobConsumerSchema,
18
+ createProvingJobBrokerClient,
19
+ proverBrokerBackoff,
20
+ } from '@aztec/prover-client/broker';
13
21
  import { type CliPXEOptions, type PXEConfig, allPxeConfigMappings } from '@aztec/pxe/config';
14
- import { AztecNodeAdminApiSchema, AztecNodeApiSchema } from '@aztec/stdlib/interfaces/client';
15
- import { P2PApiSchema, ProverNodeApiSchema, type ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
22
+ import { ProverNodeApiSchema, type ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
16
23
  import {
17
24
  type TelemetryClientConfig,
18
25
  initTelemetryClient,
@@ -22,14 +29,9 @@ import {
22
29
  import { EmbeddedWallet } from '@aztec/wallets/embedded';
23
30
 
24
31
  import { createAztecNode } from '../../local-network/index.js';
25
- import {
26
- extractNamespacedOptions,
27
- extractRelevantOptions,
28
- preloadCrsDataForVerifying,
29
- setupVersionChecker,
30
- } from '../util.js';
32
+ import { extractNamespacedOptions, extractRelevantOptions, preloadCrsDataForVerifying } from '../util.js';
31
33
  import { getVersions } from '../versioning.js';
32
- import { computeExpectedGenesisRoot, waitForCompatibleRollup } from './standby.js';
34
+ import { computeExpectedGenesisRoot, setupAutoShutdown, waitForCompatibleRollup } from './standby.js';
33
35
  import { startProverBroker } from './start_prover_broker.js';
34
36
 
35
37
  export async function startNode(
@@ -65,12 +67,8 @@ export async function startNode(
65
67
  if (nodeConfig.proverBrokerUrl) {
66
68
  // at 1TPS we'd enqueue ~1k chonk verifier proofs and ~1k AVM proofs immediately
67
69
  // set a lower connection limit such that we don't overload the server
68
- // Keep retrying up to 30s
69
- const fetch = makeTracedFetch(
70
- [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3],
71
- false,
72
- makeUndiciFetch(new Agent({ connections: 100 })),
73
- );
70
+ // Retry indefinitely until the epoch proving times out and the chain reorgs
71
+ const fetch = makeTracedFetch(proverBrokerBackoff, false, makeUndiciFetch(new Agent({ connections: 100 })));
74
72
  broker = createProvingJobBrokerClient(nodeConfig.proverBrokerUrl, getVersions(nodeConfig), fetch);
75
73
  } else if (options.proverBroker) {
76
74
  ({ broker } = await startProverBroker(options, signalHandlers, services, userLog));
@@ -83,12 +81,12 @@ export async function startNode(
83
81
  await preloadCrsDataForVerifying(nodeConfig, userLog);
84
82
 
85
83
  const genesisConfig = getGenesisStateConfigEnvVars();
86
- const { genesisArchiveRoot, prefilledPublicData } = await computeExpectedGenesisRoot(genesisConfig, userLog);
84
+ const { genesisArchiveRoot, genesis } = await computeExpectedGenesisRoot(genesisConfig, userLog);
87
85
 
88
86
  const followsCanonicalRollup =
89
87
  typeof nodeConfig.rollupVersion !== 'number' || (nodeConfig.rollupVersion as unknown as string) === 'canonical';
90
88
 
91
- if (!nodeConfig.l1Contracts.registryAddress || nodeConfig.l1Contracts.registryAddress.isZero()) {
89
+ if (!nodeConfig.registryAddress || nodeConfig.registryAddress.isZero()) {
92
90
  throw new Error('L1 registry address is required to start Aztec Node');
93
91
  }
94
92
 
@@ -102,7 +100,7 @@ export async function startNode(
102
100
  );
103
101
 
104
102
  const { addresses, config } = await getL1Config(
105
- nodeConfig.l1Contracts.registryAddress,
103
+ nodeConfig.registryAddress,
106
104
  nodeConfig.l1RpcUrls,
107
105
  nodeConfig.l1ChainId,
108
106
  nodeConfig.rollupVersion,
@@ -116,13 +114,9 @@ export async function startNode(
116
114
  );
117
115
  }
118
116
 
119
- // TODO(#12272): will clean this up.
120
117
  nodeConfig = {
121
118
  ...nodeConfig,
122
- l1Contracts: {
123
- ...addresses,
124
- slashFactoryAddress: nodeConfig.l1Contracts.slashFactoryAddress,
125
- },
119
+ ...addresses,
126
120
  ...config,
127
121
  };
128
122
 
@@ -158,17 +152,14 @@ export async function startNode(
158
152
  const telemetry = await initTelemetryClient(telemetryConfig);
159
153
 
160
154
  // Create and start Aztec Node
161
- const node = await createAztecNode(nodeConfig, { telemetry, proverBroker: broker }, { prefilledPublicData });
155
+ const node = await createAztecNode(nodeConfig, { telemetry, proverBroker: broker }, { genesis });
162
156
 
163
- // Add node and p2p to services list
164
- services.node = [node, AztecNodeApiSchema];
165
- services.p2p = [node.getP2P(), P2PApiSchema];
166
- adminServices.nodeAdmin = [node, AztecNodeAdminApiSchema];
157
+ registerAztecNodeRpcHandlers(node, services, adminServices, { debug: options.nodeDebug });
167
158
 
168
159
  // Register prover-node services if the prover node subsystem is running
169
160
  const proverNode = node.getProverNode();
170
161
  if (proverNode) {
171
- services.prover = [proverNode, ProverNodeApiSchema];
162
+ adminServices.prover = [proverNode, ProverNodeApiSchema];
172
163
  if (!nodeConfig.proverBrokerUrl) {
173
164
  services.provingJobSource = [proverNode.getProver().getProvingJobSource(), ProvingJobConsumerSchema];
174
165
  }
@@ -187,15 +178,14 @@ export async function startNode(
187
178
  await addBot(options, signalHandlers, services, wallet, node, telemetry, undefined);
188
179
  }
189
180
 
190
- if (nodeConfig.enableVersionCheck && networkName !== 'local') {
191
- const cacheDir = process.env.DATA_DIRECTORY ? `${process.env.DATA_DIRECTORY}/cache` : undefined;
181
+ if (nodeConfig.enableAutoShutdown && networkName !== 'local' && followsCanonicalRollup) {
192
182
  try {
193
- await setupVersionChecker(
194
- networkName,
195
- followsCanonicalRollup,
196
- getPublicClient(nodeConfig!),
183
+ await setupAutoShutdown(
184
+ nodeConfig,
185
+ nodeConfig.registryAddress,
186
+ (nodeConfig.rollupVersion as number | 'canonical') ?? 'canonical',
187
+ { genesisArchiveRoot, vkTreeRoot: getVKTreeRoot(), protocolContractsHash },
197
188
  signalHandlers,
198
- cacheDir,
199
189
  );
200
190
  } catch {
201
191
  /* no-op */
@@ -9,6 +9,7 @@ import {
9
9
  createProofStore,
10
10
  createProvingJobBrokerClient,
11
11
  proverAgentConfigMappings,
12
+ proverBrokerBackoff,
12
13
  } from '@aztec/prover-client/broker';
13
14
  import { getProverNodeAgentConfigFromEnv } from '@aztec/prover-node';
14
15
  import { ProverAgentApiSchema } from '@aztec/stdlib/interfaces/server';
@@ -23,8 +24,8 @@ export async function startProverAgent(
23
24
  services: NamespacedApiHandlers,
24
25
  userLog: LogFn,
25
26
  ) {
26
- if (options.node || options.sequencer || options.pxe || options.p2pBootstrap || options.txe) {
27
- userLog(`Starting a prover agent with --node, --sequencer, --pxe, --p2p-bootstrap, or --txe is not supported.`);
27
+ if (options.node || options.sequencer || options.p2pBootstrap || options.txe) {
28
+ userLog(`Starting a prover agent with --node, --sequencer, --p2p-bootstrap, or --txe is not supported.`);
28
29
  process.exit(1);
29
30
  }
30
31
 
@@ -45,12 +46,8 @@ export async function startProverAgent(
45
46
 
46
47
  await preloadCrsDataForServerSideProving(config, userLog);
47
48
 
48
- const fetch = makeTracedFetch(
49
- // retry connections every 3s, up to 30s before giving up
50
- [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3],
51
- false,
52
- makeUndiciFetch(new Agent({ connections: 10 })),
53
- );
49
+ // Retry indefinitely until the epoch proving times out and the chain reorgs
50
+ const fetch = makeTracedFetch(proverBrokerBackoff, false, makeUndiciFetch(new Agent({ connections: 10 })));
54
51
  const broker = createProvingJobBrokerClient(config.proverBrokerUrl, getVersions(), fetch);
55
52
 
56
53
  const telemetry = await initTelemetryClient(extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'));
@@ -24,38 +24,37 @@ export async function startProverBroker(
24
24
  services: NamespacedApiHandlers,
25
25
  userLog: LogFn,
26
26
  ): Promise<{ broker: ProvingJobBroker; config: ProverBrokerConfig }> {
27
- if (options.node || options.sequencer || options.pxe || options.p2pBootstrap || options.txe) {
28
- userLog(`Starting a prover broker with --node, --sequencer, --pxe, --p2p-bootstrap, or --txe is not supported.`);
27
+ if (options.node || options.sequencer || options.p2pBootstrap || options.txe) {
28
+ userLog(`Starting a prover broker with --node, --sequencer, --p2p-bootstrap, or --txe is not supported.`);
29
29
  process.exit(1);
30
30
  }
31
31
 
32
- const config: ProverBrokerConfig = {
32
+ const baseConfig: ProverBrokerConfig = {
33
33
  ...getProverNodeBrokerConfigFromEnv(), // get default config from env
34
34
  ...extractRelevantOptions<ProverBrokerConfig>(options, proverBrokerConfigMappings, 'proverBroker'), // override with command line options
35
35
  };
36
36
 
37
- if (!config.l1Contracts.registryAddress || config.l1Contracts.registryAddress.isZero()) {
37
+ if (!baseConfig.registryAddress || baseConfig.registryAddress.isZero()) {
38
38
  throw new Error('L1 registry address is required to start Aztec Node without --deploy-aztec-contracts option');
39
39
  }
40
40
 
41
41
  const genesisConfig = getGenesisStateConfigEnvVars();
42
42
  const { genesisArchiveRoot } = await computeExpectedGenesisRoot(genesisConfig, userLog);
43
43
  await waitForCompatibleRollup(
44
- config,
44
+ baseConfig,
45
45
  { genesisArchiveRoot, vkTreeRoot: getVKTreeRoot(), protocolContractsHash },
46
46
  options.port,
47
47
  userLog,
48
48
  );
49
49
 
50
50
  const { addresses, config: rollupConfig } = await getL1Config(
51
- config.l1Contracts.registryAddress,
52
- config.l1RpcUrls,
53
- config.l1ChainId,
54
- config.rollupVersion,
51
+ baseConfig.registryAddress,
52
+ baseConfig.l1RpcUrls,
53
+ baseConfig.l1ChainId,
54
+ baseConfig.rollupVersion,
55
55
  );
56
56
 
57
- config.l1Contracts = addresses;
58
- config.rollupVersion = rollupConfig.rollupVersion;
57
+ const config: ProverBrokerConfig = { ...baseConfig, ...addresses, rollupVersion: rollupConfig.rollupVersion };
59
58
 
60
59
  const client = await initTelemetryClient(getTelemetryClientConfig());
61
60
  const broker = await createAndStartProvingBroker(config, client);
@@ -1,15 +1,17 @@
1
1
  import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server';
2
2
  import type { Logger } from '@aztec/foundation/log';
3
- import { createTXERpcServer } from '@aztec/txe';
3
+ import { createTXERpcServer } from '@aztec/txe/server';
4
4
 
5
- export async function startTXE(options: any, debugLogger: Logger) {
5
+ export async function startTXE(options: any, signalHandlers: Array<() => Promise<void>>, debugLogger: Logger) {
6
6
  debugLogger.info(`Setting up TXE...`);
7
7
 
8
- const txeServer = createTXERpcServer(debugLogger);
9
- const { port } = await startHttpRpcServer(txeServer, {
8
+ const txeServer = await createTXERpcServer(debugLogger);
9
+ const httpServer = await startHttpRpcServer(txeServer, {
10
10
  port: options.port,
11
11
  timeoutMs: 1e3 * 60 * 5,
12
12
  });
13
13
 
14
- debugLogger.info(`TXE listening on port ${port}`);
14
+ signalHandlers.push(() => new Promise<void>(resolve => httpServer.close(() => resolve())));
15
+
16
+ debugLogger.info(`TXE listening on port ${httpServer.port}`);
15
17
  }
@@ -6,6 +6,11 @@ export interface CompiledArtifact {
6
6
  file_map: unknown;
7
7
  functions: ContractFunction[];
8
8
  bytecode?: string;
9
+ /**
10
+ * Set to true by the AVM transpiler (invoked via `bb aztec_process`) once the contract has been transpiled and its
11
+ * verification keys generated. Absent on raw `nargo compile` output, hence optional.
12
+ */
13
+ transpiled?: boolean;
9
14
  }
10
15
 
11
16
  export interface ContractFunction {