@aztec/bb-prover 0.0.0-test.0 → 0.0.1-commit.24de95ac
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/avm_proving_tests/avm_proving_tester.d.ts +14 -17
- package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
- package/dest/avm_proving_tests/avm_proving_tester.js +128 -78
- package/dest/bb/execute.d.ts +13 -46
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +120 -228
- package/dest/config.d.ts +2 -0
- package/dest/config.d.ts.map +1 -1
- package/dest/honk.d.ts +2 -2
- package/dest/honk.d.ts.map +1 -1
- package/dest/honk.js +3 -2
- package/dest/index.d.ts +1 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/instrumentation.d.ts +2 -2
- package/dest/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation.js +2 -4
- package/dest/prover/{bb_private_kernel_prover.d.ts → client/bb_private_kernel_prover.d.ts} +10 -10
- package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -0
- package/dest/prover/{bb_private_kernel_prover.js → client/bb_private_kernel_prover.js} +21 -18
- package/dest/prover/client/native/bb_native_private_kernel_prover.d.ts +23 -0
- package/dest/prover/client/native/bb_native_private_kernel_prover.d.ts.map +1 -0
- package/dest/prover/{bb_native_private_kernel_prover.js → client/native/bb_native_private_kernel_prover.js} +19 -22
- package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.d.ts +15 -0
- package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.d.ts.map +1 -0
- package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.js +46 -0
- package/dest/prover/client/wasm/bundle.d.ts +6 -0
- package/dest/prover/client/wasm/bundle.d.ts.map +1 -0
- package/dest/{wasm → prover/client/wasm}/bundle.js +2 -2
- package/dest/prover/client/wasm/lazy.d.ts +6 -0
- package/dest/prover/client/wasm/lazy.d.ts.map +1 -0
- package/dest/{wasm → prover/client/wasm}/lazy.js +2 -2
- package/dest/prover/index.d.ts +2 -3
- package/dest/prover/index.d.ts.map +1 -1
- package/dest/prover/index.js +2 -3
- package/dest/prover/proof_utils.d.ts +19 -0
- package/dest/prover/proof_utils.d.ts.map +1 -0
- package/dest/prover/proof_utils.js +72 -0
- package/dest/prover/server/bb_prover.d.ts +109 -0
- package/dest/prover/server/bb_prover.d.ts.map +1 -0
- package/dest/prover/server/bb_prover.js +339 -0
- package/dest/test/delay_values.d.ts.map +1 -1
- package/dest/test/delay_values.js +30 -18
- package/dest/test/test_circuit_prover.d.ts +24 -33
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +85 -59
- package/dest/test/test_verifier.d.ts +3 -2
- package/dest/test/test_verifier.d.ts.map +1 -1
- package/dest/test/test_verifier.js +8 -1
- package/dest/verification_key/verification_key_data.d.ts +6 -0
- package/dest/verification_key/verification_key_data.d.ts.map +1 -1
- package/dest/verification_key/verification_key_data.js +23 -29
- package/dest/verifier/bb_verifier.d.ts +5 -4
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +43 -25
- package/dest/verifier/index.d.ts +1 -0
- package/dest/verifier/index.d.ts.map +1 -1
- package/dest/verifier/index.js +1 -0
- package/dest/verifier/queued_chonk_verifier.d.ts +15 -0
- package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -0
- package/dest/verifier/queued_chonk_verifier.js +132 -0
- package/package.json +32 -31
- package/src/avm_proving_tests/avm_proving_tester.ts +209 -103
- package/src/bb/execute.ts +98 -242
- package/src/config.ts +2 -0
- package/src/honk.ts +3 -2
- package/src/index.ts +1 -0
- package/src/instrumentation.ts +2 -4
- package/src/prover/{bb_private_kernel_prover.ts → client/bb_private_kernel_prover.ts} +53 -29
- package/src/prover/{bb_native_private_kernel_prover.ts → client/native/bb_native_private_kernel_prover.ts} +23 -37
- package/src/{wasm → prover/client/wasm}/bb_wasm_private_kernel_prover.ts +18 -15
- package/src/{wasm → prover/client/wasm}/bundle.ts +3 -3
- package/src/{wasm → prover/client/wasm}/lazy.ts +3 -3
- package/src/prover/index.ts +2 -3
- package/src/prover/proof_utils.ts +115 -0
- package/src/prover/server/bb_prover.ts +733 -0
- package/src/test/delay_values.ts +30 -18
- package/src/test/test_circuit_prover.ts +260 -147
- package/src/test/test_verifier.ts +7 -3
- package/src/verification_key/verification_key_data.ts +29 -24
- package/src/verifier/bb_verifier.ts +60 -32
- package/src/verifier/index.ts +1 -0
- package/src/verifier/queued_chonk_verifier.ts +140 -0
- package/dest/prover/bb_native_private_kernel_prover.d.ts +0 -25
- package/dest/prover/bb_native_private_kernel_prover.d.ts.map +0 -1
- package/dest/prover/bb_private_kernel_prover.d.ts.map +0 -1
- package/dest/prover/bb_prover.d.ts +0 -120
- package/dest/prover/bb_prover.d.ts.map +0 -1
- package/dest/prover/bb_prover.js +0 -423
- package/dest/prover/client_ivc_proof_utils.d.ts +0 -25
- package/dest/prover/client_ivc_proof_utils.d.ts.map +0 -1
- package/dest/prover/client_ivc_proof_utils.js +0 -43
- package/dest/stats.d.ts +0 -5
- package/dest/stats.d.ts.map +0 -1
- package/dest/stats.js +0 -62
- package/dest/wasm/bb_wasm_private_kernel_prover.d.ts +0 -17
- package/dest/wasm/bb_wasm_private_kernel_prover.d.ts.map +0 -1
- package/dest/wasm/bb_wasm_private_kernel_prover.js +0 -46
- package/dest/wasm/bundle.d.ts +0 -6
- package/dest/wasm/bundle.d.ts.map +0 -1
- package/dest/wasm/lazy.d.ts +0 -6
- package/dest/wasm/lazy.d.ts.map +0 -1
- package/src/prover/bb_prover.ts +0 -781
- package/src/prover/client_ivc_proof_utils.ts +0 -42
- package/src/stats.ts +0 -64
package/src/bb/execute.ts
CHANGED
|
@@ -8,16 +8,13 @@ import { promises as fs } from 'fs';
|
|
|
8
8
|
import { basename, dirname, join } from 'path';
|
|
9
9
|
|
|
10
10
|
import type { UltraHonkFlavor } from '../honk.js';
|
|
11
|
-
import { CLIENT_IVC_PROOF_FILE_NAME, CLIENT_IVC_VK_FILE_NAME } from '../prover/client_ivc_proof_utils.js';
|
|
12
11
|
|
|
13
12
|
export const VK_FILENAME = 'vk';
|
|
14
|
-
export const
|
|
13
|
+
export const PUBLIC_INPUTS_FILENAME = 'public_inputs';
|
|
15
14
|
export const PROOF_FILENAME = 'proof';
|
|
16
|
-
export const PROOF_FIELDS_FILENAME = 'proof_fields.json';
|
|
17
15
|
export const AVM_INPUTS_FILENAME = 'avm_inputs.bin';
|
|
18
16
|
export const AVM_BYTECODE_FILENAME = 'avm_bytecode.bin';
|
|
19
17
|
export const AVM_PUBLIC_INPUTS_FILENAME = 'avm_public_inputs.bin';
|
|
20
|
-
export const AVM_HINTS_FILENAME = 'avm_hints.bin';
|
|
21
18
|
|
|
22
19
|
export enum BB_RESULT {
|
|
23
20
|
SUCCESS,
|
|
@@ -31,7 +28,7 @@ export type BBSuccess = {
|
|
|
31
28
|
/** Full path of the public key. */
|
|
32
29
|
pkPath?: string;
|
|
33
30
|
/** Base directory for the VKs (raw, fields). */
|
|
34
|
-
|
|
31
|
+
vkDirectoryPath?: string;
|
|
35
32
|
/** Full path of the proof. */
|
|
36
33
|
proofPath?: string;
|
|
37
34
|
/** Full path of the contract. */
|
|
@@ -48,8 +45,6 @@ export type BBFailure = {
|
|
|
48
45
|
|
|
49
46
|
export type BBResult = BBSuccess | BBFailure;
|
|
50
47
|
|
|
51
|
-
export type VerificationFunction = typeof verifyProof | typeof verifyAvmProof;
|
|
52
|
-
|
|
53
48
|
type BBExecResult = {
|
|
54
49
|
status: BB_RESULT;
|
|
55
50
|
exitCode: number;
|
|
@@ -62,6 +57,7 @@ type BBExecResult = {
|
|
|
62
57
|
* @param command - The command to execute
|
|
63
58
|
* @param args - The arguments to pass
|
|
64
59
|
* @param logger - A log function
|
|
60
|
+
* @param timeout - An optional timeout before killing the BB process
|
|
65
61
|
* @param resultParser - An optional handler for detecting success or failure
|
|
66
62
|
* @returns The completed partial witness outputted from the circuit
|
|
67
63
|
*/
|
|
@@ -70,16 +66,39 @@ export function executeBB(
|
|
|
70
66
|
command: string,
|
|
71
67
|
args: string[],
|
|
72
68
|
logger: LogFn,
|
|
69
|
+
concurrency?: number,
|
|
70
|
+
timeout?: number,
|
|
73
71
|
resultParser = (code: number) => code === 0,
|
|
74
72
|
): Promise<BBExecResult> {
|
|
75
73
|
return new Promise<BBExecResult>(resolve => {
|
|
76
74
|
// spawn the bb process
|
|
77
75
|
const { HARDWARE_CONCURRENCY: _, ...envWithoutConcurrency } = process.env;
|
|
78
|
-
|
|
76
|
+
|
|
77
|
+
const env = envWithoutConcurrency;
|
|
78
|
+
// We prioritise the concurrency argument if provided and > 0
|
|
79
|
+
if (concurrency && concurrency > 0) {
|
|
80
|
+
env.HARDWARE_CONCURRENCY = concurrency.toString();
|
|
81
|
+
} else if (process.env.HARDWARE_CONCURRENCY) {
|
|
82
|
+
env.HARDWARE_CONCURRENCY = process.env.HARDWARE_CONCURRENCY;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
logger(`BB concurrency: ${env.HARDWARE_CONCURRENCY}`);
|
|
79
86
|
logger(`Executing BB with: ${pathToBB} ${command} ${args.join(' ')}`);
|
|
80
87
|
const bb = proc.spawn(pathToBB, [command, ...args], {
|
|
81
88
|
env,
|
|
82
89
|
});
|
|
90
|
+
|
|
91
|
+
let timeoutId: NodeJS.Timeout | undefined;
|
|
92
|
+
if (timeout !== undefined) {
|
|
93
|
+
timeoutId = setTimeout(() => {
|
|
94
|
+
logger(`BB execution timed out after ${timeout}ms, killing process`);
|
|
95
|
+
if (bb.pid) {
|
|
96
|
+
bb.kill('SIGKILL');
|
|
97
|
+
}
|
|
98
|
+
resolve({ status: BB_RESULT.FAILURE, exitCode: -1, signal: 'TIMEOUT' });
|
|
99
|
+
}, timeout);
|
|
100
|
+
}
|
|
101
|
+
|
|
83
102
|
bb.stdout.on('data', data => {
|
|
84
103
|
const message = data.toString('utf-8').replace(/\n$/, '');
|
|
85
104
|
logger(message);
|
|
@@ -89,6 +108,9 @@ export function executeBB(
|
|
|
89
108
|
logger(message);
|
|
90
109
|
});
|
|
91
110
|
bb.on('close', (exitCode: number, signal?: string) => {
|
|
111
|
+
if (timeoutId) {
|
|
112
|
+
clearTimeout(timeoutId);
|
|
113
|
+
}
|
|
92
114
|
if (resultParser(exitCode)) {
|
|
93
115
|
resolve({ status: BB_RESULT.SUCCESS, exitCode, signal });
|
|
94
116
|
} else {
|
|
@@ -98,18 +120,17 @@ export function executeBB(
|
|
|
98
120
|
}).catch(_ => ({ status: BB_RESULT.FAILURE, exitCode: -1, signal: undefined }));
|
|
99
121
|
}
|
|
100
122
|
|
|
101
|
-
|
|
102
|
-
export async function executeBbClientIvcProof(
|
|
123
|
+
export async function executeBbChonkProof(
|
|
103
124
|
pathToBB: string,
|
|
104
125
|
workingDirectory: string,
|
|
105
|
-
|
|
106
|
-
witnessStackPath: string,
|
|
126
|
+
inputsPath: string,
|
|
107
127
|
log: LogFn,
|
|
128
|
+
writeVk = false,
|
|
108
129
|
): Promise<BBFailure | BBSuccess> {
|
|
109
130
|
// Check that the working directory exists
|
|
110
131
|
try {
|
|
111
132
|
await fs.access(workingDirectory);
|
|
112
|
-
} catch
|
|
133
|
+
} catch {
|
|
113
134
|
return { status: BB_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
|
|
114
135
|
}
|
|
115
136
|
|
|
@@ -126,28 +147,16 @@ export async function executeBbClientIvcProof(
|
|
|
126
147
|
|
|
127
148
|
try {
|
|
128
149
|
// Write the bytecode to the working directory
|
|
129
|
-
log(`
|
|
130
|
-
log(`outputPath ${outputPath}`);
|
|
131
|
-
const args = [
|
|
132
|
-
'-o',
|
|
133
|
-
outputPath,
|
|
134
|
-
'-b',
|
|
135
|
-
bytecodeStackPath,
|
|
136
|
-
'-w',
|
|
137
|
-
witnessStackPath,
|
|
138
|
-
'-v',
|
|
139
|
-
'--scheme',
|
|
140
|
-
'client_ivc',
|
|
141
|
-
'--input_type',
|
|
142
|
-
'runtime_stack',
|
|
143
|
-
'--write_vk',
|
|
144
|
-
];
|
|
145
|
-
|
|
150
|
+
log(`inputsPath ${inputsPath}`);
|
|
146
151
|
const timer = new Timer();
|
|
147
152
|
const logFunction = (message: string) => {
|
|
148
153
|
log(`bb - ${message}`);
|
|
149
154
|
};
|
|
150
155
|
|
|
156
|
+
const args = ['-o', outputPath, '--ivc_inputs_path', inputsPath, '-v', '--scheme', 'chonk'];
|
|
157
|
+
if (writeVk) {
|
|
158
|
+
args.push('--write_vk');
|
|
159
|
+
}
|
|
151
160
|
const result = await executeBB(pathToBB, 'prove', args, logFunction);
|
|
152
161
|
const durationMs = timer.ms();
|
|
153
162
|
|
|
@@ -157,7 +166,7 @@ export async function executeBbClientIvcProof(
|
|
|
157
166
|
durationMs,
|
|
158
167
|
proofPath: `${outputPath}`,
|
|
159
168
|
pkPath: undefined,
|
|
160
|
-
|
|
169
|
+
vkDirectoryPath: `${outputPath}`,
|
|
161
170
|
};
|
|
162
171
|
}
|
|
163
172
|
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
@@ -179,6 +188,9 @@ function getArgs(flavor: UltraHonkFlavor) {
|
|
|
179
188
|
case 'ultra_keccak_honk': {
|
|
180
189
|
return ['--scheme', 'ultra_honk', '--oracle_hash', 'keccak'];
|
|
181
190
|
}
|
|
191
|
+
case 'ultra_starknet_honk': {
|
|
192
|
+
return ['--scheme', 'ultra_honk', '--oracle_hash', 'starknet'];
|
|
193
|
+
}
|
|
182
194
|
case 'ultra_rollup_honk': {
|
|
183
195
|
return ['--scheme', 'ultra_honk', '--oracle_hash', 'poseidon2', '--ipa_accumulation'];
|
|
184
196
|
}
|
|
@@ -201,20 +213,21 @@ export async function generateProof(
|
|
|
201
213
|
workingDirectory: string,
|
|
202
214
|
circuitName: string,
|
|
203
215
|
bytecode: Buffer,
|
|
204
|
-
|
|
216
|
+
verificationKey: Buffer,
|
|
205
217
|
inputWitnessFile: string,
|
|
206
218
|
flavor: UltraHonkFlavor,
|
|
207
|
-
log:
|
|
219
|
+
log: Logger,
|
|
208
220
|
): Promise<BBFailure | BBSuccess> {
|
|
209
221
|
// Check that the working directory exists
|
|
210
222
|
try {
|
|
211
223
|
await fs.access(workingDirectory);
|
|
212
|
-
} catch
|
|
224
|
+
} catch {
|
|
213
225
|
return { status: BB_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
|
|
214
226
|
}
|
|
215
227
|
|
|
216
|
-
// The bytecode is written to e.g. /workingDirectory/
|
|
228
|
+
// The bytecode is written to e.g. /workingDirectory/ParityBaseArtifact-bytecode
|
|
217
229
|
const bytecodePath = `${workingDirectory}/${circuitName}-bytecode`;
|
|
230
|
+
const vkPath = `${workingDirectory}/${circuitName}-vk`;
|
|
218
231
|
|
|
219
232
|
// The proof is written to e.g. /workingDirectory/ultra_honk/proof
|
|
220
233
|
const outputPath = `${workingDirectory}`;
|
|
@@ -228,26 +241,28 @@ export async function generateProof(
|
|
|
228
241
|
}
|
|
229
242
|
|
|
230
243
|
try {
|
|
231
|
-
// Write the bytecode to the working directory
|
|
232
|
-
await fs.writeFile(bytecodePath, bytecode);
|
|
244
|
+
// Write the bytecode and vk to the working directory
|
|
245
|
+
await Promise.all([fs.writeFile(bytecodePath, bytecode), fs.writeFile(vkPath, verificationKey)]);
|
|
233
246
|
const args = getArgs(flavor).concat([
|
|
234
|
-
'--
|
|
235
|
-
'bytes_and_fields',
|
|
236
|
-
'--write_vk',
|
|
247
|
+
'--disable_zk',
|
|
237
248
|
'-o',
|
|
238
249
|
outputPath,
|
|
239
250
|
'-b',
|
|
240
251
|
bytecodePath,
|
|
252
|
+
'-k',
|
|
253
|
+
vkPath,
|
|
241
254
|
'-w',
|
|
242
255
|
inputWitnessFile,
|
|
243
256
|
'-v',
|
|
244
257
|
]);
|
|
245
|
-
|
|
246
|
-
|
|
258
|
+
const loggingArg = log.level === 'debug' || log.level === 'trace' ? '-d' : log.level === 'verbose' ? '-v' : '';
|
|
259
|
+
if (loggingArg !== '') {
|
|
260
|
+
args.push(loggingArg);
|
|
247
261
|
}
|
|
262
|
+
|
|
248
263
|
const timer = new Timer();
|
|
249
264
|
const logFunction = (message: string) => {
|
|
250
|
-
log(`${circuitName} BB out - ${message}`);
|
|
265
|
+
log.info(`${circuitName} BB out - ${message}`);
|
|
251
266
|
};
|
|
252
267
|
const result = await executeBB(pathToBB, `prove`, args, logFunction);
|
|
253
268
|
const duration = timer.ms();
|
|
@@ -258,80 +273,7 @@ export async function generateProof(
|
|
|
258
273
|
durationMs: duration,
|
|
259
274
|
proofPath: `${outputPath}`,
|
|
260
275
|
pkPath: undefined,
|
|
261
|
-
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
265
|
-
return {
|
|
266
|
-
status: BB_RESULT.FAILURE,
|
|
267
|
-
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
268
|
-
retry: !!result.signal,
|
|
269
|
-
};
|
|
270
|
-
} catch (error) {
|
|
271
|
-
return { status: BB_RESULT.FAILURE, reason: `${error}` };
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Used for generating proofs of the tube circuit
|
|
277
|
-
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
|
|
278
|
-
* @param pathToBB - The full path to the bb binary
|
|
279
|
-
* @param workingDirectory - A working directory for use by bb
|
|
280
|
-
* @param circuitName - An identifier for the circuit
|
|
281
|
-
* @param bytecode - The compiled circuit bytecode
|
|
282
|
-
* @param inputWitnessFile - The circuit input witness
|
|
283
|
-
* @param log - A logging function
|
|
284
|
-
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
285
|
-
*/
|
|
286
|
-
export async function generateTubeProof(
|
|
287
|
-
pathToBB: string,
|
|
288
|
-
workingDirectory: string,
|
|
289
|
-
log: LogFn,
|
|
290
|
-
): Promise<BBFailure | BBSuccess> {
|
|
291
|
-
// Check that the working directory exists
|
|
292
|
-
try {
|
|
293
|
-
await fs.access(workingDirectory);
|
|
294
|
-
} catch (error) {
|
|
295
|
-
return { status: BB_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// // Paths for the inputs
|
|
299
|
-
const vkPath = join(workingDirectory, CLIENT_IVC_VK_FILE_NAME);
|
|
300
|
-
const proofPath = join(workingDirectory, CLIENT_IVC_PROOF_FILE_NAME);
|
|
301
|
-
|
|
302
|
-
// The proof is written to e.g. /workingDirectory/proof
|
|
303
|
-
const outputPath = workingDirectory;
|
|
304
|
-
const filePresent = async (file: string) =>
|
|
305
|
-
await fs
|
|
306
|
-
.access(file, fs.constants.R_OK)
|
|
307
|
-
.then(_ => true)
|
|
308
|
-
.catch(_ => false);
|
|
309
|
-
|
|
310
|
-
const binaryPresent = await filePresent(pathToBB);
|
|
311
|
-
if (!binaryPresent) {
|
|
312
|
-
return { status: BB_RESULT.FAILURE, reason: `Failed to find bb binary at ${pathToBB}` };
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
try {
|
|
316
|
-
if (!(await filePresent(vkPath)) || !(await filePresent(proofPath))) {
|
|
317
|
-
return { status: BB_RESULT.FAILURE, reason: `Client IVC input files not present in ${workingDirectory}` };
|
|
318
|
-
}
|
|
319
|
-
const args = ['-o', outputPath, '-v'];
|
|
320
|
-
|
|
321
|
-
const timer = new Timer();
|
|
322
|
-
const logFunction = (message: string) => {
|
|
323
|
-
log(`TubeCircuit (prove) BB out - ${message}`);
|
|
324
|
-
};
|
|
325
|
-
const result = await executeBB(pathToBB, 'prove_tube', args, logFunction);
|
|
326
|
-
const durationMs = timer.ms();
|
|
327
|
-
|
|
328
|
-
if (result.status == BB_RESULT.SUCCESS) {
|
|
329
|
-
return {
|
|
330
|
-
status: BB_RESULT.SUCCESS,
|
|
331
|
-
durationMs,
|
|
332
|
-
proofPath: outputPath,
|
|
333
|
-
pkPath: undefined,
|
|
334
|
-
vkPath: outputPath,
|
|
276
|
+
vkDirectoryPath: `${outputPath}`,
|
|
335
277
|
};
|
|
336
278
|
}
|
|
337
279
|
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
@@ -351,19 +293,21 @@ export async function generateTubeProof(
|
|
|
351
293
|
* @param pathToBB - The full path to the bb binary
|
|
352
294
|
* @param workingDirectory - A working directory for use by bb
|
|
353
295
|
* @param input - The inputs for the public function to be proven
|
|
354
|
-
* @param
|
|
296
|
+
* @param logger - A logging function
|
|
297
|
+
* @param checkCircuitOnly - A boolean to toggle a "check-circuit only" operation instead of proving.
|
|
355
298
|
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
356
299
|
*/
|
|
357
|
-
export async function
|
|
300
|
+
export async function generateAvmProof(
|
|
358
301
|
pathToBB: string,
|
|
359
302
|
workingDirectory: string,
|
|
360
303
|
input: AvmCircuitInputs,
|
|
361
304
|
logger: Logger,
|
|
305
|
+
checkCircuitOnly: boolean = false,
|
|
362
306
|
): Promise<BBFailure | BBSuccess> {
|
|
363
307
|
// Check that the working directory exists
|
|
364
308
|
try {
|
|
365
309
|
await fs.access(workingDirectory);
|
|
366
|
-
} catch
|
|
310
|
+
} catch {
|
|
367
311
|
return { status: BB_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
|
|
368
312
|
}
|
|
369
313
|
|
|
@@ -391,107 +335,19 @@ export async function generateAvmProofV2(
|
|
|
391
335
|
return { status: BB_RESULT.FAILURE, reason: `Could not write avm inputs to ${avmInputsPath}` };
|
|
392
336
|
}
|
|
393
337
|
|
|
394
|
-
const args = ['--avm-inputs', avmInputsPath, '-o', outputPath];
|
|
338
|
+
const args = checkCircuitOnly ? ['--avm-inputs', avmInputsPath] : ['--avm-inputs', avmInputsPath, '-o', outputPath];
|
|
395
339
|
const loggingArg =
|
|
396
340
|
logger.level === 'debug' || logger.level === 'trace' ? '-d' : logger.level === 'verbose' ? '-v' : '';
|
|
397
341
|
if (loggingArg !== '') {
|
|
398
342
|
args.push(loggingArg);
|
|
399
343
|
}
|
|
400
344
|
const timer = new Timer();
|
|
401
|
-
const logFunction = (message: string) => {
|
|
402
|
-
logger.verbose(`AvmCircuit (prove) BB out - ${message}`);
|
|
403
|
-
};
|
|
404
|
-
const result = await executeBB(pathToBB, 'avm2_prove', args, logFunction);
|
|
405
|
-
const duration = timer.ms();
|
|
406
|
-
|
|
407
|
-
if (result.status == BB_RESULT.SUCCESS) {
|
|
408
|
-
return {
|
|
409
|
-
status: BB_RESULT.SUCCESS,
|
|
410
|
-
durationMs: duration,
|
|
411
|
-
proofPath: join(outputPath, PROOF_FILENAME),
|
|
412
|
-
pkPath: undefined,
|
|
413
|
-
vkPath: outputPath,
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
417
|
-
return {
|
|
418
|
-
status: BB_RESULT.FAILURE,
|
|
419
|
-
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
420
|
-
retry: !!result.signal,
|
|
421
|
-
};
|
|
422
|
-
} catch (error) {
|
|
423
|
-
return { status: BB_RESULT.FAILURE, reason: `${error}` };
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* Used for generating AVM proofs (or doing check-circuit).
|
|
429
|
-
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
|
|
430
|
-
* @param pathToBB - The full path to the bb binary
|
|
431
|
-
* @param workingDirectory - A working directory for use by bb
|
|
432
|
-
* @param bytecode - The AVM bytecode for the public function to be proven (expected to be decompressed)
|
|
433
|
-
* @param log - A logging function
|
|
434
|
-
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
435
|
-
*/
|
|
436
|
-
export async function generateAvmProof(
|
|
437
|
-
pathToBB: string,
|
|
438
|
-
workingDirectory: string,
|
|
439
|
-
_input: AvmCircuitInputs,
|
|
440
|
-
logger: Logger,
|
|
441
|
-
checkCircuitOnly: boolean = false,
|
|
442
|
-
): Promise<BBFailure | BBSuccess> {
|
|
443
|
-
// Check that the working directory exists
|
|
444
|
-
try {
|
|
445
|
-
await fs.access(workingDirectory);
|
|
446
|
-
} catch (error) {
|
|
447
|
-
return { status: BB_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// Paths for the inputs
|
|
451
|
-
const publicInputsPath = join(workingDirectory, AVM_PUBLIC_INPUTS_FILENAME);
|
|
452
|
-
const avmHintsPath = join(workingDirectory, AVM_HINTS_FILENAME);
|
|
453
|
-
|
|
454
|
-
// The proof is written to e.g. /workingDirectory/proof
|
|
455
|
-
const outputPath = workingDirectory;
|
|
456
|
-
|
|
457
|
-
const filePresent = async (file: string) =>
|
|
458
|
-
await fs
|
|
459
|
-
.access(file, fs.constants.R_OK)
|
|
460
|
-
.then(_ => true)
|
|
461
|
-
.catch(_ => false);
|
|
462
|
-
|
|
463
|
-
const binaryPresent = await filePresent(pathToBB);
|
|
464
|
-
if (!binaryPresent) {
|
|
465
|
-
return { status: BB_RESULT.FAILURE, reason: `Failed to find bb binary at ${pathToBB}` };
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
try {
|
|
469
|
-
// Write the inputs to the working directory.
|
|
470
|
-
|
|
471
|
-
// WARNING: Not writing the inputs since VM1 is disabled!
|
|
472
|
-
// await fs.writeFile(publicInputsPath, input.publicInputs.toBuffer());
|
|
473
|
-
// if (!(await filePresent(publicInputsPath))) {
|
|
474
|
-
// return { status: BB_RESULT.FAILURE, reason: `Could not write publicInputs at ${publicInputsPath}` };
|
|
475
|
-
// }
|
|
476
|
-
|
|
477
|
-
// await fs.writeFile(avmHintsPath, input.avmHints.toBuffer());
|
|
478
|
-
// if (!(await filePresent(avmHintsPath))) {
|
|
479
|
-
// return { status: BB_RESULT.FAILURE, reason: `Could not write avmHints at ${avmHintsPath}` };
|
|
480
|
-
// }
|
|
481
|
-
|
|
482
|
-
const args = ['--avm-public-inputs', publicInputsPath, '--avm-hints', avmHintsPath, '-o', outputPath];
|
|
483
|
-
const loggingArg =
|
|
484
|
-
logger.level === 'debug' || logger.level === 'trace' ? '-d' : logger.level === 'verbose' ? '-v' : '';
|
|
485
|
-
if (loggingArg !== '') {
|
|
486
|
-
args.push(loggingArg);
|
|
487
|
-
}
|
|
488
345
|
|
|
489
|
-
const
|
|
490
|
-
const cmd = checkCircuitOnly ? 'check_circuit' : 'prove';
|
|
346
|
+
const cmd = checkCircuitOnly ? 'avm_check_circuit' : 'avm_prove';
|
|
491
347
|
const logFunction = (message: string) => {
|
|
492
348
|
logger.verbose(`AvmCircuit (${cmd}) BB out - ${message}`);
|
|
493
349
|
};
|
|
494
|
-
const result = await executeBB(pathToBB,
|
|
350
|
+
const result = await executeBB(pathToBB, cmd, args, logFunction);
|
|
495
351
|
const duration = timer.ms();
|
|
496
352
|
|
|
497
353
|
if (result.status == BB_RESULT.SUCCESS) {
|
|
@@ -500,14 +356,14 @@ export async function generateAvmProof(
|
|
|
500
356
|
durationMs: duration,
|
|
501
357
|
proofPath: join(outputPath, PROOF_FILENAME),
|
|
502
358
|
pkPath: undefined,
|
|
503
|
-
|
|
359
|
+
vkDirectoryPath: outputPath,
|
|
504
360
|
};
|
|
505
361
|
}
|
|
506
362
|
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
507
363
|
return {
|
|
508
364
|
status: BB_RESULT.FAILURE,
|
|
509
|
-
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
510
|
-
retry:
|
|
365
|
+
reason: `Failed to generate proof. AVM proof for TX hash ${input.hints.tx.hash}. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
366
|
+
retry: result.signal === 'SIGKILL', // retry on SIGKILL because the oomkiller might have stopped the process
|
|
511
367
|
};
|
|
512
368
|
} catch (error) {
|
|
513
369
|
return { status: BB_RESULT.FAILURE, reason: `${error}` };
|
|
@@ -539,24 +395,7 @@ export async function verifyProof(
|
|
|
539
395
|
);
|
|
540
396
|
}
|
|
541
397
|
|
|
542
|
-
/**
|
|
543
|
-
* Used for verifying proofs of the AVM
|
|
544
|
-
* @param pathToBB - The full path to the bb binary
|
|
545
|
-
* @param proofFullPath - The full path to the proof to be verified
|
|
546
|
-
* @param verificationKeyPath - The full path to the circuit verification key
|
|
547
|
-
* @param log - A logging function
|
|
548
|
-
* @returns An object containing a result indication and duration taken
|
|
549
|
-
*/
|
|
550
398
|
export async function verifyAvmProof(
|
|
551
|
-
pathToBB: string,
|
|
552
|
-
proofFullPath: string,
|
|
553
|
-
verificationKeyPath: string,
|
|
554
|
-
logger: Logger,
|
|
555
|
-
): Promise<BBFailure | BBSuccess> {
|
|
556
|
-
return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, 'avm_verify', logger);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
export async function verifyAvmProofV2(
|
|
560
399
|
pathToBB: string,
|
|
561
400
|
workingDirectory: string,
|
|
562
401
|
proofFullPath: string,
|
|
@@ -578,25 +417,27 @@ export async function verifyAvmProofV2(
|
|
|
578
417
|
return { status: BB_RESULT.FAILURE, reason: `Could not write avm inputs to ${avmInputsPath}` };
|
|
579
418
|
}
|
|
580
419
|
|
|
581
|
-
return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, '
|
|
420
|
+
return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, 'avm_verify', logger, [
|
|
582
421
|
'--avm-public-inputs',
|
|
583
422
|
avmInputsPath,
|
|
584
423
|
]);
|
|
585
424
|
}
|
|
586
425
|
|
|
587
426
|
/**
|
|
588
|
-
* Verifies a
|
|
427
|
+
* Verifies a ChonkProof
|
|
589
428
|
* TODO(#7370) The verification keys should be supplied separately
|
|
590
429
|
* @param pathToBB - The full path to the bb binary
|
|
591
430
|
* @param targetPath - The path to the folder with the proof, accumulator, and verification keys
|
|
592
431
|
* @param log - A logging function
|
|
432
|
+
* @param concurrency - The number of threads to use for the verification
|
|
593
433
|
* @returns An object containing a result indication and duration taken
|
|
594
434
|
*/
|
|
595
|
-
export async function
|
|
435
|
+
export async function verifyChonkProof(
|
|
596
436
|
pathToBB: string,
|
|
597
437
|
proofPath: string,
|
|
598
438
|
keyPath: string,
|
|
599
439
|
log: LogFn,
|
|
440
|
+
concurrency = 1,
|
|
600
441
|
): Promise<BBFailure | BBSuccess> {
|
|
601
442
|
const binaryPresent = await fs
|
|
602
443
|
.access(pathToBB, fs.constants.R_OK)
|
|
@@ -607,10 +448,11 @@ export async function verifyClientIvcProof(
|
|
|
607
448
|
}
|
|
608
449
|
|
|
609
450
|
try {
|
|
610
|
-
const args = ['--scheme', '
|
|
451
|
+
const args = ['--scheme', 'chonk', '-p', proofPath, '-k', keyPath, '-v'];
|
|
611
452
|
const timer = new Timer();
|
|
612
453
|
const command = 'verify';
|
|
613
|
-
|
|
454
|
+
|
|
455
|
+
const result = await executeBB(pathToBB, command, args, log, concurrency);
|
|
614
456
|
const duration = timer.ms();
|
|
615
457
|
if (result.status == BB_RESULT.SUCCESS) {
|
|
616
458
|
return { status: BB_RESULT.SUCCESS, durationMs: duration };
|
|
@@ -639,7 +481,7 @@ async function verifyProofInternal(
|
|
|
639
481
|
pathToBB: string,
|
|
640
482
|
proofFullPath: string,
|
|
641
483
|
verificationKeyPath: string,
|
|
642
|
-
command: 'verify' | 'avm_verify'
|
|
484
|
+
command: 'verify' | 'avm_verify',
|
|
643
485
|
logger: Logger,
|
|
644
486
|
extraArgs: string[] = [],
|
|
645
487
|
): Promise<BBFailure | BBSuccess> {
|
|
@@ -656,12 +498,26 @@ async function verifyProofInternal(
|
|
|
656
498
|
};
|
|
657
499
|
|
|
658
500
|
try {
|
|
659
|
-
|
|
501
|
+
let args;
|
|
502
|
+
|
|
503
|
+
if (command == 'verify') {
|
|
504
|
+
// Specify the public inputs path in the case of UH verification.
|
|
505
|
+
// Take proofFullPath and remove the suffix past the / to get the directory.
|
|
506
|
+
const proofDir = proofFullPath.substring(0, proofFullPath.lastIndexOf('/'));
|
|
507
|
+
const publicInputsFullPath = join(proofDir, '/public_inputs');
|
|
508
|
+
logger.debug(`public inputs path: ${publicInputsFullPath}`);
|
|
509
|
+
|
|
510
|
+
args = ['-p', proofFullPath, '-k', verificationKeyPath, '-i', publicInputsFullPath, '--disable_zk', ...extraArgs];
|
|
511
|
+
} else {
|
|
512
|
+
args = ['-p', proofFullPath, '-k', verificationKeyPath, ...extraArgs];
|
|
513
|
+
}
|
|
514
|
+
|
|
660
515
|
const loggingArg =
|
|
661
516
|
logger.level === 'debug' || logger.level === 'trace' ? '-d' : logger.level === 'verbose' ? '-v' : '';
|
|
662
517
|
if (loggingArg !== '') {
|
|
663
518
|
args.push(loggingArg);
|
|
664
519
|
}
|
|
520
|
+
|
|
665
521
|
const timer = new Timer();
|
|
666
522
|
const result = await executeBB(pathToBB, command, args, logFunction);
|
|
667
523
|
const duration = timer.ms();
|
|
@@ -752,11 +608,11 @@ export async function computeGateCountForCircuit(
|
|
|
752
608
|
// Check that the working directory exists
|
|
753
609
|
try {
|
|
754
610
|
await fs.access(workingDirectory);
|
|
755
|
-
} catch
|
|
611
|
+
} catch {
|
|
756
612
|
return { status: BB_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
|
|
757
613
|
}
|
|
758
614
|
|
|
759
|
-
// The bytecode is written to e.g. /workingDirectory/
|
|
615
|
+
// The bytecode is written to e.g. /workingDirectory/ParityBaseArtifact-bytecode
|
|
760
616
|
const bytecodePath = `${workingDirectory}/${circuitName}-bytecode`;
|
|
761
617
|
|
|
762
618
|
const binaryPresent = await fs
|
|
@@ -782,7 +638,7 @@ export async function computeGateCountForCircuit(
|
|
|
782
638
|
const result = await executeBB(
|
|
783
639
|
pathToBB,
|
|
784
640
|
'gates',
|
|
785
|
-
['--scheme', flavor === 'mega_honk' ? '
|
|
641
|
+
['--scheme', flavor === 'mega_honk' ? 'chonk' : 'ultra_honk', '-b', bytecodePath, '-v'],
|
|
786
642
|
logHandler,
|
|
787
643
|
);
|
|
788
644
|
const duration = timer.ms();
|
|
@@ -844,7 +700,7 @@ async function fsCache<T>(
|
|
|
844
700
|
|
|
845
701
|
try {
|
|
846
702
|
await fs.writeFile(cacheFilePath, expectedCacheKey);
|
|
847
|
-
} catch
|
|
703
|
+
} catch {
|
|
848
704
|
logger(`Couldn't write cache data to ${cacheFilePath}. Skipping cache...`);
|
|
849
705
|
// ignore
|
|
850
706
|
}
|
package/src/config.ts
CHANGED
package/src/honk.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ServerProtocolArtifact } from '@aztec/noir-protocol-circuits-types/server';
|
|
2
2
|
|
|
3
|
-
export type UltraHonkFlavor = 'ultra_honk' | 'ultra_keccak_honk' | 'ultra_rollup_honk';
|
|
3
|
+
export type UltraHonkFlavor = 'ultra_honk' | 'ultra_keccak_honk' | 'ultra_starknet_honk' | 'ultra_rollup_honk';
|
|
4
4
|
|
|
5
5
|
const UltraKeccakHonkCircuits = ['RootRollupArtifact'] as const satisfies ServerProtocolArtifact[];
|
|
6
|
-
const UltraHonkCircuits = ['
|
|
6
|
+
const UltraHonkCircuits = ['ParityBaseArtifact', 'ParityRootArtifact'] as const satisfies ServerProtocolArtifact[];
|
|
7
7
|
|
|
8
8
|
export type UltraKeccakHonkServerProtocolArtifact = (typeof UltraKeccakHonkCircuits)[number];
|
|
9
9
|
export type UltraHonkServerProtocolArtifact = (typeof UltraHonkCircuits)[number];
|
|
@@ -17,6 +17,7 @@ export function getUltraHonkFlavorForCircuit(artifact: UltraHonkServerProtocolAr
|
|
|
17
17
|
export function getUltraHonkFlavorForCircuit(artifact: UltraRollupHonkServerProtocolArtifact): 'ultra_rollup_honk';
|
|
18
18
|
export function getUltraHonkFlavorForCircuit(artifact: ServerProtocolArtifact): UltraHonkFlavor;
|
|
19
19
|
export function getUltraHonkFlavorForCircuit(artifact: ServerProtocolArtifact): UltraHonkFlavor {
|
|
20
|
+
// STARKNET: how to allow for the distinction between keccak/starknet? ultra_keccak_honk is returned in both cases
|
|
20
21
|
if (isUltraKeccakHonkCircuit(artifact)) {
|
|
21
22
|
return 'ultra_keccak_honk';
|
|
22
23
|
} else if (UltraHonkCircuits.includes(artifact as UltraHonkServerProtocolArtifact)) {
|
package/src/index.ts
CHANGED
|
@@ -4,5 +4,6 @@ export * from './verifier/index.js';
|
|
|
4
4
|
export * from './config.js';
|
|
5
5
|
export * from './bb/execute.js';
|
|
6
6
|
export * from './honk.js';
|
|
7
|
+
export * from './verification_key/verification_key_data.js';
|
|
7
8
|
|
|
8
9
|
export { type ClientProtocolCircuitVerifier } from '@aztec/stdlib/interfaces/server';
|
package/src/instrumentation.ts
CHANGED
|
@@ -86,13 +86,12 @@ export class ProverInstrumentation {
|
|
|
86
86
|
*/
|
|
87
87
|
recordDuration(
|
|
88
88
|
metric: 'simulationDuration' | 'witGenDuration' | 'provingDuration',
|
|
89
|
-
circuitName: CircuitName
|
|
89
|
+
circuitName: CircuitName,
|
|
90
90
|
timerOrMS: Timer | number,
|
|
91
91
|
) {
|
|
92
92
|
const s = typeof timerOrMS === 'number' ? timerOrMS / 1000 : timerOrMS.s();
|
|
93
93
|
this[metric].record(s, {
|
|
94
94
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
|
|
95
|
-
[Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
|
|
96
95
|
});
|
|
97
96
|
}
|
|
98
97
|
|
|
@@ -117,12 +116,11 @@ export class ProverInstrumentation {
|
|
|
117
116
|
*/
|
|
118
117
|
recordSize(
|
|
119
118
|
metric: 'witGenInputSize' | 'witGenOutputSize' | 'proofSize' | 'circuitSize' | 'circuitPublicInputCount',
|
|
120
|
-
circuitName: CircuitName
|
|
119
|
+
circuitName: CircuitName,
|
|
121
120
|
size: number,
|
|
122
121
|
) {
|
|
123
122
|
this[metric].record(Math.ceil(size), {
|
|
124
123
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
|
|
125
|
-
[Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
|
|
126
124
|
});
|
|
127
125
|
}
|
|
128
126
|
|