@aztec/bb-prover 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0

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 (68) hide show
  1. package/dest/avm_proving_tests/avm_proving_tester.d.ts +16 -10
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +178 -111
  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/file_names.d.ts +4 -0
  11. package/dest/bb/file_names.d.ts.map +1 -0
  12. package/dest/bb/file_names.js +5 -0
  13. package/dest/config.d.ts +17 -1
  14. package/dest/config.d.ts.map +1 -1
  15. package/dest/index.d.ts +3 -2
  16. package/dest/index.d.ts.map +1 -1
  17. package/dest/index.js +2 -1
  18. package/dest/instrumentation.d.ts +1 -1
  19. package/dest/instrumentation.d.ts.map +1 -1
  20. package/dest/instrumentation.js +12 -4
  21. package/dest/prover/client/bb_private_kernel_prover.d.ts +21 -5
  22. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
  23. package/dest/prover/client/bb_private_kernel_prover.js +79 -15
  24. package/dest/prover/proof_utils.d.ts +11 -1
  25. package/dest/prover/proof_utils.d.ts.map +1 -1
  26. package/dest/prover/proof_utils.js +24 -1
  27. package/dest/prover/server/bb_prover.d.ts +6 -7
  28. package/dest/prover/server/bb_prover.d.ts.map +1 -1
  29. package/dest/prover/server/bb_prover.js +207 -80
  30. package/dest/test/delay_values.js +1 -1
  31. package/dest/test/test_circuit_prover.d.ts +3 -3
  32. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  33. package/dest/test/test_circuit_prover.js +2 -2
  34. package/dest/verification_key/verification_key_data.js +1 -1
  35. package/dest/verifier/batch_chonk_verifier.d.ts +56 -0
  36. package/dest/verifier/batch_chonk_verifier.d.ts.map +1 -0
  37. package/dest/verifier/batch_chonk_verifier.js +384 -0
  38. package/dest/verifier/bb_verifier.d.ts +4 -1
  39. package/dest/verifier/bb_verifier.d.ts.map +1 -1
  40. package/dest/verifier/bb_verifier.js +134 -45
  41. package/dest/verifier/index.d.ts +2 -1
  42. package/dest/verifier/index.d.ts.map +1 -1
  43. package/dest/verifier/index.js +1 -0
  44. package/dest/verifier/queued_chonk_verifier.d.ts +2 -3
  45. package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -1
  46. package/dest/verifier/queued_chonk_verifier.js +8 -7
  47. package/package.json +19 -17
  48. package/src/avm_proving_tests/avm_proving_tester.ts +85 -126
  49. package/src/bb/bb_js_backend.ts +435 -0
  50. package/src/bb/bb_js_debug.ts +227 -0
  51. package/src/bb/file_names.ts +6 -0
  52. package/src/config.ts +16 -0
  53. package/src/index.ts +2 -1
  54. package/src/instrumentation.ts +12 -4
  55. package/src/prover/client/bb_private_kernel_prover.ts +242 -21
  56. package/src/prover/proof_utils.ts +41 -1
  57. package/src/prover/server/bb_prover.ts +127 -141
  58. package/src/test/delay_values.ts +1 -1
  59. package/src/test/test_circuit_prover.ts +3 -5
  60. package/src/verification_key/verification_key_data.ts +1 -1
  61. package/src/verifier/batch_chonk_verifier.ts +415 -0
  62. package/src/verifier/bb_verifier.ts +66 -76
  63. package/src/verifier/index.ts +1 -0
  64. package/src/verifier/queued_chonk_verifier.ts +8 -8
  65. package/dest/bb/execute.d.ts +0 -107
  66. package/dest/bb/execute.d.ts.map +0 -1
  67. package/dest/bb/execute.js +0 -647
  68. package/src/bb/execute.ts +0 -678
package/src/index.ts CHANGED
@@ -2,7 +2,8 @@ export * from './prover/index.js';
2
2
  export * from './test/index.js';
3
3
  export * from './verifier/index.js';
4
4
  export * from './config.js';
5
- export * from './bb/execute.js';
5
+ export * from './bb/file_names.js';
6
+ export * from './bb/bb_js_backend.js';
6
7
  export * from './honk.js';
