@aztec/bb-prover 0.0.1-commit.5daedc8 → 0.0.1-commit.6201a7b05
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 +5 -4
- package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
- package/dest/avm_proving_tests/avm_proving_tester.js +26 -10
- package/dest/bb/execute.d.ts +7 -6
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +64 -76
- package/dest/config.d.ts +12 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/instrumentation.d.ts +1 -1
- package/dest/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation.js +21 -43
- package/dest/prover/client/bb_private_kernel_prover.d.ts +9 -3
- package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
- package/dest/prover/client/bb_private_kernel_prover.js +29 -7
- package/dest/prover/client/bundle.d.ts +3 -3
- package/dest/prover/client/bundle.d.ts.map +1 -1
- package/dest/prover/client/bundle.js +2 -3
- package/dest/prover/client/lazy.d.ts +3 -3
- package/dest/prover/client/lazy.d.ts.map +1 -1
- package/dest/prover/client/lazy.js +2 -3
- package/dest/prover/proof_utils.js +1 -1
- package/dest/prover/server/bb_prover.d.ts +6 -9
- package/dest/prover/server/bb_prover.d.ts.map +1 -1
- package/dest/prover/server/bb_prover.js +416 -43
- package/dest/test/delay_values.d.ts +1 -1
- package/dest/test/delay_values.d.ts.map +1 -1
- package/dest/test/delay_values.js +28 -26
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -0
- package/dest/test/test_circuit_prover.d.ts +4 -4
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +462 -59
- package/dest/verification_key/verification_key_data.d.ts +1 -8
- package/dest/verification_key/verification_key_data.d.ts.map +1 -1
- package/dest/verification_key/verification_key_data.js +1 -20
- package/dest/verifier/batch_chonk_verifier.d.ts +45 -0
- package/dest/verifier/batch_chonk_verifier.d.ts.map +1 -0
- package/dest/verifier/batch_chonk_verifier.js +232 -0
- package/dest/verifier/bb_verifier.d.ts +1 -1
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +1 -4
- package/dest/verifier/index.d.ts +2 -1
- package/dest/verifier/index.d.ts.map +1 -1
- package/dest/verifier/index.js +1 -0
- package/dest/verifier/queued_chonk_verifier.d.ts +2 -3
- package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -1
- package/dest/verifier/queued_chonk_verifier.js +15 -45
- package/package.json +20 -19
- package/src/avm_proving_tests/avm_proving_tester.ts +31 -19
- package/src/bb/execute.ts +54 -60
- package/src/config.ts +11 -0
- package/src/instrumentation.ts +20 -43
- package/src/prover/client/bb_private_kernel_prover.ts +35 -9
- package/src/prover/client/bundle.ts +3 -4
- package/src/prover/client/lazy.ts +3 -4
- package/src/prover/proof_utils.ts +1 -1
- package/src/prover/server/bb_prover.ts +23 -38
- package/src/test/delay_values.ts +30 -26
- package/src/test/index.ts +1 -0
- package/src/test/test_circuit_prover.ts +10 -13
- package/src/verification_key/verification_key_data.ts +1 -26
- package/src/verifier/batch_chonk_verifier.ts +276 -0
- package/src/verifier/bb_verifier.ts +1 -5
- package/src/verifier/index.ts +1 -0
- package/src/verifier/queued_chonk_verifier.ts +15 -47
|
@@ -8,8 +8,9 @@ import {
|
|
|
8
8
|
type TestPrivateInsertions,
|
|
9
9
|
} from '@aztec/simulator/public/fixtures';
|
|
10
10
|
import type { PublicTxResult } from '@aztec/simulator/server';
|
|
11
|
-
import { AvmCircuitInputs, AvmCircuitPublicInputs } from '@aztec/stdlib/avm';
|
|
11
|
+
import { AvmCircuitInputs, AvmCircuitPublicInputs, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
12
12
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
+
import type { Gas } from '@aztec/stdlib/gas';
|
|
13
14
|
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
14
15
|
import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
15
16
|
import { NativeWorldStateService } from '@aztec/world-state';
|
|
@@ -18,14 +19,7 @@ import fs from 'node:fs/promises';
|
|
|
18
19
|
import { tmpdir } from 'node:os';
|
|
19
20
|
import path from 'path';
|
|
20
21
|
|
|
21
|
-
import {
|
|
22
|
-
type BBResult,
|
|
23
|
-
type BBSuccess,
|
|
24
|
-
BB_RESULT,
|
|
25
|
-
VK_FILENAME,
|
|
26
|
-
generateAvmProof,
|
|
27
|
-
verifyAvmProof,
|
|
28
|
-
} from '../bb/execute.js';
|
|
22
|
+
import { type BBResult, type BBSuccess, BB_RESULT, generateAvmProof, verifyAvmProof } from '../bb/execute.js';
|
|
29
23
|
|
|
30
24
|
const BB_PATH = path.resolve('../../barretenberg/cpp/build/bin/bb-avm');
|
|
31
25
|
|
|
@@ -51,6 +45,10 @@ class InterceptingLogger implements Logger {
|
|
|
51
45
|
throw new Error('Not implemented');
|
|
52
46
|
}
|
|
53
47
|
|
|
48
|
+
getBindings() {
|
|
49
|
+
return this.logger.getBindings();
|
|
50
|
+
}
|
|
51
|
+
|
|
54
52
|
private intercept(level: LogLevel, msg: string, ...args: any[]) {
|
|
55
53
|
this.logs.push(...msg.split('\n'));
|
|
56
54
|
// Forward to the wrapped logger
|
|
@@ -88,6 +86,16 @@ class InterceptingLogger implements Logger {
|
|
|
88
86
|
}
|
|
89
87
|
}
|
|
90
88
|
|
|
89
|
+
// Config with collectHints enabled for proving tests
|
|
90
|
+
const provingConfig: PublicSimulatorConfig = PublicSimulatorConfig.from({
|
|
91
|
+
skipFeeEnforcement: false,
|
|
92
|
+
collectCallMetadata: true, // For results.
|
|
93
|
+
collectDebugLogs: false,
|
|
94
|
+
collectHints: true, // Required for proving!
|
|
95
|
+
collectPublicInputs: true, // Required for proving!
|
|
96
|
+
collectStatistics: false,
|
|
97
|
+
});
|
|
98
|
+
|
|
91
99
|
export class AvmProvingTester extends PublicTxSimulationTester {
|
|
92
100
|
private bbWorkingDirectory: string = '';
|
|
93
101
|
|
|
@@ -98,7 +106,8 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
98
106
|
globals?: GlobalVariables,
|
|
99
107
|
metrics?: TestExecutorMetrics,
|
|
100
108
|
) {
|
|
101
|
-
|
|
109
|
+
// simulator factory is undefined because for proving, we use the default C++ simulator
|
|
110
|
+
super(merkleTrees, contractDataSource, globals, metrics, /*simulatorFactory=*/ undefined, provingConfig);
|
|
102
111
|
}
|
|
103
112
|
|
|
104
113
|
static async new(
|
|
@@ -182,14 +191,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
182
191
|
return proofRes;
|
|
183
192
|
}
|
|
184
193
|
|
|
185
|
-
return await verifyAvmProof(
|
|
186
|
-
BB_PATH,
|
|
187
|
-
this.bbWorkingDirectory,
|
|
188
|
-
proofRes.proofPath!,
|
|
189
|
-
publicInputs,
|
|
190
|
-
path.join(proofRes.vkDirectoryPath!, VK_FILENAME),
|
|
191
|
-
this.logger,
|
|
192
|
-
);
|
|
194
|
+
return await verifyAvmProof(BB_PATH, this.bbWorkingDirectory, proofRes.proofPath!, publicInputs, this.logger);
|
|
193
195
|
}
|
|
194
196
|
|
|
195
197
|
public async proveVerify(avmCircuitInputs: AvmCircuitInputs, txLabel: string = 'unlabeledTx') {
|
|
@@ -210,7 +212,9 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
210
212
|
privateInsertions?: TestPrivateInsertions,
|
|
211
213
|
txLabel: string = 'unlabeledTx',
|
|
212
214
|
disableRevertCheck: boolean = false,
|
|
215
|
+
gasLimits?: Gas,
|
|
213
216
|
): Promise<PublicTxResult> {
|
|
217
|
+
const simTimer = new Timer();
|
|
214
218
|
const simRes = await this.simulateTx(
|
|
215
219
|
sender,
|
|
216
220
|
setupCalls,
|
|
@@ -219,7 +223,10 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
219
223
|
feePayer,
|
|
220
224
|
privateInsertions,
|
|
221
225
|
txLabel,
|
|
226
|
+
gasLimits,
|
|
222
227
|
);
|
|
228
|
+
const simDuration = simTimer.ms();
|
|
229
|
+
this.logger.info(`Simulation took ${simDuration} ms for tx ${txLabel}`);
|
|
223
230
|
|
|
224
231
|
if (!disableRevertCheck) {
|
|
225
232
|
expect(simRes.revertCode.isOK()).toBe(expectRevert ? false : true);
|
|
@@ -227,7 +234,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
227
234
|
|
|
228
235
|
const opString = this.checkCircuitOnly ? 'Check circuit' : 'Proving and verification';
|
|
229
236
|
|
|
230
|
-
const avmCircuitInputs = new AvmCircuitInputs(simRes.hints!, simRes.publicInputs);
|
|
237
|
+
const avmCircuitInputs = new AvmCircuitInputs(simRes.hints!, simRes.publicInputs!);
|
|
231
238
|
const timer = new Timer();
|
|
232
239
|
await this.proveVerify(avmCircuitInputs, txLabel);
|
|
233
240
|
this.logger.info(`${opString} took ${timer.ms()} ms for tx ${txLabel}`);
|
|
@@ -243,6 +250,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
243
250
|
teardownCall?: TestEnqueuedCall,
|
|
244
251
|
feePayer?: AztecAddress,
|
|
245
252
|
privateInsertions?: TestPrivateInsertions,
|
|
253
|
+
gasLimits?: Gas,
|
|
246
254
|
) {
|
|
247
255
|
return await this.simProveVerify(
|
|
248
256
|
sender,
|
|
@@ -254,6 +262,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
254
262
|
privateInsertions,
|
|
255
263
|
txLabel,
|
|
256
264
|
true,
|
|
265
|
+
gasLimits,
|
|
257
266
|
);
|
|
258
267
|
}
|
|
259
268
|
|
|
@@ -261,6 +270,7 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
261
270
|
appCall: TestEnqueuedCall,
|
|
262
271
|
expectRevert?: boolean,
|
|
263
272
|
txLabel: string = 'unlabeledTx',
|
|
273
|
+
gasLimits?: Gas,
|
|
264
274
|
) {
|
|
265
275
|
await this.simProveVerify(
|
|
266
276
|
/*sender=*/ AztecAddress.fromNumber(42),
|
|
@@ -271,6 +281,8 @@ export class AvmProvingTester extends PublicTxSimulationTester {
|
|
|
271
281
|
/*feePayer=*/ undefined,
|
|
272
282
|
/*privateInsertions=*/ undefined,
|
|
273
283
|
txLabel,
|
|
284
|
+
/*disableRevertCheck=*/ false,
|
|
285
|
+
gasLimits,
|
|
274
286
|
);
|
|
275
287
|
}
|
|
276
288
|
}
|
package/src/bb/execute.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sha256 } from '@aztec/foundation/crypto';
|
|
1
|
+
import { sha256 } from '@aztec/foundation/crypto/sha256';
|
|
2
2
|
import type { LogFn, Logger } from '@aztec/foundation/log';
|
|
3
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
4
|
import type { AvmCircuitInputs, AvmCircuitPublicInputs } from '@aztec/stdlib/avm';
|
|
@@ -52,6 +52,8 @@ type BBExecResult = {
|
|
|
52
52
|
signal: string | undefined;
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
+
export const DEFAULT_BB_VERIFY_CONCURRENCY = 4;
|
|
56
|
+
|
|
55
57
|
/**
|
|
56
58
|
* Invokes the Barretenberg binary with the provided command and args
|
|
57
59
|
* @param pathToBB - The path to the BB binary
|
|
@@ -101,6 +103,16 @@ export function executeBB(
|
|
|
101
103
|
}, timeout);
|
|
102
104
|
}
|
|
103
105
|
|
|
106
|
+
// Forward termination signals so bb doesn't survive as an orphan when the node parent exits.
|
|
107
|
+
const forwardSignal = (signal: NodeJS.Signals) => {
|
|
108
|
+
if (bb.pid) {
|
|
109
|
+
bb.kill(signal);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
process.on('SIGINT', forwardSignal);
|
|
113
|
+
process.on('SIGTERM', forwardSignal);
|
|
114
|
+
process.on('SIGHUP', forwardSignal);
|
|
115
|
+
|
|
104
116
|
readline.createInterface({ input: bb.stdout }).on('line', logger);
|
|
105
117
|
readline.createInterface({ input: bb.stderr }).on('line', logger);
|
|
106
118
|
|
|
@@ -108,6 +120,9 @@ export function executeBB(
|
|
|
108
120
|
if (timeoutId) {
|
|
109
121
|
clearTimeout(timeoutId);
|
|
110
122
|
}
|
|
123
|
+
process.off('SIGINT', forwardSignal);
|
|
124
|
+
process.off('SIGTERM', forwardSignal);
|
|
125
|
+
process.off('SIGHUP', forwardSignal);
|
|
111
126
|
if (resultParser(exitCode)) {
|
|
112
127
|
resolve({ status: BB_RESULT.SUCCESS, exitCode, signal });
|
|
113
128
|
} else {
|
|
@@ -353,7 +368,7 @@ export async function generateAvmProof(
|
|
|
353
368
|
durationMs: duration,
|
|
354
369
|
proofPath: join(outputPath, PROOF_FILENAME),
|
|
355
370
|
pkPath: undefined,
|
|
356
|
-
vkDirectoryPath:
|
|
371
|
+
vkDirectoryPath: undefined, // AVM VK is fixed in the binary.
|
|
357
372
|
};
|
|
358
373
|
}
|
|
359
374
|
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
@@ -372,7 +387,7 @@ export async function generateAvmProof(
|
|
|
372
387
|
* @param pathToBB - The full path to the bb binary
|
|
373
388
|
* @param proofFullPath - The full path to the proof to be verified
|
|
374
389
|
* @param verificationKeyPath - The full path to the circuit verification key
|
|
375
|
-
* @param
|
|
390
|
+
* @param logger - A logger
|
|
376
391
|
* @returns An object containing a result indication and duration taken
|
|
377
392
|
*/
|
|
378
393
|
export async function verifyProof(
|
|
@@ -380,16 +395,32 @@ export async function verifyProof(
|
|
|
380
395
|
proofFullPath: string,
|
|
381
396
|
verificationKeyPath: string,
|
|
382
397
|
ultraHonkFlavor: UltraHonkFlavor,
|
|
383
|
-
|
|
398
|
+
logger: Logger,
|
|
384
399
|
): Promise<BBFailure | BBSuccess> {
|
|
385
|
-
|
|
386
|
-
|
|
400
|
+
// Specify the public inputs path in the case of UH verification.
|
|
401
|
+
// Take proofFullPath and remove the suffix past the / to get the directory.
|
|
402
|
+
const proofDir = proofFullPath.substring(0, proofFullPath.lastIndexOf('/'));
|
|
403
|
+
const publicInputsFullPath = join(proofDir, '/public_inputs');
|
|
404
|
+
logger.debug(`public inputs path: ${publicInputsFullPath}`);
|
|
405
|
+
|
|
406
|
+
const args = [
|
|
407
|
+
'-p',
|
|
387
408
|
proofFullPath,
|
|
409
|
+
'-k',
|
|
388
410
|
verificationKeyPath,
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
411
|
+
'-i',
|
|
412
|
+
publicInputsFullPath,
|
|
413
|
+
'--disable_zk',
|
|
414
|
+
...getArgs(ultraHonkFlavor),
|
|
415
|
+
];
|
|
416
|
+
|
|
417
|
+
let concurrency = DEFAULT_BB_VERIFY_CONCURRENCY;
|
|
418
|
+
|
|
419
|
+
if (process.env.VERIFY_HARDWARE_CONCURRENCY) {
|
|
420
|
+
concurrency = parseInt(process.env.VERIFY_HARDWARE_CONCURRENCY, 10);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return await verifyProofInternal(pathToBB, `verify`, args, logger, concurrency);
|
|
393
424
|
}
|
|
394
425
|
|
|
395
426
|
export async function verifyAvmProof(
|
|
@@ -397,7 +428,6 @@ export async function verifyAvmProof(
|
|
|
397
428
|
workingDirectory: string,
|
|
398
429
|
proofFullPath: string,
|
|
399
430
|
publicInputs: AvmCircuitPublicInputs,
|
|
400
|
-
verificationKeyPath: string,
|
|
401
431
|
logger: Logger,
|
|
402
432
|
): Promise<BBFailure | BBSuccess> {
|
|
403
433
|
const inputsBuffer = publicInputs.serializeWithMessagePack();
|
|
@@ -414,10 +444,8 @@ export async function verifyAvmProof(
|
|
|
414
444
|
return { status: BB_RESULT.FAILURE, reason: `Could not write avm inputs to ${avmInputsPath}` };
|
|
415
445
|
}
|
|
416
446
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
avmInputsPath,
|
|
420
|
-
]);
|
|
447
|
+
const args = ['-p', proofFullPath, '--avm-public-inputs', avmInputsPath];
|
|
448
|
+
return await verifyProofInternal(pathToBB, 'avm_verify', args, logger);
|
|
421
449
|
}
|
|
422
450
|
|
|
423
451
|
/**
|
|
@@ -425,7 +453,7 @@ export async function verifyAvmProof(
|
|
|
425
453
|
* TODO(#7370) The verification keys should be supplied separately
|
|
426
454
|
* @param pathToBB - The full path to the bb binary
|
|
427
455
|
* @param targetPath - The path to the folder with the proof, accumulator, and verification keys
|
|
428
|
-
* @param
|
|
456
|
+
* @param logger - A logger
|
|
429
457
|
* @param concurrency - The number of threads to use for the verification
|
|
430
458
|
* @returns An object containing a result indication and duration taken
|
|
431
459
|
*/
|
|
@@ -433,7 +461,7 @@ export async function verifyChonkProof(
|
|
|
433
461
|
pathToBB: string,
|
|
434
462
|
proofPath: string,
|
|
435
463
|
keyPath: string,
|
|
436
|
-
|
|
464
|
+
logger: Logger,
|
|
437
465
|
concurrency = 1,
|
|
438
466
|
): Promise<BBFailure | BBSuccess> {
|
|
439
467
|
const binaryPresent = await fs
|
|
@@ -444,43 +472,25 @@ export async function verifyChonkProof(
|
|
|
444
472
|
return { status: BB_RESULT.FAILURE, reason: `Failed to find bb binary at ${pathToBB}` };
|
|
445
473
|
}
|
|
446
474
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
const timer = new Timer();
|
|
450
|
-
const command = 'verify';
|
|
451
|
-
|
|
452
|
-
const result = await executeBB(pathToBB, command, args, log, concurrency);
|
|
453
|
-
const duration = timer.ms();
|
|
454
|
-
if (result.status == BB_RESULT.SUCCESS) {
|
|
455
|
-
return { status: BB_RESULT.SUCCESS, durationMs: duration };
|
|
456
|
-
}
|
|
457
|
-
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
458
|
-
return {
|
|
459
|
-
status: BB_RESULT.FAILURE,
|
|
460
|
-
reason: `Failed to verify proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
461
|
-
retry: !!result.signal,
|
|
462
|
-
};
|
|
463
|
-
} catch (error) {
|
|
464
|
-
return { status: BB_RESULT.FAILURE, reason: `${error}` };
|
|
465
|
-
}
|
|
475
|
+
const args = ['--scheme', 'chonk', '-p', proofPath, '-k', keyPath, '-v'];
|
|
476
|
+
return await verifyProofInternal(pathToBB, 'verify', args, logger, concurrency);
|
|
466
477
|
}
|
|
467
478
|
|
|
468
479
|
/**
|
|
469
480
|
* Used for verifying proofs with BB
|
|
470
481
|
* @param pathToBB - The full path to the bb binary
|
|
471
|
-
* @param proofFullPath - The full path to the proof to be verified
|
|
472
|
-
* @param verificationKeyPath - The full path to the circuit verification key
|
|
473
482
|
* @param command - The BB command to execute (verify/avm_verify)
|
|
474
|
-
* @param
|
|
483
|
+
* @param args - The arguments to pass to the command
|
|
484
|
+
* @param logger - A logger
|
|
485
|
+
* @param concurrency - The number of threads to use for the verification
|
|
475
486
|
* @returns An object containing a result indication and duration taken
|
|
476
487
|
*/
|
|
477
488
|
async function verifyProofInternal(
|
|
478
489
|
pathToBB: string,
|
|
479
|
-
proofFullPath: string,
|
|
480
|
-
verificationKeyPath: string,
|
|
481
490
|
command: 'verify' | 'avm_verify',
|
|
491
|
+
args: string[],
|
|
482
492
|
logger: Logger,
|
|
483
|
-
|
|
493
|
+
concurrency?: number,
|
|
484
494
|
): Promise<BBFailure | BBSuccess> {
|
|
485
495
|
const binaryPresent = await fs
|
|
486
496
|
.access(pathToBB, fs.constants.R_OK)
|
|
@@ -495,28 +505,12 @@ async function verifyProofInternal(
|
|
|
495
505
|
};
|
|
496
506
|
|
|
497
507
|
try {
|
|
498
|
-
let args;
|
|
499
|
-
|
|
500
|
-
if (command == 'verify') {
|
|
501
|
-
// Specify the public inputs path in the case of UH verification.
|
|
502
|
-
// Take proofFullPath and remove the suffix past the / to get the directory.
|
|
503
|
-
const proofDir = proofFullPath.substring(0, proofFullPath.lastIndexOf('/'));
|
|
504
|
-
const publicInputsFullPath = join(proofDir, '/public_inputs');
|
|
505
|
-
logger.debug(`public inputs path: ${publicInputsFullPath}`);
|
|
506
|
-
|
|
507
|
-
args = ['-p', proofFullPath, '-k', verificationKeyPath, '-i', publicInputsFullPath, '--disable_zk', ...extraArgs];
|
|
508
|
-
} else {
|
|
509
|
-
args = ['-p', proofFullPath, '-k', verificationKeyPath, ...extraArgs];
|
|
510
|
-
}
|
|
511
|
-
|
|
512
508
|
const loggingArg =
|
|
513
509
|
logger.level === 'debug' || logger.level === 'trace' ? '-d' : logger.level === 'verbose' ? '-v' : '';
|
|
514
|
-
|
|
515
|
-
args.push(loggingArg);
|
|
516
|
-
}
|
|
510
|
+
const finalArgs = loggingArg !== '' ? [...args, loggingArg] : args;
|
|
517
511
|
|
|
518
512
|
const timer = new Timer();
|
|
519
|
-
const result = await executeBB(pathToBB, command,
|
|
513
|
+
const result = await executeBB(pathToBB, command, finalArgs, logFunction, concurrency);
|
|
520
514
|
const duration = timer.ms();
|
|
521
515
|
if (result.status == BB_RESULT.SUCCESS) {
|
|
522
516
|
return { status: BB_RESULT.SUCCESS, durationMs: duration };
|
package/src/config.ts
CHANGED
|
@@ -3,8 +3,19 @@ export interface BBConfig {
|
|
|
3
3
|
bbWorkingDirectory: string;
|
|
4
4
|
/** Whether to skip tmp dir cleanup for debugging purposes */
|
|
5
5
|
bbSkipCleanup: boolean;
|
|
6
|
+
/** Max concurrent verifications for the RPC verifier (QueuedIVCVerifier). */
|
|
6
7
|
numConcurrentIVCVerifiers: number;
|
|
8
|
+
/** Thread count for the RPC IVC verifier. */
|
|
7
9
|
bbIVCConcurrency: number;
|
|
10
|
+
/**
|
|
11
|
+
* Upper bound on proofs per batch for the peer chonk batch verifier.
|
|
12
|
+
* Proofs are verified immediately as they arrive — this only caps how many
|
|
13
|
+
* can accumulate while a batch is already being processed.
|
|
14
|
+
* Default 16: at 4 cores, a full batch of 16 verifies in ~245ms wall time.
|
|
15
|
+
*/
|
|
16
|
+
bbChonkVerifyMaxBatch: number;
|
|
17
|
+
/** Thread count for the peer batch verifier parallel reduce. Default 6 to leave cores for the rest of the node. */
|
|
18
|
+
bbChonkVerifyConcurrency: number;
|
|
8
19
|
}
|
|
9
20
|
|
|
10
21
|
export interface ACVMConfig {
|
package/src/instrumentation.ts
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
Metrics,
|
|
8
8
|
type TelemetryClient,
|
|
9
9
|
type Tracer,
|
|
10
|
-
ValueType,
|
|
11
10
|
} from '@aztec/telemetry-client';
|
|
12
11
|
|
|
13
12
|
/**
|
|
@@ -31,51 +30,21 @@ export class ProverInstrumentation {
|
|
|
31
30
|
this.tracer = telemetry.getTracer(name);
|
|
32
31
|
const meter = telemetry.getMeter(name);
|
|
33
32
|
|
|
34
|
-
this.simulationDuration = meter.createHistogram(Metrics.CIRCUIT_SIMULATION_DURATION
|
|
35
|
-
description: 'Records how long it takes to simulate a circuit',
|
|
36
|
-
unit: 'ms',
|
|
37
|
-
valueType: ValueType.INT,
|
|
38
|
-
});
|
|
33
|
+
this.simulationDuration = meter.createHistogram(Metrics.CIRCUIT_SIMULATION_DURATION);
|
|
39
34
|
|
|
40
|
-
this.witGenDuration = meter.createHistogram(Metrics.CIRCUIT_WITNESS_GEN_DURATION
|
|
41
|
-
description: 'Records how long it takes to generate the partial witness for a circuit',
|
|
42
|
-
unit: 's',
|
|
43
|
-
valueType: ValueType.DOUBLE,
|
|
44
|
-
});
|
|
35
|
+
this.witGenDuration = meter.createHistogram(Metrics.CIRCUIT_WITNESS_GEN_DURATION);
|
|
45
36
|
|
|
46
|
-
this.provingDuration = meter.createHistogram(Metrics.CIRCUIT_PROVING_DURATION
|
|
47
|
-
unit: 's',
|
|
48
|
-
description: 'Records how long it takes to prove a circuit',
|
|
49
|
-
valueType: ValueType.DOUBLE,
|
|
50
|
-
});
|
|
37
|
+
this.provingDuration = meter.createHistogram(Metrics.CIRCUIT_PROVING_DURATION);
|
|
51
38
|
|
|
52
|
-
this.witGenInputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_INPUT_SIZE
|
|
53
|
-
unit: 'By',
|
|
54
|
-
description: 'Records the size of the input to the witness generation',
|
|
55
|
-
valueType: ValueType.INT,
|
|
56
|
-
});
|
|
39
|
+
this.witGenInputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_INPUT_SIZE);
|
|
57
40
|
|
|
58
|
-
this.witGenOutputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_OUTPUT_SIZE
|
|
59
|
-
unit: 'By',
|
|
60
|
-
description: 'Records the size of the output of the witness generation',
|
|
61
|
-
valueType: ValueType.INT,
|
|
62
|
-
});
|
|
41
|
+
this.witGenOutputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_OUTPUT_SIZE);
|
|
63
42
|
|
|
64
|
-
this.proofSize = meter.createGauge(Metrics.CIRCUIT_PROVING_PROOF_SIZE
|
|
65
|
-
unit: 'By',
|
|
66
|
-
description: 'Records the size of the proof generated for a circuit',
|
|
67
|
-
valueType: ValueType.INT,
|
|
68
|
-
});
|
|
43
|
+
this.proofSize = meter.createGauge(Metrics.CIRCUIT_PROVING_PROOF_SIZE);
|
|
69
44
|
|
|
70
|
-
this.circuitPublicInputCount = meter.createGauge(Metrics.CIRCUIT_PUBLIC_INPUTS_COUNT
|
|
71
|
-
description: 'Records the number of public inputs in a circuit',
|
|
72
|
-
valueType: ValueType.INT,
|
|
73
|
-
});
|
|
45
|
+
this.circuitPublicInputCount = meter.createGauge(Metrics.CIRCUIT_PUBLIC_INPUTS_COUNT);
|
|
74
46
|
|
|
75
|
-
this.circuitSize = meter.createGauge(Metrics.CIRCUIT_SIZE
|
|
76
|
-
description: 'Records the size of the circuit in gates',
|
|
77
|
-
valueType: ValueType.INT,
|
|
78
|
-
});
|
|
47
|
+
this.circuitSize = meter.createGauge(Metrics.CIRCUIT_SIZE);
|
|
79
48
|
}
|
|
80
49
|
|
|
81
50
|
/**
|
|
@@ -89,10 +58,18 @@ export class ProverInstrumentation {
|
|
|
89
58
|
circuitName: CircuitName,
|
|
90
59
|
timerOrMS: Timer | number,
|
|
91
60
|
) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
61
|
+
// Simulation duration is stored in ms, while the others are stored in seconds
|
|
62
|
+
if (metric === 'simulationDuration') {
|
|
63
|
+
const ms = typeof timerOrMS === 'number' ? timerOrMS : timerOrMS.ms();
|
|
64
|
+
this[metric].record(Math.trunc(ms), {
|
|
65
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
const s = typeof timerOrMS === 'number' ? timerOrMS / 1000 : timerOrMS.s();
|
|
69
|
+
this[metric].record(s, {
|
|
70
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
96
73
|
}
|
|
97
74
|
|
|
98
75
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AztecClientBackend, Barretenberg } from '@aztec/bb.js';
|
|
2
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
1
|
+
import { AztecClientBackend, type BackendOptions, Barretenberg } from '@aztec/bb.js';
|
|
2
|
+
import { type LogLevel, type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
4
|
import { serializeWitness } from '@aztec/noir-noirc_abi';
|
|
5
5
|
import {
|
|
@@ -45,12 +45,17 @@ import type { CircuitSimulationStats, CircuitWitnessGenerationStats } from '@azt
|
|
|
45
45
|
|
|
46
46
|
import { ungzip } from 'pako';
|
|
47
47
|
|
|
48
|
+
export type BBPrivateKernelProverOptions = Omit<BackendOptions, 'logger'> & { logger?: Logger };
|
|
48
49
|
export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
50
|
+
private log: Logger;
|
|
51
|
+
|
|
49
52
|
constructor(
|
|
50
53
|
protected artifactProvider: ArtifactProvider,
|
|
51
54
|
protected simulator: CircuitSimulator,
|
|
52
|
-
protected
|
|
53
|
-
) {
|
|
55
|
+
protected options: BBPrivateKernelProverOptions = {},
|
|
56
|
+
) {
|
|
57
|
+
this.log = options.logger || createLogger('bb-prover:private-kernel');
|
|
58
|
+
}
|
|
54
59
|
|
|
55
60
|
public async generateInitOutput(
|
|
56
61
|
inputs: PrivateKernelInitCircuitPrivateInputs,
|
|
@@ -271,26 +276,47 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
|
|
|
271
276
|
public async createChonkProof(executionSteps: PrivateExecutionStep[]): Promise<ChonkProofWithPublicInputs> {
|
|
272
277
|
const timer = new Timer();
|
|
273
278
|
this.log.info(`Generating ClientIVC proof...`);
|
|
279
|
+
const barretenberg = await Barretenberg.initSingleton({
|
|
280
|
+
...this.options,
|
|
281
|
+
logger: this.options.logger?.verbose,
|
|
282
|
+
});
|
|
274
283
|
const backend = new AztecClientBackend(
|
|
275
284
|
executionSteps.map(step => ungzip(step.bytecode)),
|
|
276
|
-
|
|
285
|
+
barretenberg,
|
|
286
|
+
executionSteps.map(step => step.functionName),
|
|
277
287
|
);
|
|
278
288
|
|
|
279
|
-
|
|
289
|
+
// Use compressed prove path to get both proof fields and compressed proof bytes
|
|
290
|
+
const result = await backend.prove(
|
|
280
291
|
executionSteps.map(step => ungzip(serializeWitness(step.witness))),
|
|
281
292
|
executionSteps.map(step => step.vk),
|
|
293
|
+
{ compress: true },
|
|
282
294
|
);
|
|
283
295
|
this.log.info(`Generated ClientIVC proof`, {
|
|
284
296
|
eventName: 'client-ivc-proof-generation',
|
|
285
297
|
duration: timer.ms(),
|
|
286
|
-
proofSize:
|
|
298
|
+
proofSize: result.proofFields.length,
|
|
299
|
+
compressedSize: result.compressedProof?.length,
|
|
287
300
|
});
|
|
288
|
-
|
|
301
|
+
|
|
302
|
+
// Create ChonkProofWithPublicInputs from the flat field elements
|
|
303
|
+
const proofWithPubInputs = ChonkProofWithPublicInputs.fromBufferArray(result.proofFields);
|
|
304
|
+
|
|
305
|
+
// Attach compressed proof bytes to the ChonkProof (without public inputs).
|
|
306
|
+
// The compressed bytes are for the full proof WITH public inputs from bb;
|
|
307
|
+
// when deserializing, the decompressor will strip them to match CHONK_PROOF_LENGTH.
|
|
308
|
+
proofWithPubInputs.compressedProof = result.compressedProof ? Buffer.from(result.compressedProof) : undefined;
|
|
309
|
+
|
|
310
|
+
return proofWithPubInputs;
|
|
289
311
|
}
|
|
290
312
|
|
|
291
313
|
public async computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
|
|
292
314
|
// Note we do not pass the vk to the backend. This is unneeded for gate counts.
|
|
293
|
-
const
|
|
315
|
+
const barretenberg = await Barretenberg.initSingleton({
|
|
316
|
+
...this.options,
|
|
317
|
+
logger: this.options.logger?.[(process.env.LOG_LEVEL as LogLevel) || 'verbose'],
|
|
318
|
+
});
|
|
319
|
+
const backend = new AztecClientBackend([ungzip(_bytecode)], barretenberg, [_circuitName]);
|
|
294
320
|
const gateCount = await backend.gates();
|
|
295
321
|
return gateCount[0];
|
|
296
322
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
2
1
|
import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
|
|
3
2
|
import type { CircuitSimulator } from '@aztec/simulator/client';
|
|
4
3
|
|
|
5
|
-
import { BBPrivateKernelProver } from './bb_private_kernel_prover.js';
|
|
4
|
+
import { BBPrivateKernelProver, type BBPrivateKernelProverOptions } from './bb_private_kernel_prover.js';
|
|
6
5
|
|
|
7
6
|
export class BBBundlePrivateKernelProver extends BBPrivateKernelProver {
|
|
8
|
-
constructor(simulator: CircuitSimulator,
|
|
9
|
-
super(new BundleArtifactProvider(), simulator,
|
|
7
|
+
constructor(simulator: CircuitSimulator, options: BBPrivateKernelProverOptions = {}) {
|
|
8
|
+
super(new BundleArtifactProvider(), simulator, options);
|
|
10
9
|
}
|
|
11
10
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
2
1
|
import { LazyArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/lazy';
|
|
3
2
|
import type { CircuitSimulator } from '@aztec/simulator/client';
|
|
4
3
|
|
|
5
|
-
import { BBPrivateKernelProver } from './bb_private_kernel_prover.js';
|
|
4
|
+
import { BBPrivateKernelProver, type BBPrivateKernelProverOptions } from './bb_private_kernel_prover.js';
|
|
6
5
|
|
|
7
6
|
export class BBLazyPrivateKernelProver extends BBPrivateKernelProver {
|
|
8
|
-
constructor(simulator: CircuitSimulator,
|
|
9
|
-
super(new LazyArtifactProvider(), simulator,
|
|
7
|
+
constructor(simulator: CircuitSimulator, options: BBPrivateKernelProverOptions = {}) {
|
|
8
|
+
super(new LazyArtifactProvider(), simulator, options);
|
|
10
9
|
}
|
|
11
10
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
PAIRING_POINTS_SIZE,
|
|
8
8
|
ULTRA_KECCAK_PROOF_LENGTH,
|
|
9
9
|
} from '@aztec/constants';
|
|
10
|
-
import { Fr } from '@aztec/foundation/
|
|
10
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
11
11
|
import type { Logger } from '@aztec/foundation/log';
|
|
12
12
|
import { ChonkProofWithPublicInputs, Proof, RecursiveProof } from '@aztec/stdlib/proofs';
|
|
13
13
|
import type { VerificationKeyData } from '@aztec/stdlib/vks';
|