@aztec/aztec 4.0.0-rc.7 → 4.0.0-rc.8
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 +5 -1
- package/dest/cli/cli.d.ts +1 -1
- package/dest/cli/cli.d.ts.map +1 -1
- package/dest/cli/cli.js +0 -1
- package/dest/cli/cmds/compile.d.ts +4 -0
- package/dest/cli/cmds/compile.d.ts.map +1 -0
- package/dest/cli/cmds/compile.js +68 -0
- 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/package.json +34 -34
- package/scripts/aztec.sh +6 -2
- package/src/bin/index.ts +5 -1
- package/src/cli/cli.ts +0 -1
- package/src/cli/cmds/compile.ts +80 -0
- 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/scripts/compile.sh +0 -44
- package/scripts/extract_function.js +0 -47
- package/scripts/flamegraph.sh +0 -59
package/dest/bin/index.js
CHANGED
|
@@ -12,7 +12,9 @@ import { injectCommands as injectValidatorKeysCommands } from '@aztec/cli/valida
|
|
|
12
12
|
import { getActiveNetworkName } from '@aztec/foundation/config';
|
|
13
13
|
import { createConsoleLogger, createLogger } from '@aztec/foundation/log';
|
|
14
14
|
import { Command } from 'commander';
|
|
15
|
+
import { injectCompileCommand } from '../cli/cmds/compile.js';
|
|
15
16
|
import { injectMigrateCommand } from '../cli/cmds/migrate_ha_db.js';
|
|
17
|
+
import { injectProfileCommand } from '../cli/cmds/profile.js';
|
|
16
18
|
import { injectAztecCommands } from '../cli/index.js';
|
|
17
19
|
import { getCliVersion } from '../cli/release_version.js';
|
|
18
20
|
const NETWORK_FLAG = 'network';
|
|
@@ -36,7 +38,7 @@ const debugLogger = createLogger('cli');
|
|
|
36
38
|
enrichEnvironmentWithChainName(networkName);
|
|
37
39
|
const cliVersion = getCliVersion();
|
|
38
40
|
let program = new Command('aztec');
|
|
39
|
-
program.description('Aztec command line interface').version(cliVersion);
|
|
41
|
+
program.description('Aztec command line interface').version(cliVersion).enablePositionalOptions();
|
|
40
42
|
program = injectAztecCommands(program, userLog, debugLogger);
|
|
41
43
|
program = injectBuilderCommands(program);
|
|
42
44
|
program = injectContractCommands(program, userLog, debugLogger);
|
|
@@ -45,6 +47,8 @@ const debugLogger = createLogger('cli');
|
|
|
45
47
|
program = injectAztecNodeCommands(program, userLog, debugLogger);
|
|
46
48
|
program = injectMiscCommands(program, userLog);
|
|
47
49
|
program = injectValidatorKeysCommands(program, userLog);
|
|
50
|
+
program = injectCompileCommand(program, userLog);
|
|
51
|
+
program = injectProfileCommand(program, userLog);
|
|
48
52
|
program = injectMigrateCommand(program, userLog);
|
|
49
53
|
await program.parseAsync(process.argv);
|
|
50
54
|
}
|
package/dest/cli/cli.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ import { Command } from 'commander';
|
|
|
6
6
|
* @param debugLogger - logger for logging debug messages.
|
|
7
7
|
*/
|
|
8
8
|
export declare function injectAztecCommands(program: Command, userLog: LogFn, debugLogger: Logger): Command;
|
|
9
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xpLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY2xpL2NsaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFFM0QsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLFdBQVcsQ0FBQztBQUtwQzs7OztHQUlHO0FBQ0gsd0JBQWdCLG1CQUFtQixDQUFDLE9BQU8sRUFBRSxPQUFPLEVBQUUsT0FBTyxFQUFFLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0EyQ2xHIn0=
|
package/dest/cli/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CA2ClG"}
|
package/dest/cli/cli.js
CHANGED
|
@@ -26,7 +26,6 @@ Additional commands:
|
|
|
26
26
|
|
|
27
27
|
init [folder] [options] creates a new Aztec Noir project.
|
|
28
28
|
new <path> [options] creates a new Aztec Noir project in a new directory.
|
|
29
|
-
compile [options] compiles Aztec Noir contracts.
|
|
30
29
|
test [options] starts a TXE and runs "nargo test" using it as the oracle resolver.
|
|
31
30
|
`);
|
|
32
31
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
2
|
+
import type { Command } from 'commander';
|
|
3
|
+
export declare function injectCompileCommand(program: Command, log: LogFn): Command;
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcGlsZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2NsaS9jbWRzL2NvbXBpbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsS0FBSyxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFHbkQsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0sV0FBVyxDQUFDO0FBc0R6Qyx3QkFBZ0Isb0JBQW9CLENBQUMsT0FBTyxFQUFFLE9BQU8sRUFBRSxHQUFHLEVBQUUsS0FBSyxHQUFHLE9BQU8sQ0FzQjFFIn0=
|
|
@@ -0,0 +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;AAsDzC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,CAsB1E"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { execFileSync } from 'child_process';
|
|
2
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
3
|
+
import { readArtifactFiles } from './utils/artifacts.js';
|
|
4
|
+
import { run } from './utils/spawn.js';
|
|
5
|
+
/** Returns paths to contract artifacts in the target directory. */ async function collectContractArtifacts() {
|
|
6
|
+
let files;
|
|
7
|
+
try {
|
|
8
|
+
files = await readArtifactFiles('target');
|
|
9
|
+
} catch (err) {
|
|
10
|
+
if (err?.message?.includes('does not exist')) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
throw err;
|
|
14
|
+
}
|
|
15
|
+
return files.filter((f)=>Array.isArray(f.content.functions)).map((f)=>f.filePath);
|
|
16
|
+
}
|
|
17
|
+
/** Strips the `__aztec_nr_internals__` prefix from function names in contract artifacts. */ async function stripInternalPrefixes(artifactPaths) {
|
|
18
|
+
for (const path of artifactPaths){
|
|
19
|
+
const artifact = JSON.parse(await readFile(path, 'utf-8'));
|
|
20
|
+
for (const fn of artifact.functions){
|
|
21
|
+
if (typeof fn.name === 'string') {
|
|
22
|
+
fn.name = fn.name.replace(/^__aztec_nr_internals__/, '');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
await writeFile(path, JSON.stringify(artifact, null, 2) + '\n');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Compiles Aztec Noir contracts and postprocesses artifacts. */ async function compileAztecContract(nargoArgs, log) {
|
|
29
|
+
const nargo = process.env.NARGO ?? 'nargo';
|
|
30
|
+
const bb = process.env.BB ?? 'bb';
|
|
31
|
+
await run(nargo, [
|
|
32
|
+
'compile',
|
|
33
|
+
...nargoArgs
|
|
34
|
+
]);
|
|
35
|
+
const artifacts = await collectContractArtifacts();
|
|
36
|
+
if (artifacts.length > 0) {
|
|
37
|
+
log('Postprocessing contracts...');
|
|
38
|
+
const bbArgs = artifacts.flatMap((a)=>[
|
|
39
|
+
'-i',
|
|
40
|
+
a
|
|
41
|
+
]);
|
|
42
|
+
await run(bb, [
|
|
43
|
+
'aztec_process',
|
|
44
|
+
...bbArgs
|
|
45
|
+
]);
|
|
46
|
+
// TODO: This should be part of bb aztec_process!
|
|
47
|
+
await stripInternalPrefixes(artifacts);
|
|
48
|
+
}
|
|
49
|
+
log('Compilation complete!');
|
|
50
|
+
}
|
|
51
|
+
export function injectCompileCommand(program, log) {
|
|
52
|
+
program.command('compile').argument('[nargo-args...]').passThroughOptions().allowUnknownOption().description('Compile Aztec Noir contracts using nargo and postprocess them to generate transpiled artifacts and verification keys. All options are forwarded to nargo compile.').addHelpText('after', ()=>{
|
|
53
|
+
// Show nargo's own compile options so users see all available flags in one place.
|
|
54
|
+
const nargo = process.env.NARGO ?? 'nargo';
|
|
55
|
+
try {
|
|
56
|
+
const output = execFileSync(nargo, [
|
|
57
|
+
'compile',
|
|
58
|
+
'--help'
|
|
59
|
+
], {
|
|
60
|
+
encoding: 'utf-8'
|
|
61
|
+
});
|
|
62
|
+
return `\nUnderlying nargo compile options:\n\n${output}`;
|
|
63
|
+
} catch {
|
|
64
|
+
return '\n(Run "nargo compile --help" to see available nargo options)';
|
|
65
|
+
}
|
|
66
|
+
}).action((nargoArgs)=>compileAztecContract(nargoArgs, log));
|
|
67
|
+
return program;
|
|
68
|
+
}
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/aztec",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.8",
|
|
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": "4.0.0-rc.
|
|
32
|
-
"@aztec/archiver": "4.0.0-rc.
|
|
33
|
-
"@aztec/aztec-faucet": "4.0.0-rc.
|
|
34
|
-
"@aztec/aztec-node": "4.0.0-rc.
|
|
35
|
-
"@aztec/aztec.js": "4.0.0-rc.
|
|
36
|
-
"@aztec/bb-prover": "4.0.0-rc.
|
|
37
|
-
"@aztec/bb.js": "4.0.0-rc.
|
|
38
|
-
"@aztec/blob-client": "4.0.0-rc.
|
|
39
|
-
"@aztec/bot": "4.0.0-rc.
|
|
40
|
-
"@aztec/builder": "4.0.0-rc.
|
|
41
|
-
"@aztec/cli": "4.0.0-rc.
|
|
42
|
-
"@aztec/constants": "4.0.0-rc.
|
|
43
|
-
"@aztec/entrypoints": "4.0.0-rc.
|
|
44
|
-
"@aztec/ethereum": "4.0.0-rc.
|
|
45
|
-
"@aztec/foundation": "4.0.0-rc.
|
|
46
|
-
"@aztec/kv-store": "4.0.0-rc.
|
|
47
|
-
"@aztec/l1-artifacts": "4.0.0-rc.
|
|
48
|
-
"@aztec/node-lib": "4.0.0-rc.
|
|
49
|
-
"@aztec/noir-contracts.js": "4.0.0-rc.
|
|
50
|
-
"@aztec/noir-protocol-circuits-types": "4.0.0-rc.
|
|
51
|
-
"@aztec/p2p": "4.0.0-rc.
|
|
52
|
-
"@aztec/p2p-bootstrap": "4.0.0-rc.
|
|
53
|
-
"@aztec/protocol-contracts": "4.0.0-rc.
|
|
54
|
-
"@aztec/prover-client": "4.0.0-rc.
|
|
55
|
-
"@aztec/prover-node": "4.0.0-rc.
|
|
56
|
-
"@aztec/pxe": "4.0.0-rc.
|
|
57
|
-
"@aztec/sequencer-client": "4.0.0-rc.
|
|
58
|
-
"@aztec/stdlib": "4.0.0-rc.
|
|
59
|
-
"@aztec/telemetry-client": "4.0.0-rc.
|
|
60
|
-
"@aztec/txe": "4.0.0-rc.
|
|
61
|
-
"@aztec/validator-ha-signer": "4.0.0-rc.
|
|
62
|
-
"@aztec/wallets": "4.0.0-rc.
|
|
63
|
-
"@aztec/world-state": "4.0.0-rc.
|
|
31
|
+
"@aztec/accounts": "4.0.0-rc.8",
|
|
32
|
+
"@aztec/archiver": "4.0.0-rc.8",
|
|
33
|
+
"@aztec/aztec-faucet": "4.0.0-rc.8",
|
|
34
|
+
"@aztec/aztec-node": "4.0.0-rc.8",
|
|
35
|
+
"@aztec/aztec.js": "4.0.0-rc.8",
|
|
36
|
+
"@aztec/bb-prover": "4.0.0-rc.8",
|
|
37
|
+
"@aztec/bb.js": "4.0.0-rc.8",
|
|
38
|
+
"@aztec/blob-client": "4.0.0-rc.8",
|
|
39
|
+
"@aztec/bot": "4.0.0-rc.8",
|
|
40
|
+
"@aztec/builder": "4.0.0-rc.8",
|
|
41
|
+
"@aztec/cli": "4.0.0-rc.8",
|
|
42
|
+
"@aztec/constants": "4.0.0-rc.8",
|
|
43
|
+
"@aztec/entrypoints": "4.0.0-rc.8",
|
|
44
|
+
"@aztec/ethereum": "4.0.0-rc.8",
|
|
45
|
+
"@aztec/foundation": "4.0.0-rc.8",
|
|
46
|
+
"@aztec/kv-store": "4.0.0-rc.8",
|
|
47
|
+
"@aztec/l1-artifacts": "4.0.0-rc.8",
|
|
48
|
+
"@aztec/node-lib": "4.0.0-rc.8",
|
|
49
|
+
"@aztec/noir-contracts.js": "4.0.0-rc.8",
|
|
50
|
+
"@aztec/noir-protocol-circuits-types": "4.0.0-rc.8",
|
|
51
|
+
"@aztec/p2p": "4.0.0-rc.8",
|
|
52
|
+
"@aztec/p2p-bootstrap": "4.0.0-rc.8",
|
|
53
|
+
"@aztec/protocol-contracts": "4.0.0-rc.8",
|
|
54
|
+
"@aztec/prover-client": "4.0.0-rc.8",
|
|
55
|
+
"@aztec/prover-node": "4.0.0-rc.8",
|
|
56
|
+
"@aztec/pxe": "4.0.0-rc.8",
|
|
57
|
+
"@aztec/sequencer-client": "4.0.0-rc.8",
|
|
58
|
+
"@aztec/stdlib": "4.0.0-rc.8",
|
|
59
|
+
"@aztec/telemetry-client": "4.0.0-rc.8",
|
|
60
|
+
"@aztec/txe": "4.0.0-rc.8",
|
|
61
|
+
"@aztec/validator-ha-signer": "4.0.0-rc.8",
|
|
62
|
+
"@aztec/wallets": "4.0.0-rc.8",
|
|
63
|
+
"@aztec/world-state": "4.0.0-rc.8",
|
|
64
64
|
"@types/chalk": "^2.2.0",
|
|
65
65
|
"abitype": "^0.8.11",
|
|
66
66
|
"chalk": "^5.3.0",
|
package/scripts/aztec.sh
CHANGED
|
@@ -21,7 +21,7 @@ function aztec {
|
|
|
21
21
|
|
|
22
22
|
case $cmd in
|
|
23
23
|
test)
|
|
24
|
-
export LOG_LEVEL="${LOG_LEVEL:-error}"
|
|
24
|
+
export LOG_LEVEL="${LOG_LEVEL:-"error;trace:contract_log"}"
|
|
25
25
|
aztec start --txe --port 8081 &
|
|
26
26
|
server_pid=$!
|
|
27
27
|
trap 'kill $server_pid &>/dev/null || true' EXIT
|
|
@@ -54,9 +54,13 @@ case $cmd in
|
|
|
54
54
|
|
|
55
55
|
aztec start "$@"
|
|
56
56
|
;;
|
|
57
|
-
|
|
57
|
+
new|init)
|
|
58
58
|
$script_dir/${cmd}.sh "$@"
|
|
59
59
|
;;
|
|
60
|
+
flamegraph)
|
|
61
|
+
echo "Warning: 'aztec flamegraph' is deprecated. Use 'aztec profile flamegraph' instead." >&2
|
|
62
|
+
aztec profile flamegraph "$@"
|
|
63
|
+
;;
|
|
60
64
|
*)
|
|
61
65
|
aztec $cmd "$@"
|
|
62
66
|
;;
|
package/src/bin/index.ts
CHANGED
|
@@ -14,7 +14,9 @@ import { createConsoleLogger, createLogger } from '@aztec/foundation/log';
|
|
|
14
14
|
|
|
15
15
|
import { Command } from 'commander';
|
|
16
16
|
|
|
17
|
+
import { injectCompileCommand } from '../cli/cmds/compile.js';
|
|
17
18
|
import { injectMigrateCommand } from '../cli/cmds/migrate_ha_db.js';
|
|
19
|
+
import { injectProfileCommand } from '../cli/cmds/profile.js';
|
|
18
20
|
import { injectAztecCommands } from '../cli/index.js';
|
|
19
21
|
import { getCliVersion } from '../cli/release_version.js';
|
|
20
22
|
|
|
@@ -47,7 +49,7 @@ async function main() {
|
|
|
47
49
|
|
|
48
50
|
const cliVersion = getCliVersion();
|
|
49
51
|
let program = new Command('aztec');
|
|
50
|
-
program.description('Aztec command line interface').version(cliVersion);
|
|
52
|
+
program.description('Aztec command line interface').version(cliVersion).enablePositionalOptions();
|
|
51
53
|
program = injectAztecCommands(program, userLog, debugLogger);
|
|
52
54
|
program = injectBuilderCommands(program);
|
|
53
55
|
program = injectContractCommands(program, userLog, debugLogger);
|
|
@@ -56,6 +58,8 @@ async function main() {
|
|
|
56
58
|
program = injectAztecNodeCommands(program, userLog, debugLogger);
|
|
57
59
|
program = injectMiscCommands(program, userLog);
|
|
58
60
|
program = injectValidatorKeysCommands(program, userLog);
|
|
61
|
+
program = injectCompileCommand(program, userLog);
|
|
62
|
+
program = injectProfileCommand(program, userLog);
|
|
59
63
|
program = injectMigrateCommand(program, userLog);
|
|
60
64
|
|
|
61
65
|
await program.parseAsync(process.argv);
|
package/src/cli/cli.ts
CHANGED
|
@@ -39,7 +39,6 @@ Additional commands:
|
|
|
39
39
|
|
|
40
40
|
init [folder] [options] creates a new Aztec Noir project.
|
|
41
41
|
new <path> [options] creates a new Aztec Noir project in a new directory.
|
|
42
|
-
compile [options] compiles Aztec Noir contracts.
|
|
43
42
|
test [options] starts a TXE and runs "nargo test" using it as the oracle resolver.
|
|
44
43
|
`,
|
|
45
44
|
);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
2
|
+
|
|
3
|
+
import { execFileSync } from 'child_process';
|
|
4
|
+
import type { Command } from 'commander';
|
|
5
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
6
|
+
|
|
7
|
+
import { readArtifactFiles } from './utils/artifacts.js';
|
|
8
|
+
import { run } from './utils/spawn.js';
|
|
9
|
+
|
|
10
|
+
/** Returns paths to contract artifacts in the target directory. */
|
|
11
|
+
async function collectContractArtifacts(): Promise<string[]> {
|
|
12
|
+
let files;
|
|
13
|
+
try {
|
|
14
|
+
files = await readArtifactFiles('target');
|
|
15
|
+
} catch (err: any) {
|
|
16
|
+
if (err?.message?.includes('does not exist')) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
return files.filter(f => Array.isArray(f.content.functions)).map(f => f.filePath);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Strips the `__aztec_nr_internals__` prefix from function names in contract artifacts. */
|
|
25
|
+
async function stripInternalPrefixes(artifactPaths: string[]): Promise<void> {
|
|
26
|
+
for (const path of artifactPaths) {
|
|
27
|
+
const artifact = JSON.parse(await readFile(path, 'utf-8'));
|
|
28
|
+
for (const fn of artifact.functions) {
|
|
29
|
+
if (typeof fn.name === 'string') {
|
|
30
|
+
fn.name = fn.name.replace(/^__aztec_nr_internals__/, '');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
await writeFile(path, JSON.stringify(artifact, null, 2) + '\n');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Compiles Aztec Noir contracts and postprocesses artifacts. */
|
|
38
|
+
async function compileAztecContract(nargoArgs: string[], log: LogFn): Promise<void> {
|
|
39
|
+
const nargo = process.env.NARGO ?? 'nargo';
|
|
40
|
+
const bb = process.env.BB ?? 'bb';
|
|
41
|
+
|
|
42
|
+
await run(nargo, ['compile', ...nargoArgs]);
|
|
43
|
+
|
|
44
|
+
const artifacts = await collectContractArtifacts();
|
|
45
|
+
|
|
46
|
+
if (artifacts.length > 0) {
|
|
47
|
+
log('Postprocessing contracts...');
|
|
48
|
+
const bbArgs = artifacts.flatMap(a => ['-i', a]);
|
|
49
|
+
await run(bb, ['aztec_process', ...bbArgs]);
|
|
50
|
+
|
|
51
|
+
// TODO: This should be part of bb aztec_process!
|
|
52
|
+
await stripInternalPrefixes(artifacts);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
log('Compilation complete!');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function injectCompileCommand(program: Command, log: LogFn): Command {
|
|
59
|
+
program
|
|
60
|
+
.command('compile')
|
|
61
|
+
.argument('[nargo-args...]')
|
|
62
|
+
.passThroughOptions()
|
|
63
|
+
.allowUnknownOption()
|
|
64
|
+
.description(
|
|
65
|
+
'Compile Aztec Noir contracts using nargo and postprocess them to generate transpiled artifacts and verification keys. All options are forwarded to nargo compile.',
|
|
66
|
+
)
|
|
67
|
+
.addHelpText('after', () => {
|
|
68
|
+
// Show nargo's own compile options so users see all available flags in one place.
|
|
69
|
+
const nargo = process.env.NARGO ?? 'nargo';
|
|
70
|
+
try {
|
|
71
|
+
const output = execFileSync(nargo, ['compile', '--help'], { encoding: 'utf-8' });
|
|
72
|
+
return `\nUnderlying nargo compile options:\n\n${output}`;
|
|
73
|
+
} catch {
|
|
74
|
+
return '\n(Run "nargo compile --help" to see available nargo options)';
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
.action((nargoArgs: string[]) => compileAztecContract(nargoArgs, log));
|
|
78
|
+
|
|
79
|
+
return program;
|
|
80
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { mkdtemp, writeFile } from 'fs/promises';
|
|
2
|
+
import { tmpdir } from 'os';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
|
|
5
|
+
import type { CompiledArtifact, ContractFunction } from './utils/artifacts.js';
|
|
6
|
+
import { readArtifactFiles } from './utils/artifacts.js';
|
|
7
|
+
|
|
8
|
+
export const MAX_CONCURRENT = 4;
|
|
9
|
+
|
|
10
|
+
export interface DiscoveredArtifact {
|
|
11
|
+
name: string;
|
|
12
|
+
filePath: string;
|
|
13
|
+
type: 'contract-function' | 'program';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Reads a target directory and returns a list of discovered artifacts with temp files
|
|
18
|
+
* created for contract functions. Caller must clean up tmpDir when done.
|
|
19
|
+
*/
|
|
20
|
+
export async function discoverArtifacts(
|
|
21
|
+
targetDir: string,
|
|
22
|
+
): Promise<{ artifacts: DiscoveredArtifact[]; tmpDir: string }> {
|
|
23
|
+
const files = await readArtifactFiles(targetDir);
|
|
24
|
+
const tmpDir = await mkdtemp(join(tmpdir(), 'aztec-profile-'));
|
|
25
|
+
const artifacts: DiscoveredArtifact[] = [];
|
|
26
|
+
|
|
27
|
+
for (const file of files) {
|
|
28
|
+
if (Array.isArray(file.content.functions)) {
|
|
29
|
+
for (const func of file.content.functions) {
|
|
30
|
+
if (!func.bytecode || func.is_unconstrained) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const name = `${file.name}::${func.name}`;
|
|
34
|
+
const tmpPath = join(tmpDir, `${file.name}-${func.name}.json`);
|
|
35
|
+
await writeFile(tmpPath, makeFunctionArtifact(file.content, func));
|
|
36
|
+
artifacts.push({ name, filePath: tmpPath, type: 'contract-function' });
|
|
37
|
+
}
|
|
38
|
+
} else if (file.content.bytecode) {
|
|
39
|
+
artifacts.push({ name: file.name, filePath: file.filePath, type: 'program' });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { artifacts, tmpDir };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Extracts a contract function as a standalone program artifact JSON string. */
|
|
47
|
+
export function makeFunctionArtifact(artifact: CompiledArtifact, func: ContractFunction) {
|
|
48
|
+
/* eslint-disable camelcase */
|
|
49
|
+
return JSON.stringify({
|
|
50
|
+
noir_version: artifact.noir_version,
|
|
51
|
+
hash: 0,
|
|
52
|
+
abi: func.abi,
|
|
53
|
+
bytecode: func.bytecode,
|
|
54
|
+
debug_symbols: func.debug_symbols,
|
|
55
|
+
file_map: artifact.file_map,
|
|
56
|
+
});
|
|
57
|
+
/* eslint-enable camelcase */
|
|
58
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { readFile, readdir } from 'fs/promises';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
|
|
4
|
+
export interface CompiledArtifact {
|
|
5
|
+
noir_version: string;
|
|
6
|
+
file_map: unknown;
|
|
7
|
+
functions: ContractFunction[];
|
|
8
|
+
bytecode?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ContractFunction {
|
|
12
|
+
name: string;
|
|
13
|
+
abi: unknown;
|
|
14
|
+
bytecode: string;
|
|
15
|
+
debug_symbols: unknown;
|
|
16
|
+
is_unconstrained?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ArtifactFile {
|
|
20
|
+
name: string;
|
|
21
|
+
filePath: string;
|
|
22
|
+
content: CompiledArtifact;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Reads all JSON artifact files from a target directory and returns their parsed contents. */
|
|
26
|
+
export async function readArtifactFiles(targetDir: string): Promise<ArtifactFile[]> {
|
|
27
|
+
let entries: string[];
|
|
28
|
+
try {
|
|
29
|
+
entries = (await readdir(targetDir)).filter(f => f.endsWith('.json'));
|
|
30
|
+
} catch (err: any) {
|
|
31
|
+
if (err?.code === 'ENOENT') {
|
|
32
|
+
throw new Error(`Target directory '${targetDir}' does not exist. Compile first with 'aztec compile'.`);
|
|
33
|
+
}
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const artifacts: ArtifactFile[] = [];
|
|
38
|
+
for (const file of entries) {
|
|
39
|
+
const filePath = join(targetDir, file);
|
|
40
|
+
const content = JSON.parse(await readFile(filePath, 'utf-8')) as CompiledArtifact;
|
|
41
|
+
artifacts.push({ name: file.replace('.json', ''), filePath, content });
|
|
42
|
+
}
|
|
43
|
+
return artifacts;
|
|
44
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
|
|
3
|
+
/** Spawns a command with inherited stdio and rejects on non-zero exit. */
|
|
4
|
+
export function run(cmd: string, args: string[]): Promise<void> {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const child = spawn(cmd, args, { stdio: 'inherit' });
|
|
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/scripts/compile.sh
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
set -euo pipefail
|
|
3
|
-
|
|
4
|
-
NARGO=${NARGO:-nargo}
|
|
5
|
-
BB=${BB:-bb}
|
|
6
|
-
|
|
7
|
-
# If help is requested, show Aztec-specific info then run nargo compile help and then exit in order to not trigger
|
|
8
|
-
# transpilation
|
|
9
|
-
for arg in "$@"; do
|
|
10
|
-
if [ "$arg" == "--help" ] || [ "$arg" == "-h" ]; then
|
|
11
|
-
cat << 'EOF'
|
|
12
|
-
Aztec Compile - Compile Aztec Noir contracts
|
|
13
|
-
|
|
14
|
-
This command compiles Aztec Noir contracts using nargo and then automatically
|
|
15
|
-
postprocesses them to generate Aztec specific artifacts including:
|
|
16
|
-
- Transpiled contract artifacts
|
|
17
|
-
- Verification keys
|
|
18
|
-
|
|
19
|
-
The compiled contracts will be placed in the target/ directory by default.
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
Underlying nargo compile options:
|
|
23
|
-
|
|
24
|
-
EOF
|
|
25
|
-
nargo compile --help
|
|
26
|
-
exit 0
|
|
27
|
-
fi
|
|
28
|
-
done
|
|
29
|
-
|
|
30
|
-
# Run nargo compile.
|
|
31
|
-
$NARGO compile "$@"
|
|
32
|
-
|
|
33
|
-
echo "Postprocessing contract..."
|
|
34
|
-
$BB aztec_process
|
|
35
|
-
|
|
36
|
-
# Strip internal prefixes from all compiled contract JSONs in target directory
|
|
37
|
-
# TODO: This should be part of bb aztec_process!
|
|
38
|
-
for json in target/*.json; do
|
|
39
|
-
temp_file="${json}.tmp"
|
|
40
|
-
jq '.functions |= map(.name |= sub("^__aztec_nr_internals__"; ""))' "$json" > "$temp_file"
|
|
41
|
-
mv "$temp_file" "$json"
|
|
42
|
-
done
|
|
43
|
-
|
|
44
|
-
echo "Compilation complete!"
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from 'fs/promises';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
// Simple script to extract a contract function as a separate Noir artifact.
|
|
6
|
-
// We need to use this since the transpiling that we do on public functions make the contract artifacts
|
|
7
|
-
// unreadable by noir tooling, since they are no longer following the noir artifact format.
|
|
8
|
-
async function main() {
|
|
9
|
-
let [contractArtifactPath, functionName] = process.argv.slice(2);
|
|
10
|
-
if (!contractArtifactPath || !functionName) {
|
|
11
|
-
console.log('Usage: node extractFunctionAsNoirArtifact.js <contractArtifactPath> <functionName>');
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const contractArtifact = JSON.parse(await fs.readFile(contractArtifactPath, 'utf8'));
|
|
16
|
-
const func = contractArtifact.functions.find(f => f.name === functionName);
|
|
17
|
-
if (!func) {
|
|
18
|
-
console.error(`Function ${functionName} not found in ${contractArtifactPath}`);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const artifact = {
|
|
23
|
-
noir_version: contractArtifact.noir_version,
|
|
24
|
-
hash: 0,
|
|
25
|
-
abi: func.abi,
|
|
26
|
-
bytecode: func.bytecode,
|
|
27
|
-
debug_symbols: func.debug_symbols,
|
|
28
|
-
file_map: contractArtifact.file_map,
|
|
29
|
-
expression_width: {
|
|
30
|
-
Bounded: {
|
|
31
|
-
width: 4,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const outputDir = path.dirname(contractArtifactPath);
|
|
37
|
-
const outputName = path.basename(contractArtifactPath, '.json') + `-${functionName}.json`;
|
|
38
|
-
|
|
39
|
-
const outPath = path.join(outputDir, outputName);
|
|
40
|
-
|
|
41
|
-
await fs.writeFile(outPath, JSON.stringify(artifact, null, 2));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
main().catch(err => {
|
|
45
|
-
console.error(err);
|
|
46
|
-
process.exit(1);
|
|
47
|
-
});
|
package/scripts/flamegraph.sh
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
set -eu
|
|
3
|
-
|
|
4
|
-
# If first arg is -h or --help, print usage.
|
|
5
|
-
if [ $# -lt 2 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
|
|
6
|
-
cat << 'EOF'
|
|
7
|
-
Aztec Flamegraph - Generate a gate count flamegraph for an aztec contract function.
|
|
8
|
-
|
|
9
|
-
Usage: aztec flamegraph <contract_artifact> <function>
|
|
10
|
-
|
|
11
|
-
Options:
|
|
12
|
-
-h, --help Print help
|
|
13
|
-
|
|
14
|
-
Will output an svg at <artifact_path>/<contract>-<function>-flamegraph.svg.
|
|
15
|
-
You can open it in your browser to view it.
|
|
16
|
-
|
|
17
|
-
EOF
|
|
18
|
-
exit 0
|
|
19
|
-
fi
|
|
20
|
-
|
|
21
|
-
cleanup() {
|
|
22
|
-
set +e
|
|
23
|
-
if [ -f "$function_artifact" ]; then
|
|
24
|
-
rm -f "$function_artifact"
|
|
25
|
-
fi
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
trap cleanup EXIT
|
|
29
|
-
|
|
30
|
-
# Get the directory of the script
|
|
31
|
-
script_dir=$(realpath $(dirname $0))
|
|
32
|
-
|
|
33
|
-
PROFILER=${PROFILER_PATH:-noir-profiler}
|
|
34
|
-
BB=${BB:-bb}
|
|
35
|
-
|
|
36
|
-
# first console arg is contract name in camel case or path to contract artifact
|
|
37
|
-
contract=$1
|
|
38
|
-
|
|
39
|
-
# second console arg is the contract function
|
|
40
|
-
function=$2
|
|
41
|
-
|
|
42
|
-
if [ ! -f "$contract" ]; then
|
|
43
|
-
echo "Error: Contract artifact not found at: $contract"
|
|
44
|
-
exit 1
|
|
45
|
-
fi
|
|
46
|
-
artifact_path=$contract
|
|
47
|
-
function_artifact="${artifact_path%%.json}-${function}.json"
|
|
48
|
-
output_dir=$(dirname "$artifact_path")
|
|
49
|
-
|
|
50
|
-
# Extract artifact for the specific function.
|
|
51
|
-
node $script_dir/extract_function.js "$artifact_path" $function
|
|
52
|
-
|
|
53
|
-
# Generate the flamegraph
|
|
54
|
-
$PROFILER gates --artifact-path "$function_artifact" --backend-path "$BB" --backend-gates-command "gates" --output "$output_dir" --scheme chonk --include_gates_per_opcode
|
|
55
|
-
|
|
56
|
-
# Save as $artifact_name-$function-flamegraph.svg
|
|
57
|
-
output_file="${function_artifact%%.json}-flamegraph.svg"
|
|
58
|
-
mv "$output_dir/__aztec_nr_internals__${function}_gates.svg" "$output_file"
|
|
59
|
-
echo "Flamegraph generated at: $output_file"
|