7
8
  export * from './verification_key/verification_key_data.js';
8
9
 
@@ -58,10 +58,18 @@ export class ProverInstrumentation {
58
58
  circuitName: CircuitName,
59
59
  timerOrMS: Timer | number,
60
60
  ) {
61
- const s = typeof timerOrMS === 'number' ? timerOrMS / 1000 : timerOrMS.s();
62
- this[metric].record(s, {
63
- [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
64
- });
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
+ }
65
73
  }
66
74
 
67
75
  /**
@@ -5,18 +5,35 @@ import { serializeWitness } from '@aztec/noir-noirc_abi';
5
5
  import {
6
6
  convertHidingKernelPublicInputsToWitnessMapWithAbi,
7
7
  convertHidingKernelToRollupInputsToWitnessMapWithAbi,
8
+ convertPrivateKernelInit2InputsToWitnessMapWithAbi,
9
+ convertPrivateKernelInit2OutputsFromWitnessMapWithAbi,
10
+ convertPrivateKernelInit3InputsToWitnessMapWithAbi,
11
+ convertPrivateKernelInit3OutputsFromWitnessMapWithAbi,
12
+ convertPrivateKernelInit4InputsToWitnessMapWithAbi,
13
+ convertPrivateKernelInit4OutputsFromWitnessMapWithAbi,
14
+ convertPrivateKernelInit5InputsToWitnessMapWithAbi,
15
+ convertPrivateKernelInit5OutputsFromWitnessMapWithAbi,
8
16
  convertPrivateKernelInitInputsToWitnessMapWithAbi,
9
17
  convertPrivateKernelInitOutputsFromWitnessMapWithAbi,
18
+ convertPrivateKernelInner2InputsToWitnessMapWithAbi,
19
+ convertPrivateKernelInner2OutputsFromWitnessMapWithAbi,
20
+ convertPrivateKernelInner3InputsToWitnessMapWithAbi,
21
+ convertPrivateKernelInner3OutputsFromWitnessMapWithAbi,
22
+ convertPrivateKernelInner4InputsToWitnessMapWithAbi,
23
+ convertPrivateKernelInner4OutputsFromWitnessMapWithAbi,
24
+ convertPrivateKernelInner5InputsToWitnessMapWithAbi,
25
+ convertPrivateKernelInner5OutputsFromWitnessMapWithAbi,
10
26
  convertPrivateKernelInnerInputsToWitnessMapWithAbi,
11
27
  convertPrivateKernelInnerOutputsFromWitnessMapWithAbi,
12
28
  convertPrivateKernelResetInputsToWitnessMapWithAbi,
13
29
  convertPrivateKernelResetOutputsFromWitnessMapWithAbi,
30
+ convertPrivateKernelResetTailInputsToWitnessMapWithAbi,
31
+ convertPrivateKernelResetTailToPublicInputsToWitnessMapWithAbi,
14
32
  convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
15
- convertPrivateKernelTailInputsToWitnessMapWithAbi,
16
33
  convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
17
- convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
18
34
  foreignCallHandler,
19
35
  getPrivateKernelResetArtifactName,
36
+ getPrivateKernelResetTailArtifactName,
20
37
  updateResetCircuitSampleInputs,
21
38
  } from '@aztec/noir-protocol-circuits-types/client';
22
39
  import {
@@ -32,11 +49,19 @@ import type {
32
49
  HidingKernelToRollupPrivateInputs,
33
50
  PrivateExecutionStep,
34
51
  PrivateKernelCircuitPublicInputs,
52
+ PrivateKernelInit2CircuitPrivateInputs,
53
+ PrivateKernelInit3CircuitPrivateInputs,
54
+ PrivateKernelInit4CircuitPrivateInputs,
55
+ PrivateKernelInit5CircuitPrivateInputs,
35
56
  PrivateKernelInitCircuitPrivateInputs,
57
+ PrivateKernelInner2CircuitPrivateInputs,
58
+ PrivateKernelInner3CircuitPrivateInputs,
59
+ PrivateKernelInner4CircuitPrivateInputs,
60
+ PrivateKernelInner5CircuitPrivateInputs,
36
61
  PrivateKernelInnerCircuitPrivateInputs,
37
62
  PrivateKernelResetCircuitPrivateInputs,
63
+ PrivateKernelResetTailCircuitPrivateInputs,
38
64
  PrivateKernelSimulateOutput,
39
- PrivateKernelTailCircuitPrivateInputs,
40
65
  PrivateKernelTailCircuitPublicInputs,
41
66
  } from '@aztec/stdlib/kernel';
42
67
  import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
@@ -79,6 +104,94 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
79
104
  );
80
105
  }
81
106
 
107
+ public async generateInit2Output(
108
+ inputs: PrivateKernelInit2CircuitPrivateInputs,
109
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
110
+ return await this.generateCircuitOutput(
111
+ inputs,
112
+ 'PrivateKernelInit2Artifact',
113
+ convertPrivateKernelInit2InputsToWitnessMapWithAbi,
114
+ convertPrivateKernelInit2OutputsFromWitnessMapWithAbi,
115
+ );
116
+ }
117
+
118
+ public async simulateInit2(
119
+ inputs: PrivateKernelInit2CircuitPrivateInputs,
120
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
121
+ return await this.simulateCircuitOutput(
122
+ inputs,
123
+ 'PrivateKernelInit2Artifact',
124
+ convertPrivateKernelInit2InputsToWitnessMapWithAbi,
125
+ convertPrivateKernelInit2OutputsFromWitnessMapWithAbi,
126
+ );
127
+ }
128
+
129
+ public async generateInit3Output(
130
+ inputs: PrivateKernelInit3CircuitPrivateInputs,
131
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
132
+ return await this.generateCircuitOutput(
133
+ inputs,
134
+ 'PrivateKernelInit3Artifact',
135
+ convertPrivateKernelInit3InputsToWitnessMapWithAbi,
136
+ convertPrivateKernelInit3OutputsFromWitnessMapWithAbi,
137
+ );
138
+ }
139
+
140
+ public async simulateInit3(
141
+ inputs: PrivateKernelInit3CircuitPrivateInputs,
142
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
143
+ return await this.simulateCircuitOutput(
144
+ inputs,
145
+ 'PrivateKernelInit3Artifact',
146
+ convertPrivateKernelInit3InputsToWitnessMapWithAbi,
147
+ convertPrivateKernelInit3OutputsFromWitnessMapWithAbi,
148
+ );
149
+ }
150
+
151
+ public async generateInit4Output(
152
+ inputs: PrivateKernelInit4CircuitPrivateInputs,
153
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
154
+ return await this.generateCircuitOutput(
155
+ inputs,
156
+ 'PrivateKernelInit4Artifact',
157
+ convertPrivateKernelInit4InputsToWitnessMapWithAbi,
158
+ convertPrivateKernelInit4OutputsFromWitnessMapWithAbi,
159
+ );
160
+ }
161
+
162
+ public async simulateInit4(
163
+ inputs: PrivateKernelInit4CircuitPrivateInputs,
164
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
165
+ return await this.simulateCircuitOutput(
166
+ inputs,
167
+ 'PrivateKernelInit4Artifact',
168
+ convertPrivateKernelInit4InputsToWitnessMapWithAbi,
169
+ convertPrivateKernelInit4OutputsFromWitnessMapWithAbi,
170
+ );
171
+ }
172
+
173
+ public async generateInit5Output(
174
+ inputs: PrivateKernelInit5CircuitPrivateInputs,
175
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
176
+ return await this.generateCircuitOutput(
177
+ inputs,
178
+ 'PrivateKernelInit5Artifact',
179
+ convertPrivateKernelInit5InputsToWitnessMapWithAbi,
180
+ convertPrivateKernelInit5OutputsFromWitnessMapWithAbi,
181
+ );
182
+ }
183
+
184
+ public async simulateInit5(
185
+ inputs: PrivateKernelInit5CircuitPrivateInputs,
186
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
187
+ return await this.simulateCircuitOutput(
188
+ inputs,
189
+ 'PrivateKernelInit5Artifact',
190
+ convertPrivateKernelInit5InputsToWitnessMapWithAbi,
191
+ convertPrivateKernelInit5OutputsFromWitnessMapWithAbi,
192
+ );
193
+ }
194
+
82
195
  public async generateInnerOutput(
83
196
  inputs: PrivateKernelInnerCircuitPrivateInputs,
84
197
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
@@ -101,6 +214,94 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
101
214
  );
102
215
  }
103
216
 
217
+ public async generateInner2Output(
218
+ inputs: PrivateKernelInner2CircuitPrivateInputs,
219
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
220
+ return await this.generateCircuitOutput(
221
+ inputs,
222
+ 'PrivateKernelInner2Artifact',
223
+ convertPrivateKernelInner2InputsToWitnessMapWithAbi,
224
+ convertPrivateKernelInner2OutputsFromWitnessMapWithAbi,
225
+ );
226
+ }
227
+
228
+ public async simulateInner2(
229
+ inputs: PrivateKernelInner2CircuitPrivateInputs,
230
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
231
+ return await this.simulateCircuitOutput(
232
+ inputs,
233
+ 'PrivateKernelInner2Artifact',
234
+ convertPrivateKernelInner2InputsToWitnessMapWithAbi,
235
+ convertPrivateKernelInner2OutputsFromWitnessMapWithAbi,
236
+ );
237
+ }
238
+
239
+ public async generateInner3Output(
240
+ inputs: PrivateKernelInner3CircuitPrivateInputs,
241
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
242
+ return await this.generateCircuitOutput(
243
+ inputs,
244
+ 'PrivateKernelInner3Artifact',
245
+ convertPrivateKernelInner3InputsToWitnessMapWithAbi,
246
+ convertPrivateKernelInner3OutputsFromWitnessMapWithAbi,
247
+ );
248
+ }
249
+
250
+ public async simulateInner3(
251
+ inputs: PrivateKernelInner3CircuitPrivateInputs,
252
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
253
+ return await this.simulateCircuitOutput(
254
+ inputs,
255
+ 'PrivateKernelInner3Artifact',
256
+ convertPrivateKernelInner3InputsToWitnessMapWithAbi,
257
+ convertPrivateKernelInner3OutputsFromWitnessMapWithAbi,
258
+ );
259
+ }
260
+
261
+ public async generateInner4Output(
262
+ inputs: PrivateKernelInner4CircuitPrivateInputs,
263
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
264
+ return await this.generateCircuitOutput(
265
+ inputs,
266
+ 'PrivateKernelInner4Artifact',
267
+ convertPrivateKernelInner4InputsToWitnessMapWithAbi,
268
+ convertPrivateKernelInner4OutputsFromWitnessMapWithAbi,
269
+ );
270
+ }
271
+
272
+ public async simulateInner4(
273
+ inputs: PrivateKernelInner4CircuitPrivateInputs,
274
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
275
+ return await this.simulateCircuitOutput(
276
+ inputs,
277
+ 'PrivateKernelInner4Artifact',
278
+ convertPrivateKernelInner4InputsToWitnessMapWithAbi,
279
+ convertPrivateKernelInner4OutputsFromWitnessMapWithAbi,
280
+ );
281
+ }
282
+
283
+ public async generateInner5Output(
284
+ inputs: PrivateKernelInner5CircuitPrivateInputs,
285
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
286
+ return await this.generateCircuitOutput(
287
+ inputs,
288
+ 'PrivateKernelInner5Artifact',
289
+ convertPrivateKernelInner5InputsToWitnessMapWithAbi,
290
+ convertPrivateKernelInner5OutputsFromWitnessMapWithAbi,
291
+ );
292
+ }
293
+
294
+ public async simulateInner5(
295
+ inputs: PrivateKernelInner5CircuitPrivateInputs,
296
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
297
+ return await this.simulateCircuitOutput(
298
+ inputs,
299
+ 'PrivateKernelInner5Artifact',
300
+ convertPrivateKernelInner5InputsToWitnessMapWithAbi,
301
+ convertPrivateKernelInner5OutputsFromWitnessMapWithAbi,
302
+ );
303
+ }
304
+
104
305
  public async generateResetOutput(
105
306
  inputs: PrivateKernelResetCircuitPrivateInputs,
106
307
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
@@ -128,40 +329,42 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
128
329
  );
129
330
  }
130
331
 
131
- public async generateTailOutput(
132
- inputs: PrivateKernelTailCircuitPrivateInputs,
332
+ public async generateResetTailOutput(
333
+ inputs: PrivateKernelResetTailCircuitPrivateInputs,
133
334
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
335
+ const artifactName = getPrivateKernelResetTailArtifactName(inputs.dimensions, inputs.isForPublic());
134
336
  if (!inputs.isForPublic()) {
135
337
  return await this.generateCircuitOutput(
136
338
  inputs,
137
- 'PrivateKernelTailArtifact',
138
- convertPrivateKernelTailInputsToWitnessMapWithAbi,
339
+ artifactName,
340
+ convertPrivateKernelResetTailInputsToWitnessMapWithAbi,
139
341
  convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
140
342
  );
141
343
  }
142
344
  return await this.generateCircuitOutput(
143
345
  inputs,
144
- 'PrivateKernelTailToPublicArtifact',
145
- convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
346
+ artifactName,
347
+ convertPrivateKernelResetTailToPublicInputsToWitnessMapWithAbi,
146
348
  convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
147
349
  );
148
350
  }
149
351
 
150
- public async simulateTail(
151
- inputs: PrivateKernelTailCircuitPrivateInputs,
352
+ public async simulateResetTail(
353
+ inputs: PrivateKernelResetTailCircuitPrivateInputs,
152
354
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
355
+ const artifactName = getPrivateKernelResetTailArtifactName(inputs.dimensions, inputs.isForPublic());
153
356
  if (!inputs.isForPublic()) {
154
357
  return await this.simulateCircuitOutput(
155
358
  inputs,
156
- 'PrivateKernelTailArtifact',
157
- convertPrivateKernelTailInputsToWitnessMapWithAbi,
359
+ artifactName,
360
+ convertPrivateKernelResetTailInputsToWitnessMapWithAbi,
158
361
  convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
159
362
  );
160
363
  }
161
364
  return await this.simulateCircuitOutput(
162
365
  inputs,
163
- 'PrivateKernelTailToPublicArtifact',
164
- convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
366
+ artifactName,
367
+ convertPrivateKernelResetTailToPublicInputsToWitnessMapWithAbi,
165
368
  convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
166
369
  );
167
370
  }
@@ -278,32 +481,50 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
278
481
  this.log.info(`Generating ClientIVC proof...`);
279
482
  const barretenberg = await Barretenberg.initSingleton({
280
483
  ...this.options,
281
- logger: this.options.logger?.[(process.env.LOG_LEVEL as LogLevel) || 'verbose'],
484
+ logger: this.options.logger?.verbose,
282
485
  });
283
486
  const backend = new AztecClientBackend(
284
487
  executionSteps.map(step => ungzip(step.bytecode)),
285
488
  barretenberg,
489
+ executionSteps.map(step => step.functionName),
490
+ executionSteps.map(step => step.kind),
286
491
  );
287
492
 
288
- const [proof] = await backend.prove(
493
+ // Use compressed prove path to get both proof fields and compressed proof bytes
494
+ const result = await backend.prove(
289
495
  executionSteps.map(step => ungzip(serializeWitness(step.witness))),
290
496
  executionSteps.map(step => step.vk),
497
+ { compress: true },
291
498
  );
292
499
  this.log.info(`Generated ClientIVC proof`, {
293
500
  eventName: 'client-ivc-proof-generation',
294
501
  duration: timer.ms(),
295
- proofSize: proof.length,
502
+ proofSize: result.proofFields.length,
503
+ compressedSize: result.compressedProof?.length,
296
504
  });
297
- return ChonkProofWithPublicInputs.fromBufferArray(proof);
505
+
506
+ // Create ChonkProofWithPublicInputs from the flat field elements
507
+ const proofWithPubInputs = ChonkProofWithPublicInputs.fromBufferArray(result.proofFields);
508
+
509
+ // Attach compressed proof bytes to the ChonkProof (without public inputs).
510
+ // The compressed bytes are for the full proof WITH public inputs from bb;
511
+ // when deserializing, the decompressor will strip them to match CHONK_PROOF_LENGTH.
512
+ proofWithPubInputs.compressedProof = result.compressedProof ? Buffer.from(result.compressedProof) : undefined;
513
+
514
+ return proofWithPubInputs;
298
515
  }
299
516
 
300
- public async computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
517
+ public async computeGateCountForCircuit(
518
+ _bytecode: Buffer,
519
+ _circuitName: string,
520
+ _circuitKind: PrivateExecutionStep['kind'],
521
+ ): Promise<number> {
301
522
  // Note we do not pass the vk to the backend. This is unneeded for gate counts.
302
523
  const barretenberg = await Barretenberg.initSingleton({
303
524
  ...this.options,
304
525
  logger: this.options.logger?.[(process.env.LOG_LEVEL as LogLevel) || 'verbose'],
305
526
  });
306
- const backend = new AztecClientBackend([ungzip(_bytecode)], barretenberg);
527
+ const backend = new AztecClientBackend([ungzip(_bytecode)], barretenberg, [_circuitName], [_circuitKind]);
307
528
  const gateCount = await backend.gates();
308
529
  return gateCount[0];
309
530
  }
@@ -16,7 +16,7 @@ import assert from 'assert';
16
16
  import { promises as fs } from 'fs';
17
17
  import * as path from 'path';
18
18
 
19
- import { PROOF_FILENAME, PUBLIC_INPUTS_FILENAME } from '../bb/execute.js';
19
+ import { PROOF_FILENAME, PUBLIC_INPUTS_FILENAME } from '../bb/file_names.js';
20
20
 
21
21
  /**
22
22
  * Create a ChonkProof proof file.
@@ -113,3 +113,43 @@ export async function readProofsFromOutputDirectory<PROOF_LENGTH extends number>
113
113
  proofLength,
114
114
  );
115
115
  }
116
+
117
+ /**
118
+ * Construct a RecursiveProof from in-memory proof and public input field arrays
119
+ * returned by the bb.js circuitProve API, without reading from files.
120
+ *
121
+ * @param proofFields - Proof fields as 32-byte Uint8Arrays from circuitProve.
122
+ * @param publicInputFields - Public input fields as 32-byte Uint8Arrays from circuitProve.
123
+ * @param vkData - Verification key data for the circuit.
124
+ * @param proofLength - Expected proof field count.
125
+ */
126
+ export function constructRecursiveProofFromBuffers<PROOF_LENGTH extends number>(
127
+ proofFields: Uint8Array[],
128
+ publicInputFields: Uint8Array[],
129
+ vkData: VerificationKeyData,
130
+ proofLength: PROOF_LENGTH,
131
+ ): RecursiveProof<PROOF_LENGTH> {
132
+ assert(
133
+ proofLength == NESTED_RECURSIVE_PROOF_LENGTH ||
134
+ proofLength == NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH ||
135
+ proofLength == ULTRA_KECCAK_PROOF_LENGTH,
136
+ `Proof length must be one of the expected proof lengths, received ${proofLength}`,
137
+ );
138
+
139
+ // Convert Uint8Array fields to Fr instances
140
+ const proofFieldsFr = proofFields.map(f => Fr.fromBuffer(Buffer.from(f)));
141
+
142
+ assert(
143
+ proofFieldsFr.length == proofLength,
144
+ `Proof fields length mismatch: ${proofFieldsFr.length} != ${proofLength}`,
145
+ );
146
+
147
+ // Reconstruct the binary proof with public inputs prepended (same format as file-based path)
148
+ const binaryPublicInputs = Buffer.concat(publicInputFields.map(f => Buffer.from(f)));
149
+ const binaryProof = Buffer.concat(proofFields.map(f => Buffer.from(f)));
150
+ const binaryProofWithPublicInputs = Buffer.concat([binaryPublicInputs, binaryProof]);
151
+
152
+ const numPublicInputs = getNumCustomPublicInputs(proofLength, vkData);
153
+
154
+ return new RecursiveProof(proofFieldsFr, new Proof(binaryProofWithPublicInputs, numPublicInputs), true, proofLength);
155
+ }