@aztec/bb-prover 0.0.0-test.0 → 0.0.1-commit.0208eb9

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 (112) hide show
  1. package/dest/avm_proving_tests/avm_proving_tester.d.ts +14 -18
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +146 -79
  4. package/dest/bb/cli.d.ts +1 -1
  5. package/dest/bb/execute.d.ts +17 -50
  6. package/dest/bb/execute.d.ts.map +1 -1
  7. package/dest/bb/execute.js +145 -278
  8. package/dest/bb/index.d.ts +1 -1
  9. package/dest/config.d.ts +3 -1
  10. package/dest/config.d.ts.map +1 -1
  11. package/dest/honk.d.ts +3 -3
  12. package/dest/honk.d.ts.map +1 -1
  13. package/dest/honk.js +3 -2
  14. package/dest/index.d.ts +2 -1
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +1 -0
  17. package/dest/instrumentation.d.ts +3 -3
  18. package/dest/instrumentation.d.ts.map +1 -1
  19. package/dest/instrumentation.js +11 -43
  20. package/dest/prover/client/bb_private_kernel_prover.d.ts +38 -0
  21. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -0
  22. package/dest/prover/{bb_private_kernel_prover.js → client/bb_private_kernel_prover.js} +53 -21
  23. package/dest/prover/client/bundle.d.ts +6 -0
  24. package/dest/prover/client/bundle.d.ts.map +1 -0
  25. package/dest/prover/client/bundle.js +7 -0
  26. package/dest/prover/client/lazy.d.ts +6 -0
  27. package/dest/prover/client/lazy.d.ts.map +1 -0
  28. package/dest/prover/client/lazy.js +7 -0
  29. package/dest/prover/index.d.ts +3 -4
  30. package/dest/prover/index.d.ts.map +1 -1
  31. package/dest/prover/index.js +2 -3
  32. package/dest/prover/proof_utils.d.ts +19 -0
  33. package/dest/prover/proof_utils.d.ts.map +1 -0
  34. package/dest/prover/proof_utils.js +72 -0
  35. package/dest/prover/server/bb_prover.d.ts +97 -0
  36. package/dest/prover/server/bb_prover.d.ts.map +1 -0
  37. package/dest/prover/server/bb_prover.js +712 -0
  38. package/dest/test/delay_values.d.ts +1 -1
  39. package/dest/test/delay_values.d.ts.map +1 -1
  40. package/dest/test/delay_values.js +37 -23
  41. package/dest/test/index.d.ts +2 -1
  42. package/dest/test/index.d.ts.map +1 -1
  43. package/dest/test/index.js +1 -0
  44. package/dest/test/test_circuit_prover.d.ts +27 -36
  45. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  46. package/dest/test/test_circuit_prover.js +517 -88
  47. package/dest/test/test_verifier.d.ts +6 -3
  48. package/dest/test/test_verifier.d.ts.map +1 -1
  49. package/dest/test/test_verifier.js +23 -1
  50. package/dest/verification_key/verification_key_data.d.ts +1 -2
  51. package/dest/verification_key/verification_key_data.d.ts.map +1 -1
  52. package/dest/verification_key/verification_key_data.js +9 -34
  53. package/dest/verifier/bb_verifier.d.ts +6 -5
  54. package/dest/verifier/bb_verifier.d.ts.map +1 -1
  55. package/dest/verifier/bb_verifier.js +45 -27
  56. package/dest/verifier/index.d.ts +2 -1
  57. package/dest/verifier/index.d.ts.map +1 -1
  58. package/dest/verifier/index.js +1 -0
  59. package/dest/verifier/queued_chonk_verifier.d.ts +15 -0
  60. package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -0
  61. package/dest/verifier/queued_chonk_verifier.js +101 -0
  62. package/package.json +35 -33
  63. package/src/avm_proving_tests/avm_proving_tester.ts +223 -113
  64. package/src/bb/execute.ts +116 -291
  65. package/src/config.ts +2 -0
  66. package/src/honk.ts +3 -2
  67. package/src/index.ts +1 -0
  68. package/src/instrumentation.ts +10 -43
  69. package/src/prover/{bb_private_kernel_prover.ts → client/bb_private_kernel_prover.ts} +94 -33
  70. package/src/prover/client/bundle.ts +10 -0
  71. package/src/prover/client/lazy.ts +10 -0
  72. package/src/prover/index.ts +2 -3
  73. package/src/prover/proof_utils.ts +115 -0
  74. package/src/prover/server/bb_prover.ts +718 -0
  75. package/src/test/delay_values.ts +38 -22
  76. package/src/test/index.ts +1 -0
  77. package/src/test/test_circuit_prover.ts +264 -154
  78. package/src/test/test_verifier.ts +15 -3
  79. package/src/verification_key/verification_key_data.ts +11 -31
  80. package/src/verifier/bb_verifier.ts +62 -35
  81. package/src/verifier/index.ts +1 -0
  82. package/src/verifier/queued_chonk_verifier.ts +109 -0
  83. package/dest/prover/bb_native_private_kernel_prover.d.ts +0 -25
  84. package/dest/prover/bb_native_private_kernel_prover.d.ts.map +0 -1
  85. package/dest/prover/bb_native_private_kernel_prover.js +0 -69
  86. package/dest/prover/bb_private_kernel_prover.d.ts +0 -32
  87. package/dest/prover/bb_private_kernel_prover.d.ts.map +0 -1
  88. package/dest/prover/bb_prover.d.ts +0 -120
  89. package/dest/prover/bb_prover.d.ts.map +0 -1
  90. package/dest/prover/bb_prover.js +0 -423
  91. package/dest/prover/client_ivc_proof_utils.d.ts +0 -25
  92. package/dest/prover/client_ivc_proof_utils.d.ts.map +0 -1
  93. package/dest/prover/client_ivc_proof_utils.js +0 -43
  94. package/dest/stats.d.ts +0 -5
  95. package/dest/stats.d.ts.map +0 -1
  96. package/dest/stats.js +0 -62
  97. package/dest/wasm/bb_wasm_private_kernel_prover.d.ts +0 -17
  98. package/dest/wasm/bb_wasm_private_kernel_prover.d.ts.map +0 -1
  99. package/dest/wasm/bb_wasm_private_kernel_prover.js +0 -46
  100. package/dest/wasm/bundle.d.ts +0 -6
  101. package/dest/wasm/bundle.d.ts.map +0 -1
  102. package/dest/wasm/bundle.js +0 -8
  103. package/dest/wasm/lazy.d.ts +0 -6
  104. package/dest/wasm/lazy.d.ts.map +0 -1
  105. package/dest/wasm/lazy.js +0 -8
  106. package/src/prover/bb_native_private_kernel_prover.ts +0 -119
  107. package/src/prover/bb_prover.ts +0 -781
  108. package/src/prover/client_ivc_proof_utils.ts +0 -42
  109. package/src/stats.ts +0 -64
  110. package/src/wasm/bb_wasm_private_kernel_prover.ts +0 -55
  111. package/src/wasm/bundle.ts +0 -11
  112. package/src/wasm/lazy.ts +0 -11
