@aztec/aztec 0.0.1-commit.643667a5cb → 0.0.1-commit.684755437
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.
- package/dest/bin/index.js +4 -2
- package/dest/cli/aztec_start_action.d.ts +1 -1
- package/dest/cli/aztec_start_action.d.ts.map +1 -1
- package/dest/cli/aztec_start_action.js +5 -3
- package/dest/cli/aztec_start_options.d.ts +1 -1
- package/dest/cli/aztec_start_options.d.ts.map +1 -1
- package/dest/cli/aztec_start_options.js +2 -3
- package/dest/cli/cli.js +3 -3
- package/dest/cli/cmds/compile.d.ts +1 -1
- package/dest/cli/cmds/compile.d.ts.map +1 -1
- package/dest/cli/cmds/compile.js +105 -35
- package/dest/cli/cmds/profile.d.ts +4 -0
- package/dest/cli/cmds/profile.d.ts.map +1 -0
- package/dest/cli/cmds/profile.js +8 -0
- package/dest/cli/cmds/profile_flamegraph.d.ts +4 -0
- package/dest/cli/cmds/profile_flamegraph.d.ts.map +1 -0
- package/dest/cli/cmds/profile_flamegraph.js +51 -0
- package/dest/cli/cmds/profile_gates.d.ts +4 -0
- package/dest/cli/cmds/profile_gates.d.ts.map +1 -0
- package/dest/cli/cmds/profile_gates.js +57 -0
- package/dest/cli/cmds/profile_utils.d.ts +18 -0
- package/dest/cli/cmds/profile_utils.d.ts.map +1 -0
- package/dest/cli/cmds/profile_utils.js +50 -0
- package/dest/cli/cmds/standby.d.ts +27 -0
- package/dest/cli/cmds/standby.d.ts.map +1 -0
- package/dest/cli/cmds/standby.js +78 -0
- package/dest/cli/cmds/start_archiver.d.ts +2 -2
- package/dest/cli/cmds/start_archiver.d.ts.map +1 -1
- package/dest/cli/cmds/start_archiver.js +1 -1
- package/dest/cli/cmds/start_node.d.ts +3 -2
- package/dest/cli/cmds/start_node.d.ts.map +1 -1
- package/dest/cli/cmds/start_node.js +15 -17
- package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
- package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
- package/dest/cli/cmds/start_prover_broker.js +6 -6
- package/dest/cli/cmds/utils/artifacts.d.ts +21 -0
- package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -0
- package/dest/cli/cmds/utils/artifacts.js +24 -0
- package/dest/cli/cmds/utils/needs_recompile.d.ts +10 -0
- package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -0
- package/dest/cli/cmds/utils/needs_recompile.js +124 -0
- package/dest/cli/cmds/utils/spawn.d.ts +3 -0
- package/dest/cli/cmds/utils/spawn.d.ts.map +1 -0
- package/dest/cli/cmds/utils/spawn.js +16 -0
- package/dest/cli/util.d.ts +3 -5
- package/dest/cli/util.d.ts.map +1 -1
- package/dest/cli/util.js +40 -81
- package/dest/examples/token.js +4 -4
- package/dest/local-network/banana_fpc.js +1 -1
- package/dest/local-network/local-network.d.ts +1 -1
- package/dest/local-network/local-network.d.ts.map +1 -1
- package/dest/local-network/local-network.js +18 -5
- package/dest/testing/index.d.ts +2 -1
- package/dest/testing/index.d.ts.map +1 -1
- package/dest/testing/index.js +1 -0
- package/dest/testing/token_allowed_setup.d.ts +7 -0
- package/dest/testing/token_allowed_setup.d.ts.map +1 -0
- package/dest/testing/token_allowed_setup.js +20 -0
- package/package.json +35 -34
- package/scripts/add_crate.sh +102 -0
- package/scripts/aztec.sh +9 -2
- package/scripts/init.sh +23 -19
- package/scripts/new.sh +48 -24
- package/scripts/setup_workspace.sh +68 -0
- package/src/bin/index.ts +4 -2
- package/src/cli/aztec_start_action.ts +5 -3
- package/src/cli/aztec_start_options.ts +2 -3
- package/src/cli/cli.ts +3 -3
- package/src/cli/cmds/compile.ts +119 -36
- package/src/cli/cmds/profile.ts +25 -0
- package/src/cli/cmds/profile_flamegraph.ts +63 -0
- package/src/cli/cmds/profile_gates.ts +67 -0
- package/src/cli/cmds/profile_utils.ts +58 -0
- package/src/cli/cmds/standby.ts +111 -0
- package/src/cli/cmds/start_archiver.ts +1 -1
- package/src/cli/cmds/start_node.ts +25 -24
- package/src/cli/cmds/start_prover_broker.ts +7 -14
- package/src/cli/cmds/utils/artifacts.ts +44 -0
- package/src/cli/cmds/utils/needs_recompile.ts +139 -0
- package/src/cli/cmds/utils/spawn.ts +16 -0
- package/src/cli/util.ts +43 -76
- package/src/examples/token.ts +6 -4
- package/src/local-network/banana_fpc.ts +1 -1
- package/src/local-network/local-network.ts +13 -3
- package/src/testing/index.ts +1 -0
- package/src/testing/token_allowed_setup.ts +19 -0
- package/dest/cli/release_version.d.ts +0 -2
- package/dest/cli/release_version.d.ts.map +0 -1
- package/dest/cli/release_version.js +0 -14
- package/scripts/extract_function.js +0 -47
- package/scripts/flamegraph.sh +0 -59
- package/scripts/setup_project.sh +0 -31
- package/src/cli/release_version.ts +0 -21
package/scripts/new.sh
CHANGED
|
@@ -1,59 +1,83 @@
|
|
|
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
|
-
|
|
6
|
+
project_path=""
|
|
8
7
|
|
|
9
8
|
while [[ $# -gt 0 ]]; do
|
|
10
9
|
case $1 in
|
|
11
10
|
--help|-h)
|
|
12
11
|
cat << 'EOF'
|
|
13
|
-
Aztec New - Create a new Aztec Noir project
|
|
12
|
+
Aztec New - Create a new Aztec Noir project or add a contract to an existing workspace
|
|
14
13
|
|
|
15
|
-
Usage: aztec new
|
|
14
|
+
Usage: aztec new <NAME>
|
|
16
15
|
|
|
17
16
|
Arguments:
|
|
18
|
-
<
|
|
17
|
+
<NAME> The name for the new contract (also used as the directory name when
|
|
18
|
+
creating a new workspace)
|
|
19
19
|
|
|
20
20
|
Options:
|
|
21
|
-
--name <NAME> Name of the package [default: package directory name]
|
|
22
|
-
--lib Create a library template instead of a contract
|
|
23
21
|
-h, --help Print help
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
When run outside an existing workspace:
|
|
24
|
+
Creates a new directory with a workspace containing a contract crate and a
|
|
25
|
+
test crate, and automatically adds the Aztec.nr dependency to both.
|
|
26
|
+
|
|
27
|
+
When run inside an existing workspace (Nargo.toml with [workspace] exists):
|
|
28
|
+
Adds a new contract crate and test crate to the existing workspace.
|
|
27
29
|
EOF
|
|
28
30
|
exit 0
|
|
29
31
|
;;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
name_arg="--name $2"
|
|
36
|
-
shift 2
|
|
32
|
+
-*)
|
|
33
|
+
echo "Error: unknown option '$1'"
|
|
34
|
+
echo "Usage: aztec new <NAME>"
|
|
35
|
+
echo "Run 'aztec new --help' for more information"
|
|
36
|
+
exit 1
|
|
37
37
|
;;
|
|
38
38
|
*)
|
|
39
|
+
if [ -n "$project_path" ]; then
|
|
40
|
+
echo "Error: unexpected argument '$1'"
|
|
41
|
+
echo "Usage: aztec new <NAME>"
|
|
42
|
+
echo "Run 'aztec new --help' for more information"
|
|
43
|
+
exit 1
|
|
44
|
+
fi
|
|
39
45
|
project_path=$1
|
|
40
46
|
shift
|
|
41
|
-
break
|
|
42
47
|
;;
|
|
43
48
|
esac
|
|
44
49
|
done
|
|
45
50
|
|
|
46
51
|
if [ -z "$project_path" ]; then
|
|
47
|
-
echo "Error:
|
|
48
|
-
echo "Usage: aztec new
|
|
52
|
+
echo "Error: NAME argument is required"
|
|
53
|
+
echo "Usage: aztec new <NAME>"
|
|
49
54
|
echo "Run 'aztec new --help' for more information"
|
|
50
55
|
exit 1
|
|
51
56
|
fi
|
|
52
57
|
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
package_name="$(basename $project_path)"
|
|
59
|
+
|
|
60
|
+
# Validate that the name contains only valid Noir identifier characters
|
|
61
|
+
if ! [[ "$package_name" =~ ^[a-zA-Z][a-zA-Z0-9_]*$ ]]; then
|
|
62
|
+
echo "Error: '$package_name' is not a valid contract name"
|
|
63
|
+
echo "Name must start with a letter and contain only letters, digits, and underscores"
|
|
64
|
+
exit 1
|
|
65
|
+
fi
|
|
66
|
+
|
|
67
|
+
# Check if we're inside an existing workspace
|
|
68
|
+
if [ -f "Nargo.toml" ] && grep -q '\[workspace\]' Nargo.toml; then
|
|
69
|
+
# Add crate pair to existing workspace
|
|
70
|
+
echo "Adding contract '$package_name' to existing workspace..."
|
|
71
|
+
$script_path/add_crate.sh "$package_name"
|
|
72
|
+
else
|
|
73
|
+
# Create new workspace
|
|
74
|
+
if [ -d "$project_path" ] && [ "$(ls -A $project_path 2>/dev/null)" ]; then
|
|
75
|
+
echo "Error: $project_path already exists and is not empty"
|
|
76
|
+
exit 1
|
|
77
|
+
fi
|
|
55
78
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
$
|
|
79
|
+
echo "Creating new Aztec contract project at $project_path..."
|
|
80
|
+
mkdir -p "$project_path"
|
|
81
|
+
cd "$project_path"
|
|
82
|
+
$script_path/setup_workspace.sh "$package_name"
|
|
59
83
|
fi
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
script_path=$(realpath $(dirname "$0"))
|
|
10
|
+
|
|
11
|
+
if [ -z "$package_name" ]; then
|
|
12
|
+
echo "Error: package name is required"
|
|
13
|
+
exit 1
|
|
14
|
+
fi
|
|
15
|
+
|
|
16
|
+
if [ -f "Nargo.toml" ]; then
|
|
17
|
+
echo "Error: Nargo.toml already exists in the current directory."
|
|
18
|
+
echo "To add another contract crate to this workspace, use 'aztec new <name>' instead."
|
|
19
|
+
exit 1
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
# Create workspace root Nargo.toml with empty members (add_crate.sh will populate)
|
|
23
|
+
cat > Nargo.toml << 'EOF'
|
|
24
|
+
[workspace]
|
|
25
|
+
members = []
|
|
26
|
+
EOF
|
|
27
|
+
|
|
28
|
+
# Create the first crate pair
|
|
29
|
+
$script_path/add_crate.sh "$package_name"
|
|
30
|
+
|
|
31
|
+
# Create README
|
|
32
|
+
cat > README.md << REOF
|
|
33
|
+
# ${package_name}
|
|
34
|
+
|
|
35
|
+
An Aztec Noir contract project.
|
|
36
|
+
|
|
37
|
+
## Compile
|
|
38
|
+
|
|
39
|
+
\`\`\`bash
|
|
40
|
+
aztec compile
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
This compiles all contract crates and outputs artifacts to \`target/\`.
|
|
44
|
+
|
|
45
|
+
## Test
|
|
46
|
+
|
|
47
|
+
\`\`\`bash
|
|
48
|
+
aztec test
|
|
49
|
+
\`\`\`
|
|
50
|
+
|
|
51
|
+
This runs all tests in the workspace.
|
|
52
|
+
|
|
53
|
+
## Generate TypeScript bindings
|
|
54
|
+
|
|
55
|
+
\`\`\`bash
|
|
56
|
+
aztec codegen target -o src/artifacts
|
|
57
|
+
\`\`\`
|
|
58
|
+
|
|
59
|
+
This generates TypeScript contract artifacts from the compiled output in \`target/\` into \`src/artifacts/\`.
|
|
60
|
+
REOF
|
|
61
|
+
|
|
62
|
+
# Create .gitignore
|
|
63
|
+
cat > .gitignore << 'GEOF'
|
|
64
|
+
target/
|
|
65
|
+
codegenCache.json
|
|
66
|
+
GEOF
|
|
67
|
+
|
|
68
|
+
echo "Created Aztec contract workspace with crates '${package_name}_contract' and '${package_name}_test'"
|
package/src/bin/index.ts
CHANGED
|
@@ -11,13 +11,14 @@ import { injectCommands as injectMiscCommands } from '@aztec/cli/misc';
|
|
|
11
11
|
import { injectCommands as injectValidatorKeysCommands } from '@aztec/cli/validator_keys';
|
|
12
12
|
import { getActiveNetworkName } from '@aztec/foundation/config';
|
|
13
13
|
import { createConsoleLogger, createLogger } from '@aztec/foundation/log';
|
|
14
|
+
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
14
15
|
|
|
15
16
|
import { Command } from 'commander';
|
|
16
17
|
|
|
17
18
|
import { injectCompileCommand } from '../cli/cmds/compile.js';
|
|
18
19
|
import { injectMigrateCommand } from '../cli/cmds/migrate_ha_db.js';
|
|
20
|
+
import { injectProfileCommand } from '../cli/cmds/profile.js';
|
|
19
21
|
import { injectAztecCommands } from '../cli/index.js';
|
|
20
|
-
import { getCliVersion } from '../cli/release_version.js';
|
|
21
22
|
|
|
22
23
|
const NETWORK_FLAG = 'network';
|
|
23
24
|
|
|
@@ -46,7 +47,7 @@ async function main() {
|
|
|
46
47
|
await enrichEnvironmentWithNetworkConfig(networkName);
|
|
47
48
|
enrichEnvironmentWithChainName(networkName);
|
|
48
49
|
|
|
49
|
-
const cliVersion =
|
|
50
|
+
const cliVersion = getPackageVersion() ?? 'unknown';
|
|
50
51
|
let program = new Command('aztec');
|
|
51
52
|
program.description('Aztec command line interface').version(cliVersion).enablePositionalOptions();
|
|
52
53
|
program = injectAztecCommands(program, userLog, debugLogger);
|
|
@@ -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);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getActiveNetworkName } from '@aztec/foundation/config';
|
|
1
2
|
import {
|
|
2
3
|
type NamespacedApiHandlers,
|
|
3
4
|
createNamespacedSafeJsonRpcServer,
|
|
@@ -7,13 +8,13 @@ import {
|
|
|
7
8
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
8
9
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
9
10
|
import { AztecNodeApiSchema } from '@aztec/stdlib/interfaces/client';
|
|
11
|
+
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
10
12
|
import { getVersioningMiddleware } from '@aztec/stdlib/versioning';
|
|
11
13
|
import { getOtelJsonRpcPropagationMiddleware } from '@aztec/telemetry-client';
|
|
12
14
|
|
|
13
15
|
import { createLocalNetwork } from '../local-network/index.js';
|
|
14
16
|
import { github, splash } from '../splash.js';
|
|
15
17
|
import { resolveAdminApiKey } from './admin_api_key_store.js';
|
|
16
|
-
import { getCliVersion } from './release_version.js';
|
|
17
18
|
import { extractNamespacedOptions, installSignalHandlers } from './util.js';
|
|
18
19
|
import { getVersions } from './versioning.js';
|
|
19
20
|
|
|
@@ -25,7 +26,7 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
|
|
|
25
26
|
let config: ChainConfig | undefined = undefined;
|
|
26
27
|
|
|
27
28
|
if (options.localNetwork) {
|
|
28
|
-
const cliVersion =
|
|
29
|
+
const cliVersion = getPackageVersion() ?? 'unknown';
|
|
29
30
|
const localNetwork = extractNamespacedOptions(options, 'local-network');
|
|
30
31
|
localNetwork.testAccounts = true;
|
|
31
32
|
userLog(`${splash}\n${github}\n\n`);
|
|
@@ -57,7 +58,8 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
|
|
|
57
58
|
|
|
58
59
|
if (options.node) {
|
|
59
60
|
const { startNode } = await import('./cmds/start_node.js');
|
|
60
|
-
|
|
61
|
+
const networkName = getActiveNetworkName(options.network);
|
|
62
|
+
({ config } = await startNode(options, signalHandlers, services, adminServices, userLog, networkName));
|
|
61
63
|
} else if (options.bot) {
|
|
62
64
|
const { startBot } = await import('./cmds/start_bot.js');
|
|
63
65
|
await startBot(options, signalHandlers, services, userLog);
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
isBooleanConfigValue,
|
|
13
13
|
omitConfigMappings,
|
|
14
14
|
} from '@aztec/foundation/config';
|
|
15
|
-
import { dataConfigMappings } from '@aztec/kv-store/config';
|
|
16
15
|
import { sharedNodeConfigMappings } from '@aztec/node-lib/config';
|
|
17
16
|
import { bootnodeConfigMappings, p2pConfigMappings } from '@aztec/p2p/config';
|
|
18
17
|
import { proverAgentConfigMappings, proverBrokerConfigMappings } from '@aztec/prover-client/broker/config';
|
|
@@ -20,6 +19,7 @@ import { proverNodeConfigMappings } from '@aztec/prover-node/config';
|
|
|
20
19
|
import { allPxeConfigMappings } from '@aztec/pxe/config';
|
|
21
20
|
import { sequencerClientConfigMappings } from '@aztec/sequencer-client/config';
|
|
22
21
|
import { chainConfigMappings, nodeRpcConfigMappings } from '@aztec/stdlib/config';
|
|
22
|
+
import { dataConfigMappings } from '@aztec/stdlib/kv-store';
|
|
23
23
|
import { telemetryClientConfigMappings } from '@aztec/telemetry-client/config';
|
|
24
24
|
import { worldStateConfigMappings } from '@aztec/world-state/config';
|
|
25
25
|
|
|
@@ -105,8 +105,7 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
|
|
|
105
105
|
env: 'NETWORK',
|
|
106
106
|
},
|
|
107
107
|
|
|
108
|
-
configToFlag('--
|
|
109
|
-
configToFlag('--auto-update-url', sharedNodeConfigMappings.autoUpdateUrl),
|
|
108
|
+
configToFlag('--enable-version-check', sharedNodeConfigMappings.enableVersionCheck),
|
|
110
109
|
|
|
111
110
|
configToFlag('--sync-mode', sharedNodeConfigMappings.syncMode),
|
|
112
111
|
configToFlag('--snapshots-urls', sharedNodeConfigMappings.snapshotsUrls),
|
package/src/cli/cli.ts
CHANGED
|
@@ -37,9 +37,9 @@ export function injectAztecCommands(program: Command, userLog: LogFn, debugLogge
|
|
|
37
37
|
`
|
|
38
38
|
Additional commands:
|
|
39
39
|
|
|
40
|
-
init
|
|
41
|
-
new <
|
|
42
|
-
test [options]
|
|
40
|
+
init creates a new Aztec Noir workspace in the current directory.
|
|
41
|
+
new <name> creates a new Aztec Noir workspace in its own directory (or creates a new contract-test crates pair and adds it to the current workspace if run in workspace).
|
|
42
|
+
test [options] starts a TXE and runs "nargo test" using it as the oracle resolver.
|
|
43
43
|
`,
|
|
44
44
|
);
|
|
45
45
|
}
|
package/src/cli/cmds/compile.ts
CHANGED
|
@@ -1,51 +1,26 @@
|
|
|
1
1
|
import type { LogFn } from '@aztec/foundation/log';
|
|
2
2
|
|
|
3
|
-
import { execFileSync
|
|
3
|
+
import { execFileSync } from 'child_process';
|
|
4
4
|
import type { Command } from 'commander';
|
|
5
|
-
import { readFile,
|
|
5
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
6
6
|
import { join } from 'path';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 { needsRecompile } from './utils/needs_recompile.js';
|
|
10
|
+
import { run } from './utils/spawn.js';
|
|
22
11
|
|
|
23
|
-
/** Returns paths to contract artifacts in the target directory.
|
|
24
|
-
* Contract artifacts are identified by having a `functions` array in the JSON.
|
|
25
|
-
*/
|
|
12
|
+
/** Returns paths to contract artifacts in the target directory. */
|
|
26
13
|
async function collectContractArtifacts(): Promise<string[]> {
|
|
27
|
-
let files
|
|
14
|
+
let files;
|
|
28
15
|
try {
|
|
29
|
-
files = await
|
|
16
|
+
files = await readArtifactFiles('target');
|
|
30
17
|
} catch (err: any) {
|
|
31
|
-
if (err?.
|
|
18
|
+
if (err?.message?.includes('does not exist')) {
|
|
32
19
|
return [];
|
|
33
20
|
}
|
|
34
|
-
throw
|
|
21
|
+
throw err;
|
|
35
22
|
}
|
|
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
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return artifacts;
|
|
23
|
+
return files.filter(f => Array.isArray(f.content.functions)).map(f => f.filePath);
|
|
49
24
|
}
|
|
50
25
|
|
|
51
26
|
/** Strips the `__aztec_nr_internals__` prefix from function names in contract artifacts. */
|
|
@@ -61,13 +36,121 @@ async function stripInternalPrefixes(artifactPaths: string[]): Promise<void> {
|
|
|
61
36
|
}
|
|
62
37
|
}
|
|
63
38
|
|
|
39
|
+
/** Returns the set of package names that are contract crates in the current workspace. */
|
|
40
|
+
async function getContractPackageNames(): Promise<Set<string>> {
|
|
41
|
+
const contractNames = new Set<string>();
|
|
42
|
+
|
|
43
|
+
let rootToml: string;
|
|
44
|
+
try {
|
|
45
|
+
rootToml = await readFile('Nargo.toml', 'utf-8');
|
|
46
|
+
} catch {
|
|
47
|
+
return contractNames;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const membersMatch = rootToml.match(/members\s*=\s*\[([^\]]*)\]/);
|
|
51
|
+
if (membersMatch) {
|
|
52
|
+
const members = membersMatch[1]
|
|
53
|
+
.split(',')
|
|
54
|
+
.map(m => m.trim().replace(/^"|"$/g, ''))
|
|
55
|
+
.filter(m => m.length > 0);
|
|
56
|
+
|
|
57
|
+
for (const member of members) {
|
|
58
|
+
try {
|
|
59
|
+
const memberToml = await readFile(join(member, 'Nargo.toml'), 'utf-8');
|
|
60
|
+
if (/type\s*=\s*"contract"/.test(memberToml)) {
|
|
61
|
+
const nameMatch = memberToml.match(/name\s*=\s*"([^"]+)"/);
|
|
62
|
+
if (nameMatch) {
|
|
63
|
+
contractNames.add(nameMatch[1]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} catch {
|
|
67
|
+
// Member directory might not exist or have no Nargo.toml; skip.
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
// Single-crate project (no workspace): check if the root Nargo.toml itself is a contract.
|
|
72
|
+
if (/type\s*=\s*"contract"/.test(rootToml)) {
|
|
73
|
+
const nameMatch = rootToml.match(/name\s*=\s*"([^"]+)"/);
|
|
74
|
+
if (nameMatch) {
|
|
75
|
+
contractNames.add(nameMatch[1]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return contractNames;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Checks that no tests exist in contract crates and fails with a helpful message if they do. */
|
|
84
|
+
async function checkNoTestsInContracts(nargo: string, log: LogFn): Promise<void> {
|
|
85
|
+
const contractPackages = await getContractPackageNames();
|
|
86
|
+
if (contractPackages.size === 0) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let output: string;
|
|
91
|
+
try {
|
|
92
|
+
// We list tests for all the crates in the workspace
|
|
93
|
+
output = execFileSync(nargo, ['test', '--list-tests', '--silence-warnings'], {
|
|
94
|
+
encoding: 'utf-8',
|
|
95
|
+
stdio: ['pipe', 'pipe', 'inherit'],
|
|
96
|
+
});
|
|
97
|
+
} catch {
|
|
98
|
+
// If listing tests fails (e.g. test crate has compile errors), skip the check.
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// The output of the `nargo test --list-tests` command is as follows:
|
|
103
|
+
// ```
|
|
104
|
+
// crate_name_1 test_name_1
|
|
105
|
+
// crate_name_2 test_name_2
|
|
106
|
+
// ...
|
|
107
|
+
// crate_name_n test_name_n
|
|
108
|
+
// ```
|
|
109
|
+
//
|
|
110
|
+
// We parse the individual lines and then we check if any contract crate appeared in the parsed output.
|
|
111
|
+
const lines = output
|
|
112
|
+
.trim()
|
|
113
|
+
.split('\n')
|
|
114
|
+
.filter(line => line.length > 0);
|
|
115
|
+
const testsInContracts: { packageName: string; testName: string }[] = [];
|
|
116
|
+
|
|
117
|
+
for (const line of lines) {
|
|
118
|
+
const spaceIndex = line.indexOf(' ');
|
|
119
|
+
if (spaceIndex === -1) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const packageName = line.substring(0, spaceIndex);
|
|
123
|
+
const testName = line.substring(spaceIndex + 1);
|
|
124
|
+
if (contractPackages.has(packageName)) {
|
|
125
|
+
testsInContracts.push({ packageName, testName });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (testsInContracts.length > 0) {
|
|
130
|
+
const details = testsInContracts.map(t => ` ${t.packageName}::${t.testName}`).join('\n');
|
|
131
|
+
log(
|
|
132
|
+
`WARNING: Found tests in contract crate(s):\n${details}\n\n` +
|
|
133
|
+
`Tests should be in a dedicated test crate, not in the contract crate.\n` +
|
|
134
|
+
`Learn more: https://docs.aztec.network/errors/1`,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
64
139
|
/** Compiles Aztec Noir contracts and postprocesses artifacts. */
|
|
65
140
|
async function compileAztecContract(nargoArgs: string[], log: LogFn): Promise<void> {
|
|
141
|
+
if (!(await needsRecompile())) {
|
|
142
|
+
log('No source changes detected, skipping compilation.');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
66
146
|
const nargo = process.env.NARGO ?? 'nargo';
|
|
67
147
|
const bb = process.env.BB ?? 'bb';
|
|
68
148
|
|
|
69
149
|
await run(nargo, ['compile', ...nargoArgs]);
|
|
70
150
|
|
|
151
|
+
// Ensure contract crates contain no tests (tests belong in the test crate).
|
|
152
|
+
await checkNoTestsInContracts(nargo, log);
|
|
153
|
+
|
|
71
154
|
const artifacts = await collectContractArtifacts();
|
|
72
155
|
|
|
73
156
|
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
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
2
|
+
|
|
3
|
+
import { readFile, rename, rm, writeFile } from 'fs/promises';
|
|
4
|
+
import { basename, dirname, join } from 'path';
|
|
5
|
+
|
|
6
|
+
import { makeFunctionArtifact } from './profile_utils.js';
|
|
7
|
+
import type { CompiledArtifact } from './utils/artifacts.js';
|
|
8
|
+
import { run } from './utils/spawn.js';
|
|
9
|
+
|
|
10
|
+
/** Generates a gate count flamegraph SVG for a single contract function. */
|
|
11
|
+
export async function profileFlamegraph(artifactPath: string, functionName: string, log: LogFn): Promise<void> {
|
|
12
|
+
const raw = await readFile(artifactPath, 'utf-8');
|
|
13
|
+
const artifact: CompiledArtifact = JSON.parse(raw);
|
|
14
|
+
|
|
15
|
+
if (!Array.isArray(artifact.functions)) {
|
|
16
|
+
throw new Error(`${artifactPath} does not appear to be a contract artifact (no functions array)`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const func = artifact.functions.find(f => f.name === functionName);
|
|
20
|
+
if (!func) {
|
|
21
|
+
const available = artifact.functions.map(f => f.name).join(', ');
|
|
22
|
+
throw new Error(`Function "${functionName}" not found in artifact. Available: ${available}`);
|
|
23
|
+
}
|
|
24
|
+
if (func.is_unconstrained) {
|
|
25
|
+
throw new Error(`Function "${functionName}" is unconstrained and cannot be profiled`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const outputDir = dirname(artifactPath);
|
|
29
|
+
const contractName = basename(artifactPath, '.json');
|
|
30
|
+
const functionArtifact = join(outputDir, `${contractName}-${functionName}.json`);
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
await writeFile(functionArtifact, makeFunctionArtifact(artifact, func));
|
|
34
|
+
|
|
35
|
+
const profiler = process.env.PROFILER_PATH ?? 'noir-profiler';
|
|
36
|
+
const bb = process.env.BB ?? 'bb';
|
|
37
|
+
|
|
38
|
+
await run(profiler, [
|
|
39
|
+
'gates',
|
|
40
|
+
'--artifact-path',
|
|
41
|
+
functionArtifact,
|
|
42
|
+
'--backend-path',
|
|
43
|
+
bb,
|
|
44
|
+
'--backend-gates-command',
|
|
45
|
+
'gates',
|
|
46
|
+
'--output',
|
|
47
|
+
outputDir,
|
|
48
|
+
'--scheme',
|
|
49
|
+
'chonk',
|
|
50
|
+
'--include_gates_per_opcode',
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
// noir-profiler names the SVG using the internal function name which
|
|
54
|
+
// retains the __aztec_nr_internals__ prefix in the bytecode metadata.
|
|
55
|
+
const srcSvg = join(outputDir, `__aztec_nr_internals__${functionName}_gates.svg`);
|
|
56
|
+
const destSvg = join(outputDir, `${contractName}-${functionName}-flamegraph.svg`);
|
|
57
|
+
await rename(srcSvg, destSvg);
|
|
58
|
+
|
|
59
|
+
log(`Flamegraph written to ${destSvg}`);
|
|
60
|
+
} finally {
|
|
61
|
+
await rm(functionArtifact, { force: true });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
2
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
3
|
+
|
|
4
|
+
import { execFile as execFileCb } from 'child_process';
|
|
5
|
+
import { rm } from 'fs/promises';
|
|
6
|
+
import { promisify } from 'util';
|
|
7
|
+
|
|
8
|
+
import { MAX_CONCURRENT, discoverArtifacts } from './profile_utils.js';
|
|
9
|
+
|
|
10
|
+
const execFile = promisify(execFileCb);
|
|
11
|
+
|
|
12
|
+
interface GateCountResult {
|
|
13
|
+
name: string;
|
|
14
|
+
gateCount: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Parses circuit_size from bb gates JSON output: { "functions": [{ "circuit_size": N }] } */
|
|
18
|
+
function parseGateCount(stdout: string): number {
|
|
19
|
+
const parsed = JSON.parse(stdout);
|
|
20
|
+
const size = parsed?.functions?.[0]?.circuit_size;
|
|
21
|
+
if (typeof size !== 'number') {
|
|
22
|
+
throw new Error('Failed to parse circuit_size from bb gates output');
|
|
23
|
+
}
|
|
24
|
+
return size;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Runs bb gates on a single artifact file and returns the gate count. */
|
|
28
|
+
async function getGateCount(bb: string, artifactPath: string): Promise<number> {
|
|
29
|
+
const { stdout } = await execFile(bb, ['gates', '--scheme', 'chonk', '-b', artifactPath]);
|
|
30
|
+
return parseGateCount(stdout);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Profiles all compiled artifacts in a target directory and prints gate counts. */
|
|
34
|
+
export async function profileGates(targetDir: string, log: LogFn): Promise<void> {
|
|
35
|
+
const bb = process.env.BB ?? 'bb';
|
|
36
|
+
const { artifacts, tmpDir } = await discoverArtifacts(targetDir);
|
|
37
|
+
|
|
38
|
+
if (artifacts.length === 0) {
|
|
39
|
+
log('No artifacts found in target directory.');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const results: GateCountResult[] = await asyncPool(MAX_CONCURRENT, artifacts, async artifact => ({
|
|
45
|
+
name: artifact.name,
|
|
46
|
+
gateCount: await getGateCount(bb, artifact.filePath),
|
|
47
|
+
}));
|
|
48
|
+
results.sort((a, b) => a.name.localeCompare(b.name));
|
|
49
|
+
|
|
50
|
+
if (results.length === 0) {
|
|
51
|
+
log('No constrained circuits found.');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const maxNameLen = Math.max(...results.map(r => r.name.length));
|
|
56
|
+
log('');
|
|
57
|
+
log('Gate counts:');
|
|
58
|
+
log('-'.repeat(maxNameLen + 16));
|
|
59
|
+
for (const { name, gateCount } of results) {
|
|
60
|
+
log(`${name.padEnd(maxNameLen)} ${gateCount.toLocaleString().padStart(12)}`);
|
|
61
|
+
}
|
|
62
|
+
log('-'.repeat(maxNameLen + 16));
|
|
63
|
+
log(`Total: ${results.length} circuit(s)`);
|
|
64
|
+
} finally {
|
|
65
|
+
await rm(tmpDir, { recursive: true, force: true });
|
|
66
|
+
}
|
|
67
|
+
}
|