@aztec/bb-prover 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928

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 (66) hide show
  1. package/dest/avm_proving_tests/avm_proving_tester.d.ts +13 -8
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +153 -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 +385 -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 +12 -4
  22. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
  23. package/dest/prover/client/bb_private_kernel_prover.js +47 -11
  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 +210 -79
  30. package/dest/test/test_circuit_prover.d.ts +3 -3
  31. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  32. package/dest/test/test_circuit_prover.js +2 -2
  33. package/dest/verification_key/verification_key_data.js +1 -1
  34. package/dest/verifier/batch_chonk_verifier.d.ts +46 -0
  35. package/dest/verifier/batch_chonk_verifier.d.ts.map +1 -0
  36. package/dest/verifier/batch_chonk_verifier.js +237 -0
  37. package/dest/verifier/bb_verifier.d.ts +4 -1
  38. package/dest/verifier/bb_verifier.d.ts.map +1 -1
  39. package/dest/verifier/bb_verifier.js +134 -45
  40. package/dest/verifier/index.d.ts +2 -1
  41. package/dest/verifier/index.d.ts.map +1 -1
  42. package/dest/verifier/index.js +1 -0
  43. package/dest/verifier/queued_chonk_verifier.d.ts +14 -3
  44. package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -1
  45. package/dest/verifier/queued_chonk_verifier.js +7 -6
  46. package/package.json +19 -17
  47. package/src/avm_proving_tests/avm_proving_tester.ts +54 -127
  48. package/src/bb/bb_js_backend.ts +441 -0
  49. package/src/bb/bb_js_debug.ts +227 -0
  50. package/src/bb/file_names.ts +6 -0
  51. package/src/config.ts +16 -0
  52. package/src/index.ts +2 -1
  53. package/src/instrumentation.ts +12 -4
  54. package/src/prover/client/bb_private_kernel_prover.ts +134 -19
  55. package/src/prover/proof_utils.ts +41 -1
  56. package/src/prover/server/bb_prover.ts +130 -141
  57. package/src/test/test_circuit_prover.ts +3 -5
  58. package/src/verification_key/verification_key_data.ts +1 -1
  59. package/src/verifier/batch_chonk_verifier.ts +281 -0
  60. package/src/verifier/bb_verifier.ts +66 -76
  61. package/src/verifier/index.ts +1 -0
  62. package/src/verifier/queued_chonk_verifier.ts +8 -8
  63. package/dest/bb/execute.d.ts +0 -107
  64. package/dest/bb/execute.d.ts.map +0 -1
  65. package/dest/bb/execute.js +0 -647
  66. 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,27 @@ import { serializeWitness } from '@aztec/noir-noirc_abi';
5
5
  import {
6
6
  convertHidingKernelPublicInputsToWitnessMapWithAbi,
7
7
  convertHidingKernelToRollupInputsToWitnessMapWithAbi,
8
+ convertPrivateKernelInit2InputsToWitnessMapWithAbi,
9
+ convertPrivateKernelInit2OutputsFromWitnessMapWithAbi,
10
+ convertPrivateKernelInit3InputsToWitnessMapWithAbi,
11
+ convertPrivateKernelInit3OutputsFromWitnessMapWithAbi,
8
12
  convertPrivateKernelInitInputsToWitnessMapWithAbi,
9
13
  convertPrivateKernelInitOutputsFromWitnessMapWithAbi,
14
+ convertPrivateKernelInner2InputsToWitnessMapWithAbi,
15
+ convertPrivateKernelInner2OutputsFromWitnessMapWithAbi,
16
+ convertPrivateKernelInner3InputsToWitnessMapWithAbi,
17
+ convertPrivateKernelInner3OutputsFromWitnessMapWithAbi,
10
18
  convertPrivateKernelInnerInputsToWitnessMapWithAbi,
11
19
  convertPrivateKernelInnerOutputsFromWitnessMapWithAbi,
12
20
  convertPrivateKernelResetInputsToWitnessMapWithAbi,
13
21
  convertPrivateKernelResetOutputsFromWitnessMapWithAbi,
22
+ convertPrivateKernelResetTailInputsToWitnessMapWithAbi,
23
+ convertPrivateKernelResetTailToPublicInputsToWitnessMapWithAbi,
14
24
  convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
15
- convertPrivateKernelTailInputsToWitnessMapWithAbi,
16
25
  convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
17
- convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
18
26
  foreignCallHandler,
19
27
  getPrivateKernelResetArtifactName,
28
+ getPrivateKernelResetTailArtifactName,
20
29
  updateResetCircuitSampleInputs,
21
30
  } from '@aztec/noir-protocol-circuits-types/client';