@@ -1,17 +1,15 @@
1
- import { sha256 } from '@aztec/foundation/crypto';
1
+ import { sha256 } from '@aztec/foundation/crypto/sha256';
2
2
  import { Timer } from '@aztec/foundation/timer';
3
3
  import * as proc from 'child_process';
4
4
  import { promises as fs } from 'fs';
5
5
  import { basename, dirname, join } from 'path';
6
- import { CLIENT_IVC_PROOF_FILE_NAME, CLIENT_IVC_VK_FILE_NAME } from '../prover/client_ivc_proof_utils.js';
6
+ import readline from 'readline';
7
7
  export const VK_FILENAME = 'vk';
8
- export const VK_FIELDS_FILENAME = 'vk_fields.json';
8
+ export const PUBLIC_INPUTS_FILENAME = 'public_inputs';
9
9
  export const PROOF_FILENAME = 'proof';
10
- export const PROOF_FIELDS_FILENAME = 'proof_fields.json';
11
10
  export const AVM_INPUTS_FILENAME = 'avm_inputs.bin';
12
11
  export const AVM_BYTECODE_FILENAME = 'avm_bytecode.bin';
13
12
  export const AVM_PUBLIC_INPUTS_FILENAME = 'avm_public_inputs.bin';
14
- export const AVM_HINTS_FILENAME = 'avm_hints.bin';
15
13
  export var BB_RESULT = /*#__PURE__*/ function(BB_RESULT) {
16
14
  BB_RESULT[BB_RESULT["SUCCESS"] = 0] = "SUCCESS";
17
15
  BB_RESULT[BB_RESULT["FAILURE"] = 1] = "FAILURE";
@@ -24,29 +22,57 @@ export var BB_RESULT = /*#__PURE__*/ function(BB_RESULT) {
24
22
  * @param command - The command to execute
25
23
  * @param args - The arguments to pass
26
24
  * @param logger - A log function
25
+ * @param timeout - An optional timeout before killing the BB process
27
26
  * @param resultParser - An optional handler for detecting success or failure
28
27
  * @returns The completed partial witness outputted from the circuit
29
- */ export function executeBB(pathToBB, command, args, logger, resultParser = (code)=>code === 0) {
28
+ */ export function executeBB(pathToBB, command, args, logger, concurrency, timeout, resultParser = (code)=>code === 0) {
30
29
  return new Promise((resolve)=>{
31
30
  // spawn the bb process
32
31
  const { HARDWARE_CONCURRENCY: _, ...envWithoutConcurrency } = process.env;
33
- const env = process.env.HARDWARE_CONCURRENCY ? process.env : envWithoutConcurrency;
32
+ const env = envWithoutConcurrency;
33
+ // We prioritise the concurrency argument if provided and > 0
34
+ if (concurrency && concurrency > 0) {
35
+ env.HARDWARE_CONCURRENCY = concurrency.toString();
36
+ } else if (process.env.HARDWARE_CONCURRENCY) {
37
+ env.HARDWARE_CONCURRENCY = process.env.HARDWARE_CONCURRENCY;
38
+ }
39
+ logger(`BB concurrency: ${env.HARDWARE_CONCURRENCY}`);
34
40
  logger(`Executing BB with: ${pathToBB} ${command} ${args.join(' ')}`);
35
41
  const bb = proc.spawn(pathToBB, [
36
42
  command,
37
43
  ...args
38
44
  ], {
45
+ stdio: [
46
+ 'ignore',
47
+ 'pipe',
48
+ 'pipe'
49
+ ],
39
50
  env
40
51
  });
41
- bb.stdout.on('data', (data)=>{
42
- const message = data.toString('utf-8').replace(/\n$/, '');
43
- logger(message);
44
- });
45
- bb.stderr.on('data', (data)=>{
46
- const message = data.toString('utf-8').replace(/\n$/, '');
47
- logger(message);
48
- });
52
+ let timeoutId;
53
+ if (timeout !== undefined) {
54
+ timeoutId = setTimeout(()=>{
55
+ logger(`BB execution timed out after ${timeout}ms, killing process`);
56
+ if (bb.pid) {
57
+ bb.kill('SIGKILL');
58
+ }
59
+ resolve({
60
+ status: 1,
61
+ exitCode: -1,
62
+ signal: 'TIMEOUT'
63
+ });
64
+ }, timeout);
65
+ }
66
+ readline.createInterface({
67
+ input: bb.stdout
68
+ }).on('line', logger);
69
+ readline.createInterface({
70
+ input: bb.stderr
71
+ }).on('line', logger);
49
72
  bb.on('close', (exitCode, signal)=>{
73
+ if (timeoutId) {
74
+ clearTimeout(timeoutId);
75
+ }
50
76
  if (resultParser(exitCode)) {
51
77
  resolve({
52
78
  status: 0,
@@ -67,12 +93,11 @@ export var BB_RESULT = /*#__PURE__*/ function(BB_RESULT) {
67
93
  signal: undefined
68
94
  }));
69
95
  }
70
- // TODO(#7369) comment this etc (really just take inspiration from this and rewrite it all O:))
71
- export async function executeBbClientIvcProof(pathToBB, workingDirectory, bytecodeStackPath, witnessStackPath, log) {
96
+ export async function executeBbChonkProof(pathToBB, workingDirectory, inputsPath, log, writeVk = false) {
72
97
  // Check that the working directory exists
73
98
  try {
74
99
  await fs.access(workingDirectory);
75
- } catch (error) {
100
+ } catch {
76
101
  return {
77
102
  status: 1,
78
103
  reason: `Working directory ${workingDirectory} does not exist`
@@ -89,26 +114,23 @@ export async function executeBbClientIvcProof(pathToBB, workingDirectory, byteco
89
114
  }
90
115
  try {
91
116
  // Write the bytecode to the working directory
92
- log(`bytecodePath ${bytecodeStackPath}`);
93
- log(`outputPath ${outputPath}`);
117
+ log(`inputsPath ${inputsPath}`);
118
+ const timer = new Timer();
119
+ const logFunction = (message)=>{
120
+ log(`bb - ${message}`);
121
+ };
94
122
  const args = [
95
123
  '-o',
96
124
  outputPath,
97
- '-b',
98
- bytecodeStackPath,
99
- '-w',
100
- witnessStackPath,
125
+ '--ivc_inputs_path',
126
+ inputsPath,
101
127
  '-v',
102
128
  '--scheme',
103
- 'client_ivc',
104
- '--input_type',
105
- 'runtime_stack',
106
- '--write_vk'
129
+ 'chonk'
107
130
  ];
108
- const timer = new Timer();
109
- const logFunction = (message)=>{
110
- log(`bb - ${message}`);
111
- };
131
+ if (writeVk) {
132
+ args.push('--write_vk');
133
+ }
112
134
  const result = await executeBB(pathToBB, 'prove', args, logFunction);
113
135
  const durationMs = timer.ms();
114
136
  if (result.status == 0) {
@@ -117,7 +139,7 @@ export async function executeBbClientIvcProof(pathToBB, workingDirectory, byteco
117
139
  durationMs,
118
140
  proofPath: `${outputPath}`,
119
141
  pkPath: undefined,
120
- vkPath: `${outputPath}`
142
+ vkDirectoryPath: `${outputPath}`
121
143
  };
122
144
  }
123
145
  // Not a great error message here but it is difficult to decipher what comes from bb
@@ -153,6 +175,15 @@ function getArgs(flavor) {
153
175
  'keccak'
154
176
  ];
155
177
  }
178
+ case 'ultra_starknet_honk':
179
+ {
180
+ return [
181
+ '--scheme',
182
+ 'ultra_honk',
183
+ '--oracle_hash',
184
+ 'starknet'
185
+ ];
186
+ }
156
187
  case 'ultra_rollup_honk':
157
188
  {
158
189
  return [
@@ -175,18 +206,19 @@ function getArgs(flavor) {
175
206
  * @param inputWitnessFile - The circuit input witness
176
207
  * @param log - A logging function
177
208
  * @returns An object containing a result indication, the location of the proof and the duration taken
178
- */ export async function generateProof(pathToBB, workingDirectory, circuitName, bytecode, recursive, inputWitnessFile, flavor, log) {
209
+ */ export async function generateProof(pathToBB, workingDirectory, circuitName, bytecode, verificationKey, inputWitnessFile, flavor, log) {
179
210
  // Check that the working directory exists
180
211
  try {
181
212
  await fs.access(workingDirectory);
182
- } catch (error) {
213
+ } catch {
183
214
  return {
184
215
  status: 1,
185
216
  reason: `Working directory ${workingDirectory} does not exist`
186
217
  };
187
218
  }
188
- // The bytecode is written to e.g. /workingDirectory/BaseParityArtifact-bytecode
219
+ // The bytecode is written to e.g. /workingDirectory/ParityBaseArtifact-bytecode
189
220
  const bytecodePath = `${workingDirectory}/${circuitName}-bytecode`;
221
+ const vkPath = `${workingDirectory}/${circuitName}-vk`;
190
222
  // The proof is written to e.g. /workingDirectory/ultra_honk/proof
191
223
  const outputPath = `${workingDirectory}`;
192
224
  const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
@@ -197,26 +229,30 @@ function getArgs(flavor) {
197
229
  };
198
230
  }
199
231
  try {
200
- // Write the bytecode to the working directory
201
- await fs.writeFile(bytecodePath, bytecode);
232
+ // Write the bytecode and vk to the working directory
233
+ await Promise.all([
234
+ fs.writeFile(bytecodePath, bytecode),
235
+ fs.writeFile(vkPath, verificationKey)
236
+ ]);
202
237
  const args = getArgs(flavor).concat([
203
- '--output_format',
204
- 'bytes_and_fields',
205
- '--write_vk',
238
+ '--disable_zk',
206
239
  '-o',
207
240
  outputPath,
208
241
  '-b',
209
242
  bytecodePath,
243
+ '-k',
244
+ vkPath,
210
245
  '-w',
211
246
  inputWitnessFile,
212
247
  '-v'
213
248
  ]);
214
- if (recursive) {
215
- args.push('--init_kzg_accumulator');
249
+ const loggingArg = log.level === 'debug' || log.level === 'trace' ? '-d' : log.level === 'verbose' ? '-v' : '';
250
+ if (loggingArg !== '') {
251
+ args.push(loggingArg);
216
252
  }
217
253
  const timer = new Timer();
218
254
  const logFunction = (message)=>{
219
- log(`${circuitName} BB out - ${message}`);
255
+ log.info(`${circuitName} BB out - ${message}`);
220
256
  };
221
257
  const result = await executeBB(pathToBB, `prove`, args, logFunction);
222
258
  const duration = timer.ms();
@@ -226,80 +262,7 @@ function getArgs(flavor) {
226
262
  durationMs: duration,
227
263
  proofPath: `${outputPath}`,
228
264
  pkPath: undefined,
229
- vkPath: `${outputPath}`
230
- };
231
- }
232
- // Not a great error message here but it is difficult to decipher what comes from bb
233
- return {
234
- status: 1,
235
- reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
236
- retry: !!result.signal
237
- };
238
- } catch (error) {
239
- return {
240
- status: 1,
241
- reason: `${error}`
242
- };
243
- }
244
- }
245
- /**
246
- * Used for generating proofs of the tube circuit
247
- * It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
248
- * @param pathToBB - The full path to the bb binary
249
- * @param workingDirectory - A working directory for use by bb
250
- * @param circuitName - An identifier for the circuit
251
- * @param bytecode - The compiled circuit bytecode
252
- * @param inputWitnessFile - The circuit input witness
253
- * @param log - A logging function
254
- * @returns An object containing a result indication, the location of the proof and the duration taken
255
- */ export async function generateTubeProof(pathToBB, workingDirectory, log) {
256
- // Check that the working directory exists
257
- try {
258
- await fs.access(workingDirectory);
259
- } catch (error) {
260
- return {
261
- status: 1,
262
- reason: `Working directory ${workingDirectory} does not exist`
263
- };
264
- }
265
- // // Paths for the inputs
266
- const vkPath = join(workingDirectory, CLIENT_IVC_VK_FILE_NAME);
267
- const proofPath = join(workingDirectory, CLIENT_IVC_PROOF_FILE_NAME);
268
- // The proof is written to e.g. /workingDirectory/proof
269
- const outputPath = workingDirectory;
270
- const filePresent = async (file)=>await fs.access(file, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
271
- const binaryPresent = await filePresent(pathToBB);
272
- if (!binaryPresent) {
273
- return {
274
- status: 1,
275
- reason: `Failed to find bb binary at ${pathToBB}`
276
- };
277
- }
278
- try {
279
- if (!await filePresent(vkPath) || !await filePresent(proofPath)) {
280
- return {
281
- status: 1,
282
- reason: `Client IVC input files not present in ${workingDirectory}`
283
- };
284
- }
285
- const args = [
286
- '-o',
287
- outputPath,
288
- '-v'
289
- ];
290
- const timer = new Timer();
291
- const logFunction = (message)=>{
292
- log(`TubeCircuit (prove) BB out - ${message}`);
293
- };
294
- const result = await executeBB(pathToBB, 'prove_tube', args, logFunction);
295
- const durationMs = timer.ms();
296
- if (result.status == 0) {
297
- return {
298
- status: 0,
299
- durationMs,
300
- proofPath: outputPath,
301
- pkPath: undefined,
302
- vkPath: outputPath
265
+ vkDirectoryPath: `${outputPath}`
303
266
  };
304
267
  }
305
268
  // Not a great error message here but it is difficult to decipher what comes from bb
@@ -321,13 +284,14 @@ function getArgs(flavor) {
321
284
  * @param pathToBB - The full path to the bb binary
322
285
  * @param workingDirectory - A working directory for use by bb
323
286
  * @param input - The inputs for the public function to be proven
324
- * @param log - A logging function
287
+ * @param logger - A logging function
288
+ * @param checkCircuitOnly - A boolean to toggle a "check-circuit only" operation instead of proving.
325
289
  * @returns An object containing a result indication, the location of the proof and the duration taken
326
- */ export async function generateAvmProofV2(pathToBB, workingDirectory, input, logger) {
290
+ */ export async function generateAvmProof(pathToBB, workingDirectory, input, logger, checkCircuitOnly = false) {
327
291
  // Check that the working directory exists
328
292
  try {
329
293
  await fs.access(workingDirectory);
330
- } catch (error) {
294
+ } catch {
331
295
  return {
332
296
  status: 1,
333
297
  reason: `Working directory ${workingDirectory} does not exist`
@@ -354,7 +318,10 @@ function getArgs(flavor) {
354
318
  reason: `Could not write avm inputs to ${avmInputsPath}`
355
319
  };
356
320
  }
357
- const args = [
321
+ const args = checkCircuitOnly ? [
322
+ '--avm-inputs',
323
+ avmInputsPath
324
+ ] : [
358
325
  '--avm-inputs',
359
326
  avmInputsPath,
360
327
  '-o',
@@ -365,93 +332,11 @@ function getArgs(flavor) {
365
332
  args.push(loggingArg);
366
333
  }
367
334
  const timer = new Timer();
368
- const logFunction = (message)=>{
369
- logger.verbose(`AvmCircuit (prove) BB out - ${message}`);
370
- };
371
- const result = await executeBB(pathToBB, 'avm2_prove', args, logFunction);
372
- const duration = timer.ms();
373
- if (result.status == 0) {
374
- return {
375
- status: 0,
376
- durationMs: duration,
377
- proofPath: join(outputPath, PROOF_FILENAME),
378
- pkPath: undefined,
379
- vkPath: outputPath
380
- };
381
- }
382
- // Not a great error message here but it is difficult to decipher what comes from bb
383
- return {
384
- status: 1,
385
- reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
386
- retry: !!result.signal
387
- };
388
- } catch (error) {
389
- return {
390
- status: 1,
391
- reason: `${error}`
392
- };
393
- }
394
- }
395
- /**
396
- * Used for generating AVM proofs (or doing check-circuit).
397
- * It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
398
- * @param pathToBB - The full path to the bb binary
399
- * @param workingDirectory - A working directory for use by bb
400
- * @param bytecode - The AVM bytecode for the public function to be proven (expected to be decompressed)
401
- * @param log - A logging function
402
- * @returns An object containing a result indication, the location of the proof and the duration taken
403
- */ export async function generateAvmProof(pathToBB, workingDirectory, _input, logger, checkCircuitOnly = false) {
404
- // Check that the working directory exists
405
- try {
406
- await fs.access(workingDirectory);
407
- } catch (error) {
408
- return {
409
- status: 1,
410
- reason: `Working directory ${workingDirectory} does not exist`
411
- };
412
- }
413
- // Paths for the inputs
414
- const publicInputsPath = join(workingDirectory, AVM_PUBLIC_INPUTS_FILENAME);
415
- const avmHintsPath = join(workingDirectory, AVM_HINTS_FILENAME);
416
- // The proof is written to e.g. /workingDirectory/proof
417
- const outputPath = workingDirectory;
418
- const filePresent = async (file)=>await fs.access(file, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
419
- const binaryPresent = await filePresent(pathToBB);
420
- if (!binaryPresent) {
421
- return {
422
- status: 1,
423
- reason: `Failed to find bb binary at ${pathToBB}`
424
- };
425
- }
426
- try {
427
- // Write the inputs to the working directory.
428
- // WARNING: Not writing the inputs since VM1 is disabled!
429
- // await fs.writeFile(publicInputsPath, input.publicInputs.toBuffer());
430
- // if (!(await filePresent(publicInputsPath))) {
431
- // return { status: BB_RESULT.FAILURE, reason: `Could not write publicInputs at ${publicInputsPath}` };
432
- // }
433
- // await fs.writeFile(avmHintsPath, input.avmHints.toBuffer());
434
- // if (!(await filePresent(avmHintsPath))) {
435
- // return { status: BB_RESULT.FAILURE, reason: `Could not write avmHints at ${avmHintsPath}` };
436
- // }
437
- const args = [
438
- '--avm-public-inputs',
439
- publicInputsPath,
440
- '--avm-hints',
441
- avmHintsPath,
442
- '-o',
443
- outputPath
444
- ];
445
- const loggingArg = logger.level === 'debug' || logger.level === 'trace' ? '-d' : logger.level === 'verbose' ? '-v' : '';
446
- if (loggingArg !== '') {
447
- args.push(loggingArg);
448
- }
449
- const timer = new Timer();
450
- const cmd = checkCircuitOnly ? 'check_circuit' : 'prove';
335
+ const cmd = checkCircuitOnly ? 'avm_check_circuit' : 'avm_prove';
451
336
  const logFunction = (message)=>{
452
337
  logger.verbose(`AvmCircuit (${cmd}) BB out - ${message}`);
453
338
  };
454
- const result = await executeBB(pathToBB, `avm_${cmd}`, args, logFunction);
339
+ const result = await executeBB(pathToBB, cmd, args, logFunction);
455
340
  const duration = timer.ms();
456
341
  if (result.status == 0) {
457
342
  return {
@@ -459,14 +344,14 @@ function getArgs(flavor) {
459
344
  durationMs: duration,
460
345
  proofPath: join(outputPath, PROOF_FILENAME),
461
346
  pkPath: undefined,
462
- vkPath: outputPath
347
+ vkDirectoryPath: undefined
463
348
  };
464
349
  }
465
350
  // Not a great error message here but it is difficult to decipher what comes from bb
466
351
  return {
467
352
  status: 1,
468
- reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
469
- retry: !!result.signal
353
+ reason: `Failed to generate proof. AVM proof for TX hash ${input.hints.tx.hash}. Exit code ${result.exitCode}. Signal ${result.signal}.`,
354
+ retry: result.signal === 'SIGKILL'
470
355
  };
471
356
  } catch (error) {
472
357
  return {
@@ -480,22 +365,27 @@ function getArgs(flavor) {
480
365
  * @param pathToBB - The full path to the bb binary
481
366
  * @param proofFullPath - The full path to the proof to be verified
482
367
  * @param verificationKeyPath - The full path to the circuit verification key
483
- * @param log - A logging function
484
- * @returns An object containing a result indication and duration taken
485
- */ export async function verifyProof(pathToBB, proofFullPath, verificationKeyPath, ultraHonkFlavor, log) {
486
- return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, `verify`, log, getArgs(ultraHonkFlavor));
487
- }
488
- /**
489
- * Used for verifying proofs of the AVM
490
- * @param pathToBB - The full path to the bb binary
491
- * @param proofFullPath - The full path to the proof to be verified
492
- * @param verificationKeyPath - The full path to the circuit verification key
493
- * @param log - A logging function
368
+ * @param logger - A logger
494
369
  * @returns An object containing a result indication and duration taken
495
- */ export async function verifyAvmProof(pathToBB, proofFullPath, verificationKeyPath, logger) {
496
- return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, 'avm_verify', logger);
370
+ */ export async function verifyProof(pathToBB, proofFullPath, verificationKeyPath, ultraHonkFlavor, logger) {
371
+ // Specify the public inputs path in the case of UH verification.
372
+ // Take proofFullPath and remove the suffix past the / to get the directory.
373
+ const proofDir = proofFullPath.substring(0, proofFullPath.lastIndexOf('/'));
374
+ const publicInputsFullPath = join(proofDir, '/public_inputs');
375
+ logger.debug(`public inputs path: ${publicInputsFullPath}`);
376
+ const args = [
377
+ '-p',
378
+ proofFullPath,
379
+ '-k',
380
+ verificationKeyPath,
381
+ '-i',
382
+ publicInputsFullPath,
383
+ '--disable_zk',
384
+ ...getArgs(ultraHonkFlavor)
385
+ ];
386
+ return await verifyProofInternal(pathToBB, `verify`, args, logger);
497
387
  }
498
- export async function verifyAvmProofV2(pathToBB, workingDirectory, proofFullPath, publicInputs, verificationKeyPath, logger) {
388
+ export async function verifyAvmProof(pathToBB, workingDirectory, proofFullPath, publicInputs, logger) {
499
389
  const inputsBuffer = publicInputs.serializeWithMessagePack();
500
390
  // Write the inputs to the working directory.
501
391
  const filePresent = async (file)=>await fs.access(file, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
@@ -507,19 +397,23 @@ export async function verifyAvmProofV2(pathToBB, workingDirectory, proofFullPath
507
397
  reason: `Could not write avm inputs to ${avmInputsPath}`
508
398
  };
509
399
  }
510
- return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, 'avm2_verify', logger, [
400
+ const args = [
401
+ '-p',
402
+ proofFullPath,
511
403
  '--avm-public-inputs',
512
404
  avmInputsPath
513
- ]);
405
+ ];
406
+ return await verifyProofInternal(pathToBB, 'avm_verify', args, logger);
514
407
  }
515
408
  /**
516
- * Verifies a ClientIvcProof
409
+ * Verifies a ChonkProof
517
410
  * TODO(#7370) The verification keys should be supplied separately
518
411
  * @param pathToBB - The full path to the bb binary
519
412
  * @param targetPath - The path to the folder with the proof, accumulator, and verification keys
520
- * @param log - A logging function
413
+ * @param logger - A logger
414
+ * @param concurrency - The number of threads to use for the verification
521
415
  * @returns An object containing a result indication and duration taken
522
- */ export async function verifyClientIvcProof(pathToBB, proofPath, keyPath, log) {
416
+ */ export async function verifyChonkProof(pathToBB, proofPath, keyPath, logger, concurrency = 1) {
523
417
  const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
524
418
  if (!binaryPresent) {
525
419
  return {
@@ -527,47 +421,26 @@ export async function verifyAvmProofV2(pathToBB, workingDirectory, proofFullPath
527
421
  reason: `Failed to find bb binary at ${pathToBB}`
528
422
  };
529
423
  }
530
- try {
531
- const args = [
532
- '--scheme',
533
- 'client_ivc',
534
- '-p',
535
- proofPath,
536
- '-k',
537
- keyPath
538
- ];
539
- const timer = new Timer();
540
- const command = 'verify';
541
- const result = await executeBB(pathToBB, command, args, log);
542
- const duration = timer.ms();
543
- if (result.status == 0) {
544
- return {
545
- status: 0,
546
- durationMs: duration
547
- };
548
- }
549
- // Not a great error message here but it is difficult to decipher what comes from bb
550
- return {
551
- status: 1,
552
- reason: `Failed to verify proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
553
- retry: !!result.signal
554
- };
555
- } catch (error) {
556
- return {
557
- status: 1,
558
- reason: `${error}`
559
- };
560
- }
424
+ const args = [
425
+ '--scheme',
426
+ 'chonk',
427
+ '-p',
428
+ proofPath,
429
+ '-k',
430
+ keyPath,
431
+ '-v'
432
+ ];
433
+ return await verifyProofInternal(pathToBB, 'verify', args, logger, concurrency);
561
434
  }
562
435
  /**
563
436
  * Used for verifying proofs with BB
564
437
  * @param pathToBB - The full path to the bb binary
565
- * @param proofFullPath - The full path to the proof to be verified
566
- * @param verificationKeyPath - The full path to the circuit verification key
567
438
  * @param command - The BB command to execute (verify/avm_verify)
568
- * @param log - A logging function
439
+ * @param args - The arguments to pass to the command
440
+ * @param logger - A logger
441
+ * @param concurrency - The number of threads to use for the verification
569
442
  * @returns An object containing a result indication and duration taken
570
- */ async function verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, command, logger, extraArgs = []) {
443
+ */ async function verifyProofInternal(pathToBB, command, args, logger, concurrency) {
571
444
  const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
572
445
  if (!binaryPresent) {
573
446
  return {
@@ -579,19 +452,13 @@ export async function verifyAvmProofV2(pathToBB, workingDirectory, proofFullPath
579
452
  logger.verbose(`bb-prover (verify) BB out - ${message}`);
580
453
  };
581
454
  try {
582
- const args = [
583
- '-p',
584
- proofFullPath,
585
- '-k',
586
- verificationKeyPath,
587
- ...extraArgs
588
- ];
589
455
  const loggingArg = logger.level === 'debug' || logger.level === 'trace' ? '-d' : logger.level === 'verbose' ? '-v' : '';
590
- if (loggingArg !== '') {
591
- args.push(loggingArg);
592
- }
456
+ const finalArgs = loggingArg !== '' ? [
457
+ ...args,
458
+ loggingArg
459
+ ] : args;
593
460
  const timer = new Timer();
594
- const result = await executeBB(pathToBB, command, args, logFunction);
461
+ const result = await executeBB(pathToBB, command, finalArgs, logFunction, concurrency);
595
462
  const duration = timer.ms();
596
463
  if (result.status == 0) {
597
464
  return {
@@ -685,13 +552,13 @@ export async function generateContractForVerificationKey(pathToBB, vkFilePath, c
685
552
  // Check that the working directory exists
686
553
  try {
687
554
  await fs.access(workingDirectory);
688
- } catch (error) {
555
+ } catch {
689
556
  return {
690
557
  status: 1,
691
558
  reason: `Working directory ${workingDirectory} does not exist`
692
559
  };
693
560
  }
694
- // The bytecode is written to e.g. /workingDirectory/BaseParityArtifact-bytecode
561
+ // The bytecode is written to e.g. /workingDirectory/ParityBaseArtifact-bytecode
695
562
  const bytecodePath = `${workingDirectory}/${circuitName}-bytecode`;
696
563
  const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
697
564
  if (!binaryPresent) {
@@ -712,7 +579,7 @@ export async function generateContractForVerificationKey(pathToBB, vkFilePath, c
712
579
  const timer = new Timer();
713
580
  const result = await executeBB(pathToBB, 'gates', [
714
581
  '--scheme',
715
- flavor === 'mega_honk' ? 'client_ivc' : 'ultra_honk',
582
+ flavor === 'mega_honk' ? 'chonk' : 'ultra_honk',
716
583
  '-b',
717
584
  bytecodePath,
718
585
  '-v'
@@ -772,7 +639,7 @@ async function fsCache(dir, expectedCacheKey, logger, force, action) {
772
639
  }
773
640
  try {
774
641
  await fs.writeFile(cacheFilePath, expectedCacheKey);
775
- } catch (err) {
642
+ } catch {
776
643
  logger(`Couldn't write cache data to ${cacheFilePath}. Skipping cache...`);
777
644
  // ignore
778
645
  }
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env -S node --no-warnings
2
2
  import 'source-map-support/register.js';
3
- //# sourceMappingURL=index.d.ts.map
3
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBR0EsT0FBTyxnQ0FBZ0MsQ0FBQyJ9
package/dest/config.d.ts CHANGED
@@ -3,6 +3,8 @@ export interface BBConfig {
3
3
  bbWorkingDirectory: string;
4
4
  /** Whether to skip tmp dir cleanup for debugging purposes */
5
5
  bbSkipCleanup: boolean;
6
+ numConcurrentIVCVerifiers: number;
7
+ bbIVCConcurrency: number;
6
8
  }
7
9
  export interface ACVMConfig {
8
10
  /** The path to the ACVM binary */
@@ -10,4 +12,4 @@ export interface ACVMConfig {
10
12
  /** The working directory to use for simulation/proving */
11
13
  acvmWorkingDirectory: string;
12
14
  }
13
- //# sourceMappingURL=config.d.ts.map
15
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE1BQU0sV0FBVyxRQUFRO0lBQ3ZCLFlBQVksRUFBRSxNQUFNLENBQUM7SUFDckIsa0JBQWtCLEVBQUUsTUFBTSxDQUFDO0lBQzNCLDZEQUE2RDtJQUM3RCxhQUFhLEVBQUUsT0FBTyxDQUFDO0lBQ3ZCLHlCQUF5QixFQUFFLE1BQU0sQ0FBQztJQUNsQyxnQkFBZ0IsRUFBRSxNQUFNLENBQUM7Q0FDMUI7QUFFRCxNQUFNLFdBQVcsVUFBVTtJQUN6QixrQ0FBa0M7SUFDbEMsY0FBYyxFQUFFLE1BQU0sQ0FBQztJQUN2QiwwREFBMEQ7SUFDMUQsb0JBQW9CLEVBQUUsTUFBTSxDQUFDO0NBQzlCIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,6DAA6D;IAC7D,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,kCAAkC;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,0DAA0D;IAC1D,oBAAoB,EAAE,MAAM,CAAC;CAC9B"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,6DAA6D;IAC7D,aAAa,EAAE,OAAO,CAAC;IACvB,yBAAyB,EAAE,MAAM,CAAC;IAClC,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,UAAU;IACzB,kCAAkC;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,0DAA0D;IAC1D,oBAAoB,EAAE,MAAM,CAAC;CAC9B"}