@aztec/aztec 0.0.1-commit.7ac86ea28 → 0.0.1-commit.7b86788

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 (50) hide show
  1. package/dest/bin/index.js +2 -0
  2. package/dest/cli/admin_api_key_store.d.ts +3 -3
  3. package/dest/cli/admin_api_key_store.d.ts.map +1 -1
  4. package/dest/cli/admin_api_key_store.js +3 -3
  5. package/dest/cli/aztec_start_action.js +2 -2
  6. package/dest/cli/aztec_start_options.d.ts +1 -1
  7. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  8. package/dest/cli/aztec_start_options.js +4 -3
  9. package/dest/cli/cmds/compile.d.ts +1 -1
  10. package/dest/cli/cmds/compile.d.ts.map +1 -1
  11. package/dest/cli/cmds/compile.js +100 -35
  12. package/dest/cli/cmds/profile.d.ts +4 -0
  13. package/dest/cli/cmds/profile.d.ts.map +1 -0
  14. package/dest/cli/cmds/profile.js +8 -0
  15. package/dest/cli/cmds/profile_flamegraph.d.ts +4 -0
  16. package/dest/cli/cmds/profile_flamegraph.d.ts.map +1 -0
  17. package/dest/cli/cmds/profile_flamegraph.js +51 -0
  18. package/dest/cli/cmds/profile_gates.d.ts +4 -0
  19. package/dest/cli/cmds/profile_gates.d.ts.map +1 -0
  20. package/dest/cli/cmds/profile_gates.js +57 -0
  21. package/dest/cli/cmds/profile_utils.d.ts +18 -0
  22. package/dest/cli/cmds/profile_utils.d.ts.map +1 -0
  23. package/dest/cli/cmds/profile_utils.js +50 -0
  24. package/dest/cli/cmds/utils/artifacts.d.ts +21 -0
  25. package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -0
  26. package/dest/cli/cmds/utils/artifacts.js +24 -0
  27. package/dest/cli/cmds/utils/spawn.d.ts +3 -0
  28. package/dest/cli/cmds/utils/spawn.d.ts.map +1 -0
  29. package/dest/cli/cmds/utils/spawn.js +16 -0
  30. package/dest/cli/util.js +3 -3
  31. package/package.json +34 -34
  32. package/scripts/aztec.sh +6 -2
  33. package/scripts/init.sh +23 -13
  34. package/scripts/new.sh +17 -16
  35. package/scripts/setup_workspace.sh +124 -0
  36. package/src/bin/index.ts +2 -0
  37. package/src/cli/admin_api_key_store.ts +4 -4
  38. package/src/cli/aztec_start_action.ts +2 -2
  39. package/src/cli/aztec_start_options.ts +4 -3
  40. package/src/cli/cmds/compile.ts +113 -36
  41. package/src/cli/cmds/profile.ts +25 -0
  42. package/src/cli/cmds/profile_flamegraph.ts +63 -0
  43. package/src/cli/cmds/profile_gates.ts +67 -0
  44. package/src/cli/cmds/profile_utils.ts +58 -0
  45. package/src/cli/cmds/utils/artifacts.ts +44 -0
  46. package/src/cli/cmds/utils/spawn.ts +16 -0
  47. package/src/cli/util.ts +2 -2
  48. package/scripts/extract_function.js +0 -47
  49. package/scripts/flamegraph.sh +0 -59
  50. package/scripts/setup_project.sh +0 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/aztec",
