@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.
- package/dest/bin/index.js +2 -0
- package/dest/cli/admin_api_key_store.d.ts +3 -3
- package/dest/cli/admin_api_key_store.d.ts.map +1 -1
- package/dest/cli/admin_api_key_store.js +3 -3
- package/dest/cli/aztec_start_action.js +2 -2
- 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 +4 -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 +100 -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/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/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.js +3 -3
- package/package.json +34 -34
- package/scripts/aztec.sh +6 -2
- package/scripts/init.sh +23 -13
- package/scripts/new.sh +17 -16
- package/scripts/setup_workspace.sh +124 -0
- package/src/bin/index.ts +2 -0
- package/src/cli/admin_api_key_store.ts +4 -4
- package/src/cli/aztec_start_action.ts +2 -2
- package/src/cli/aztec_start_options.ts +4 -3
- package/src/cli/cmds/compile.ts +113 -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/utils/artifacts.ts +44 -0
- package/src/cli/cmds/utils/spawn.ts +16 -0
- package/src/cli/util.ts +2 -2
- package/scripts/extract_function.js +0 -47
- package/scripts/flamegraph.sh +0 -59
- package/scripts/setup_project.sh +0 -31
package/dest/bin/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import { createConsoleLogger, createLogger } from '@aztec/foundation/log';
|
|
|
14
14
|
import { Command } from 'commander';
|
|
15
15
|
import { injectCompileCommand } from '../cli/cmds/compile.js';
|
|
16
16
|
import { injectMigrateCommand } from '../cli/cmds/migrate_ha_db.js';
|
|
17
|
+
import { injectProfileCommand } from '../cli/cmds/profile.js';
|
|
17
18
|
import { injectAztecCommands } from '../cli/index.js';
|
|
18
19
|
import { getCliVersion } from '../cli/release_version.js';
|
|
19
20
|
const NETWORK_FLAG = 'network';
|
|
@@ -47,6 +48,7 @@ const debugLogger = createLogger('cli');
|
|
|
47
48
|
program = injectMiscCommands(program, userLog);
|
|
48
49
|
program = injectValidatorKeysCommands(program, userLog);
|
|
49
50
|
program = injectCompileCommand(program, userLog);
|
|
51
|
+
program = injectProfileCommand(program, userLog);
|
|
50
52
|
program = injectMigrateCommand(program, userLog);
|
|
51
53
|
await program.parseAsync(process.argv);
|
|
52
54
|
}
|
|
@@ -17,7 +17,7 @@ export interface ResolveAdminApiKeyOptions {
|
|
|
17
17
|
/** SHA-256 hex hash of a pre-generated API key. When set, the node uses this hash directly. */
|
|
18
18
|
adminApiKeyHash?: string;
|
|
19
19
|
/** If true, disable admin API key auth entirely. */
|
|
20
|
-
|
|
20
|
+
disableAdminApiKey?: boolean;
|
|
21
21
|
/** If true, force-generate a new key even if one is already persisted. */
|
|
22
22
|
resetAdminApiKey?: boolean;
|
|
23
23
|
/** Root data directory for persistent storage. */
|
|
@@ -27,7 +27,7 @@ export interface ResolveAdminApiKeyOptions {
|
|
|
27
27
|
* Resolves the admin API key for the admin RPC endpoint.
|
|
28
28
|
*
|
|
29
29
|
* Strategy:
|
|
30
|
-
* 1. If opt-out flag is set (`
|
|
30
|
+
* 1. If opt-out flag is set (`disableAdminApiKey`), return undefined (no auth).
|
|
31
31
|
* 2. If a pre-generated hash is provided (`adminApiKeyHash`), use it directly.
|
|
32
32
|
* 3. If a data directory exists, look for a persisted hash file
|
|
33
33
|
* at `<dataDirectory>/admin/api_key_hash`:
|
|
@@ -42,4 +42,4 @@ export interface ResolveAdminApiKeyOptions {
|
|
|
42
42
|
* @returns The resolved API key hash, or undefined if auth is disabled.
|
|
43
43
|
*/
|
|
44
44
|
export declare function resolveAdminApiKey(options: ResolveAdminApiKeyOptions, log: Logger): Promise<AdminApiKeyResolution | undefined>;
|
|
45
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
45
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRtaW5fYXBpX2tleV9zdG9yZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NsaS9hZG1pbl9hcGlfa2V5X3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBLE9BQU8sS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBU3BEOzs7O0dBSUc7QUFDSCxNQUFNLFdBQVcscUJBQXFCO0lBQ3BDLHVDQUF1QztJQUN2QyxVQUFVLEVBQUUsTUFBTSxDQUFDO0lBQ25COzs7T0FHRztJQUNILE1BQU0sQ0FBQyxFQUFFLE1BQU0sQ0FBQztDQUNqQjtBQUVELE1BQU0sV0FBVyx5QkFBeUI7SUFDeEMsK0ZBQStGO0lBQy9GLGVBQWUsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUN6QixvREFBb0Q7SUFDcEQsa0JBQWtCLENBQUMsRUFBRSxPQUFPLENBQUM7SUFDN0IsMEVBQTBFO0lBQzFFLGdCQUFnQixDQUFDLEVBQUUsT0FBTyxDQUFDO0lBQzNCLGtEQUFrRDtJQUNsRCxhQUFhLENBQUMsRUFBRSxNQUFNLENBQUM7Q0FDeEI7QUFFRDs7Ozs7Ozs7Ozs7Ozs7Ozs7R0FpQkc7QUFDSCx3QkFBc0Isa0JBQWtCLENBQ3RDLE9BQU8sRUFBRSx5QkFBeUIsRUFDbEMsR0FBRyxFQUFFLE1BQU0sR0FDVixPQUFPLENBQUMscUJBQXFCLEdBQUcsU0FBUyxDQUFDLENBMkQ1QyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin_api_key_store.d.ts","sourceRoot":"","sources":["../../src/cli/admin_api_key_store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AASpD;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB;IACxC,+FAA+F;IAC/F,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oDAAoD;IACpD,
|
|
1
|
+
{"version":3,"file":"admin_api_key_store.d.ts","sourceRoot":"","sources":["../../src/cli/admin_api_key_store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AASpD;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB;IACxC,+FAA+F;IAC/F,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oDAAoD;IACpD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,0EAA0E;IAC1E,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kDAAkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,EAClC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CA2D5C"}
|
|
@@ -8,7 +8,7 @@ const HASH_FILE_NAME = 'api_key_hash';
|
|
|
8
8
|
* Resolves the admin API key for the admin RPC endpoint.
|
|
9
9
|
*
|
|
10
10
|
* Strategy:
|
|
11
|
-
* 1. If opt-out flag is set (`
|
|
11
|
+
* 1. If opt-out flag is set (`disableAdminApiKey`), return undefined (no auth).
|
|
12
12
|
* 2. If a pre-generated hash is provided (`adminApiKeyHash`), use it directly.
|
|
13
13
|
* 3. If a data directory exists, look for a persisted hash file
|
|
14
14
|
* at `<dataDirectory>/admin/api_key_hash`:
|
|
@@ -23,8 +23,8 @@ const HASH_FILE_NAME = 'api_key_hash';
|
|
|
23
23
|
* @returns The resolved API key hash, or undefined if auth is disabled.
|
|
24
24
|
*/ export async function resolveAdminApiKey(options, log) {
|
|
25
25
|
// Operator explicitly opted out of admin auth
|
|
26
|
-
if (options.
|
|
27
|
-
log.warn('Admin API key authentication is DISABLED (--
|
|
26
|
+
if (options.disableAdminApiKey) {
|
|
27
|
+
log.warn('Admin API key authentication is DISABLED (--disable-admin-api-key / AZTEC_DISABLE_ADMIN_API_KEY)');
|
|
28
28
|
return undefined;
|
|
29
29
|
}
|
|
30
30
|
// Operator provided a pre-generated hash (e.g. via AZTEC_ADMIN_API_KEY_HASH env var)
|
|
@@ -99,7 +99,7 @@ export async function aztecStart(options, userLog, debugLogger) {
|
|
|
99
99
|
// Resolve the admin API key (auto-generated and persisted, or opt-out)
|
|
100
100
|
const apiKeyResolution = await resolveAdminApiKey({
|
|
101
101
|
adminApiKeyHash: options.adminApiKeyHash,
|
|
102
|
-
|
|
102
|
+
disableAdminApiKey: options.disableAdminApiKey,
|
|
103
103
|
resetAdminApiKey: options.resetAdminApiKey,
|
|
104
104
|
dataDirectory: options.dataDirectory
|
|
105
105
|
}, debugLogger);
|
|
@@ -136,7 +136,7 @@ export async function aztecStart(options, userLog, debugLogger) {
|
|
|
136
136
|
userLog(' The key hash has been persisted — on next restart, the same key will be used.');
|
|
137
137
|
}
|
|
138
138
|
userLog('');
|
|
139
|
-
userLog(' To disable admin auth: --
|
|
139
|
+
userLog(' To disable admin auth: --disable-admin-api-key or AZTEC_DISABLE_ADMIN_API_KEY=true');
|
|
140
140
|
userLog(separator);
|
|
141
141
|
userLog('');
|
|
142
142
|
}
|
|
@@ -14,4 +14,4 @@ export declare const NETWORK_FLAG = "network";
|
|
|
14
14
|
export declare const aztecStartOptions: {
|
|
15
15
|
[key: string]: AztecStartOption[];
|
|
16
16
|
};
|
|
17
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
17
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXp0ZWNfc3RhcnRfb3B0aW9ucy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NsaS9henRlY19zdGFydF9vcHRpb25zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU9BLE9BQU8sRUFDTCxLQUFLLGFBQWEsRUFDbEIsS0FBSyxNQUFNLEVBSVosTUFBTSwwQkFBMEIsQ0FBQztBQWVsQyxNQUFNLFdBQVcsZ0JBQWdCO0lBQy9CLElBQUksRUFBRSxNQUFNLENBQUM7SUFDYixXQUFXLEVBQUUsTUFBTSxDQUFDO0lBQ3BCLFlBQVksRUFBRSxHQUFHLENBQUM7SUFDbEIsWUFBWSxDQUFDLEVBQUUsQ0FBQyxHQUFHLEVBQUUsR0FBRyxLQUFLLE1BQU0sQ0FBQztJQUNwQyxHQUFHLEVBQUUsTUFBTSxHQUFHLFNBQVMsQ0FBQztJQUN4QixRQUFRLENBQUMsRUFBRSxNQUFNLEVBQUUsQ0FBQztJQUNwQixRQUFRLENBQUMsRUFBRSxDQUFDLEdBQUcsRUFBRSxNQUFNLEtBQUssR0FBRyxDQUFDO0NBQ2pDO0FBRUQsZUFBTyxNQUFNLFVBQVUsMEZBb0J0QixDQUFDO0FBdUJGLGVBQU8sTUFBTSxnQkFBZ0IsVUFZNUIsQ0FBQztBQUVGLGVBQU8sTUFBTSxZQUFZLFlBQVksQ0FBQztBQUd0QyxlQUFPLE1BQU0saUJBQWlCLEVBQUU7SUFBRSxDQUFDLEdBQUcsRUFBRSxNQUFNLEdBQUcsZ0JBQWdCLEVBQUUsQ0FBQTtDQXVPbEUsQ0FBQyJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aztec_start_options.d.ts","sourceRoot":"","sources":["../../src/cli/aztec_start_options.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,MAAM,EAIZ,MAAM,0BAA0B,CAAC;AAelC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC;IAClB,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC;IACpC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,CAAC;CACjC;AAED,eAAO,MAAM,UAAU,0FAoBtB,CAAC;AAuBF,eAAO,MAAM,gBAAgB,UAY5B,CAAC;AAEF,eAAO,MAAM,YAAY,YAAY,CAAC;AAGtC,eAAO,MAAM,iBAAiB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"aztec_start_options.d.ts","sourceRoot":"","sources":["../../src/cli/aztec_start_options.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,MAAM,EAIZ,MAAM,0BAA0B,CAAC;AAelC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC;IAClB,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAC;IACpC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,GAAG,CAAC;CACjC;AAED,eAAO,MAAM,UAAU,0FAoBtB,CAAC;AAuBF,eAAO,MAAM,gBAAgB,UAY5B,CAAC;AAEF,eAAO,MAAM,YAAY,YAAY,CAAC;AAGtC,eAAO,MAAM,iBAAiB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAAA;CAuOlE,CAAC"}
|
|
@@ -118,11 +118,12 @@ export const aztecStartOptions = {
|
|
|
118
118
|
env: 'AZTEC_ADMIN_API_KEY_HASH'
|
|
119
119
|
},
|
|
120
120
|
{
|
|
121
|
-
flag: '--
|
|
121
|
+
flag: '--disable-admin-api-key',
|
|
122
122
|
description: 'Disable API key authentication on the admin RPC endpoint. By default, a key is auto-generated, displayed once, and its hash is persisted.',
|
|
123
123
|
defaultValue: false,
|
|
124
|
-
env: '
|
|
125
|
-
|
|
124
|
+
env: 'AZTEC_DISABLE_ADMIN_API_KEY',
|
|
125
|
+
// undefined means the flag was passed without a value (boolean toggle), treat as true.
|
|
126
|
+
parseVal: (val)=>val === undefined || val === 'true' || val === '1'
|
|
126
127
|
},
|
|
127
128
|
{
|
|
128
129
|
flag: '--reset-admin-api-key',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { LogFn } from '@aztec/foundation/log';
|
|
2
2
|
import type { Command } from 'commander';
|
|
3
3
|
export declare function injectCompileCommand(program: Command, log: LogFn): Command;
|
|
4
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcGlsZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2NsaS9jbWRzL2NvbXBpbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsS0FBSyxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFHbkQsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0sV0FBVyxDQUFDO0FBOEp6Qyx3QkFBZ0Isb0JBQW9CLENBQUMsT0FBTyxFQUFFLE9BQU8sRUFBRSxHQUFHLEVBQUUsS0FBSyxHQUFHLE9BQU8sQ0FzQjFFIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/cli/cmds/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/cli/cmds/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8JzC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,CAsB1E"}
|
package/dest/cli/cmds/compile.js
CHANGED
|
@@ -1,45 +1,19 @@
|
|
|
1
|
-
import { execFileSync
|
|
2
|
-
import { readFile,
|
|
1
|
+
import { execFileSync } from 'child_process';
|
|
2
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
3
3
|
import { join } from 'path';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
stdio: 'inherit'
|
|
8
|
-
});
|
|
9
|
-
child.on('error', reject);
|
|
10
|
-
child.on('close', (code)=>{
|
|
11
|
-
if (code !== 0) {
|
|
12
|
-
reject(new Error(`${cmd} exited with code ${code}`));
|
|
13
|
-
} else {
|
|
14
|
-
resolve();
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
/** Returns paths to contract artifacts in the target directory.
|
|
20
|
-
* Contract artifacts are identified by having a `functions` array in the JSON.
|
|
21
|
-
*/ async function collectContractArtifacts() {
|
|
4
|
+
import { readArtifactFiles } from './utils/artifacts.js';
|
|
5
|
+
import { run } from './utils/spawn.js';
|
|
6
|
+
/** Returns paths to contract artifacts in the target directory. */ async function collectContractArtifacts() {
|
|
22
7
|
let files;
|
|
23
8
|
try {
|
|
24
|
-
files = await
|
|
9
|
+
files = await readArtifactFiles('target');
|
|
25
10
|
} catch (err) {
|
|
26
|
-
if (err?.
|
|
11
|
+
if (err?.message?.includes('does not exist')) {
|
|
27
12
|
return [];
|
|
28
13
|
}
|
|
29
|
-
throw
|
|
30
|
-
}
|
|
31
|
-
const artifacts = [];
|
|
32
|
-
for (const file of files){
|
|
33
|
-
if (!file.endsWith('.json')) {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
const filePath = join('target', file);
|
|
37
|
-
const content = JSON.parse(await readFile(filePath, 'utf-8'));
|
|
38
|
-
if (Array.isArray(content.functions)) {
|
|
39
|
-
artifacts.push(filePath);
|
|
40
|
-
}
|
|
14
|
+
throw err;
|
|
41
15
|
}
|
|
42
|
-
return
|
|
16
|
+
return files.filter((f)=>Array.isArray(f.content.functions)).map((f)=>f.filePath);
|
|
43
17
|
}
|
|
44
18
|
/** Strips the `__aztec_nr_internals__` prefix from function names in contract artifacts. */ async function stripInternalPrefixes(artifactPaths) {
|
|
45
19
|
for (const path of artifactPaths){
|
|
@@ -52,6 +26,95 @@ import { join } from 'path';
|
|
|
52
26
|
await writeFile(path, JSON.stringify(artifact, null, 2) + '\n');
|
|
53
27
|
}
|
|
54
28
|
}
|
|
29
|
+
/** Returns the set of package names that are contract crates in the current workspace. */ async function getContractPackageNames() {
|
|
30
|
+
const contractNames = new Set();
|
|
31
|
+
let rootToml;
|
|
32
|
+
try {
|
|
33
|
+
rootToml = await readFile('Nargo.toml', 'utf-8');
|
|
34
|
+
} catch {
|
|
35
|
+
return contractNames;
|
|
36
|
+
}
|
|
37
|
+
const membersMatch = rootToml.match(/members\s*=\s*\[([^\]]*)\]/);
|
|
38
|
+
if (membersMatch) {
|
|
39
|
+
const members = membersMatch[1].split(',').map((m)=>m.trim().replace(/^"|"$/g, '')).filter((m)=>m.length > 0);
|
|
40
|
+
for (const member of members){
|
|
41
|
+
try {
|
|
42
|
+
const memberToml = await readFile(join(member, 'Nargo.toml'), 'utf-8');
|
|
43
|
+
if (/type\s*=\s*"contract"/.test(memberToml)) {
|
|
44
|
+
const nameMatch = memberToml.match(/name\s*=\s*"([^"]+)"/);
|
|
45
|
+
if (nameMatch) {
|
|
46
|
+
contractNames.add(nameMatch[1]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} catch {
|
|
50
|
+
// Member directory might not exist or have no Nargo.toml; skip.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
// Single-crate project (no workspace): check if the root Nargo.toml itself is a contract.
|
|
55
|
+
if (/type\s*=\s*"contract"/.test(rootToml)) {
|
|
56
|
+
const nameMatch = rootToml.match(/name\s*=\s*"([^"]+)"/);
|
|
57
|
+
if (nameMatch) {
|
|
58
|
+
contractNames.add(nameMatch[1]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return contractNames;
|
|
63
|
+
}
|
|
64
|
+
/** Checks that no tests exist in contract crates and fails with a helpful message if they do. */ async function checkNoTestsInContracts(nargo, log) {
|
|
65
|
+
const contractPackages = await getContractPackageNames();
|
|
66
|
+
if (contractPackages.size === 0) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
let output;
|
|
70
|
+
try {
|
|
71
|
+
// We list tests for all the crates in the workspace
|
|
72
|
+
output = execFileSync(nargo, [
|
|
73
|
+
'test',
|
|
74
|
+
'--list-tests',
|
|
75
|
+
'--silence-warnings'
|
|
76
|
+
], {
|
|
77
|
+
encoding: 'utf-8',
|
|
78
|
+
stdio: [
|
|
79
|
+
'pipe',
|
|
80
|
+
'pipe',
|
|
81
|
+
'inherit'
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
} catch {
|
|
85
|
+
// If listing tests fails (e.g. test crate has compile errors), skip the check.
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// The output of the `nargo test --list-tests` command is as follows:
|
|
89
|
+
// ```
|
|
90
|
+
// crate_name_1 test_name_1
|
|
91
|
+
// crate_name_2 test_name_2
|
|
92
|
+
// ...
|
|
93
|
+
// crate_name_n test_name_n
|
|
94
|
+
// ```
|
|
95
|
+
//
|
|
96
|
+
// We parse the individual lines and then we check if any contract crate appeared in the parsed output.
|
|
97
|
+
const lines = output.trim().split('\n').filter((line)=>line.length > 0);
|
|
98
|
+
const testsInContracts = [];
|
|
99
|
+
for (const line of lines){
|
|
100
|
+
const spaceIndex = line.indexOf(' ');
|
|
101
|
+
if (spaceIndex === -1) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const packageName = line.substring(0, spaceIndex);
|
|
105
|
+
const testName = line.substring(spaceIndex + 1);
|
|
106
|
+
if (contractPackages.has(packageName)) {
|
|
107
|
+
testsInContracts.push({
|
|
108
|
+
packageName,
|
|
109
|
+
testName
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (testsInContracts.length > 0) {
|
|
114
|
+
const details = testsInContracts.map((t)=>` ${t.packageName}::${t.testName}`).join('\n');
|
|
115
|
+
log(`WARNING: Found tests in contract crate(s):\n${details}\n\n` + `Tests should be in a dedicated test crate, not in the contract crate.\n` + `Learn more: https://docs.aztec.network/errors/1`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
55
118
|
/** Compiles Aztec Noir contracts and postprocesses artifacts. */ async function compileAztecContract(nargoArgs, log) {
|
|
56
119
|
const nargo = process.env.NARGO ?? 'nargo';
|
|
57
120
|
const bb = process.env.BB ?? 'bb';
|
|
@@ -59,6 +122,8 @@ import { join } from 'path';
|
|
|
59
122
|
'compile',
|
|
60
123
|
...nargoArgs
|
|
61
124
|
]);
|
|
125
|
+
// Ensure contract crates contain no tests (tests belong in the test crate).
|
|
126
|
+
await checkNoTestsInContracts(nargo, log);
|
|
62
127
|
const artifacts = await collectContractArtifacts();
|
|
63
128
|
if (artifacts.length > 0) {
|
|
64
129
|
log('Postprocessing contracts...');
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
2
|
+
import type { Command } from 'commander';
|
|
3
|
+
export declare function injectProfileCommand(program: Command, log: LogFn): Command;
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvZmlsZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2NsaS9jbWRzL3Byb2ZpbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsS0FBSyxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFFbkQsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0sV0FBVyxDQUFDO0FBS3pDLHdCQUFnQixvQkFBb0IsQ0FBQyxPQUFPLEVBQUUsT0FBTyxFQUFFLEdBQUcsRUFBRSxLQUFLLEdBQUcsT0FBTyxDQWlCMUUifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../../src/cli/cmds/profile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,CAiB1E"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { profileFlamegraph } from './profile_flamegraph.js';
|
|
2
|
+
import { profileGates } from './profile_gates.js';
|
|
3
|
+
export function injectProfileCommand(program, log) {
|
|
4
|
+
const profile = program.command('profile').description('Profile compiled Aztec artifacts.');
|
|
5
|
+
profile.command('gates').argument('[target-dir]', 'Path to the compiled artifacts directory', './target').description('Display gate counts for all compiled Aztec artifacts in a target directory.').action((targetDir)=>profileGates(targetDir, log));
|
|
6
|
+
profile.command('flamegraph').argument('<contract-artifact>', 'Path to the compiled contract artifact JSON').argument('<function>', 'Name of the contract function to profile').description('Generate a gate count flamegraph SVG for a contract function.').action((artifactPath, functionName)=>profileFlamegraph(artifactPath, functionName, log));
|
|
7
|
+
return program;
|
|
8
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
2
|
+
/** Generates a gate count flamegraph SVG for a single contract function. */
|
|
3
|
+
export declare function profileFlamegraph(artifactPath: string, functionName: string, log: LogFn): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvZmlsZV9mbGFtZWdyYXBoLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY2xpL2NtZHMvcHJvZmlsZV9mbGFtZWdyYXBoLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLEtBQUssRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBU25ELDRFQUE0RTtBQUM1RSx3QkFBc0IsaUJBQWlCLENBQUMsWUFBWSxFQUFFLE1BQU0sRUFBRSxZQUFZLEVBQUUsTUFBTSxFQUFFLEdBQUcsRUFBRSxLQUFLLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQW9EN0cifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile_flamegraph.d.ts","sourceRoot":"","sources":["../../../src/cli/cmds/profile_flamegraph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AASnD,4EAA4E;AAC5E,wBAAsB,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAoD7G"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { readFile, rename, rm, writeFile } from 'fs/promises';
|
|
2
|
+
import { basename, dirname, join } from 'path';
|
|
3
|
+
import { makeFunctionArtifact } from './profile_utils.js';
|
|
4
|
+
import { run } from './utils/spawn.js';
|
|
5
|
+
/** Generates a gate count flamegraph SVG for a single contract function. */ export async function profileFlamegraph(artifactPath, functionName, log) {
|
|
6
|
+
const raw = await readFile(artifactPath, 'utf-8');
|
|
7
|
+
const artifact = JSON.parse(raw);
|
|
8
|
+
if (!Array.isArray(artifact.functions)) {
|
|
9
|
+
throw new Error(`${artifactPath} does not appear to be a contract artifact (no functions array)`);
|
|
10
|
+
}
|
|
11
|
+
const func = artifact.functions.find((f)=>f.name === functionName);
|
|
12
|
+
if (!func) {
|
|
13
|
+
const available = artifact.functions.map((f)=>f.name).join(', ');
|
|
14
|
+
throw new Error(`Function "${functionName}" not found in artifact. Available: ${available}`);
|
|
15
|
+
}
|
|
16
|
+
if (func.is_unconstrained) {
|
|
17
|
+
throw new Error(`Function "${functionName}" is unconstrained and cannot be profiled`);
|
|
18
|
+
}
|
|
19
|
+
const outputDir = dirname(artifactPath);
|
|
20
|
+
const contractName = basename(artifactPath, '.json');
|
|
21
|
+
const functionArtifact = join(outputDir, `${contractName}-${functionName}.json`);
|
|
22
|
+
try {
|
|
23
|
+
await writeFile(functionArtifact, makeFunctionArtifact(artifact, func));
|
|
24
|
+
const profiler = process.env.PROFILER_PATH ?? 'noir-profiler';
|
|
25
|
+
const bb = process.env.BB ?? 'bb';
|
|
26
|
+
await run(profiler, [
|
|
27
|
+
'gates',
|
|
28
|
+
'--artifact-path',
|
|
29
|
+
functionArtifact,
|
|
30
|
+
'--backend-path',
|
|
31
|
+
bb,
|
|
32
|
+
'--backend-gates-command',
|
|
33
|
+
'gates',
|
|
34
|
+
'--output',
|
|
35
|
+
outputDir,
|
|
36
|
+
'--scheme',
|
|
37
|
+
'chonk',
|
|
38
|
+
'--include_gates_per_opcode'
|
|
39
|
+
]);
|
|
40
|
+
// noir-profiler names the SVG using the internal function name which
|
|
41
|
+
// retains the __aztec_nr_internals__ prefix in the bytecode metadata.
|
|
42
|
+
const srcSvg = join(outputDir, `__aztec_nr_internals__${functionName}_gates.svg`);
|
|
43
|
+
const destSvg = join(outputDir, `${contractName}-${functionName}-flamegraph.svg`);
|
|
44
|
+
await rename(srcSvg, destSvg);
|
|
45
|
+
log(`Flamegraph written to ${destSvg}`);
|
|
46
|
+
} finally{
|
|
47
|
+
await rm(functionArtifact, {
|
|
48
|
+
force: true
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
2
|
+
/** Profiles all compiled artifacts in a target directory and prints gate counts. */
|
|
3
|
+
export declare function profileGates(targetDir: string, log: LogFn): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvZmlsZV9nYXRlcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2NsaS9jbWRzL3Byb2ZpbGVfZ2F0ZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsS0FBSyxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUErQm5ELG9GQUFvRjtBQUNwRix3QkFBc0IsWUFBWSxDQUFDLFNBQVMsRUFBRSxNQUFNLEVBQUUsR0FBRyxFQUFFLEtBQUssR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBaUMvRSJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile_gates.d.ts","sourceRoot":"","sources":["../../../src/cli/cmds/profile_gates.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AA+BnD,oFAAoF;AACpF,wBAAsB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAiC/E"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { asyncPool } from '@aztec/foundation/async-pool';
|
|
2
|
+
import { execFile as execFileCb } from 'child_process';
|
|
3
|
+
import { rm } from 'fs/promises';
|
|
4
|
+
import { promisify } from 'util';
|
|
5
|
+
import { MAX_CONCURRENT, discoverArtifacts } from './profile_utils.js';
|
|
6
|
+
const execFile = promisify(execFileCb);
|
|
7
|
+
/** Parses circuit_size from bb gates JSON output: { "functions": [{ "circuit_size": N }] } */ function parseGateCount(stdout) {
|
|
8
|
+
const parsed = JSON.parse(stdout);
|
|
9
|
+
const size = parsed?.functions?.[0]?.circuit_size;
|
|
10
|
+
if (typeof size !== 'number') {
|
|
11
|
+
throw new Error('Failed to parse circuit_size from bb gates output');
|
|
12
|
+
}
|
|
13
|
+
return size;
|
|
14
|
+
}
|
|
15
|
+
/** Runs bb gates on a single artifact file and returns the gate count. */ async function getGateCount(bb, artifactPath) {
|
|
16
|
+
const { stdout } = await execFile(bb, [
|
|
17
|
+
'gates',
|
|
18
|
+
'--scheme',
|
|
19
|
+
'chonk',
|
|
20
|
+
'-b',
|
|
21
|
+
artifactPath
|
|
22
|
+
]);
|
|
23
|
+
return parseGateCount(stdout);
|
|
24
|
+
}
|
|
25
|
+
/** Profiles all compiled artifacts in a target directory and prints gate counts. */ export async function profileGates(targetDir, log) {
|
|
26
|
+
const bb = process.env.BB ?? 'bb';
|
|
27
|
+
const { artifacts, tmpDir } = await discoverArtifacts(targetDir);
|
|
28
|
+
if (artifacts.length === 0) {
|
|
29
|
+
log('No artifacts found in target directory.');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const results = await asyncPool(MAX_CONCURRENT, artifacts, async (artifact)=>({
|
|
34
|
+
name: artifact.name,
|
|
35
|
+
gateCount: await getGateCount(bb, artifact.filePath)
|
|
36
|
+
}));
|
|
37
|
+
results.sort((a, b)=>a.name.localeCompare(b.name));
|
|
38
|
+
if (results.length === 0) {
|
|
39
|
+
log('No constrained circuits found.');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const maxNameLen = Math.max(...results.map((r)=>r.name.length));
|
|
43
|
+
log('');
|
|
44
|
+
log('Gate counts:');
|
|
45
|
+
log('-'.repeat(maxNameLen + 16));
|
|
46
|
+
for (const { name, gateCount } of results){
|
|
47
|
+
log(`${name.padEnd(maxNameLen)} ${gateCount.toLocaleString().padStart(12)}`);
|
|
48
|
+
}
|
|
49
|
+
log('-'.repeat(maxNameLen + 16));
|
|
50
|
+
log(`Total: ${results.length} circuit(s)`);
|
|
51
|
+
} finally{
|
|
52
|
+
await rm(tmpDir, {
|
|
53
|
+
recursive: true,
|
|
54
|
+
force: true
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CompiledArtifact, ContractFunction } from './utils/artifacts.js';
|
|
2
|
+
export declare const MAX_CONCURRENT = 4;
|
|
3
|
+
export interface DiscoveredArtifact {
|
|
4
|
+
name: string;
|
|
5
|
+
filePath: string;
|
|
6
|
+
type: 'contract-function' | 'program';
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Reads a target directory and returns a list of discovered artifacts with temp files
|
|
10
|
+
* created for contract functions. Caller must clean up tmpDir when done.
|
|
11
|
+
*/
|
|
12
|
+
export declare function discoverArtifacts(targetDir: string): Promise<{
|
|
13
|
+
artifacts: DiscoveredArtifact[];
|
|
14
|
+
tmpDir: string;
|
|
15
|
+
}>;
|
|
16
|
+
/** Extracts a contract function as a standalone program artifact JSON string. */
|
|
17
|
+
export declare function makeFunctionArtifact(artifact: CompiledArtifact, func: ContractFunction): string;
|
|
18
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvZmlsZV91dGlscy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2NsaS9jbWRzL3Byb2ZpbGVfdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSUEsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUcvRSxlQUFPLE1BQU0sY0FBYyxJQUFJLENBQUM7QUFFaEMsTUFBTSxXQUFXLGtCQUFrQjtJQUNqQyxJQUFJLEVBQUUsTUFBTSxDQUFDO0lBQ2IsUUFBUSxFQUFFLE1BQU0sQ0FBQztJQUNqQixJQUFJLEVBQUUsbUJBQW1CLEdBQUcsU0FBUyxDQUFDO0NBQ3ZDO0FBRUQ7OztHQUdHO0FBQ0gsd0JBQXNCLGlCQUFpQixDQUNyQyxTQUFTLEVBQUUsTUFBTSxHQUNoQixPQUFPLENBQUM7SUFBRSxTQUFTLEVBQUUsa0JBQWtCLEVBQUUsQ0FBQztJQUFDLE1BQU0sRUFBRSxNQUFNLENBQUE7Q0FBRSxDQUFDLENBc0I5RDtBQUVELGlGQUFpRjtBQUNqRix3QkFBZ0Isb0JBQW9CLENBQUMsUUFBUSxFQUFFLGdCQUFnQixFQUFFLElBQUksRUFBRSxnQkFBZ0IsVUFXdEYifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile_utils.d.ts","sourceRoot":"","sources":["../../../src/cli/cmds/profile_utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAG/E,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,mBAAmB,GAAG,SAAS,CAAC;CACvC;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC;IAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAsB9D;AAED,iFAAiF;AACjF,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,gBAAgB,UAWtF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { mkdtemp, writeFile } from 'fs/promises';
|
|
2
|
+
import { tmpdir } from 'os';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { readArtifactFiles } from './utils/artifacts.js';
|
|
5
|
+
export const MAX_CONCURRENT = 4;
|
|
6
|
+
/**
|
|
7
|
+
* Reads a target directory and returns a list of discovered artifacts with temp files
|
|
8
|
+
* created for contract functions. Caller must clean up tmpDir when done.
|
|
9
|
+
*/ export async function discoverArtifacts(targetDir) {
|
|
10
|
+
const files = await readArtifactFiles(targetDir);
|
|
11
|
+
const tmpDir = await mkdtemp(join(tmpdir(), 'aztec-profile-'));
|
|
12
|
+
const artifacts = [];
|
|
13
|
+
for (const file of files){
|
|
14
|
+
if (Array.isArray(file.content.functions)) {
|
|
15
|
+
for (const func of file.content.functions){
|
|
16
|
+
if (!func.bytecode || func.is_unconstrained) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const name = `${file.name}::${func.name}`;
|
|
20
|
+
const tmpPath = join(tmpDir, `${file.name}-${func.name}.json`);
|
|
21
|
+
await writeFile(tmpPath, makeFunctionArtifact(file.content, func));
|
|
22
|
+
artifacts.push({
|
|
23
|
+
name,
|
|
24
|
+
filePath: tmpPath,
|
|
25
|
+
type: 'contract-function'
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
} else if (file.content.bytecode) {
|
|
29
|
+
artifacts.push({
|
|
30
|
+
name: file.name,
|
|
31
|
+
filePath: file.filePath,
|
|
32
|
+
type: 'program'
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
artifacts,
|
|
38
|
+
tmpDir
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Extracts a contract function as a standalone program artifact JSON string. */ export function makeFunctionArtifact(artifact, func) {
|
|
42
|
+
/* eslint-disable camelcase */ return JSON.stringify({
|
|
43
|
+
noir_version: artifact.noir_version,
|
|
44
|
+
hash: 0,
|
|
45
|
+
abi: func.abi,
|
|
46
|
+
bytecode: func.bytecode,
|
|
47
|
+
debug_symbols: func.debug_symbols,
|
|
48
|
+
file_map: artifact.file_map
|
|
49
|
+
});
|
|
50
|
+
/* eslint-enable camelcase */ }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface CompiledArtifact {
|
|
2
|
+
noir_version: string;
|
|
3
|
+
file_map: unknown;
|
|
4
|
+
functions: ContractFunction[];
|
|
5
|
+
bytecode?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ContractFunction {
|
|
8
|
+
name: string;
|
|
9
|
+
abi: unknown;
|
|
10
|
+
bytecode: string;
|
|
11
|
+
debug_symbols: unknown;
|
|
12
|
+
is_unconstrained?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface ArtifactFile {
|
|
15
|
+
name: string;
|
|
16
|
+
filePath: string;
|
|
17
|
+
content: CompiledArtifact;
|
|
18
|
+
}
|
|
19
|
+
/** Reads all JSON artifact files from a target directory and returns their parsed contents. */
|
|
20
|
+
export declare function readArtifactFiles(targetDir: string): Promise<ArtifactFile[]>;
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXJ0aWZhY3RzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvY2xpL2NtZHMvdXRpbHMvYXJ0aWZhY3RzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUdBLE1BQU0sV0FBVyxnQkFBZ0I7SUFDL0IsWUFBWSxFQUFFLE1BQU0sQ0FBQztJQUNyQixRQUFRLEVBQUUsT0FBTyxDQUFDO0lBQ2xCLFNBQVMsRUFBRSxnQkFBZ0IsRUFBRSxDQUFDO0lBQzlCLFFBQVEsQ0FBQyxFQUFFLE1BQU0sQ0FBQztDQUNuQjtBQUVELE1BQU0sV0FBVyxnQkFBZ0I7SUFDL0IsSUFBSSxFQUFFLE1BQU0sQ0FBQztJQUNiLEdBQUcsRUFBRSxPQUFPLENBQUM7SUFDYixRQUFRLEVBQUUsTUFBTSxDQUFDO0lBQ2pCLGFBQWEsRUFBRSxPQUFPLENBQUM7SUFDdkIsZ0JBQWdCLENBQUMsRUFBRSxPQUFPLENBQUM7Q0FDNUI7QUFFRCxNQUFNLFdBQVcsWUFBWTtJQUMzQixJQUFJLEVBQUUsTUFBTSxDQUFDO0lBQ2IsUUFBUSxFQUFFLE1BQU0sQ0FBQztJQUNqQixPQUFPLEVBQUUsZ0JBQWdCLENBQUM7Q0FDM0I7QUFFRCwrRkFBK0Y7QUFDL0Ysd0JBQXNCLGlCQUFpQixDQUFDLFNBQVMsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLFlBQVksRUFBRSxDQUFDLENBa0JsRiJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifacts.d.ts","sourceRoot":"","sources":["../../../../src/cli/cmds/utils/artifacts.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,gBAAgB,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,gBAAgB,CAAC;CAC3B;AAED,+FAA+F;AAC/F,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAkBlF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { readFile, readdir } from 'fs/promises';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
/** Reads all JSON artifact files from a target directory and returns their parsed contents. */ export async function readArtifactFiles(targetDir) {
|
|
4
|
+
let entries;
|
|
5
|
+
try {
|
|
6
|
+
entries = (await readdir(targetDir)).filter((f)=>f.endsWith('.json'));
|
|
7
|
+
} catch (err) {
|
|
8
|
+
if (err?.code === 'ENOENT') {
|
|
9
|
+
throw new Error(`Target directory '${targetDir}' does not exist. Compile first with 'aztec compile'.`);
|
|
10
|
+
}
|
|
11
|
+
throw err;
|
|
12
|
+
}
|
|
13
|
+
const artifacts = [];
|
|
14
|
+
for (const file of entries){
|
|
15
|
+
const filePath = join(targetDir, file);
|
|
16
|
+
const content = JSON.parse(await readFile(filePath, 'utf-8'));
|
|
17
|
+
artifacts.push({
|
|
18
|
+
name: file.replace('.json', ''),
|
|
19
|
+
filePath,
|
|
20
|
+
content
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return artifacts;
|
|
24
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Spawns a command with inherited stdio and rejects on non-zero exit. */
|
|
2
|
+
export declare function run(cmd: string, args: string[]): Promise<void>;
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3Bhd24uZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jbGkvY21kcy91dGlscy9zcGF3bi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSwwRUFBMEU7QUFDMUUsd0JBQWdCLEdBQUcsQ0FBQyxHQUFHLEVBQUUsTUFBTSxFQUFFLElBQUksRUFBRSxNQUFNLEVBQUUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBWTlEIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../../../src/cli/cmds/utils/spawn.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAY9D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
/** Spawns a command with inherited stdio and rejects on non-zero exit. */ export function run(cmd, args) {
|
|
3
|
+
return new Promise((resolve, reject)=>{
|
|
4
|
+
const child = spawn(cmd, args, {
|
|
5
|
+
stdio: 'inherit'
|
|
6
|
+
});
|
|
7
|
+
child.on('error', reject);
|
|
8
|
+
child.on('close', (code)=>{
|
|
9
|
+
if (code !== 0) {
|
|
10
|
+
reject(new Error(`${cmd} exited with code ${code}`));
|
|
11
|
+
} else {
|
|
12
|
+
resolve();
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
package/dest/cli/util.js
CHANGED
|
@@ -220,7 +220,7 @@ export const printAztecStartHelpText = ()=>{
|
|
|
220
220
|
const { Crs, GrumpkinCrs } = await import('@aztec/bb.js');
|
|
221
221
|
await Promise.all([
|
|
222
222
|
Crs.new(2 ** 1, undefined, log),
|
|
223
|
-
GrumpkinCrs.new(2 ** 16
|
|
223
|
+
GrumpkinCrs.new(2 ** 16, undefined, log)
|
|
224
224
|
]);
|
|
225
225
|
}
|
|
226
226
|
}
|
|
@@ -232,8 +232,8 @@ export const printAztecStartHelpText = ()=>{
|
|
|
232
232
|
if (realProofs) {
|
|
233
233
|
const { Crs, GrumpkinCrs } = await import('@aztec/bb.js');
|
|
234
234
|
await Promise.all([
|
|
235
|
-
Crs.new(2 ** 25
|
|
236
|
-
GrumpkinCrs.new(2 ** 18
|
|
235
|
+
Crs.new(2 ** 25, undefined, log),
|
|
236
|
+
GrumpkinCrs.new(2 ** 18, undefined, log)
|
|
237
237
|
]);
|
|
238
238
|
}
|
|
239
239
|
}
|