@aztec/aztec 0.0.1-commit.03f7ef2 → 0.0.1-commit.0658669b3
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 -1
- 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 +50 -9
- 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 +27 -8
- package/dest/cli/cli.d.ts +1 -1
- package/dest/cli/cli.d.ts.map +1 -1
- package/dest/cli/cli.js +4 -37
- 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/migrate_ha_db.d.ts +3 -0
- package/dest/cli/cmds/migrate_ha_db.d.ts.map +1 -0
- package/dest/cli/cmds/migrate_ha_db.js +27 -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/start_archiver.d.ts +1 -1
- package/dest/cli/cmds/start_archiver.d.ts.map +1 -1
- package/dest/cli/cmds/start_archiver.js +5 -7
- 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 +1 -1
- package/dest/cli/cmds/start_node.d.ts.map +1 -1
- package/dest/cli/cmds/start_node.js +62 -10
- 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.d.ts +1 -1
- package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
- package/dest/cli/cmds/start_prover_agent.js +3 -3
- 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 +2 -2
- 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 +5 -14
- package/dest/cli/util.d.ts.map +1 -1
- package/dest/cli/util.js +11 -6
- package/dest/examples/token.js +5 -5
- 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 +2 -2
- 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 +51 -20
- 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/cheat_codes.d.ts +3 -1
- package/dest/testing/cheat_codes.d.ts.map +1 -1
- package/dest/testing/epoch_test_settler.d.ts +19 -0
- package/dest/testing/epoch_test_settler.d.ts.map +1 -0
- package/dest/testing/epoch_test_settler.js +62 -0
- 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/package.json +35 -34
- package/scripts/aztec.sh +18 -8
- package/scripts/init.sh +23 -13
- package/scripts/new.sh +17 -16
- package/scripts/setup_workspace.sh +124 -0
- package/src/bin/index.ts +7 -1
- package/src/cli/admin_api_key_store.ts +128 -0
- package/src/cli/aztec_start_action.ts +53 -4
- package/src/cli/aztec_start_options.ts +28 -6
- package/src/cli/cli.ts +4 -37
- package/src/cli/cmds/compile.ts +80 -0
- package/src/cli/cmds/migrate_ha_db.ts +43 -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/start_archiver.ts +2 -13
- package/src/cli/cmds/start_bot.ts +8 -5
- package/src/cli/cmds/start_node.ts +51 -9
- package/src/cli/cmds/start_p2p_bootstrap.ts +2 -2
- package/src/cli/cmds/start_prover_agent.ts +3 -11
- package/src/cli/cmds/start_prover_broker.ts +5 -1
- package/src/cli/cmds/utils/artifacts.ts +44 -0
- package/src/cli/cmds/utils/spawn.ts +16 -0
- package/src/cli/util.ts +15 -20
- package/src/examples/token.ts +5 -7
- package/src/local-network/banana_fpc.ts +10 -6
- package/src/local-network/local-network.ts +72 -27
- package/src/testing/anvil_test_watcher.ts +59 -15
- package/src/testing/epoch_test_settler.ts +71 -0
- package/src/testing/index.ts +1 -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/scripts/compile.sh +0 -44
- package/scripts/extract_function.js +0 -47
- package/scripts/flamegraph.sh +0 -59
- package/scripts/setup_project.sh +0 -31
- package/src/cli/cmds/start_prover_node.ts +0 -124
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type NamespacedApiHandlers,
|
|
3
3
|
createNamespacedSafeJsonRpcServer,
|
|
4
|
+
getApiKeyAuthMiddleware,
|
|
4
5
|
startHttpRpcServer,
|
|
5
6
|
} from '@aztec/foundation/json-rpc/server';
|
|
6
7
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
@@ -11,6 +12,7 @@ import { getOtelJsonRpcPropagationMiddleware } from '@aztec/telemetry-client';
|
|
|
11
12
|
|
|
12
13
|
import { createLocalNetwork } from '../local-network/index.js';
|
|
13
14
|
import { github, splash } from '../splash.js';
|
|
15
|
+
import { resolveAdminApiKey } from './admin_api_key_store.js';
|
|
14
16
|
import { getCliVersion } from './release_version.js';
|
|
15
17
|
import { extractNamespacedOptions, installSignalHandlers } from './util.js';
|
|
16
18
|
import { getVersions } from './versioning.js';
|
|
@@ -35,6 +37,11 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
|
|
|
35
37
|
l1RpcUrls: options.l1RpcUrls,
|
|
36
38
|
testAccounts: localNetwork.testAccounts,
|
|
37
39
|
realProofs: false,
|
|
40
|
+
// Setting the epoch duration to 2 by default for local network. This allows the epoch to be "proven" faster, so
|
|
41
|
+
// the users can consume out hash without having to wait for a long time.
|
|
42
|
+
// Note: We are not proving anything in the local network (realProofs == false). But in `createLocalNetwork`,
|
|
43
|
+
// the EpochTestSettler will set the out hash to the outbox when an epoch is complete.
|
|
44
|
+
aztecEpochDuration: 2,
|
|
38
45
|
},
|
|
39
46
|
userLog,
|
|
40
47
|
);
|
|
@@ -43,15 +50,17 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
|
|
|
43
50
|
signalHandlers.push(stop);
|
|
44
51
|
services.node = [node, AztecNodeApiSchema];
|
|
45
52
|
} else {
|
|
53
|
+
// Route --prover-node through startNode
|
|
54
|
+
if (options.proverNode && !options.node) {
|
|
55
|
+
options.node = true;
|
|
56
|
+
}
|
|
57
|
+
|
|
46
58
|
if (options.node) {
|
|
47
59
|
const { startNode } = await import('./cmds/start_node.js');
|
|
48
60
|
({ config } = await startNode(options, signalHandlers, services, adminServices, userLog));
|
|
49
61
|
} else if (options.bot) {
|
|
50
62
|
const { startBot } = await import('./cmds/start_bot.js');
|
|
51
63
|
await startBot(options, signalHandlers, services, userLog);
|
|
52
|
-
} else if (options.proverNode) {
|
|
53
|
-
const { startProverNode } = await import('./cmds/start_prover_node.js');
|
|
54
|
-
({ config } = await startProverNode(options, signalHandlers, services, userLog));
|
|
55
64
|
} else if (options.archiver) {
|
|
56
65
|
const { startArchiver } = await import('./cmds/start_archiver.js');
|
|
57
66
|
({ config } = await startArchiver(options, signalHandlers, services));
|
|
@@ -94,14 +103,54 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
|
|
|
94
103
|
|
|
95
104
|
// If there are any admin services, start a separate JSON-RPC server for them
|
|
96
105
|
if (Object.entries(adminServices).length > 0) {
|
|
106
|
+
const adminMiddlewares = [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions)];
|
|
107
|
+
|
|
108
|
+
// Resolve the admin API key (auto-generated and persisted, or opt-out)
|
|
109
|
+
const apiKeyResolution = await resolveAdminApiKey(
|
|
110
|
+
{
|
|
111
|
+
adminApiKeyHash: options.adminApiKeyHash,
|
|
112
|
+
disableAdminApiKey: options.disableAdminApiKey,
|
|
113
|
+
resetAdminApiKey: options.resetAdminApiKey,
|
|
114
|
+
dataDirectory: options.dataDirectory,
|
|
115
|
+
},
|
|
116
|
+
debugLogger,
|
|
117
|
+
);
|
|
118
|
+
if (apiKeyResolution) {
|
|
119
|
+
adminMiddlewares.unshift(getApiKeyAuthMiddleware(apiKeyResolution.apiKeyHash));
|
|
120
|
+
} else {
|
|
121
|
+
debugLogger.warn('No admin API key set — admin endpoint is unauthenticated');
|
|
122
|
+
}
|
|
123
|
+
|
|
97
124
|
const rpcServer = createNamespacedSafeJsonRpcServer(adminServices, {
|
|
98
125
|
http200OnError: false,
|
|
99
126
|
log: debugLogger,
|
|
100
|
-
middlewares:
|
|
127
|
+
middlewares: adminMiddlewares,
|
|
101
128
|
maxBatchSize: options.rpcMaxBatchSize,
|
|
102
129
|
maxBodySizeBytes: options.rpcMaxBodySize,
|
|
103
130
|
});
|
|
104
131
|
const { port } = await startHttpRpcServer(rpcServer, { port: options.adminPort });
|
|
105
132
|
debugLogger.info(`Aztec Server admin API listening on port ${port}`, versions);
|
|
133
|
+
|
|
134
|
+
// Display the API key after the server has started
|
|
135
|
+
// Uses userLog which is never filtered by LOG_LEVEL.
|
|
136
|
+
if (apiKeyResolution?.rawKey) {
|
|
137
|
+
const separator = '='.repeat(70);
|
|
138
|
+
userLog('');
|
|
139
|
+
userLog(separator);
|
|
140
|
+
userLog(' ADMIN API KEY (save this — it will NOT be shown again)');
|
|
141
|
+
userLog('');
|
|
142
|
+
userLog(` ${apiKeyResolution.rawKey}`);
|
|
143
|
+
userLog('');
|
|
144
|
+
userLog(` Use via header: x-api-key: <key>`);
|
|
145
|
+
userLog(` Or via header: Authorization: Bearer <key>`);
|
|
146
|
+
if (options.dataDirectory) {
|
|
147
|
+
userLog('');
|
|
148
|
+
userLog(' The key hash has been persisted — on next restart, the same key will be used.');
|
|
149
|
+
}
|
|
150
|
+
userLog('');
|
|
151
|
+
userLog(' To disable admin auth: --disable-admin-api-key or AZTEC_DISABLE_ADMIN_API_KEY=true');
|
|
152
|
+
userLog(separator);
|
|
153
|
+
userLog('');
|
|
154
|
+
}
|
|
106
155
|
}
|
|
107
156
|
}
|
|
@@ -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
|
|
|
@@ -142,12 +142,38 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
|
|
|
142
142
|
env: 'AZTEC_ADMIN_PORT',
|
|
143
143
|
parseVal: val => parseInt(val, 10),
|
|
144
144
|
},
|
|
145
|
+
{
|
|
146
|
+
flag: '--admin-api-key-hash <value>',
|
|
147
|
+
description:
|
|
148
|
+
'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.',
|
|
149
|
+
defaultValue: undefined,
|
|
150
|
+
env: 'AZTEC_ADMIN_API_KEY_HASH',
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
flag: '--disable-admin-api-key',
|
|
154
|
+
description:
|
|
155
|
+
'Disable API key authentication on the admin RPC endpoint. By default, a key is auto-generated, displayed once, and its hash is persisted.',
|
|
156
|
+
defaultValue: false,
|
|
157
|
+
env: 'AZTEC_DISABLE_ADMIN_API_KEY',
|
|
158
|
+
// undefined means the flag was passed without a value (boolean toggle), treat as true.
|
|
159
|
+
parseVal: val => val === undefined || val === 'true' || val === '1',
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
flag: '--reset-admin-api-key',
|
|
163
|
+
description:
|
|
164
|
+
'Force-generate a new admin API key, replacing any previously persisted key hash. The new key is displayed once at startup.',
|
|
165
|
+
defaultValue: false,
|
|
166
|
+
env: 'AZTEC_RESET_ADMIN_API_KEY',
|
|
167
|
+
parseVal: val => val === 'true' || val === '1',
|
|
168
|
+
},
|
|
145
169
|
{
|
|
146
170
|
flag: '--api-prefix <value>',
|
|
147
171
|
description: 'Prefix for API routes on any service that is started',
|
|
148
172
|
defaultValue: '',
|
|
149
173
|
env: 'API_PREFIX',
|
|
150
174
|
},
|
|
175
|
+
configToFlag('--rpcMaxBatchSize', nodeRpcConfigMappings.rpcMaxBatchSize),
|
|
176
|
+
configToFlag('--rpcMaxBodySize', nodeRpcConfigMappings.rpcMaxBodySize),
|
|
151
177
|
],
|
|
152
178
|
ETHEREUM: [
|
|
153
179
|
configToFlag('--l1-chain-id', l1ReaderConfigMappings.l1ChainId),
|
|
@@ -168,7 +194,7 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
|
|
|
168
194
|
'WORLD STATE': [
|
|
169
195
|
configToFlag('--world-state-data-directory', worldStateConfigMappings.worldStateDataDirectory),
|
|
170
196
|
configToFlag('--world-state-db-map-size-kb', worldStateConfigMappings.worldStateDbMapSizeKb),
|
|
171
|
-
configToFlag('--world-state-
|
|
197
|
+
configToFlag('--world-state-checkpoint-history', worldStateConfigMappings.worldStateCheckpointHistory),
|
|
172
198
|
],
|
|
173
199
|
// We can't easily auto-generate node options as they're parts of modules defined below
|
|
174
200
|
'AZTEC NODE': [
|
|
@@ -220,12 +246,8 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
|
|
|
220
246
|
'proverNode',
|
|
221
247
|
omitConfigMappings(proverNodeConfigMappings, [
|
|
222
248
|
// filter out options passed separately
|
|
223
|
-
...getKeys(archiverConfigMappings),
|
|
224
249
|
...getKeys(proverBrokerConfigMappings),
|
|
225
250
|
...getKeys(proverAgentConfigMappings),
|
|
226
|
-
...getKeys(p2pConfigMappings),
|
|
227
|
-
...getKeys(worldStateConfigMappings),
|
|
228
|
-
...getKeys(sharedNodeConfigMappings),
|
|
229
251
|
]),
|
|
230
252
|
),
|
|
231
253
|
],
|
package/src/cli/cli.ts
CHANGED
|
@@ -35,44 +35,11 @@ export function injectAztecCommands(program: Command, userLog: LogFn, debugLogge
|
|
|
35
35
|
program.addHelpText(
|
|
36
36
|
'after',
|
|
37
37
|
`
|
|
38
|
+
Additional commands:
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
Options:
|
|
43
|
-
--name <name> Name of the package
|
|
44
|
-
--contract Use a contract template (default)
|
|
45
|
-
--lib Use a library template
|
|
46
|
-
--bin Use a binary template
|
|
47
|
-
Examples:
|
|
48
|
-
$ aztec init # creates a contract project in current directory
|
|
49
|
-
$ aztec init --lib # creates a library project
|
|
50
|
-
|
|
51
|
-
new <path> [options]: creates a new Noir project in a new directory
|
|
52
|
-
Options:
|
|
53
|
-
--name <name> Name of the package
|
|
54
|
-
--contract Use a contract template (default)
|
|
55
|
-
--lib Use a library template
|
|
56
|
-
--bin Use a binary template
|
|
57
|
-
Examples:
|
|
58
|
-
$ aztec new my-project # creates a contract project in ./my-project
|
|
59
|
-
$ aztec new my-lib --lib # creates a library project in ./my-lib
|
|
60
|
-
|
|
61
|
-
compile [options]: compiles Aztec Noir contracts
|
|
62
|
-
Compiles contracts with nargo compile and then postprocesses them to generate Aztec-specific artifacts including:
|
|
63
|
-
- Transpiled contract artifacts
|
|
64
|
-
- Verification keys
|
|
65
|
-
The compiled contracts will be placed in the target/ directory by default.
|
|
66
|
-
Supports standard nargo compile options.
|
|
67
|
-
|
|
68
|
-
test [options]: starts a dockerized TXE node via
|
|
69
|
-
$ aztec start --txe
|
|
70
|
-
then runs
|
|
71
|
-
$ aztec test --silence-warnings --oracle-resolver=<TXE_ADDRESS> [options]
|
|
72
|
-
|
|
73
|
-
preload-crs: Downloads and caches the Common Reference String (CRS) data required for zero-knowledge proofs.
|
|
74
|
-
Example:
|
|
75
|
-
$ aztec preload-crs # preloads CRS data
|
|
40
|
+
init [folder] [options] creates a new Aztec Noir project.
|
|
41
|
+
new <path> [options] creates a new Aztec Noir project in a new directory.
|
|
42
|
+
test [options] starts a TXE and runs "nargo test" using it as the oracle resolver.
|
|
76
43
|
`,
|
|
77
44
|
);
|
|
78
45
|
}
|
|
@@ -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,43 @@
|
|
|
1
|
+
import { runMigrations } from '@aztec/validator-ha-signer/migrations';
|
|
2
|
+
|
|
3
|
+
import type { Command } from 'commander';
|
|
4
|
+
|
|
5
|
+
export function injectMigrateCommand(program: Command, log: (msg: string) => void): Command {
|
|
6
|
+
const migrateCommand = program.command('migrate-ha-db').description('Run validator-ha-signer database migrations');
|
|
7
|
+
|
|
8
|
+
migrateCommand
|
|
9
|
+
.command('up')
|
|
10
|
+
.description('Apply pending migrations')
|
|
11
|
+
.requiredOption('--database-url <string>', 'PostgreSQL connection string', process.env.DATABASE_URL)
|
|
12
|
+
.option('--verbose', 'Enable verbose output', false)
|
|
13
|
+
.action(async options => {
|
|
14
|
+
const migrations = await runMigrations(options.databaseUrl, {
|
|
15
|
+
direction: 'up',
|
|
16
|
+
verbose: options.verbose,
|
|
17
|
+
});
|
|
18
|
+
if (migrations.length > 0) {
|
|
19
|
+
log(`Applied migrations: ${migrations.join(', ')}`);
|
|
20
|
+
} else {
|
|
21
|
+
log('No migrations to apply - schema is up to date');
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
migrateCommand
|
|
26
|
+
.command('down')
|
|
27
|
+
.description('Rollback the last migration')
|
|
28
|
+
.requiredOption('--database-url <string>', 'PostgreSQL connection string', process.env.DATABASE_URL)
|
|
29
|
+
.option('--verbose', 'Enable verbose output', false)
|
|
30
|
+
.action(async options => {
|
|
31
|
+
const migrations = await runMigrations(options.databaseUrl, {
|
|
32
|
+
direction: 'down',
|
|
33
|
+
verbose: options.verbose,
|
|
34
|
+
});
|
|
35
|
+
if (migrations.length > 0) {
|
|
36
|
+
log(`Rolled back migrations: ${migrations.join(', ')}`);
|
|
37
|
+
} else {
|
|
38
|
+
log('No migrations to rollback');
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return program;
|
|
43
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Archiver,
|
|
3
|
-
type ArchiverConfig,
|
|
4
|
-
KVArchiverDataStore,
|
|
5
|
-
archiverConfigMappings,
|
|
6
|
-
getArchiverConfigFromEnv,
|
|
7
|
-
} from '@aztec/archiver';
|
|
1
|
+
import { type ArchiverConfig, archiverConfigMappings, createArchiver, getArchiverConfigFromEnv } from '@aztec/archiver';
|
|
8
2
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
9
3
|
import { type BlobClientConfig, blobClientConfigMapping, createBlobClient } from '@aztec/blob-client/client';
|
|
10
4
|
import { getL1Config } from '@aztec/cli/config';
|
|
11
5
|
import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
|
|
12
6
|
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
|
|
13
|
-
import { createStore } from '@aztec/kv-store/lmdb-v2';
|
|
14
7
|
import { ArchiverApiSchema } from '@aztec/stdlib/interfaces/server';
|
|
15
8
|
import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client';
|
|
16
9
|
|
|
@@ -47,13 +40,9 @@ export async function startArchiver(
|
|
|
47
40
|
archiverConfig.l1Contracts = addresses;
|
|
48
41
|
archiverConfig = { ...archiverConfig, ...l1Config };
|
|
49
42
|
|
|
50
|
-
const storeLog = createLogger('archiver:lmdb');
|
|
51
|
-
const store = await createStore('archiver', KVArchiverDataStore.SCHEMA_VERSION, archiverConfig, storeLog);
|
|
52
|
-
const archiverStore = new KVArchiverDataStore(store, archiverConfig.maxLogs);
|
|
53
|
-
|
|
54
43
|
const telemetry = await initTelemetryClient(getTelemetryClientConfig());
|
|
55
44
|
const blobClient = createBlobClient(archiverConfig, { logger: createLogger('archiver:blob-client:client') });
|
|
56
|
-
const archiver = await
|
|
45
|
+
const archiver = await createArchiver(archiverConfig, { telemetry, blobClient }, { blockUntilSync: true });
|
|
57
46
|
services.archiver = [archiver, ArchiverApiSchema];
|
|
58
47
|
signalHandlers.push(archiver.stop);
|
|
59
48
|
|
|
@@ -10,9 +10,9 @@ import {
|
|
|
10
10
|
initTelemetryClient,
|
|
11
11
|
makeTracedFetch,
|
|
12
12
|
} from '@aztec/telemetry-client';
|
|
13
|
-
import {
|
|
13
|
+
import { EmbeddedWallet } from '@aztec/wallets/embedded';
|
|
14
14
|
|
|
15
|
-
import { extractRelevantOptions } from '../util.js';
|
|
15
|
+
import { extractRelevantOptions, stringifyConfig } from '../util.js';
|
|
16
16
|
import { getVersions } from '../versioning.js';
|
|
17
17
|
|
|
18
18
|
export async function startBot(
|
|
@@ -38,22 +38,25 @@ export async function startBot(
|
|
|
38
38
|
const aztecNode = createAztecNodeClient(config.nodeUrl, getVersions(), fetch);
|
|
39
39
|
|
|
40
40
|
const pxeConfig = extractRelevantOptions<PXEConfig & CliPXEOptions>(options, allPxeConfigMappings, 'pxe');
|
|
41
|
-
|
|
41
|
+
userLog(`Creating bot wallet with config ${stringifyConfig(pxeConfig)}`);
|
|
42
|
+
const wallet = await EmbeddedWallet.create(aztecNode, { pxeConfig });
|
|
42
43
|
|
|
43
44
|
const telemetry = await initTelemetryClient(getTelemetryClientConfig());
|
|
44
|
-
await addBot(options, signalHandlers, services, wallet, aztecNode, telemetry, undefined);
|
|
45
|
+
await addBot(options, signalHandlers, services, wallet, aztecNode, telemetry, undefined, userLog);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
export async function addBot(
|
|
48
49
|
options: any,
|
|
49
50
|
signalHandlers: (() => Promise<void>)[],
|
|
50
51
|
services: NamespacedApiHandlers,
|
|
51
|
-
wallet:
|
|
52
|
+
wallet: EmbeddedWallet,
|
|
52
53
|
aztecNode: AztecNode,
|
|
53
54
|
telemetry: TelemetryClient,
|
|
54
55
|
aztecNodeAdmin?: AztecNodeAdmin,
|
|
56
|
+
userLog?: LogFn,
|
|
55
57
|
) {
|
|
56
58
|
const config = extractRelevantOptions<BotConfig>(options, botConfigMappings, 'bot');
|
|
59
|
+
userLog?.(`Starting bot with config ${stringifyConfig(config)}`);
|
|
57
60
|
|
|
58
61
|
const db = await (config.dataDirectory
|
|
59
62
|
? createStore('bot', BotStore.SCHEMA_VERSION, config)
|