3
- "version": "0.0.1-commit.7ac86ea28",
3
+ "version": "0.0.1-commit.7b86788",
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.7ac86ea28",
32
- "@aztec/archiver": "0.0.1-commit.7ac86ea28",
33
- "@aztec/aztec-faucet": "0.0.1-commit.7ac86ea28",
34
- "@aztec/aztec-node": "0.0.1-commit.7ac86ea28",
35
- "@aztec/aztec.js": "0.0.1-commit.7ac86ea28",
36
- "@aztec/bb-prover": "0.0.1-commit.7ac86ea28",
37
- "@aztec/bb.js": "0.0.1-commit.7ac86ea28",
38
- "@aztec/blob-client": "0.0.1-commit.7ac86ea28",
39
- "@aztec/bot": "0.0.1-commit.7ac86ea28",
40
- "@aztec/builder": "0.0.1-commit.7ac86ea28",
41
- "@aztec/cli": "0.0.1-commit.7ac86ea28",
42
- "@aztec/constants": "0.0.1-commit.7ac86ea28",
43
- "@aztec/entrypoints": "0.0.1-commit.7ac86ea28",
44
- "@aztec/ethereum": "0.0.1-commit.7ac86ea28",
45
- "@aztec/foundation": "0.0.1-commit.7ac86ea28",
46
- "@aztec/kv-store": "0.0.1-commit.7ac86ea28",
47
- "@aztec/l1-artifacts": "0.0.1-commit.7ac86ea28",
48
- "@aztec/node-lib": "0.0.1-commit.7ac86ea28",
49
- "@aztec/noir-contracts.js": "0.0.1-commit.7ac86ea28",
50
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.7ac86ea28",
51
- "@aztec/p2p": "0.0.1-commit.7ac86ea28",
52
- "@aztec/p2p-bootstrap": "0.0.1-commit.7ac86ea28",
53
- "@aztec/protocol-contracts": "0.0.1-commit.7ac86ea28",
54
- "@aztec/prover-client": "0.0.1-commit.7ac86ea28",
55
- "@aztec/prover-node": "0.0.1-commit.7ac86ea28",
56
- "@aztec/pxe": "0.0.1-commit.7ac86ea28",
57
- "@aztec/sequencer-client": "0.0.1-commit.7ac86ea28",
58
- "@aztec/stdlib": "0.0.1-commit.7ac86ea28",
59
- "@aztec/telemetry-client": "0.0.1-commit.7ac86ea28",
60
- "@aztec/txe": "0.0.1-commit.7ac86ea28",
61
- "@aztec/validator-ha-signer": "0.0.1-commit.7ac86ea28",
62
- "@aztec/wallets": "0.0.1-commit.7ac86ea28",
63
- "@aztec/world-state": "0.0.1-commit.7ac86ea28",
31
+ "@aztec/accounts": "0.0.1-commit.7b86788",
32
+ "@aztec/archiver": "0.0.1-commit.7b86788",
33
+ "@aztec/aztec-faucet": "0.0.1-commit.7b86788",
34
+ "@aztec/aztec-node": "0.0.1-commit.7b86788",
35
+ "@aztec/aztec.js": "0.0.1-commit.7b86788",
36
+ "@aztec/bb-prover": "0.0.1-commit.7b86788",
37
+ "@aztec/bb.js": "0.0.1-commit.7b86788",
38
+ "@aztec/blob-client": "0.0.1-commit.7b86788",
39
+ "@aztec/bot": "0.0.1-commit.7b86788",
40
+ "@aztec/builder": "0.0.1-commit.7b86788",
41
+ "@aztec/cli": "0.0.1-commit.7b86788",
42
+ "@aztec/constants": "0.0.1-commit.7b86788",
43
+ "@aztec/entrypoints": "0.0.1-commit.7b86788",
44
+ "@aztec/ethereum": "0.0.1-commit.7b86788",
45
+ "@aztec/foundation": "0.0.1-commit.7b86788",
46
+ "@aztec/kv-store": "0.0.1-commit.7b86788",
47
+ "@aztec/l1-artifacts": "0.0.1-commit.7b86788",
48
+ "@aztec/node-lib": "0.0.1-commit.7b86788",
49
+ "@aztec/noir-contracts.js": "0.0.1-commit.7b86788",
50
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.7b86788",
51
+ "@aztec/p2p": "0.0.1-commit.7b86788",
52
+ "@aztec/p2p-bootstrap": "0.0.1-commit.7b86788",
53
+ "@aztec/protocol-contracts": "0.0.1-commit.7b86788",
54
+ "@aztec/prover-client": "0.0.1-commit.7b86788",
55
+ "@aztec/prover-node": "0.0.1-commit.7b86788",
56
+ "@aztec/pxe": "0.0.1-commit.7b86788",
57
+ "@aztec/sequencer-client": "0.0.1-commit.7b86788",
58
+ "@aztec/stdlib": "0.0.1-commit.7b86788",
59
+ "@aztec/telemetry-client": "0.0.1-commit.7b86788",
60
+ "@aztec/txe": "0.0.1-commit.7b86788",
61
+ "@aztec/validator-ha-signer": "0.0.1-commit.7b86788",
62
+ "@aztec/wallets": "0.0.1-commit.7b86788",
63
+ "@aztec/world-state": "0.0.1-commit.7b86788",
64
64
  "@types/chalk": "^2.2.0",
