@aztec/bb-prover 0.0.1-commit.24de95ac → 0.0.1-commit.2606882

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.
Files changed (108) hide show
  1. package/dest/avm_proving_tests/avm_proving_tester.d.ts +15 -11
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +167 -108
  4. package/dest/bb/bb_js_backend.d.ts +196 -0
  5. package/dest/bb/bb_js_backend.d.ts.map +1 -0
  6. package/dest/bb/bb_js_backend.js +379 -0
  7. package/dest/bb/bb_js_debug.d.ts +52 -0
  8. package/dest/bb/bb_js_debug.d.ts.map +1 -0
  9. package/dest/bb/bb_js_debug.js +176 -0
  10. package/dest/bb/cli.d.ts +1 -1
  11. package/dest/bb/file_names.d.ts +4 -0
  12. package/dest/bb/file_names.d.ts.map +1 -0
  13. package/dest/bb/file_names.js +5 -0
  14. package/dest/bb/index.d.ts +1 -1
  15. package/dest/config.d.ts +17 -1
  16. package/dest/config.d.ts.map +1 -1
  17. package/dest/honk.d.ts +1 -1
  18. package/dest/index.d.ts +3 -2
  19. package/dest/index.d.ts.map +1 -1
  20. package/dest/index.js +2 -1
  21. package/dest/instrumentation.d.ts +1 -1
  22. package/dest/instrumentation.d.ts.map +1 -1
  23. package/dest/instrumentation.js +21 -43
  24. package/dest/prover/client/bb_private_kernel_prover.d.ts +20 -6
  25. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
  26. package/dest/prover/client/bb_private_kernel_prover.js +73 -8
  27. package/dest/prover/client/bundle.d.ts +6 -0
  28. package/dest/prover/client/bundle.d.ts.map +1 -0
  29. package/dest/prover/client/bundle.js +7 -0
  30. package/dest/prover/client/lazy.d.ts +6 -0
  31. package/dest/prover/client/lazy.d.ts.map +1 -0
  32. package/dest/prover/client/lazy.js +7 -0
  33. package/dest/prover/index.d.ts +1 -1
  34. package/dest/prover/proof_utils.d.ts +11 -1
  35. package/dest/prover/proof_utils.d.ts.map +1 -1
  36. package/dest/prover/proof_utils.js +25 -2
  37. package/dest/prover/server/bb_prover.d.ts +8 -21
  38. package/dest/prover/server/bb_prover.d.ts.map +1 -1
  39. package/dest/prover/server/bb_prover.js +614 -112
  40. package/dest/test/delay_values.d.ts +1 -1
  41. package/dest/test/delay_values.d.ts.map +1 -1
  42. package/dest/test/delay_values.js +29 -27
  43. package/dest/test/index.d.ts +2 -1
  44. package/dest/test/index.d.ts.map +1 -1
  45. package/dest/test/index.js +1 -0
  46. package/dest/test/test_circuit_prover.d.ts +4 -4
  47. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  48. package/dest/test/test_circuit_prover.js +462 -59
  49. package/dest/test/test_verifier.d.ts +3 -1
  50. package/dest/test/test_verifier.d.ts.map +1 -1
  51. package/dest/test/test_verifier.js +15 -0
  52. package/dest/verification_key/verification_key_data.d.ts +1 -8
  53. package/dest/verification_key/verification_key_data.d.ts.map +1 -1
  54. package/dest/verification_key/verification_key_data.js +2 -21
  55. package/dest/verifier/batch_chonk_verifier.d.ts +56 -0
  56. package/dest/verifier/batch_chonk_verifier.d.ts.map +1 -0
  57. package/dest/verifier/batch_chonk_verifier.js +384 -0
  58. package/dest/verifier/bb_verifier.d.ts +4 -1
  59. package/dest/verifier/bb_verifier.d.ts.map +1 -1
  60. package/dest/verifier/bb_verifier.js +137 -48
  61. package/dest/verifier/index.d.ts +2 -1
  62. package/dest/verifier/index.d.ts.map +1 -1
  63. package/dest/verifier/index.js +1 -0
  64. package/dest/verifier/queued_chonk_verifier.d.ts +2 -3
  65. package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -1
  66. package/dest/verifier/queued_chonk_verifier.js +15 -45
  67. package/package.json +26 -23
  68. package/src/avm_proving_tests/avm_proving_tester.ts +69 -138
  69. package/src/bb/bb_js_backend.ts +435 -0
  70. package/src/bb/bb_js_debug.ts +227 -0
  71. package/src/bb/file_names.ts +6 -0
  72. package/src/config.ts +16 -0
  73. package/src/index.ts +2 -1
  74. package/src/instrumentation.ts +20 -43
  75. package/src/prover/client/bb_private_kernel_prover.ts +158 -8
  76. package/src/prover/client/bundle.ts +10 -0
  77. package/src/prover/client/lazy.ts +10 -0
  78. package/src/prover/proof_utils.ts +42 -2
  79. package/src/prover/server/bb_prover.ts +139 -159
  80. package/src/test/delay_values.ts +31 -27
  81. package/src/test/index.ts +1 -0
  82. package/src/test/test_circuit_prover.ts +10 -13
  83. package/src/test/test_verifier.ts +8 -0
  84. package/src/verification_key/verification_key_data.ts +2 -27
  85. package/src/verifier/batch_chonk_verifier.ts +415 -0
  86. package/src/verifier/bb_verifier.ts +69 -80
  87. package/src/verifier/index.ts +1 -0
  88. package/src/verifier/queued_chonk_verifier.ts +15 -47
  89. package/dest/bb/execute.d.ts +0 -107
  90. package/dest/bb/execute.d.ts.map +0 -1
  91. package/dest/bb/execute.js +0 -672
  92. package/dest/prover/client/native/bb_native_private_kernel_prover.d.ts +0 -23
  93. package/dest/prover/client/native/bb_native_private_kernel_prover.d.ts.map +0 -1
  94. package/dest/prover/client/native/bb_native_private_kernel_prover.js +0 -66
  95. package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.d.ts +0 -15
  96. package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.d.ts.map +0 -1
  97. package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.js +0 -46
  98. package/dest/prover/client/wasm/bundle.d.ts +0 -6
  99. package/dest/prover/client/wasm/bundle.d.ts.map +0 -1
  100. package/dest/prover/client/wasm/bundle.js +0 -8
  101. package/dest/prover/client/wasm/lazy.d.ts +0 -6
  102. package/dest/prover/client/wasm/lazy.d.ts.map +0 -1
  103. package/dest/prover/client/wasm/lazy.js +0 -8
  104. package/src/bb/execute.ts +0 -709
  105. package/src/prover/client/native/bb_native_private_kernel_prover.ts +0 -105
  106. package/src/prover/client/wasm/bb_wasm_private_kernel_prover.ts +0 -58
  107. package/src/prover/client/wasm/bundle.ts +0 -11
  108. package/src/prover/client/wasm/lazy.ts +0 -11
