@aztec/bb-prover 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa

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 +18 -13
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +192 -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/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 +31 -9
  25. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -1
  26. package/dest/prover/client/bb_private_kernel_prover.js +107 -14
  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 +9 -22
  38. package/dest/prover/server/bb_prover.d.ts.map +1 -1
  39. package/dest/prover/server/bb_prover.js +613 -113
  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 +5 -5
  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 +99 -140
  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 +281 -23
  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 +132 -162
  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 +11 -16
  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
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
 
@@ -7,7 +7,6 @@ import {
7
7
  Metrics,
8
8
  type TelemetryClient,
9
9
  type Tracer,
10
- ValueType,
11
10
  } from '@aztec/telemetry-client';
12
11
 
13
12
  /**
@@ -31,51 +30,21 @@ export class ProverInstrumentation {
31
30
  this.tracer = telemetry.getTracer(name);
32
31
  const meter = telemetry.getMeter(name);
33
32
 
34
- this.simulationDuration = meter.createHistogram(Metrics.CIRCUIT_SIMULATION_DURATION, {
35
- description: 'Records how long it takes to simulate a circuit',
36
- unit: 'ms',
37
- valueType: ValueType.INT,
38
- });
33
+ this.simulationDuration = meter.createHistogram(Metrics.CIRCUIT_SIMULATION_DURATION);
39
34
 
40
- this.witGenDuration = meter.createHistogram(Metrics.CIRCUIT_WITNESS_GEN_DURATION, {
41
- description: 'Records how long it takes to generate the partial witness for a circuit',
42
- unit: 's',
43
- valueType: ValueType.DOUBLE,
44
- });
35
+ this.witGenDuration = meter.createHistogram(Metrics.CIRCUIT_WITNESS_GEN_DURATION);
45
36
 
46
- this.provingDuration = meter.createHistogram(Metrics.CIRCUIT_PROVING_DURATION, {
47
- unit: 's',
48
- description: 'Records how long it takes to prove a circuit',
49
- valueType: ValueType.DOUBLE,
50
- });
37
+ this.provingDuration = meter.createHistogram(Metrics.CIRCUIT_PROVING_DURATION);
51
38
 
52
- this.witGenInputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_INPUT_SIZE, {
53
- unit: 'By',
54
- description: 'Records the size of the input to the witness generation',
55
- valueType: ValueType.INT,
56
- });
39
+ this.witGenInputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_INPUT_SIZE);
57
40
 
58
- this.witGenOutputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_OUTPUT_SIZE, {
59
- unit: 'By',
60
- description: 'Records the size of the output of the witness generation',
61
- valueType: ValueType.INT,
62
- });
41
+ this.witGenOutputSize = meter.createGauge(Metrics.CIRCUIT_WITNESS_GEN_OUTPUT_SIZE);
63
42
 
64
- this.proofSize = meter.createGauge(Metrics.CIRCUIT_PROVING_PROOF_SIZE, {
65
- unit: 'By',
66
- description: 'Records the size of the proof generated for a circuit',
67
- valueType: ValueType.INT,
68
- });
43
+ this.proofSize = meter.createGauge(Metrics.CIRCUIT_PROVING_PROOF_SIZE);
69
44
 
70
- this.circuitPublicInputCount = meter.createGauge(Metrics.CIRCUIT_PUBLIC_INPUTS_COUNT, {
71
- description: 'Records the number of public inputs in a circuit',
72
- valueType: ValueType.INT,
73
- });
45
+ this.circuitPublicInputCount = meter.createGauge(Metrics.CIRCUIT_PUBLIC_INPUTS_COUNT);
74
46
 
75
- this.circuitSize = meter.createGauge(Metrics.CIRCUIT_SIZE, {
76
- description: 'Records the size of the circuit in gates',
77
- valueType: ValueType.INT,
78
- });
47
+ this.circuitSize = meter.createGauge(Metrics.CIRCUIT_SIZE);
79
48
  }
80
49
 
81
50
  /**
@@ -89,10 +58,18 @@ export class ProverInstrumentation {
89
58
  circuitName: CircuitName,
90
59
  timerOrMS: Timer | number,
91
60
  ) {
92
- const s = typeof timerOrMS === 'number' ? timerOrMS / 1000 : timerOrMS.s();
93
- this[metric].record(s, {
94
- [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
95
- });
61
+ // Simulation duration is stored in ms, while the others are stored in seconds
62
+ if (metric === 'simulationDuration') {
63
+ const ms = typeof timerOrMS === 'number' ? timerOrMS : timerOrMS.ms();
64
+ this[metric].record(Math.trunc(ms), {
65
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
66
+ });
67
+ } else {
68
+ const s = typeof timerOrMS === 'number' ? timerOrMS / 1000 : timerOrMS.s();
69
+ this[metric].record(s, {
70
+ [Attributes.PROTOCOL_CIRCUIT_NAME]: circuitName,
71
+ });
72
+ }
96
73
  }
97
74
 
98
75
  /**
@@ -1,19 +1,39 @@
1
- import { createLogger } from '@aztec/foundation/log';
1
+ import { AztecClientBackend, type BackendOptions, Barretenberg } from '@aztec/bb.js';
2
+ import { type LogLevel, type Logger, createLogger } from '@aztec/foundation/log';
3
+ import { Timer } from '@aztec/foundation/timer';
4
+ import { serializeWitness } from '@aztec/noir-noirc_abi';
2
5
  import {
3
6
  convertHidingKernelPublicInputsToWitnessMapWithAbi,
4
7
  convertHidingKernelToRollupInputsToWitnessMapWithAbi,
8
+ convertPrivateKernelInit2InputsToWitnessMapWithAbi,
9
+ convertPrivateKernelInit2OutputsFromWitnessMapWithAbi,
10
+ convertPrivateKernelInit3InputsToWitnessMapWithAbi,
11
+ convertPrivateKernelInit3OutputsFromWitnessMapWithAbi,
12
+ convertPrivateKernelInit4InputsToWitnessMapWithAbi,
13
+ convertPrivateKernelInit4OutputsFromWitnessMapWithAbi,
14
+ convertPrivateKernelInit5InputsToWitnessMapWithAbi,
15
+ convertPrivateKernelInit5OutputsFromWitnessMapWithAbi,
5
16
  convertPrivateKernelInitInputsToWitnessMapWithAbi,
6
17
  convertPrivateKernelInitOutputsFromWitnessMapWithAbi,
18
+ convertPrivateKernelInner2InputsToWitnessMapWithAbi,
19
+ convertPrivateKernelInner2OutputsFromWitnessMapWithAbi,
20
+ convertPrivateKernelInner3InputsToWitnessMapWithAbi,
21
+ convertPrivateKernelInner3OutputsFromWitnessMapWithAbi,
22
+ convertPrivateKernelInner4InputsToWitnessMapWithAbi,
23
+ convertPrivateKernelInner4OutputsFromWitnessMapWithAbi,
24
+ convertPrivateKernelInner5InputsToWitnessMapWithAbi,
25
+ convertPrivateKernelInner5OutputsFromWitnessMapWithAbi,
7
26
  convertPrivateKernelInnerInputsToWitnessMapWithAbi,
8
27
  convertPrivateKernelInnerOutputsFromWitnessMapWithAbi,
9
28
  convertPrivateKernelResetInputsToWitnessMapWithAbi,
10
29
  convertPrivateKernelResetOutputsFromWitnessMapWithAbi,
30
+ convertPrivateKernelResetTailInputsToWitnessMapWithAbi,
31
+ convertPrivateKernelResetTailToPublicInputsToWitnessMapWithAbi,
11
32
  convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
12
- convertPrivateKernelTailInputsToWitnessMapWithAbi,
13
33
  convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
14
- convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
15
34
  foreignCallHandler,
16
35
  getPrivateKernelResetArtifactName,
36
+ getPrivateKernelResetTailArtifactName,
17
37
  updateResetCircuitSampleInputs,
18
38
  } from '@aztec/noir-protocol-circuits-types/client';
19
39
  import {
@@ -29,23 +49,38 @@ import type {
29
49
  HidingKernelToRollupPrivateInputs,
30
50
  PrivateExecutionStep,
31
51
  PrivateKernelCircuitPublicInputs,
52
+ PrivateKernelInit2CircuitPrivateInputs,
53
+ PrivateKernelInit3CircuitPrivateInputs,
54
+ PrivateKernelInit4CircuitPrivateInputs,
55
+ PrivateKernelInit5CircuitPrivateInputs,
32
56
  PrivateKernelInitCircuitPrivateInputs,
57
+ PrivateKernelInner2CircuitPrivateInputs,
58
+ PrivateKernelInner3CircuitPrivateInputs,
59
+ PrivateKernelInner4CircuitPrivateInputs,
60
+ PrivateKernelInner5CircuitPrivateInputs,
33
61
  PrivateKernelInnerCircuitPrivateInputs,
34
62
  PrivateKernelResetCircuitPrivateInputs,
63
+ PrivateKernelResetTailCircuitPrivateInputs,
35
64
  PrivateKernelSimulateOutput,
36
- PrivateKernelTailCircuitPrivateInputs,
37
65
  PrivateKernelTailCircuitPublicInputs,
38
66
  } from '@aztec/stdlib/kernel';
39
67
  import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
40
- import type { ChonkProofWithPublicInputs } from '@aztec/stdlib/proofs';
68
+ import { ChonkProofWithPublicInputs } from '@aztec/stdlib/proofs';
41
69
  import type { CircuitSimulationStats, CircuitWitnessGenerationStats } from '@aztec/stdlib/stats';
42
70
 
71
+ import { ungzip } from 'pako';
72
+
73
+ export type BBPrivateKernelProverOptions = Omit<BackendOptions, 'logger'> & { logger?: Logger };
43
74
  export abstract class BBPrivateKernelProver implements PrivateKernelProver {
75
+ private log: Logger;
76
+
44
77
  constructor(
45
78
  protected artifactProvider: ArtifactProvider,
46
79
  protected simulator: CircuitSimulator,
47
- protected log = createLogger('bb-prover'),
48
- ) {}
80
+ protected options: BBPrivateKernelProverOptions = {},
81
+ ) {
82
+ this.log = options.logger || createLogger('bb-prover:private-kernel');
83
+ }
49
84
 
50
85
  public async generateInitOutput(
51
86
  inputs: PrivateKernelInitCircuitPrivateInputs,
@@ -69,6 +104,94 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
69
104
  );
70
105
  }
71
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
+
72
195
  public async generateInnerOutput(
73
196
  inputs: PrivateKernelInnerCircuitPrivateInputs,
74
197
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
@@ -91,6 +214,94 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
91
214
  );
92
215
  }
93
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
+
94
305
  public async generateResetOutput(
95
306
  inputs: PrivateKernelResetCircuitPrivateInputs,
96
307
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
@@ -118,40 +329,42 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
118
329
  );
119
330
  }
120
331
 
121
- public async generateTailOutput(
122
- inputs: PrivateKernelTailCircuitPrivateInputs,
332
+ public async generateResetTailOutput(
333
+ inputs: PrivateKernelResetTailCircuitPrivateInputs,
123
334
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
335
+ const artifactName = getPrivateKernelResetTailArtifactName(inputs.dimensions, inputs.isForPublic());
124
336
  if (!inputs.isForPublic()) {
125
337
  return await this.generateCircuitOutput(
126
338
  inputs,
127
- 'PrivateKernelTailArtifact',
128
- convertPrivateKernelTailInputsToWitnessMapWithAbi,
339
+ artifactName,
340
+ convertPrivateKernelResetTailInputsToWitnessMapWithAbi,
129
341
  convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
130
342
  );
131
343
  }
132
344
  return await this.generateCircuitOutput(
133
345
  inputs,
134
- 'PrivateKernelTailToPublicArtifact',
135
- convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
346
+ artifactName,
347
+ convertPrivateKernelResetTailToPublicInputsToWitnessMapWithAbi,
136
348
  convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
137
349
  );
138
350
  }
139
351
 
140
- public async simulateTail(
141
- inputs: PrivateKernelTailCircuitPrivateInputs,
352
+ public async simulateResetTail(
353
+ inputs: PrivateKernelResetTailCircuitPrivateInputs,
142
354
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
355
+ const artifactName = getPrivateKernelResetTailArtifactName(inputs.dimensions, inputs.isForPublic());
143
356
  if (!inputs.isForPublic()) {
144
357
  return await this.simulateCircuitOutput(
145
358
  inputs,
146
- 'PrivateKernelTailArtifact',
147
- convertPrivateKernelTailInputsToWitnessMapWithAbi,
359
+ artifactName,
360
+ convertPrivateKernelResetTailInputsToWitnessMapWithAbi,
148
361
  convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
149
362
  );
150
363
  }
151
364
  return await this.simulateCircuitOutput(
152
365
  inputs,
153
- 'PrivateKernelTailToPublicArtifact',
154
- convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
366
+ artifactName,
367
+ convertPrivateKernelResetTailToPublicInputsToWitnessMapWithAbi,
155
368
  convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
156
369
  );
157
370
  }
@@ -263,11 +476,56 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
263
476
  return kernelProofOutput;
264
477
  }
265
478
 
266
- public createChonkProof(_executionSteps: PrivateExecutionStep[]): Promise<ChonkProofWithPublicInputs> {
267
- throw new Error('Not implemented');
479
+ public async createChonkProof(executionSteps: PrivateExecutionStep[]): Promise<ChonkProofWithPublicInputs> {
480
+ const timer = new Timer();
481
+ this.log.info(`Generating ClientIVC proof...`);
482
+ const barretenberg = await Barretenberg.initSingleton({
483
+ ...this.options,
484
+ logger: this.options.logger?.verbose,
485
+ });
486
+ const backend = new AztecClientBackend(
487
+ executionSteps.map(step => ungzip(step.bytecode)),
488
+ barretenberg,
489
+ executionSteps.map(step => step.functionName),
490
+ executionSteps.map(step => step.kind),
491
+ );
492
+
493
+ // Use compressed prove path to get both proof fields and compressed proof bytes
494
+ const result = await backend.prove(
495
+ executionSteps.map(step => ungzip(serializeWitness(step.witness))),
496
+ executionSteps.map(step => step.vk),
497
+ { compress: true },
498
+ );
499
+ this.log.info(`Generated ClientIVC proof`, {
500
+ eventName: 'client-ivc-proof-generation',
501
+ duration: timer.ms(),
502
+ proofSize: result.proofFields.length,
503
+ compressedSize: result.compressedProof?.length,
504
+ });
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;
268
515
  }
269
516
 
270
- public computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
271
- throw new Error('Not implemented');
517
+ public async computeGateCountForCircuit(
518
+ _bytecode: Buffer,
519
+ _circuitName: string,
520
+ _circuitKind: PrivateExecutionStep['kind'],
521
+ ): Promise<number> {
522
+ // Note we do not pass the vk to the backend. This is unneeded for gate counts.
523
+ const barretenberg = await Barretenberg.initSingleton({
524
+ ...this.options,
525
+ logger: this.options.logger?.[(process.env.LOG_LEVEL as LogLevel) || 'verbose'],
526
+ });
527
+ const backend = new AztecClientBackend([ungzip(_bytecode)], barretenberg, [_circuitName], [_circuitKind]);
528
+ const gateCount = await backend.gates();
529
+ return gateCount[0];
272
530
  }
273
531
  }
@@ -0,0 +1,10 @@
1
+ import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
2
+ import type { CircuitSimulator } from '@aztec/simulator/client';
3
+
4
+ import { BBPrivateKernelProver, type BBPrivateKernelProverOptions } from './bb_private_kernel_prover.js';
5
+
6
+ export class BBBundlePrivateKernelProver extends BBPrivateKernelProver {
7
+ constructor(simulator: CircuitSimulator, options: BBPrivateKernelProverOptions = {}) {
8
+ super(new BundleArtifactProvider(), simulator, options);
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ import { LazyArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/lazy';
2
+ import type { CircuitSimulator } from '@aztec/simulator/client';
3
+
4
+ import { BBPrivateKernelProver, type BBPrivateKernelProverOptions } from './bb_private_kernel_prover.js';
5
+
6
+ export class BBLazyPrivateKernelProver extends BBPrivateKernelProver {
7
+ constructor(simulator: CircuitSimulator, options: BBPrivateKernelProverOptions = {}) {
8
+ super(new LazyArtifactProvider(), simulator, options);
9
+ }
10
+ }
@@ -7,7 +7,7 @@ import {
7
7
  PAIRING_POINTS_SIZE,
8
8
  ULTRA_KECCAK_PROOF_LENGTH,
9
9
  } from '@aztec/constants';
10
- import { Fr } from '@aztec/foundation/fields';
10
+ import { Fr } from '@aztec/foundation/curves/bn254';
11
11
  import type { Logger } from '@aztec/foundation/log';
12
12
  import { ChonkProofWithPublicInputs, Proof, RecursiveProof } from '@aztec/stdlib/proofs';
13
13
  import type { VerificationKeyData } from '@aztec/stdlib/vks';
@@ -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
+ }