65
65
  "abitype": "^0.8.11",
66
66
  "chalk": "^5.3.0",
package/scripts/aztec.sh CHANGED
@@ -46,16 +46,20 @@ case $cmd in
46
46
  export ETHEREUM_HOSTS=${ETHEREUM_HOSTS:-"http://127.0.0.1:${ANVIL_PORT}"}
47
47
 
48
48
  anvil --version
49
- anvil --silent &
49
+ anvil --silent --port "$ANVIL_PORT" &
50
50
  anvil_pid=$!
51
51
  trap 'kill $anvil_pid &>/dev/null' EXIT
52
52
  fi
53
53
 
54
54
  aztec start "$@"
55
55
  ;;
56
- new|init|flamegraph)
56
+ new|init)
57
57
  $script_dir/${cmd}.sh "$@"
58
58
  ;;
59
+ flamegraph)
60
+ echo "Warning: 'aztec flamegraph' is deprecated. Use 'aztec profile flamegraph' instead." >&2
61
+ aztec profile flamegraph "$@"
62
+ ;;
59
63
  *)
60
64
  aztec $cmd "$@"
61
65
  ;;
package/scripts/init.sh CHANGED
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
 
4
- NARGO=${NARGO:-nargo}
5
4
  script_path=$(realpath $(dirname "$0"))
6
5
 
6
+ name_arg=""
7
+
8
+ # Check for help first
7
9
  for arg in "$@"; do
8
10
  if [ "$arg" == "--help" ] || [ "$arg" == "-h" ]; then
9
11
  cat << 'EOF'
@@ -13,23 +15,31 @@ Usage: aztec init [OPTIONS]
13
15
 
14
16
  Options:
15
17
  --name <NAME> Name of the package [default: current directory name]
16
- --lib Use a library template
17
18
  -h, --help Print help
18
19
 
19
- This command creates a new Aztec Noir project in the current directory using nargo
20
- and automatically adds the Aztec.nr dependency to your Nargo.toml file.
21
-
20
+ This command creates a new Aztec Noir project in the current directory with
21
+ a workspace containing a contract crate and a test crate, and automatically
22
+ adds the Aztec.nr dependency to both.
22
23
  EOF
23
24
  exit 0
24
25
  fi
25
- if [ "$arg" == "--lib" ]; then
26
- is_contract=0
27
- fi
28
26
  done
29
27
 
30
- echo "Initializing Noir project..."
31
- $NARGO init "$@"
28
+ # Parse arguments
29
+ while [[ $# -gt 0 ]]; do
30
+ case $1 in
31
+ --name)
32
+ name_arg="$2"
33
+ shift 2
34
+ ;;
35
+ *)
36
+ shift
37
+ ;;
38
+ esac
39
+ done
40
+
41
+ # Derive package name: use --name if provided, otherwise use current directory name
42
+ package_name="${name_arg:-$(basename $(pwd))}"
32
43
 
33
- if [ "${is_contract:-1}" -eq 1 ]; then
34
- $script_path/setup_project.sh
35
- fi
44
+ echo "Initializing Aztec contract project..."
45
+ $script_path/setup_workspace.sh "$package_name"
package/scripts/new.sh CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
 