22
31
  import {
@@ -32,11 +41,15 @@ import type {
32
41
  HidingKernelToRollupPrivateInputs,
33
42
  PrivateExecutionStep,
34
43
  PrivateKernelCircuitPublicInputs,
44
+ PrivateKernelInit2CircuitPrivateInputs,
45
+ PrivateKernelInit3CircuitPrivateInputs,
35
46
  PrivateKernelInitCircuitPrivateInputs,
47
+ PrivateKernelInner2CircuitPrivateInputs,
48
+ PrivateKernelInner3CircuitPrivateInputs,
36
49
  PrivateKernelInnerCircuitPrivateInputs,
37
50
  PrivateKernelResetCircuitPrivateInputs,
51
+ PrivateKernelResetTailCircuitPrivateInputs,
38
52
  PrivateKernelSimulateOutput,
39
- PrivateKernelTailCircuitPrivateInputs,
40
53
  PrivateKernelTailCircuitPublicInputs,
41
54
  } from '@aztec/stdlib/kernel';
42
55
  import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
@@ -79,6 +92,50 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
79
92
  );
80
93
  }
81
94
 
95
+ public async generateInit2Output(
96
+ inputs: PrivateKernelInit2CircuitPrivateInputs,
97
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
98
+ return await this.generateCircuitOutput(
99
+ inputs,
100
+ 'PrivateKernelInit2Artifact',
101
+ convertPrivateKernelInit2InputsToWitnessMapWithAbi,
102
+ convertPrivateKernelInit2OutputsFromWitnessMapWithAbi,
103
+ );
104
+ }
105
+
106
+ public async simulateInit2(
107
+ inputs: PrivateKernelInit2CircuitPrivateInputs,
108
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
109
+ return await this.simulateCircuitOutput(
110
+ inputs,
111
+ 'PrivateKernelInit2Artifact',
112
+ convertPrivateKernelInit2InputsToWitnessMapWithAbi,
113
+ convertPrivateKernelInit2OutputsFromWitnessMapWithAbi,
114
+ );
115
+ }
116
+
117
+ public async generateInit3Output(
118
+ inputs: PrivateKernelInit3CircuitPrivateInputs,
119
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
120
+ return await this.generateCircuitOutput(
121
+ inputs,
122
+ 'PrivateKernelInit3Artifact',
123
+ convertPrivateKernelInit3InputsToWitnessMapWithAbi,
124
+ convertPrivateKernelInit3OutputsFromWitnessMapWithAbi,
125
+ );
126
+ }
127
+
128
+ public async simulateInit3(
129
+ inputs: PrivateKernelInit3CircuitPrivateInputs,
130
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
131
+ return await this.simulateCircuitOutput(
132
+ inputs,
133
+ 'PrivateKernelInit3Artifact',
134
+ convertPrivateKernelInit3InputsToWitnessMapWithAbi,
135
+ convertPrivateKernelInit3OutputsFromWitnessMapWithAbi,
136
+ );
137
+ }
138
+
82
139
  public async generateInnerOutput(
83
140
  inputs: PrivateKernelInnerCircuitPrivateInputs,
84
141
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
@@ -101,6 +158,50 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
101
158
  );
102
159
  }
103
160
 
161
+ public async generateInner2Output(
162
+ inputs: PrivateKernelInner2CircuitPrivateInputs,
163
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
164
+ return await this.generateCircuitOutput(
165
+ inputs,
166
+ 'PrivateKernelInner2Artifact',
167
+ convertPrivateKernelInner2InputsToWitnessMapWithAbi,
168
+ convertPrivateKernelInner2OutputsFromWitnessMapWithAbi,
169
+ );
170
+ }
171
+
172
+ public async simulateInner2(
173
+ inputs: PrivateKernelInner2CircuitPrivateInputs,
174
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
175
+ return await this.simulateCircuitOutput(
176
+ inputs,
177
+ 'PrivateKernelInner2Artifact',
178
+ convertPrivateKernelInner2InputsToWitnessMapWithAbi,
179
+ convertPrivateKernelInner2OutputsFromWitnessMapWithAbi,
180
+ );
181
+ }
182
+
183
+ public async generateInner3Output(
184
+ inputs: PrivateKernelInner3CircuitPrivateInputs,
185
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
186
+ return await this.generateCircuitOutput(
187
+ inputs,
188
+ 'PrivateKernelInner3Artifact',
189
+ convertPrivateKernelInner3InputsToWitnessMapWithAbi,
190
+ convertPrivateKernelInner3OutputsFromWitnessMapWithAbi,
191
+ );
192
+ }
193
+
194
+ public async simulateInner3(
195
+ inputs: PrivateKernelInner3CircuitPrivateInputs,
196
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
197
+ return await this.simulateCircuitOutput(
198
+ inputs,
199
+ 'PrivateKernelInner3Artifact',
200
+ convertPrivateKernelInner3InputsToWitnessMapWithAbi,
201
+ convertPrivateKernelInner3OutputsFromWitnessMapWithAbi,
202
+ );
203
+ }
204
+
104
205
  public async generateResetOutput(
105
206
  inputs: PrivateKernelResetCircuitPrivateInputs,
106
207
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
@@ -128,40 +229,42 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
128
229
  );