@@ -1,672 +0,0 @@
1
- import { sha256 } from '@aztec/foundation/crypto';
2
- import { Timer } from '@aztec/foundation/timer';
3
- import * as proc from 'child_process';
4
- import { promises as fs } from 'fs';
5
- import { basename, dirname, join } from 'path';
6
- export const VK_FILENAME = 'vk';
7
- export const PUBLIC_INPUTS_FILENAME = 'public_inputs';
8
- export const PROOF_FILENAME = 'proof';
9
- export const AVM_INPUTS_FILENAME = 'avm_inputs.bin';
10
- export const AVM_BYTECODE_FILENAME = 'avm_bytecode.bin';
11
- export const AVM_PUBLIC_INPUTS_FILENAME = 'avm_public_inputs.bin';
12
- export var BB_RESULT = /*#__PURE__*/ function(BB_RESULT) {
13
- BB_RESULT[BB_RESULT["SUCCESS"] = 0] = "SUCCESS";
14
- BB_RESULT[BB_RESULT["FAILURE"] = 1] = "FAILURE";
15
- BB_RESULT[BB_RESULT["ALREADY_PRESENT"] = 2] = "ALREADY_PRESENT";
16
- return BB_RESULT;
17
- }({});
18
- /**
19
- * Invokes the Barretenberg binary with the provided command and args
20
- * @param pathToBB - The path to the BB binary
21
- * @param command - The command to execute
22
- * @param args - The arguments to pass
23
- * @param logger - A log function
24
- * @param timeout - An optional timeout before killing the BB process
25
- * @param resultParser - An optional handler for detecting success or failure
26
- * @returns The completed partial witness outputted from the circuit
27
- */ export function executeBB(pathToBB, command, args, logger, concurrency, timeout, resultParser = (code)=>code === 0) {
28
- return new Promise((resolve)=>{
29
- // spawn the bb process
30
- const { HARDWARE_CONCURRENCY: _, ...envWithoutConcurrency } = process.env;
31
- const env = envWithoutConcurrency;
32
- // We prioritise the concurrency argument if provided and > 0
33
- if (concurrency && concurrency > 0) {
34
- env.HARDWARE_CONCURRENCY = concurrency.toString();
35
- } else if (process.env.HARDWARE_CONCURRENCY) {
36
- env.HARDWARE_CONCURRENCY = process.env.HARDWARE_CONCURRENCY;
37
- }
38
- logger(`BB concurrency: ${env.HARDWARE_CONCURRENCY}`);
39
- logger(`Executing BB with: ${pathToBB} ${command} ${args.join(' ')}`);
40
- const bb = proc.spawn(pathToBB, [
41
- command,
42
- ...args
43
- ], {
44
- env
45
- });
46
- let timeoutId;
47
- if (timeout !== undefined) {
48
- timeoutId = setTimeout(()=>{
49
- logger(`BB execution timed out after ${timeout}ms, killing process`);
50
- if (bb.pid) {
51
- bb.kill('SIGKILL');
52
- }
53
- resolve({
54
- status: 1,
55
- exitCode: -1,
56
- signal: 'TIMEOUT'
57
- });
58
- }, timeout);
59
- }
60
- bb.stdout.on('data', (data)=>{
61
- const message = data.toString('utf-8').replace(/\n$/, '');
62
- logger(message);
63
- });
64
- bb.stderr.on('data', (data)=>{
65
- const message = data.toString('utf-8').replace(/\n$/, '');
66
- logger(message);
67
- });
68
- bb.on('close', (exitCode, signal)=>{
69
- if (timeoutId) {
70
- clearTimeout(timeoutId);
71
- }
72
- if (resultParser(exitCode)) {
73
- resolve({
74
- status: 0,
75
- exitCode,
76
- signal
77
- });
78
- } else {
79
- resolve({
80
- status: 1,
81
- exitCode,
82
- signal
83
- });
84
- }
85
- });
86
- }).catch((_)=>({
87
- status: 1,
88
- exitCode: -1,
89
- signal: undefined
90
- }));
91
- }
92
- export async function executeBbChonkProof(pathToBB, workingDirectory, inputsPath, log, writeVk = false) {
93
- // Check that the working directory exists
94
- try {
95
- await fs.access(workingDirectory);
96
- } catch {
97
- return {
98
- status: 1,
99
- reason: `Working directory ${workingDirectory} does not exist`
100
- };
101
- }
102
- // The proof is written to e.g. /workingDirectory/proof
103
- const outputPath = `${workingDirectory}`;
104
- const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
105
- if (!binaryPresent) {
106
- return {
107
- status: 1,
108
- reason: `Failed to find bb binary at ${pathToBB}`
109
- };
110
- }
111
- try {
112
- // Write the bytecode to the working directory
113
- log(`inputsPath ${inputsPath}`);
114
- const timer = new Timer();
115
- const logFunction = (message)=>{
116
- log(`bb - ${message}`);
117
- };
118
- const args = [
119
- '-o',
120
- outputPath,
121
- '--ivc_inputs_path',
122
- inputsPath,
123
- '-v',
124
- '--scheme',
125
- 'chonk'
126
- ];
127
- if (writeVk) {
128
- args.push('--write_vk');
129
- }
130
- const result = await executeBB(pathToBB, 'prove', args, logFunction);
131
- const durationMs = timer.ms();
132
- if (result.status == 0) {
133
- return {
134
- status: 0,
135
- durationMs,
136
- proofPath: `${outputPath}`,
137
- pkPath: undefined,
138
- vkDirectoryPath: `${outputPath}`
139
- };
140
- }
141
- // Not a great error message here but it is difficult to decipher what comes from bb
142
- return {
143
- status: 1,
144
- reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
145
- retry: !!result.signal
146
- };
147
- } catch (error) {
148
- return {
149
- status: 1,
150
- reason: `${error}`
151
- };
152
- }
153
- }
154
- function getArgs(flavor) {
155
- switch(flavor){
156
- case 'ultra_honk':
157
- {
158
- return [
159
- '--scheme',
160
- 'ultra_honk',
161
- '--oracle_hash',
162
- 'poseidon2'
163
- ];
164
- }
165
- case 'ultra_keccak_honk':
166
- {
167
- return [
168
- '--scheme',
169
- 'ultra_honk',
170
- '--oracle_hash',
171
- 'keccak'
172
- ];
173
- }
174
- case 'ultra_starknet_honk':
175
- {
176
- return [
177
- '--scheme',
178
- 'ultra_honk',
179
- '--oracle_hash',
180
- 'starknet'
181
- ];
182
- }
183
- case 'ultra_rollup_honk':
184
- {
185
- return [
186
- '--scheme',
187
- 'ultra_honk',
188
- '--oracle_hash',
189
- 'poseidon2',
190
- '--ipa_accumulation'
191
- ];
192
- }
193
- }
194
- }
195
- /**
196
- * Used for generating proofs of noir circuits.
197
- * It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
198
- * @param pathToBB - The full path to the bb binary
199
- * @param workingDirectory - A working directory for use by bb
200
- * @param circuitName - An identifier for the circuit
201
- * @param bytecode - The compiled circuit bytecode
202
- * @param inputWitnessFile - The circuit input witness
203
- * @param log - A logging function
204
- * @returns An object containing a result indication, the location of the proof and the duration taken
205
- */ export async function generateProof(pathToBB, workingDirectory, circuitName, bytecode, verificationKey, inputWitnessFile, flavor, log) {
206
- // Check that the working directory exists
207
- try {
208
- await fs.access(workingDirectory);
209
- } catch {
210
- return {
211
- status: 1,
212
- reason: `Working directory ${workingDirectory} does not exist`
213
- };
214
- }
215
- // The bytecode is written to e.g. /workingDirectory/ParityBaseArtifact-bytecode
216
- const bytecodePath = `${workingDirectory}/${circuitName}-bytecode`;
217
- const vkPath = `${workingDirectory}/${circuitName}-vk`;
218
- // The proof is written to e.g. /workingDirectory/ultra_honk/proof
219
- const outputPath = `${workingDirectory}`;
220
- const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
221
- if (!binaryPresent) {
222
- return {
223
- status: 1,
224
- reason: `Failed to find bb binary at ${pathToBB}`
225
- };
226
- }
227
- try {
228
- // Write the bytecode and vk to the working directory
229
- await Promise.all([
230
- fs.writeFile(bytecodePath, bytecode),
231
- fs.writeFile(vkPath, verificationKey)
232
- ]);
233
- const args = getArgs(flavor).concat([
234
- '--disable_zk',
235
- '-o',
236
- outputPath,
237
- '-b',
238
- bytecodePath,
239
- '-k',
240
- vkPath,
241
- '-w',
242
- inputWitnessFile,
243
- '-v'
244
- ]);
245
- const loggingArg = log.level === 'debug' || log.level === 'trace' ? '-d' : log.level === 'verbose' ? '-v' : '';
246
- if (loggingArg !== '') {
247
- args.push(loggingArg);
248
- }
249
- const timer = new Timer();
250
- const logFunction = (message)=>{
251
- log.info(`${circuitName} BB out - ${message}`);
252
- };
253
- const result = await executeBB(pathToBB, `prove`, args, logFunction);
254
- const duration = timer.ms();
255
- if (result.status == 0) {
256
- return {
257
- status: 0,
258
- durationMs: duration,
259
- proofPath: `${outputPath}`,
260
- pkPath: undefined,
261
- vkDirectoryPath: `${outputPath}`
262
- };
263
- }
264
- // Not a great error message here but it is difficult to decipher what comes from bb
265
- return {
266
- status: 1,
267
- reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
268
- retry: !!result.signal
269
- };
270
- } catch (error) {
271
- return {
272
- status: 1,
273
- reason: `${error}`
274
- };
275
- }
276
- }
277
- /**
278
- * Used for generating AVM proofs.
279
- * It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
280
- * @param pathToBB - The full path to the bb binary
281
- * @param workingDirectory - A working directory for use by bb
282
- * @param input - The inputs for the public function to be proven
283
- * @param logger - A logging function
284
- * @param checkCircuitOnly - A boolean to toggle a "check-circuit only" operation instead of proving.
285
- * @returns An object containing a result indication, the location of the proof and the duration taken
286
- */ export async function generateAvmProof(pathToBB, workingDirectory, input, logger, checkCircuitOnly = false) {
287
- // Check that the working directory exists
288
- try {
289
- await fs.access(workingDirectory);
290
- } catch {
291
- return {
292
- status: 1,
293
- reason: `Working directory ${workingDirectory} does not exist`
294
- };
295
- }
296
- // The proof is written to e.g. /workingDirectory/proof
297
- const outputPath = workingDirectory;
298
- const filePresent = async (file)=>await fs.access(file, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
299
- const binaryPresent = await filePresent(pathToBB);
300
- if (!binaryPresent) {
301
- return {
302
- status: 1,
303
- reason: `Failed to find bb binary at ${pathToBB}`
304
- };
305
- }
306
- const inputsBuffer = input.serializeWithMessagePack();
307
- try {
308
- // Write the inputs to the working directory.
309
- const avmInputsPath = join(workingDirectory, AVM_INPUTS_FILENAME);
310
- await fs.writeFile(avmInputsPath, inputsBuffer);
311
- if (!await filePresent(avmInputsPath)) {
312
- return {
313
- status: 1,
314
- reason: `Could not write avm inputs to ${avmInputsPath}`
315
- };
316
- }
317
- const args = checkCircuitOnly ? [
318
- '--avm-inputs',
319
- avmInputsPath
320
- ] : [
321
- '--avm-inputs',
322
- avmInputsPath,
323
- '-o',
324
- outputPath
325
- ];
326
- const loggingArg = logger.level === 'debug' || logger.level === 'trace' ? '-d' : logger.level === 'verbose' ? '-v' : '';
327
- if (loggingArg !== '') {
328
- args.push(loggingArg);
329
- }
330
- const timer = new Timer();
331
- const cmd = checkCircuitOnly ? 'avm_check_circuit' : 'avm_prove';
332
- const logFunction = (message)=>{
333
- logger.verbose(`AvmCircuit (${cmd}) BB out - ${message}`);
334
- };
335
- const result = await executeBB(pathToBB, cmd, args, logFunction);
336
- const duration = timer.ms();
337
- if (result.status == 0) {
338
- return {
339
- status: 0,
340
- durationMs: duration,
341
- proofPath: join(outputPath, PROOF_FILENAME),
342
- pkPath: undefined,
343
- vkDirectoryPath: outputPath
344
- };
345
- }
346
- // Not a great error message here but it is difficult to decipher what comes from bb
347
- return {
348
- status: 1,
349
- reason: `Failed to generate proof. AVM proof for TX hash ${input.hints.tx.hash}. Exit code ${result.exitCode}. Signal ${result.signal}.`,
350
- retry: result.signal === 'SIGKILL'
351
- };
352
- } catch (error) {
353
- return {
354
- status: 1,
355
- reason: `${error}`
356
- };
357
- }
358
- }
359
- /**
360
- * Used for verifying proofs of noir circuits
361
- * @param pathToBB - The full path to the bb binary
362
- * @param proofFullPath - The full path to the proof to be verified
363
- * @param verificationKeyPath - The full path to the circuit verification key
364
- * @param log - A logging function
365
- * @returns An object containing a result indication and duration taken
366
- */ export async function verifyProof(pathToBB, proofFullPath, verificationKeyPath, ultraHonkFlavor, log) {
367
- return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, `verify`, log, getArgs(ultraHonkFlavor));
368
- }
369
- export async function verifyAvmProof(pathToBB, workingDirectory, proofFullPath, publicInputs, verificationKeyPath, logger) {
370
- const inputsBuffer = publicInputs.serializeWithMessagePack();
371
- // Write the inputs to the working directory.
372
- const filePresent = async (file)=>await fs.access(file, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
373
- const avmInputsPath = join(workingDirectory, 'avm_public_inputs.bin');
374
- await fs.writeFile(avmInputsPath, inputsBuffer);
375
- if (!await filePresent(avmInputsPath)) {
376
- return {
377
- status: 1,
378
- reason: `Could not write avm inputs to ${avmInputsPath}`
379
- };
380
- }
381
- return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, 'avm_verify', logger, [
382
- '--avm-public-inputs',
383
- avmInputsPath
384
- ]);
385
- }
386
- /**
387
- * Verifies a ChonkProof
388
- * TODO(#7370) The verification keys should be supplied separately
389
- * @param pathToBB - The full path to the bb binary
390
- * @param targetPath - The path to the folder with the proof, accumulator, and verification keys
391
- * @param log - A logging function
392
- * @param concurrency - The number of threads to use for the verification
393
- * @returns An object containing a result indication and duration taken
394
- */ export async function verifyChonkProof(pathToBB, proofPath, keyPath, log, concurrency = 1) {
395
- const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
396
- if (!binaryPresent) {
397
- return {
398
- status: 1,
399
- reason: `Failed to find bb binary at ${pathToBB}`
400
- };
401
- }
402
- try {
403
- const args = [
404
- '--scheme',
405
- 'chonk',
406
- '-p',
407
- proofPath,
408
- '-k',
409
- keyPath,
410
- '-v'
411
- ];
412
- const timer = new Timer();
413
- const command = 'verify';
414
- const result = await executeBB(pathToBB, command, args, log, concurrency);
415
- const duration = timer.ms();
416
- if (result.status == 0) {
417
- return {
418
- status: 0,
419
- durationMs: duration
420
- };
421
- }
422
- // Not a great error message here but it is difficult to decipher what comes from bb
423
- return {
424
- status: 1,
425
- reason: `Failed to verify proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
426
- retry: !!result.signal
427
- };
428
- } catch (error) {
429
- return {
430
- status: 1,
431
- reason: `${error}`
432
- };
433
- }
434
- }
435
- /**
436
- * Used for verifying proofs with BB
437
- * @param pathToBB - The full path to the bb binary
438
- * @param proofFullPath - The full path to the proof to be verified
439
- * @param verificationKeyPath - The full path to the circuit verification key
440
- * @param command - The BB command to execute (verify/avm_verify)
441
- * @param log - A logging function
442
- * @returns An object containing a result indication and duration taken
443
- */ async function verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, command, logger, extraArgs = []) {
444
- const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
445
- if (!binaryPresent) {
446
- return {
447
- status: 1,
448
- reason: `Failed to find bb binary at ${pathToBB}`
449
- };
450
- }
451
- const logFunction = (message)=>{
452
- logger.verbose(`bb-prover (verify) BB out - ${message}`);
453
- };
454
- try {
455
- let args;
456
- if (command == 'verify') {
457
- // Specify the public inputs path in the case of UH verification.
458
- // Take proofFullPath and remove the suffix past the / to get the directory.
459
- const proofDir = proofFullPath.substring(0, proofFullPath.lastIndexOf('/'));
460
- const publicInputsFullPath = join(proofDir, '/public_inputs');
461
- logger.debug(`public inputs path: ${publicInputsFullPath}`);
462
- args = [
463
- '-p',
464
- proofFullPath,
465
- '-k',
466
- verificationKeyPath,
467
- '-i',
468
- publicInputsFullPath,
469
- '--disable_zk',
470
- ...extraArgs
471
- ];
472
- } else {
473
- args = [
474
- '-p',
475
- proofFullPath,
476
- '-k',
477
- verificationKeyPath,
478
- ...extraArgs
479
- ];
480
- }
481
- const loggingArg = logger.level === 'debug' || logger.level === 'trace' ? '-d' : logger.level === 'verbose' ? '-v' : '';
482
- if (loggingArg !== '') {
483
- args.push(loggingArg);
484
- }
485
- const timer = new Timer();
486
- const result = await executeBB(pathToBB, command, args, logFunction);
487
- const duration = timer.ms();
488
- if (result.status == 0) {
489
- return {
490
- status: 0,
491
- durationMs: duration
492
- };
493
- }
494
- // Not a great error message here but it is difficult to decipher what comes from bb
495
- return {
496
- status: 1,
497
- reason: `Failed to verify proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
498
- retry: !!result.signal
499
- };
500
- } catch (error) {
501
- return {
502
- status: 1,
503
- reason: `${error}`
504
- };
505
- }
506
- }
507
- export async function generateContractForVerificationKey(pathToBB, vkFilePath, contractPath, log) {
508
- const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
509
- if (!binaryPresent) {
510
- return {
511
- status: 1,
512
- reason: `Failed to find bb binary at ${pathToBB}`
513
- };
514
- }
515
- const outputDir = dirname(contractPath);
516
- const contractName = basename(contractPath);
517
- // cache contract generation based on vk file and contract name
518
- const cacheKey = sha256(Buffer.concat([
519
- Buffer.from(contractName),
520
- await fs.readFile(vkFilePath)
521
- ]));
522
- await fs.mkdir(outputDir, {
523
- recursive: true
524
- });
525
- const res = await fsCache(outputDir, cacheKey, log, false, async ()=>{
526
- try {
527
- const args = [
528
- '--scheme',
529
- 'ultra_honk',
530
- '-k',
531
- vkFilePath,
532
- '-o',
533
- contractPath,
534
- '-v'
535
- ];
536
- const timer = new Timer();
537
- const result = await executeBB(pathToBB, 'contract', args, log);
538
- const duration = timer.ms();
539
- if (result.status == 0) {
540
- return {
541
- status: 0,
542
- durationMs: duration,
543
- contractPath
544
- };
545
- }
546
- // Not a great error message here but it is difficult to decipher what comes from bb
547
- return {
548
- status: 1,
549
- reason: `Failed to write verifier contract. Exit code ${result.exitCode}. Signal ${result.signal}.`,
550
- retry: !!result.signal
551
- };
552
- } catch (error) {
553
- return {
554
- status: 1,
555
- reason: `${error}`
556
- };
557
- }
558
- });
559
- if (!res) {
560
- return {
561
- status: 2,
562
- durationMs: 0,
563
- contractPath
564
- };
565
- }
566
- return res;
567
- }
568
- /**
569
- * Compute bb gate count for a given circuit
570
- * @param pathToBB - The full path to the bb binary
571
- * @param workingDirectory - A temporary directory for writing the bytecode
572
- * @param circuitName - The name of the circuit
573
- * @param bytecode - The bytecode of the circuit
574
- * @param flavor - The flavor of the backend - mega_honk or ultra_honk variants
575
- * @returns An object containing the status, gate count, and time taken
576
- */ export async function computeGateCountForCircuit(pathToBB, workingDirectory, circuitName, bytecode, flavor, log) {
577
- // Check that the working directory exists
578
- try {
579
- await fs.access(workingDirectory);
580
- } catch {
581
- return {
582
- status: 1,
583
- reason: `Working directory ${workingDirectory} does not exist`
584
- };
585
- }
586
- // The bytecode is written to e.g. /workingDirectory/ParityBaseArtifact-bytecode
587
- const bytecodePath = `${workingDirectory}/${circuitName}-bytecode`;
588
- const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
589
- if (!binaryPresent) {
590
- return {
591
- status: 1,
592
- reason: `Failed to find bb binary at ${pathToBB}`
593
- };
594
- }
595
- // Accumulate the stdout from bb
596
- let stdout = '';
597
- const logHandler = (message)=>{
598
- stdout += message;
599
- log(message);
600
- };
601
- try {
602
- // Write the bytecode to the working directory
603
- await fs.writeFile(bytecodePath, bytecode);
604
- const timer = new Timer();
605
- const result = await executeBB(pathToBB, 'gates', [
606
- '--scheme',
607
- flavor === 'mega_honk' ? 'chonk' : 'ultra_honk',
608
- '-b',
609
- bytecodePath,
610
- '-v'
611
- ], logHandler);
612
- const duration = timer.ms();
613
- if (result.status == 0) {
614
- // Look for "circuit_size" in the stdout and parse the number
615
- const circuitSizeMatch = stdout.match(/circuit_size": (\d+)/);
616
- if (!circuitSizeMatch) {
617
- return {
618
- status: 1,
619
- reason: 'Failed to parse circuit_size from bb gates stdout.'
620
- };
621
- }
622
- const circuitSize = parseInt(circuitSizeMatch[1]);
623
- return {
624
- status: 0,
625
- durationMs: duration,
626
- circuitSize: circuitSize
627
- };
628
- }
629
- return {
630
- status: 1,
631
- reason: 'Failed getting the gate count.'
632
- };
633
- } catch (error) {
634
- return {
635
- status: 1,
636
- reason: `${error}`
637
- };
638
- }
639
- }
640
- const CACHE_FILENAME = '.cache';
641
- async function fsCache(dir, expectedCacheKey, logger, force, action) {
642
- const cacheFilePath = join(dir, CACHE_FILENAME);
643
- let run;
644
- if (force) {
645
- run = true;
646
- } else {
647
- try {
648
- run = !expectedCacheKey.equals(await fs.readFile(cacheFilePath));
649
- } catch (err) {
650
- if (err && 'code' in err && err.code === 'ENOENT') {
651
- // cache file doesn't exist, swallow error and run
652
- run = true;
653
- } else {
654
- throw err;
655
- }
656
- }
657
- }
658
- let res;
659
- if (run) {
660
- logger(`Cache miss or forced run. Running operation in ${dir}...`);
661
- res = await action();
662
- } else {
663
- logger(`Cache hit. Skipping operation in ${dir}...`);
664
- }
665
- try {
666
- await fs.writeFile(cacheFilePath, expectedCacheKey);
667
- } catch {
668
- logger(`Couldn't write cache data to ${cacheFilePath}. Skipping cache...`);
669
- // ignore
670
- }
671
- return res;
672
- }
@@ -1,23 +0,0 @@
1
- import { type Logger } from '@aztec/foundation/log';
2
- import type { CircuitSimulator } from '@aztec/simulator/server';
3
- import { type PrivateExecutionStep } from '@aztec/stdlib/kernel';
4
- import type { ChonkProofWithPublicInputs } from '@aztec/stdlib/proofs';
5
- import type { BBConfig } from '../../../config.js';
6
- import { BBPrivateKernelProver } from '../bb_private_kernel_prover.js';
7
- /**
8
- * This proof creator implementation uses the native bb binary.
9
- */
10
- export declare class BBNativePrivateKernelProver extends BBPrivateKernelProver {
11
- private bbBinaryPath;
12
- private bbWorkingDirectory;
13
- private skipCleanup;
14
- protected simulator: CircuitSimulator;
15
- protected log: Logger;
16
- private constructor();
17
- static new(config: BBConfig, simulator: CircuitSimulator, log?: Logger): Promise<BBNativePrivateKernelProver>;
18
- private _createChonkProof;
19
- createChonkProof(executionSteps: PrivateExecutionStep[]): Promise<ChonkProofWithPublicInputs>;
20
- computeGateCountForCircuit(bytecode: Buffer, circuitName: string): Promise<number>;
21
- private runInDirectory;
22
- }
23
- //# sourceMappingURL=bb_native_private_kernel_prover.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bb_native_private_kernel_prover.d.ts","sourceRoot":"","sources":["../../../../src/prover/client/native/bb_native_private_kernel_prover.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,KAAK,oBAAoB,EAAkC,MAAM,sBAAsB,CAAC;AACjG,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAMvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAEvE;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,qBAAqB;IAElE,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,WAAW;cACA,SAAS,EAAE,gBAAgB;cAC3B,GAAG;IALxB,OAAO;WAUa,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,CAAC,EAAE,MAAM;YAWrE,iBAAiB;IAuBT,gBAAgB,CAAC,cAAc,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAQ7F,0BAA0B,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBxG,OAAO,CAAC,cAAc;CAavB"}