4
- NARGO=${NARGO:-nargo}
5
4
  script_path=$(realpath $(dirname "$0"))
6
5
 
7
- type_arg="--contract"
6
+ name_arg=""
7
+ project_path=""
8
8
 
9
9
  while [[ $# -gt 0 ]]; do
10
10
  case $1 in
@@ -19,20 +19,16 @@ Arguments:
19
19
 
20
20
  Options:
21
21
  --name <NAME> Name of the package [default: package directory name]
22
- --lib Create a library template instead of a contract
23
22
  -h, --help Print help
24
23
 
25
- This command creates a new Aztec Noir project using nargo and automatically
26
- adds the Aztec.nr dependency to your Nargo.toml file.
24
+ This command creates a new Aztec Noir project with a workspace containing
25
+ a contract crate and a test crate, and automatically adds the Aztec.nr
26
+ dependency to both.
27
27
  EOF
28
28
  exit 0
29
29
  ;;
30
- --lib)
31
- type_arg="--lib"
32
- shift
33
- ;;
34
30
  --name)
35
- name_arg="--name $2"
31
+ name_arg="$2"
36
32
  shift 2
37
33
  ;;
38
34
  *)
@@ -50,10 +46,15 @@ if [ -z "$project_path" ]; then
50
46
  exit 1
51
47
  fi
52
48
 
53
- echo "Creating new Noir project at $project_path..."
54
- $NARGO new $type_arg ${name_arg:-} $project_path
55
-
56
- if [ "$type_arg" == "--contract" ]; then
57
- cd $project_path
58
- $script_path/setup_project.sh
49
+ if [ -d "$project_path" ] && [ "$(ls -A $project_path 2>/dev/null)" ]; then
50
+ echo "Error: $project_path already exists and is not empty"
51
+ exit 1
59
52
  fi