129
230
  }
130
231
 
131
- public async generateTailOutput(
132
- inputs: PrivateKernelTailCircuitPrivateInputs,
232
+ public async generateResetTailOutput(
233
+ inputs: PrivateKernelResetTailCircuitPrivateInputs,
133
234
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
235
+ const artifactName = getPrivateKernelResetTailArtifactName(inputs.dimensions, inputs.isForPublic());
134
236
  if (!inputs.isForPublic()) {
135
237
  return await this.generateCircuitOutput(
136
238
  inputs,
137
- 'PrivateKernelTailArtifact',
138
- convertPrivateKernelTailInputsToWitnessMapWithAbi,
239
+ artifactName,
240
+ convertPrivateKernelResetTailInputsToWitnessMapWithAbi,
139
241
  convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
140
242
  );
141
243
  }
142
244
  return await this.generateCircuitOutput(
143
245
  inputs,
144
- 'PrivateKernelTailToPublicArtifact',
145
- convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
246
+ artifactName,
247
+ convertPrivateKernelResetTailToPublicInputsToWitnessMapWithAbi,
146
248
  convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
147
249
  );
148
250
  }
149
251
 
150
- public async simulateTail(
151
- inputs: PrivateKernelTailCircuitPrivateInputs,
252
+ public async simulateResetTail(
253
+ inputs: PrivateKernelResetTailCircuitPrivateInputs,
152
254
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
255
+ const artifactName = getPrivateKernelResetTailArtifactName(inputs.dimensions, inputs.isForPublic());
153
256
  if (!inputs.isForPublic()) {
154
257
  return await this.simulateCircuitOutput(
155
258
  inputs,
156
- 'PrivateKernelTailArtifact',
157
- convertPrivateKernelTailInputsToWitnessMapWithAbi,
259
+ artifactName,
260
+ convertPrivateKernelResetTailInputsToWitnessMapWithAbi,
158
261
  convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
159
262
  );
160
263
  }
161
264
  return await this.simulateCircuitOutput(
162
265
  inputs,
163
- 'PrivateKernelTailToPublicArtifact',
164
- convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
266
+ artifactName,
267
+ convertPrivateKernelResetTailToPublicInputsToWitnessMapWithAbi,
165
268
  convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
166
269
  );
167
270
  }
@@ -278,7 +381,7 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
278
381
  this.log.info(`Generating ClientIVC proof...`);
279
382
  const barretenberg = await Barretenberg.initSingleton({
280
383
  ...this.options,
281
- logger: this.options.logger?.[(process.env.LOG_LEVEL as LogLevel) || 'verbose'],
384
+ logger: this.options.logger?.verbose,
282
385
  });
283
386
  const backend = new AztecClientBackend(
284
387
  executionSteps.map(step => ungzip(step.bytecode)),
@@ -286,16 +389,28 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
286
389
  executionSteps.map(step => step.functionName),
287
390
  );
288
391
 
289
- const [proof] = await backend.prove(
392
+ // Use compressed prove path to get both proof fields and compressed proof bytes
393
+ const result = await backend.prove(
290
394
  executionSteps.map(step => ungzip(serializeWitness(step.witness))),
291
395
  executionSteps.map(step => step.vk),
396
+ { compress: true },
292
397
  );
293
398
  this.log.info(`Generated ClientIVC proof`, {
294
399
  eventName: 'client-ivc-proof-generation',
295
400
  duration: timer.ms(),
296
- proofSize: proof.length,
401
+ proofSize: result.proofFields.length,
402
+ compressedSize: result.compressedProof?.length,
297
403
  });
298
- return ChonkProofWithPublicInputs.fromBufferArray(proof);
404
+
405
+ // Create ChonkProofWithPublicInputs from the flat field elements
406
+ const proofWithPubInputs = ChonkProofWithPublicInputs.fromBufferArray(result.proofFields);
407
+
408
+ // Attach compressed proof bytes to the ChonkProof (without public inputs).
409
+ // The compressed bytes are for the full proof WITH public inputs from bb;
410
+ // when deserializing, the decompressor will strip them to match CHONK_PROOF_LENGTH.
411
+ proofWithPubInputs.compressedProof = result.compressedProof ? Buffer.from(result.compressedProof) : undefined;
412
+
413
+ return proofWithPubInputs;
299
414
  }
300
415
 
301
416
  public async computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
@@ -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
+ }