@aztec/aztec 0.0.1-commit.3469e52 → 0.0.1-commit.381b1a9
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 +7 -3
- package/dest/cli/admin_api_key_store.d.ts +45 -0
- package/dest/cli/admin_api_key_store.d.ts.map +1 -0
- package/dest/cli/admin_api_key_store.js +98 -0
- package/dest/cli/aztec_start_action.d.ts +1 -1
- package/dest/cli/aztec_start_action.d.ts.map +1 -1
- package/dest/cli/aztec_start_action.js +56 -15
- 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 +28 -10
- 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/standby.d.ts +32 -0
- package/dest/cli/cmds/standby.d.ts.map +1 -0
- package/dest/cli/cmds/standby.js +97 -0
- package/dest/cli/cmds/start_bot.d.ts +3 -3
- package/dest/cli/cmds/start_bot.d.ts.map +1 -1
- package/dest/cli/cmds/start_bot.js +9 -5
- package/dest/cli/cmds/start_node.d.ts +3 -2
- package/dest/cli/cmds/start_node.d.ts.map +1 -1
- package/dest/cli/cmds/start_node.js +83 -27
- package/dest/cli/cmds/start_p2p_bootstrap.d.ts +2 -2
- package/dest/cli/cmds/start_p2p_bootstrap.d.ts.map +1 -1
- package/dest/cli/cmds/start_p2p_bootstrap.js +1 -2
- package/dest/cli/cmds/start_prover_agent.js +2 -2
- package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
- package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
- package/dest/cli/cmds/start_prover_broker.js +14 -8
- 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.d.ts +7 -18
- package/dest/cli/util.d.ts.map +1 -1
- package/dest/cli/util.js +47 -83
- package/dest/examples/token.js +9 -9
- package/dest/local-network/banana_fpc.d.ts +1 -1
- package/dest/local-network/banana_fpc.d.ts.map +1 -1
- package/dest/local-network/banana_fpc.js +3 -3
- package/dest/local-network/local-network.d.ts +4 -3
- package/dest/local-network/local-network.d.ts.map +1 -1
- package/dest/local-network/local-network.js +52 -21
- package/dest/testing/anvil_test_watcher.d.ts +9 -1
- package/dest/testing/anvil_test_watcher.d.ts.map +1 -1
- package/dest/testing/anvil_test_watcher.js +52 -15
- package/dest/testing/epoch_test_settler.d.ts +4 -2
- package/dest/testing/epoch_test_settler.d.ts.map +1 -1
- package/dest/testing/epoch_test_settler.js +18 -9
- package/dest/testing/index.d.ts +2 -1
- package/dest/testing/index.d.ts.map +1 -1
- package/dest/testing/index.js +1 -0
- package/dest/testing/token_allowed_setup.d.ts +7 -0
- package/dest/testing/token_allowed_setup.d.ts.map +1 -0
- package/dest/testing/token_allowed_setup.js +20 -0
- package/package.json +34 -34
- package/scripts/aztec.sh +7 -3
- package/src/bin/index.ts +7 -3
- package/src/cli/admin_api_key_store.ts +128 -0
- package/src/cli/aztec_start_action.ts +58 -11
- package/src/cli/aztec_start_options.ts +29 -8
- 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/standby.ts +132 -0
- package/src/cli/cmds/start_bot.ts +8 -5
- package/src/cli/cmds/start_node.ts +83 -33
- package/src/cli/cmds/start_p2p_bootstrap.ts +2 -2
- package/src/cli/cmds/start_prover_agent.ts +2 -2
- package/src/cli/cmds/start_prover_broker.ts +19 -15
- package/src/cli/cmds/utils/artifacts.ts +44 -0
- package/src/cli/cmds/utils/spawn.ts +16 -0
- package/src/cli/util.ts +55 -93
- package/src/examples/token.ts +10 -10
- package/src/local-network/banana_fpc.ts +11 -7
- package/src/local-network/local-network.ts +62 -23
- package/src/testing/anvil_test_watcher.ts +59 -15
- package/src/testing/epoch_test_settler.ts +19 -8
- package/src/testing/index.ts +1 -0
- package/src/testing/token_allowed_setup.ts +19 -0
- package/dest/cli/cmds/start_prover_node.d.ts +0 -7
- package/dest/cli/cmds/start_prover_node.d.ts.map +0 -1
- package/dest/cli/cmds/start_prover_node.js +0 -108
- package/dest/cli/release_version.d.ts +0 -2
- package/dest/cli/release_version.d.ts.map +0 -1
- package/dest/cli/release_version.js +0 -14
- package/scripts/compile.sh +0 -44
- package/scripts/extract_function.js +0 -47
- package/scripts/flamegraph.sh +0 -59
- package/src/cli/cmds/start_prover_node.ts +0 -124
- package/src/cli/release_version.ts +0 -21
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import { getActiveNetworkName } from '@aztec/foundation/config';
|
|
1
2
|
import {
|
|
2
3
|
type NamespacedApiHandlers,
|
|
3
4
|
createNamespacedSafeJsonRpcServer,
|
|
5
|
+
getApiKeyAuthMiddleware,
|
|
4
6
|
startHttpRpcServer,
|
|
5
7
|
} from '@aztec/foundation/json-rpc/server';
|
|
6
8
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
7
9
|
import type { ChainConfig } from '@aztec/stdlib/config';
|
|
8
10
|
import { AztecNodeApiSchema } from '@aztec/stdlib/interfaces/client';
|
|
11
|
+
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
9
12
|
import { getVersioningMiddleware } from '@aztec/stdlib/versioning';
|
|
10
13
|
import { getOtelJsonRpcPropagationMiddleware } from '@aztec/telemetry-client';
|
|
11
14
|
|
|
12
15
|
import { createLocalNetwork } from '../local-network/index.js';
|
|
13
16
|
import { github, splash } from '../splash.js';
|
|
14
|
-
import {
|
|
17
|
+
import { resolveAdminApiKey } from './admin_api_key_store.js';
|
|
15
18
|
import { extractNamespacedOptions, installSignalHandlers } from './util.js';
|
|
16
19
|
import { getVersions } from './versioning.js';
|
|
17
20
|
|
|
@@ -20,14 +23,14 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
|
|
|
20
23
|
const signalHandlers: Array<() => Promise<void>> = [];
|
|
21
24
|
const services: NamespacedApiHandlers = {};
|
|
22
25
|
const adminServices: NamespacedApiHandlers = {};
|
|
26
|
+
const packageVersion = getPackageVersion();
|
|
23
27
|
let config: ChainConfig | undefined = undefined;
|
|
24
28
|
|
|
25
29
|
if (options.localNetwork) {
|
|
26
|
-
const cliVersion = getCliVersion();
|
|
27
30
|
const localNetwork = extractNamespacedOptions(options, 'local-network');
|
|
28
31
|
localNetwork.testAccounts = true;
|
|
29
32
|
userLog(`${splash}\n${github}\n\n`);
|
|
30
|
-
userLog(`Setting up Aztec local network ${
|
|
33
|
+
userLog(`Setting up Aztec local network ${packageVersion ?? 'unknown'}, please stand by...`);
|
|
31
34
|
|
|
32
35
|
const { node, stop } = await createLocalNetwork(
|
|
33
36
|
{
|
|
@@ -35,11 +38,11 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
|
|
|
35
38
|
l1RpcUrls: options.l1RpcUrls,
|
|
36
39
|
testAccounts: localNetwork.testAccounts,
|
|
37
40
|
realProofs: false,
|
|
38
|
-
// Setting the epoch duration to
|
|
41
|
+
// Setting the epoch duration to 2 by default for local network. This allows the epoch to be "proven" faster, so
|
|
39
42
|
// the users can consume out hash without having to wait for a long time.
|
|
40
43
|
// Note: We are not proving anything in the local network (realProofs == false). But in `createLocalNetwork`,
|
|
41
44
|
// the EpochTestSettler will set the out hash to the outbox when an epoch is complete.
|
|
42
|
-
aztecEpochDuration:
|
|
45
|
+
aztecEpochDuration: 2,
|
|
43
46
|
},
|
|
44
47
|
userLog,
|
|
45
48
|
);
|
|
@@ -48,15 +51,18 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
|
|
|
48
51
|
signalHandlers.push(stop);
|
|
49
52
|
services.node = [node, AztecNodeApiSchema];
|
|
50
53
|
} else {
|
|
54
|
+
// Route --prover-node through startNode
|
|
55
|
+
if (options.proverNode && !options.node) {
|
|
56
|
+
options.node = true;
|
|
57
|
+
}
|
|
58
|
+
|
|
51
59
|
if (options.node) {
|
|
52
60
|
const { startNode } = await import('./cmds/start_node.js');
|
|
53
|
-
|
|
61
|
+
const networkName = getActiveNetworkName(options.network);
|
|
62
|
+
({ config } = await startNode(options, signalHandlers, services, adminServices, userLog, networkName));
|
|
54
63
|
} else if (options.bot) {
|
|
55
64
|
const { startBot } = await import('./cmds/start_bot.js');
|
|
56
65
|
await startBot(options, signalHandlers, services, userLog);
|
|
57
|
-
} else if (options.proverNode) {
|
|
58
|
-
const { startProverNode } = await import('./cmds/start_prover_node.js');
|
|
59
|
-
({ config } = await startProverNode(options, signalHandlers, services, userLog));
|
|
60
66
|
} else if (options.archiver) {
|
|
61
67
|
const { startArchiver } = await import('./cmds/start_archiver.js');
|
|
62
68
|
({ config } = await startArchiver(options, signalHandlers, services));
|
|
@@ -83,13 +89,14 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
|
|
|
83
89
|
|
|
84
90
|
installSignalHandlers(debugLogger.info, signalHandlers);
|
|
85
91
|
const versions = getVersions(config);
|
|
92
|
+
const versioningOpts = { packageVersion };
|
|
86
93
|
|
|
87
94
|
// Start the main JSON-RPC server
|
|
88
95
|
if (Object.entries(services).length > 0) {
|
|
89
96
|
const rpcServer = createNamespacedSafeJsonRpcServer(services, {
|
|
90
97
|
http200OnError: false,
|
|
91
98
|
log: debugLogger,
|
|
92
|
-
middlewares: [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions)],
|
|
99
|
+
middlewares: [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions, versioningOpts)],
|
|
93
100
|
maxBatchSize: options.rpcMaxBatchSize,
|
|
94
101
|
maxBodySizeBytes: options.rpcMaxBodySize,
|
|
95
102
|
});
|
|
@@ -99,14 +106,54 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
|
|
|
99
106
|
|
|
100
107
|
// If there are any admin services, start a separate JSON-RPC server for them
|
|
101
108
|
if (Object.entries(adminServices).length > 0) {
|
|
109
|
+
const adminMiddlewares = [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions, versioningOpts)];
|
|
110
|
+
|
|
111
|
+
// Resolve the admin API key (auto-generated and persisted, or opt-out)
|
|
112
|
+
const apiKeyResolution = await resolveAdminApiKey(
|
|
113
|
+
{
|
|
114
|
+
adminApiKeyHash: options.adminApiKeyHash,
|
|
115
|
+
disableAdminApiKey: options.disableAdminApiKey,
|
|
116
|
+
resetAdminApiKey: options.resetAdminApiKey,
|
|
117
|
+
dataDirectory: options.dataDirectory,
|
|
118
|
+
},
|
|
119
|
+
debugLogger,
|
|
120
|
+
);
|
|
121
|
+
if (apiKeyResolution) {
|
|
122
|
+
adminMiddlewares.unshift(getApiKeyAuthMiddleware(apiKeyResolution.apiKeyHash));
|
|
123
|
+
} else {
|
|
124
|
+
debugLogger.warn('No admin API key set — admin endpoint is unauthenticated');
|
|
125
|
+
}
|
|
126
|
+
|
|
102
127
|
const rpcServer = createNamespacedSafeJsonRpcServer(adminServices, {
|
|
103
128
|
http200OnError: false,
|
|
104
129
|
log: debugLogger,
|
|
105
|
-
middlewares:
|
|
130
|
+
middlewares: adminMiddlewares,
|
|
106
131
|
maxBatchSize: options.rpcMaxBatchSize,
|
|
107
132
|
maxBodySizeBytes: options.rpcMaxBodySize,
|
|
108
133
|
});
|
|
109
134
|
const { port } = await startHttpRpcServer(rpcServer, { port: options.adminPort });
|
|
110
135
|
debugLogger.info(`Aztec Server admin API listening on port ${port}`, versions);
|
|
136
|
+
|
|
137
|
+
// Display the API key after the server has started
|
|
138
|
+
// Uses userLog which is never filtered by LOG_LEVEL.
|
|
139
|
+
if (apiKeyResolution?.rawKey) {
|
|
140
|
+
const separator = '='.repeat(70);
|
|
141
|
+
userLog('');
|
|
142
|
+
userLog(separator);
|
|
143
|
+
userLog(' ADMIN API KEY (save this — it will NOT be shown again)');
|
|
144
|
+
userLog('');
|
|
145
|
+
userLog(` ${apiKeyResolution.rawKey}`);
|
|
146
|
+
userLog('');
|
|
147
|
+
userLog(` Use via header: x-api-key: <key>`);
|
|
148
|
+
userLog(` Or via header: Authorization: Bearer <key>`);
|
|
149
|
+
if (options.dataDirectory) {
|
|
150
|
+
userLog('');
|
|
151
|
+
userLog(' The key hash has been persisted — on next restart, the same key will be used.');
|
|
152
|
+
}
|
|
153
|
+
userLog('');
|
|
154
|
+
userLog(' To disable admin auth: --disable-admin-api-key or AZTEC_DISABLE_ADMIN_API_KEY=true');
|
|
155
|
+
userLog(separator);
|
|
156
|
+
userLog('');
|
|
157
|
+
}
|
|
111
158
|
}
|
|
112
159
|
}
|
|
@@ -19,7 +19,7 @@ import { proverAgentConfigMappings, proverBrokerConfigMappings } from '@aztec/pr
|
|
|
19
19
|
import { proverNodeConfigMappings } from '@aztec/prover-node/config';
|
|
20
20
|
import { allPxeConfigMappings } from '@aztec/pxe/config';
|
|
21
21
|
import { sequencerClientConfigMappings } from '@aztec/sequencer-client/config';
|
|
22
|
-
import { chainConfigMappings } from '@aztec/stdlib/config';
|
|
22
|
+
import { chainConfigMappings, nodeRpcConfigMappings } from '@aztec/stdlib/config';
|
|
23
23
|
import { telemetryClientConfigMappings } from '@aztec/telemetry-client/config';
|
|
24
24
|
import { worldStateConfigMappings } from '@aztec/world-state/config';
|
|
25
25
|
|
|
@@ -105,8 +105,7 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
|
|
|
105
105
|
env: 'NETWORK',
|
|
106
106
|
},
|
|
107
107
|
|
|
108
|
-
configToFlag('--
|
|
109
|
-
configToFlag('--auto-update-url', sharedNodeConfigMappings.autoUpdateUrl),
|
|
108
|
+
configToFlag('--enable-version-check', sharedNodeConfigMappings.enableVersionCheck),
|
|
110
109
|
|
|
111
110
|
configToFlag('--sync-mode', sharedNodeConfigMappings.syncMode),
|
|
112
111
|
configToFlag('--snapshots-urls', sharedNodeConfigMappings.snapshotsUrls),
|
|
@@ -142,12 +141,38 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
|
|
|
142
141
|
env: 'AZTEC_ADMIN_PORT',
|
|
143
142
|
parseVal: val => parseInt(val, 10),
|
|
144
143
|
},
|
|
144
|
+
{
|
|
145
|
+
flag: '--admin-api-key-hash <value>',
|
|
146
|
+
description:
|
|
147
|
+
'SHA-256 hex hash of a pre-generated admin API key. When set, the node uses this hash for authentication instead of auto-generating a key.',
|
|
148
|
+
defaultValue: undefined,
|
|
149
|
+
env: 'AZTEC_ADMIN_API_KEY_HASH',
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
flag: '--disable-admin-api-key',
|
|
153
|
+
description:
|
|
154
|
+
'Disable API key authentication on the admin RPC endpoint. By default, a key is auto-generated, displayed once, and its hash is persisted.',
|
|
155
|
+
defaultValue: false,
|
|
156
|
+
env: 'AZTEC_DISABLE_ADMIN_API_KEY',
|
|
157
|
+
// undefined means the flag was passed without a value (boolean toggle), treat as true.
|
|
158
|
+
parseVal: val => val === undefined || val === 'true' || val === '1',
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
flag: '--reset-admin-api-key',
|
|
162
|
+
description:
|
|
163
|
+
'Force-generate a new admin API key, replacing any previously persisted key hash. The new key is displayed once at startup.',
|
|
164
|
+
defaultValue: false,
|
|
165
|
+
env: 'AZTEC_RESET_ADMIN_API_KEY',
|
|
166
|
+
parseVal: val => val === 'true' || val === '1',
|
|
167
|
+
},
|
|
145
168
|
{
|
|
146
169
|
flag: '--api-prefix <value>',
|
|
147
170
|
description: 'Prefix for API routes on any service that is started',
|
|
148
171
|
defaultValue: '',
|
|
149
172
|
env: 'API_PREFIX',
|
|
150
173
|
},
|
|
174
|
+
configToFlag('--rpcMaxBatchSize', nodeRpcConfigMappings.rpcMaxBatchSize),
|
|
175
|
+
configToFlag('--rpcMaxBodySize', nodeRpcConfigMappings.rpcMaxBodySize),
|
|
151
176
|
],
|
|
152
177
|
ETHEREUM: [
|
|
153
178
|
configToFlag('--l1-chain-id', l1ReaderConfigMappings.l1ChainId),
|
|
@@ -168,7 +193,7 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
|
|
|
168
193
|
'WORLD STATE': [
|
|
169
194
|
configToFlag('--world-state-data-directory', worldStateConfigMappings.worldStateDataDirectory),
|
|
170
195
|
configToFlag('--world-state-db-map-size-kb', worldStateConfigMappings.worldStateDbMapSizeKb),
|
|
171
|
-
configToFlag('--world-state-
|
|
196
|
+
configToFlag('--world-state-checkpoint-history', worldStateConfigMappings.worldStateCheckpointHistory),
|
|
172
197
|
],
|
|
173
198
|
// We can't easily auto-generate node options as they're parts of modules defined below
|
|
174
199
|
'AZTEC NODE': [
|
|
@@ -220,12 +245,8 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
|
|
|
220
245
|
'proverNode',
|
|
221
246
|
omitConfigMappings(proverNodeConfigMappings, [
|
|
222
247
|
// filter out options passed separately
|
|
223
|
-
...getKeys(archiverConfigMappings),
|
|
224
248
|
...getKeys(proverBrokerConfigMappings),
|
|
225
249
|
...getKeys(proverAgentConfigMappings),
|
|
226
|
-
...getKeys(p2pConfigMappings),
|
|
227
|
-
...getKeys(worldStateConfigMappings),
|
|
228
|
-
...getKeys(sharedNodeConfigMappings),
|
|
229
250
|
]),
|
|
230
251
|
),
|
|
231
252
|
],
|
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,132 @@
|
|
|
1
|
+
import { getInitialTestAccountsData } from '@aztec/accounts/testing';
|
|
2
|
+
import type { Fr } from '@aztec/aztec.js/fields';
|
|
3
|
+
import { getSponsoredFPCAddress } from '@aztec/cli/cli-utils';
|
|
4
|
+
import { getPublicClient } from '@aztec/ethereum/client';
|
|
5
|
+
import type { GenesisStateConfig } from '@aztec/ethereum/config';
|
|
6
|
+
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
7
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
8
|
+
import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server';
|
|
9
|
+
import type { LogFn } from '@aztec/foundation/log';
|
|
10
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
11
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
|
+
import { getGenesisValues } from '@aztec/world-state/testing';
|
|
13
|
+
|
|
14
|
+
import Koa from 'koa';
|
|
15
|
+
|
|
16
|
+
const ROLLUP_POLL_INTERVAL_S = 60;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Computes the expected genesis archive root from the genesis state config.
|
|
20
|
+
* Reads test accounts and sponsored FPC addresses as specified, then computes
|
|
21
|
+
* the genesis values including the archive root and prefilled public data.
|
|
22
|
+
*/
|
|
23
|
+
export async function computeExpectedGenesisRoot(config: GenesisStateConfig, userLog: LogFn) {
|
|
24
|
+
const testAccounts = config.testAccounts ? (await getInitialTestAccountsData()).map(a => a.address) : [];
|
|
25
|
+
const sponsoredFPCAccounts = config.sponsoredFPC ? [await getSponsoredFPCAddress()] : [];
|
|
26
|
+
const prefundAddresses = (config.prefundAddresses ?? []).map(a => AztecAddress.fromString(a));
|
|
27
|
+
const initialFundedAccounts = testAccounts.concat(sponsoredFPCAccounts).concat(prefundAddresses);
|
|
28
|
+
|
|
29
|
+
userLog(`Initial funded accounts: ${initialFundedAccounts.map(a => a.toString()).join(', ')}`);
|
|
30
|
+
|
|
31
|
+
const { genesisArchiveRoot, prefilledPublicData } = await getGenesisValues(initialFundedAccounts);
|
|
32
|
+
|
|
33
|
+
userLog(`Genesis archive root: ${genesisArchiveRoot.toString()}`);
|
|
34
|
+
|
|
35
|
+
return { genesisArchiveRoot, prefilledPublicData };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function checkRollupCompatibility(
|
|
39
|
+
rollup: RollupContract,
|
|
40
|
+
expected: { genesisArchiveRoot: Fr; vkTreeRoot: Fr; protocolContractsHash: Fr },
|
|
41
|
+
): Promise<string[]> {
|
|
42
|
+
const mismatches: string[] = [];
|
|
43
|
+
const [l1Genesis, l1Vk, l1Protocol] = await Promise.all([
|
|
44
|
+
rollup.getGenesisArchiveTreeRoot(),
|
|
45
|
+
rollup.getVkTreeRoot(),
|
|
46
|
+
rollup.getProtocolContractsHash(),
|
|
47
|
+
]);
|
|
48
|
+
if (!l1Genesis.equals(expected.genesisArchiveRoot)) {
|
|
49
|
+
mismatches.push(`genesis archive root (expected ${expected.genesisArchiveRoot}, got ${l1Genesis})`);
|
|
50
|
+
}
|
|
51
|
+
if (!l1Vk.equals(expected.vkTreeRoot)) {
|
|
52
|
+
mismatches.push(`VK tree root (expected ${expected.vkTreeRoot}, got ${l1Vk})`);
|
|
53
|
+
}
|
|
54
|
+
if (!l1Protocol.equals(expected.protocolContractsHash)) {
|
|
55
|
+
mismatches.push(`protocol contracts hash (expected ${expected.protocolContractsHash}, got ${l1Protocol})`);
|
|
56
|
+
}
|
|
57
|
+
return mismatches;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Waits until the canonical rollup's genesis archive root, VK tree root, and protocol contracts hash
|
|
62
|
+
* all match the expected local values. If the rollup is not yet compatible (e.g. during L1 contract upgrades),
|
|
63
|
+
* enters standby mode: starts a lightweight HTTP server for K8s liveness probes and polls every 60s
|
|
64
|
+
* until a compatible rollup appears.
|
|
65
|
+
*/
|
|
66
|
+
export async function waitForCompatibleRollup(
|
|
67
|
+
config: {
|
|
68
|
+
l1RpcUrls: string[];
|
|
69
|
+
l1ChainId: number;
|
|
70
|
+
l1Contracts: { registryAddress: EthAddress };
|
|
71
|
+
rollupVersion?: number;
|
|
72
|
+
},
|
|
73
|
+
expected: { genesisArchiveRoot: Fr; vkTreeRoot: Fr; protocolContractsHash: Fr },
|
|
74
|
+
port: number | undefined,
|
|
75
|
+
userLog: LogFn,
|
|
76
|
+
): Promise<void> {
|
|
77
|
+
const publicClient = getPublicClient(config);
|
|
78
|
+
const rollupVersion: number | 'canonical' = config.rollupVersion ?? 'canonical';
|
|
79
|
+
|
|
80
|
+
const registry = new RegistryContract(publicClient, config.l1Contracts.registryAddress);
|
|
81
|
+
const rollupAddress = await registry.getRollupAddress(rollupVersion);
|
|
82
|
+
const rollup = new RollupContract(publicClient, rollupAddress.toString());
|
|
83
|
+
|
|
84
|
+
let mismatches: string[];
|
|
85
|
+
try {
|
|
86
|
+
mismatches = await checkRollupCompatibility(rollup, expected);
|
|
87
|
+
} catch (err: any) {
|
|
88
|
+
throw new Error(`Could not retrieve rollup config from canonical rollup at ${rollupAddress}: ${err.message}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (mismatches.length === 0) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
userLog(
|
|
96
|
+
`Rollup at ${rollupAddress} is incompatible: ${mismatches.join('; ')}. ` +
|
|
97
|
+
`Entering standby mode. Will poll every ${ROLLUP_POLL_INTERVAL_S}s for a compatible rollup...`,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const standbyServer = await startHttpRpcServer({ getApp: () => new Koa(), isHealthy: () => true }, { port });
|
|
101
|
+
userLog(`Standby status server listening on port ${standbyServer.port}`);
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
await retryUntil(
|
|
105
|
+
async () => {
|
|
106
|
+
const currentRollupAddress = await registry.getRollupAddress(rollupVersion);
|
|
107
|
+
const currentRollup = new RollupContract(publicClient, currentRollupAddress.toString());
|
|
108
|
+
|
|
109
|
+
let currentMismatches: string[];
|
|
110
|
+
try {
|
|
111
|
+
currentMismatches = await checkRollupCompatibility(currentRollup, expected);
|
|
112
|
+
} catch {
|
|
113
|
+
userLog(`Failed to fetch rollup config from rollup at ${currentRollupAddress}. Retrying...`);
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (currentMismatches.length === 0) {
|
|
118
|
+
userLog(`Compatible rollup found at ${currentRollupAddress}. Exiting standby mode.`);
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
userLog(`Still waiting. Rollup at ${currentRollupAddress}: ${currentMismatches.join('; ')}.`);
|
|
123
|
+
return undefined;
|
|
124
|
+
},
|
|
125
|
+
'compatible rollup',
|
|
126
|
+
0,
|
|
127
|
+
ROLLUP_POLL_INTERVAL_S,
|
|
128
|
+
);
|
|
129
|
+
} finally {
|
|
130
|
+
await new Promise<void>((resolve, reject) => standbyServer.close(err => (err ? reject(err) : resolve())));
|
|
131
|
+
}
|
|
132
|
+
}
|