53
+
54
+ # Derive package name: use --name if provided, otherwise use directory basename
55
+ package_name="${name_arg:-$(basename $project_path)}"
56
+
57
+ echo "Creating new Aztec contract project at $project_path..."
58
+ mkdir -p "$project_path"
59
+ cd "$project_path"
60
+ $script_path/setup_workspace.sh "$package_name"
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # Creates an Aztec contract workspace with a contract crate and a test crate.
5
+ # Usage: setup_workspace.sh <package_name>
6
+ # Must be called from the workspace root directory.
7
+
8
+ package_name=$1
9
+
10
+ if [ -z "$package_name" ]; then
11
+ echo "Error: package name is required"
12
+ exit 1
13
+ fi
14
+
15
+ if [ -f "Nargo.toml" ]; then
16
+ echo "Error: Nargo.toml already exists in the current directory"
17
+ exit 1
18
+ fi
19
+
20
+ # Get the actual aztec version for the git tag.
21
+ AZTEC_VERSION=$(jq -r '.version' $(dirname $0)/../package.json)
22
+
23
+ # Create workspace root Nargo.toml
24
+ cat > Nargo.toml << 'EOF'
25
+ [workspace]
26
+ members = ["contract", "test"]
27
+ EOF
28
+
29
+ # Create contract crate
30
+ mkdir -p contract/src
31
+ cat > contract/Nargo.toml << CEOF
32
+ [package]
33
+ name = "${package_name}"
34
+ type = "contract"
35
+
36
+ [dependencies]
37
+ aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v${AZTEC_VERSION}", directory="aztec" }
38
+ CEOF
39
+
40
+ cat > contract/src/main.nr << 'EOF'
41
+ use aztec::macros::aztec;
42
+
43
+ #[aztec]
44
+ pub contract Main {
45
+ use aztec::macros::functions::{external, initializer};
46
+
47
+ #[initializer]
48
+ #[external("private")]
49
+ fn constructor() {}
50
+ }
51
+ EOF
52
+
53
+ # Create test crate
54
+ mkdir -p test/src
55
+ cat > test/Nargo.toml << TEOF
56
+ [package]
57
+ name = "${package_name}_test"
58
+ type = "lib"
59
+
60
+ [dependencies]
61
+ aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v${AZTEC_VERSION}", directory="aztec" }
62
+ ${package_name} = { path = "../contract" }
63
+ TEOF
64
+
65
+ cat > test/src/lib.nr << 'NOIR'
66
+ use aztec::test::helpers::test_environment::TestEnvironment;
67
+ use __PACKAGE_NAME__::Main;
68
+
69
+ #[test]
70
+ unconstrained fn test_constructor() {
71
+ let mut env = TestEnvironment::new();
72
+ let deployer = env.create_light_account();
73
+
74
+ // Deploy the contract with the default constructor:
75
+ let contract_address = env.deploy("@__PACKAGE_NAME__/Main").with_private_initializer(
76
+ deployer,
77
+ Main::interface().constructor(),
78
+ );
79
+
80
+ // Deploy without an initializer:
81
+ let contract_address = env.deploy("@__PACKAGE_NAME__/Main").without_initializer();
82
+ }
83
+ NOIR
84
+
85
+ sed -i "s/__PACKAGE_NAME__/${package_name}/g" test/src/lib.nr
86
+
87
+ # Create README
88
+ cat > README.md << REOF
89
+ # ${package_name}
90
+
91
+ An Aztec Noir contract project.
92
+
93
+ ## Compile
94
+
95
+ \`\`\`bash
96
+ aztec compile
97
+ \`\`\`
98
+
99
+ This compiles the contract in \`contract/\` and outputs artifacts to \`target/\`.
100
+
101
+ ## Test
102
+
103
+ \`\`\`bash
104
+ aztec test
105
+ \`\`\`
106
+
107
+ This runs the tests in \`test/\`.
108
+
109
+ ## Generate TypeScript bindings
110
+
111
+ \`\`\`bash
112
+ aztec codegen target -o src/artifacts
113
+ \`\`\`
114
+
115
+ This generates TypeScript contract artifacts from the compiled output in \`target/\` into \`src/artifacts/\`.
116
+ REOF
117
+
118
+ # Create .gitignore
119
+ cat > .gitignore << 'GEOF'
120
+ target/
121
+ codegenCache.json
122
+ GEOF
123
+
124
+ echo "Created Aztec contract workspace with crates '${package_name}' and '${package_name}_test'"
package/src/bin/index.ts CHANGED
@@ -16,6 +16,7 @@ import { Command } from 'commander';
16
16
 
17
17
  import { injectCompileCommand } from '../cli/cmds/compile.js';
18
18
  import { injectMigrateCommand } from '../cli/cmds/migrate_ha_db.js';
19
+ import { injectProfileCommand } from '../cli/cmds/profile.js';
19
20
  import { injectAztecCommands } from '../cli/index.js';
20
21
  import { getCliVersion } from '../cli/release_version.js';
21
22
 
@@ -58,6 +59,7 @@ async function main() {
58
59
  program = injectMiscCommands(program, userLog);
59
60
  program = injectValidatorKeysCommands(program, userLog);
60
61
  program = injectCompileCommand(program, userLog);
62
+ program = injectProfileCommand(program, userLog);
61
63
  program = injectMigrateCommand(program, userLog);
62
64
 
63
65
  await program.parseAsync(process.argv);
@@ -28,7 +28,7 @@ export interface ResolveAdminApiKeyOptions {
28
28
  /** SHA-256 hex hash of a pre-generated API key. When set, the node uses this hash directly. */
29
29
  adminApiKeyHash?: string;
30
30
  /** If true, disable admin API key auth entirely. */
31
- noAdminApiKey?: boolean;
31
+ disableAdminApiKey?: boolean;
32
32
  /** If true, force-generate a new key even if one is already persisted. */
33
33
  resetAdminApiKey?: boolean;
34
34
  /** Root data directory for persistent storage. */
@@ -39,7 +39,7 @@ export interface ResolveAdminApiKeyOptions {
39
39
  * Resolves the admin API key for the admin RPC endpoint.
40
40
  *
41
41
  * Strategy:
42
- * 1. If opt-out flag is set (`noAdminApiKey`), return undefined (no auth).
42
+ * 1. If opt-out flag is set (`disableAdminApiKey`), return undefined (no auth).
43
43
  * 2. If a pre-generated hash is provided (`adminApiKeyHash`), use it directly.
44
44
  * 3. If a data directory exists, look for a persisted hash file
45
45
  * at `<dataDirectory>/admin/api_key_hash`:
@@ -58,8 +58,8 @@ export async function resolveAdminApiKey(
58
58
  log: Logger,
59
59
  ): Promise<AdminApiKeyResolution | undefined> {
60
60
  // Operator explicitly opted out of admin auth
61
- if (options.noAdminApiKey) {
62
- log.warn('Admin API key authentication is DISABLED (--no-admin-api-key / AZTEC_NO_ADMIN_API_KEY)');
61
+ if (options.disableAdminApiKey) {
62
+ log.warn('Admin API key authentication is DISABLED (--disable-admin-api-key / AZTEC_DISABLE_ADMIN_API_KEY)');
63
63
  return undefined;
64
64
  }
65
65
 
@@ -109,7 +109,7 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
109
109
  const apiKeyResolution = await resolveAdminApiKey(
110
110
  {
111
111
  adminApiKeyHash: options.adminApiKeyHash,
112
- noAdminApiKey: options.noAdminApiKey,
112
+ disableAdminApiKey: options.disableAdminApiKey,
113
113
  resetAdminApiKey: options.resetAdminApiKey,
114
114
  dataDirectory: options.dataDirectory,
115
115
  },
@@ -148,7 +148,7 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
148
148
  userLog(' The key hash has been persisted — on next restart, the same key will be used.');
149
149
  }
150
150
  userLog('');
151
- userLog(' To disable admin auth: --no-admin-api-key or AZTEC_NO_ADMIN_API_KEY=true');
151
+ userLog(' To disable admin auth: --disable-admin-api-key or AZTEC_DISABLE_ADMIN_API_KEY=true');
152
152
  userLog(separator);
153
153
  userLog('');
154
154
  }
@@ -150,12 +150,13 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
150
150
  env: 'AZTEC_ADMIN_API_KEY_HASH',
151
151
  },
152
152
  {
153
- flag: '--no-admin-api-key',
153
+ flag: '--disable-admin-api-key',
154
154
  description:
155
155
  'Disable API key authentication on the admin RPC endpoint. By default, a key is auto-generated, displayed once, and its hash is persisted.',
156
156
  defaultValue: false,
157
- env: 'AZTEC_NO_ADMIN_API_KEY',
158
- parseVal: val => val === 'true' || val === '1',
157
+ env: 'AZTEC_DISABLE_ADMIN_API_KEY',
158
+ // undefined means the flag was passed without a value (boolean toggle), treat as true.
159
+ parseVal: val => val === undefined || val === 'true' || val === '1',
159
160
  },
160
161
  {
161
162
  flag: '--reset-admin-api-key',
@@ -1,51 +1,25 @@
1
1
  import type { LogFn } from '@aztec/foundation/log';
2
2
 
3
- import { execFileSync, spawn } from 'child_process';
3
+ import { execFileSync } from 'child_process';
4
4
  import type { Command } from 'commander';
5
- import { readFile, readdir, writeFile } from 'fs/promises';
5
+ import { readFile, writeFile } from 'fs/promises';
6
6
  import { join } from 'path';
7
7
 
8
- /** Spawns a command with inherited stdio and rejects on non-zero exit. */
9
- function run(cmd: string, args: string[]): Promise<void> {
10
- return new Promise((resolve, reject) => {
11
- const child = spawn(cmd, args, { stdio: 'inherit' });
12
- child.on('error', reject);
13
- child.on('close', code => {
14
- if (code !== 0) {
15
- reject(new Error(`${cmd} exited with code ${code}`));
16
- } else {
17
- resolve();
18
- }
19
- });
20
- });
21
- }
8
+ import { readArtifactFiles } from './utils/artifacts.js';
9
+ import { run } from './utils/spawn.js';
22
10
 
23
- /** Returns paths to contract artifacts in the target directory.
24
- * Contract artifacts are identified by having a `functions` array in the JSON.
25
- */
11
+ /** Returns paths to contract artifacts in the target directory. */
26
12
  async function collectContractArtifacts(): Promise<string[]> {
27
- let files: string[];
13
+ let files;
28
14
  try {
29
- files = await readdir('target');
15
+ files = await readArtifactFiles('target');
30
16
  } catch (err: any) {
31
- if (err?.code === 'ENOENT') {
17
+ if (err?.message?.includes('does not exist')) {
32
18
  return [];
33
19
  }
34
- throw new Error(`Failed to read target directory: ${err.message}`);
35
- }
36
-
37
- const artifacts: string[] = [];
38
- for (const file of files) {
39
- if (!file.endsWith('.json')) {
40
- continue;
41
- }
42
- const filePath = join('target', file);
43
- const content = JSON.parse(await readFile(filePath, 'utf-8'));
44
- if (Array.isArray(content.functions)) {
45
- artifacts.push(filePath);
46
- }
20
+ throw err;
47
21
  }
48
- return artifacts;
22
+ return files.filter(f => Array.isArray(f.content.functions)).map(f => f.filePath);
49
23
  }
50
24
 
51
25
  /** Strips the `__aztec_nr_internals__` prefix from function names in contract artifacts. */
@@ -61,6 +35,106 @@ async function stripInternalPrefixes(artifactPaths: string[]): Promise<void> {
61
35
  }
62
36
  }
63
37
 
38
+ /** Returns the set of package names that are contract crates in the current workspace. */
39
+ async function getContractPackageNames(): Promise<Set<string>> {
40
+ const contractNames = new Set<string>();
41
+
42
+ let rootToml: string;
43
+ try {
44
+ rootToml = await readFile('Nargo.toml', 'utf-8');
45
+ } catch {
46
+ return contractNames;
47
+ }
48
+
49
+ const membersMatch = rootToml.match(/members\s*=\s*\[([^\]]*)\]/);
50
+ if (membersMatch) {
51
+ const members = membersMatch[1]
52
+ .split(',')
53
+ .map(m => m.trim().replace(/^"|"$/g, ''))
54
+ .filter(m => m.length > 0);
55
+
56
+ for (const member of members) {
57
+ try {
58
+ const memberToml = await readFile(join(member, 'Nargo.toml'), 'utf-8');
59
+ if (/type\s*=\s*"contract"/.test(memberToml)) {
60
+ const nameMatch = memberToml.match(/name\s*=\s*"([^"]+)"/);
61
+ if (nameMatch) {
62
+ contractNames.add(nameMatch[1]);
63
+ }
64
+ }
65
+ } catch {
66
+ // Member directory might not exist or have no Nargo.toml; skip.
67
+ }
68
+ }
69
+ } else {
70
+ // Single-crate project (no workspace): check if the root Nargo.toml itself is a contract.
71
+ if (/type\s*=\s*"contract"/.test(rootToml)) {
72
+ const nameMatch = rootToml.match(/name\s*=\s*"([^"]+)"/);
73
+ if (nameMatch) {
74
+ contractNames.add(nameMatch[1]);
75
+ }
76
+ }
77
+ }
78
+
79
+ return contractNames;
80
+ }
81
+
82
+ /** Checks that no tests exist in contract crates and fails with a helpful message if they do. */
83
+ async function checkNoTestsInContracts(nargo: string, log: LogFn): Promise<void> {
84
+ const contractPackages = await getContractPackageNames();
85
+ if (contractPackages.size === 0) {
86
+ return;
87
+ }
88
+
89
+ let output: string;
90
+ try {
91
+ // We list tests for all the crates in the workspace
92
+ output = execFileSync(nargo, ['test', '--list-tests', '--silence-warnings'], {
93
+ encoding: 'utf-8',
94
+ stdio: ['pipe', 'pipe', 'inherit'],
95
+ });
96
+ } catch {
97
+ // If listing tests fails (e.g. test crate has compile errors), skip the check.
98
+ return;
99
+ }
100
+
101
+ // The output of the `nargo test --list-tests` command is as follows:
102
+ // ```
103
+ // crate_name_1 test_name_1
104
+ // crate_name_2 test_name_2
105
+ // ...
106
+ // crate_name_n test_name_n
107
+ // ```
108
+ //
109
+ // We parse the individual lines and then we check if any contract crate appeared in the parsed output.
110
+ const lines = output
111
+ .trim()
112
+ .split('\n')
113
+ .filter(line => line.length > 0);
114
+ const testsInContracts: { packageName: string; testName: string }[] = [];
115
+
116
+ for (const line of lines) {
117
+ const spaceIndex = line.indexOf(' ');
118
+ if (spaceIndex === -1) {
119
+ continue;
120
+ }
121
+ const packageName = line.substring(0, spaceIndex);
122
+ const testName = line.substring(spaceIndex + 1);
123
+ if (contractPackages.has(packageName)) {
124
+ testsInContracts.push({ packageName, testName });
125
+ }
126
+ }
127
+
128
+ if (testsInContracts.length > 0) {
129
+ const details = testsInContracts.map(t => ` ${t.packageName}::${t.testName}`).join('\n');
130
+ log(
131
+ `WARNING: Found tests in contract crate(s):\n${details}\n\n` +
132
+ `Tests should be in a dedicated test crate, not in the contract crate.\n` +
133
+ `Learn more: https://docs.aztec.network/errors/1`,
134
+ );
135
+ }
136
+ }
137
+
64
138
  /** Compiles Aztec Noir contracts and postprocesses artifacts. */
65
139
  async function compileAztecContract(nargoArgs: string[], log: LogFn): Promise<void> {
66
140
  const nargo = process.env.NARGO ?? 'nargo';
@@ -68,6 +142,9 @@ async function compileAztecContract(nargoArgs: string[], log: LogFn): Promise<vo
68
142
 
69
143
  await run(nargo, ['compile', ...nargoArgs]);
70
144
 
145
+ // Ensure contract crates contain no tests (tests belong in the test crate).
146
+ await checkNoTestsInContracts(nargo, log);
147
+
71
148
  const artifacts = await collectContractArtifacts();
72
149
 
73
150
  if (artifacts.length > 0) {
@@ -0,0 +1,25 @@
1
+ import type { LogFn } from '@aztec/foundation/log';
2
+
3
+ import type { Command } from 'commander';
4
+
5
+ import { profileFlamegraph } from './profile_flamegraph.js';
6
+ import { profileGates } from './profile_gates.js';
7
+
8
+ export function injectProfileCommand(program: Command, log: LogFn): Command {
9
+ const profile = program.command('profile').description('Profile compiled Aztec artifacts.');
10
+
11
+ profile
12
+ .command('gates')
13
+ .argument('[target-dir]', 'Path to the compiled artifacts directory', './target')
14
+ .description('Display gate counts for all compiled Aztec artifacts in a target directory.')
15
+ .action((targetDir: string) => profileGates(targetDir, log));
16
+
17
+ profile
18
+ .command('flamegraph')
19
+ .argument('<contract-artifact>', 'Path to the compiled contract artifact JSON')
20
+ .argument('<function>', 'Name of the contract function to profile')
21
+ .description('Generate a gate count flamegraph SVG for a contract function.')
22
+ .action((artifactPath: string, functionName: string) => profileFlamegraph(artifactPath, functionName, log));
23
+
24
+ return program;
25
+ }