@aztec/bb-prover 0.0.0-test.0 → 0.0.1-commit.24de95ac

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 (105) hide show
  1. package/dest/avm_proving_tests/avm_proving_tester.d.ts +14 -17
  2. package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
  3. package/dest/avm_proving_tests/avm_proving_tester.js +128 -78
  4. package/dest/bb/execute.d.ts +13 -46
  5. package/dest/bb/execute.d.ts.map +1 -1
  6. package/dest/bb/execute.js +120 -228
  7. package/dest/config.d.ts +2 -0
  8. package/dest/config.d.ts.map +1 -1
  9. package/dest/honk.d.ts +2 -2
  10. package/dest/honk.d.ts.map +1 -1
  11. package/dest/honk.js +3 -2
  12. package/dest/index.d.ts +1 -0
  13. package/dest/index.d.ts.map +1 -1
  14. package/dest/index.js +1 -0
  15. package/dest/instrumentation.d.ts +2 -2
  16. package/dest/instrumentation.d.ts.map +1 -1
  17. package/dest/instrumentation.js +2 -4
  18. package/dest/prover/{bb_private_kernel_prover.d.ts → client/bb_private_kernel_prover.d.ts} +10 -10
  19. package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -0
  20. package/dest/prover/{bb_private_kernel_prover.js → client/bb_private_kernel_prover.js} +21 -18
  21. package/dest/prover/client/native/bb_native_private_kernel_prover.d.ts +23 -0
  22. package/dest/prover/client/native/bb_native_private_kernel_prover.d.ts.map +1 -0
  23. package/dest/prover/{bb_native_private_kernel_prover.js → client/native/bb_native_private_kernel_prover.js} +19 -22
  24. package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.d.ts +15 -0
  25. package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.d.ts.map +1 -0
  26. package/dest/prover/client/wasm/bb_wasm_private_kernel_prover.js +46 -0
  27. package/dest/prover/client/wasm/bundle.d.ts +6 -0
  28. package/dest/prover/client/wasm/bundle.d.ts.map +1 -0
  29. package/dest/{wasm → prover/client/wasm}/bundle.js +2 -2
  30. package/dest/prover/client/wasm/lazy.d.ts +6 -0
  31. package/dest/prover/client/wasm/lazy.d.ts.map +1 -0
  32. package/dest/{wasm → prover/client/wasm}/lazy.js +2 -2
  33. package/dest/prover/index.d.ts +2 -3
  34. package/dest/prover/index.d.ts.map +1 -1
  35. package/dest/prover/index.js +2 -3
  36. package/dest/prover/proof_utils.d.ts +19 -0
  37. package/dest/prover/proof_utils.d.ts.map +1 -0
  38. package/dest/prover/proof_utils.js +72 -0
  39. package/dest/prover/server/bb_prover.d.ts +109 -0
  40. package/dest/prover/server/bb_prover.d.ts.map +1 -0
  41. package/dest/prover/server/bb_prover.js +339 -0
  42. package/dest/test/delay_values.d.ts.map +1 -1
  43. package/dest/test/delay_values.js +30 -18
  44. package/dest/test/test_circuit_prover.d.ts +24 -33
  45. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  46. package/dest/test/test_circuit_prover.js +85 -59
  47. package/dest/test/test_verifier.d.ts +3 -2
  48. package/dest/test/test_verifier.d.ts.map +1 -1
  49. package/dest/test/test_verifier.js +8 -1
  50. package/dest/verification_key/verification_key_data.d.ts +6 -0
  51. package/dest/verification_key/verification_key_data.d.ts.map +1 -1
  52. package/dest/verification_key/verification_key_data.js +23 -29
  53. package/dest/verifier/bb_verifier.d.ts +5 -4
  54. package/dest/verifier/bb_verifier.d.ts.map +1 -1
  55. package/dest/verifier/bb_verifier.js +43 -25
  56. package/dest/verifier/index.d.ts +1 -0
  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 +132 -0
  62. package/package.json +32 -31
  63. package/src/avm_proving_tests/avm_proving_tester.ts +209 -103
  64. package/src/bb/execute.ts +98 -242
  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 +2 -4
  69. package/src/prover/{bb_private_kernel_prover.ts → client/bb_private_kernel_prover.ts} +53 -29
  70. package/src/prover/{bb_native_private_kernel_prover.ts → client/native/bb_native_private_kernel_prover.ts} +23 -37
  71. package/src/{wasm → prover/client/wasm}/bb_wasm_private_kernel_prover.ts +18 -15
  72. package/src/{wasm → prover/client/wasm}/bundle.ts +3 -3
  73. package/src/{wasm → prover/client/wasm}/lazy.ts +3 -3
  74. package/src/prover/index.ts +2 -3
  75. package/src/prover/proof_utils.ts +115 -0
  76. package/src/prover/server/bb_prover.ts +733 -0
  77. package/src/test/delay_values.ts +30 -18
  78. package/src/test/test_circuit_prover.ts +260 -147
  79. package/src/test/test_verifier.ts +7 -3
  80. package/src/verification_key/verification_key_data.ts +29 -24
  81. package/src/verifier/bb_verifier.ts +60 -32
  82. package/src/verifier/index.ts +1 -0
  83. package/src/verifier/queued_chonk_verifier.ts +140 -0
  84. package/dest/prover/bb_native_private_kernel_prover.d.ts +0 -25
  85. package/dest/prover/bb_native_private_kernel_prover.d.ts.map +0 -1
  86. package/dest/prover/bb_private_kernel_prover.d.ts.map +0 -1
  87. package/dest/prover/bb_prover.d.ts +0 -120
  88. package/dest/prover/bb_prover.d.ts.map +0 -1
  89. package/dest/prover/bb_prover.js +0 -423
  90. package/dest/prover/client_ivc_proof_utils.d.ts +0 -25
  91. package/dest/prover/client_ivc_proof_utils.d.ts.map +0 -1
  92. package/dest/prover/client_ivc_proof_utils.js +0 -43
  93. package/dest/stats.d.ts +0 -5
  94. package/dest/stats.d.ts.map +0 -1
  95. package/dest/stats.js +0 -62
  96. package/dest/wasm/bb_wasm_private_kernel_prover.d.ts +0 -17
  97. package/dest/wasm/bb_wasm_private_kernel_prover.d.ts.map +0 -1
  98. package/dest/wasm/bb_wasm_private_kernel_prover.js +0 -46
  99. package/dest/wasm/bundle.d.ts +0 -6
  100. package/dest/wasm/bundle.d.ts.map +0 -1
  101. package/dest/wasm/lazy.d.ts +0 -6
  102. package/dest/wasm/lazy.d.ts.map +0 -1
  103. package/src/prover/bb_prover.ts +0 -781
  104. package/src/prover/client_ivc_proof_utils.ts +0 -42
  105. package/src/stats.ts +0 -64
@@ -1,6 +1,7 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
- import { Timer } from '@aztec/foundation/timer';
3
2
  import {
3
+ convertHidingKernelPublicInputsToWitnessMapWithAbi,
4
+ convertHidingKernelToRollupInputsToWitnessMapWithAbi,
4
5
  convertPrivateKernelInitInputsToWitnessMapWithAbi,
5
6
  convertPrivateKernelInitOutputsFromWitnessMapWithAbi,
6
7
  convertPrivateKernelInnerInputsToWitnessMapWithAbi,
@@ -11,13 +12,22 @@ import {
11
12
  convertPrivateKernelTailInputsToWitnessMapWithAbi,
12
13
  convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
13
14
  convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
15
+ foreignCallHandler,
14
16
  getPrivateKernelResetArtifactName,
15
17
  updateResetCircuitSampleInputs,
16
18
  } from '@aztec/noir-protocol-circuits-types/client';
17
- import type { ArtifactProvider, ClientProtocolArtifact } from '@aztec/noir-protocol-circuits-types/types';
18
- import type { SimulationProvider } from '@aztec/simulator/client';
19
+ import {
20
+ type ArtifactProvider,
21
+ type ClientProtocolArtifact,
22
+ mapProtocolArtifactNameToCircuitName,
23
+ } from '@aztec/noir-protocol-circuits-types/types';
24
+ import type { Abi, WitnessMap } from '@aztec/noir-types';
25
+ import type { CircuitSimulator } from '@aztec/simulator/client';
19
26
  import type { PrivateKernelProver } from '@aztec/stdlib/interfaces/client';
20
27
  import type {
28
+ HidingKernelToPublicPrivateInputs,
29
+ HidingKernelToRollupPrivateInputs,
30
+ PrivateExecutionStep,
21
31
  PrivateKernelCircuitPublicInputs,
22
32
  PrivateKernelInitCircuitPrivateInputs,
23
33
  PrivateKernelInnerCircuitPrivateInputs,
@@ -26,18 +36,14 @@ import type {
26
36
  PrivateKernelTailCircuitPrivateInputs,
27
37
  PrivateKernelTailCircuitPublicInputs,
28
38
  } from '@aztec/stdlib/kernel';
29
- import type { NoirCompiledCircuit } from '@aztec/stdlib/noir';
30
- import type { ClientIvcProof } from '@aztec/stdlib/proofs';
39
+ import type { NoirCompiledCircuitWithName } from '@aztec/stdlib/noir';
40
+ import type { ChonkProofWithPublicInputs } from '@aztec/stdlib/proofs';
31
41
  import type { CircuitSimulationStats, CircuitWitnessGenerationStats } from '@aztec/stdlib/stats';
32
42
 
33
- import type { Abi, WitnessMap } from '@noir-lang/types';
34
-
35
- import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
36
-
37
43
  export abstract class BBPrivateKernelProver implements PrivateKernelProver {
38
44
  constructor(
39
45
  protected artifactProvider: ArtifactProvider,
40
- protected simulationProvider: SimulationProvider,
46
+ protected simulator: CircuitSimulator,
41
47
  protected log = createLogger('bb-prover'),
42
48
  ) {}
43
49
 
@@ -150,6 +156,28 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
150
156
  );
151
157
  }
152
158
 
159
+ public async generateHidingToRollupOutput(
160
+ inputs: HidingKernelToRollupPrivateInputs,
161
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
162
+ return await this.generateCircuitOutput(
163
+ inputs,
164
+ 'HidingKernelToRollup',
165
+ convertHidingKernelToRollupInputsToWitnessMapWithAbi,
166
+ convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
167
+ );
168
+ }
169
+
170
+ public async generateHidingToPublicOutput(
171
+ inputs: HidingKernelToPublicPrivateInputs,
172
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
173
+ return await this.generateCircuitOutput(
174
+ inputs,
175
+ 'HidingKernelToPublic',
176
+ convertHidingKernelPublicInputsToWitnessMapWithAbi,
177
+ convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
178
+ );
179
+ }
180
+
153
181
  public async simulateCircuitOutput<
154
182
  I extends { toBuffer: () => Buffer },
155
183
  O extends PrivateKernelCircuitPublicInputs | PrivateKernelTailCircuitPublicInputs,
@@ -159,15 +187,13 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
159
187
  convertInputs: (inputs: I, abi: Abi) => WitnessMap,
160
188
  convertOutputs: (outputs: WitnessMap, abi: Abi) => O,
161
189
  ): Promise<PrivateKernelSimulateOutput<O>> {
162
- const compiledCircuit: NoirCompiledCircuit = await this.artifactProvider.getSimulatedClientCircuitArtifactByName(
163
- circuitType,
164
- );
190
+ const compiledCircuit: NoirCompiledCircuitWithName =
191
+ await this.artifactProvider.getSimulatedClientCircuitArtifactByName(circuitType);
165
192
 
166
193
  const witnessMap = convertInputs(inputs, compiledCircuit.abi);
167
194
 
168
- const timer = new Timer();
169
- const outputWitness = await this.simulationProvider
170
- .executeProtocolCircuit(witnessMap, compiledCircuit)
195
+ const outputWitness = await this.simulator
196
+ .executeProtocolCircuit(witnessMap, compiledCircuit, foreignCallHandler)
171
197
  .catch((err: Error) => {
172
198
  this.log.debug(`Failed to simulate ${circuitType}`, {
173
199
  circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
@@ -175,12 +201,12 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
175
201
  });
176
202
  throw err;
177
203
  });
178
- const output = convertOutputs(outputWitness, compiledCircuit.abi);
204
+ const output = convertOutputs(outputWitness.witness, compiledCircuit.abi);
179
205
 
180
206
  this.log.debug(`Simulated ${circuitType}`, {
181
207
  eventName: 'circuit-simulation',
182
208
  circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
183
- duration: timer.ms(),
209
+ duration: outputWitness.duration,
184
210
  inputSize: inputs.toBuffer().length,
185
211
  outputSize: output.toBuffer().length,
186
212
  } satisfies CircuitSimulationStats);
@@ -198,30 +224,28 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
198
224
  convertOutputs: (outputs: WitnessMap, abi: Abi) => O,
199
225
  ): Promise<PrivateKernelSimulateOutput<O>> {
200
226
  this.log.debug(`Generating witness for ${circuitType}`);
201
- const compiledCircuit: NoirCompiledCircuit = await this.artifactProvider.getClientCircuitArtifactByName(
202
- circuitType,
203
- );
227
+ const compiledCircuit: NoirCompiledCircuitWithName =
228
+ await this.artifactProvider.getClientCircuitArtifactByName(circuitType);
204
229
 
205
230
  const witnessMap = convertInputs(inputs, compiledCircuit.abi);
206
- const timer = new Timer();
207
- const outputWitness = await this.simulationProvider.executeProtocolCircuit(witnessMap, compiledCircuit);
208
- const output = convertOutputs(outputWitness, compiledCircuit.abi);
231
+ const outputWitness = await this.simulator.executeProtocolCircuit(witnessMap, compiledCircuit, foreignCallHandler);
232
+ const output = convertOutputs(outputWitness.witness, compiledCircuit.abi);
209
233
 
210
234
  this.log.debug(`Generated witness for ${circuitType}`, {
211
235
  eventName: 'circuit-witness-generation',
212
236
  circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
213
- duration: timer.ms(),
237
+ duration: outputWitness.duration,
214
238
  inputSize: inputs.toBuffer().length,
215
239
  outputSize: output.toBuffer().length,
216
240
  } satisfies CircuitWitnessGenerationStats);
217
241
 
218
- const verificationKey = (await this.artifactProvider.getCircuitVkByName(circuitType)).keyAsFields;
242
+ const verificationKey = await this.artifactProvider.getCircuitVkByName(circuitType);
219
243
  const bytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
220
244
 
221
245
  const kernelOutput: PrivateKernelSimulateOutput<O> = {
222
246
  publicInputs: output,
223
247
  verificationKey,
224
- outputWitness,
248
+ outputWitness: outputWitness.witness,
225
249
  bytecode,
226
250
  };
227
251
  return kernelOutput;
@@ -232,14 +256,14 @@ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
232
256
  >(publicInputs: PublicInputsType, circuitType: ClientProtocolArtifact) {
233
257
  const kernelProofOutput: PrivateKernelSimulateOutput<PublicInputsType> = {
234
258
  publicInputs,
235
- verificationKey: (await this.artifactProvider.getCircuitVkByName(circuitType)).keyAsFields,
259
+ verificationKey: await this.artifactProvider.getCircuitVkByName(circuitType),
236
260
  outputWitness: new Map(),
237
261
  bytecode: Buffer.from([]),
238
262
  };
239
263
  return kernelProofOutput;
240
264
  }
241
265
 
242
- public createClientIvcProof(_acirs: Buffer[], _witnessStack: WitnessMap[]): Promise<ClientIvcProof> {
266
+ public createChonkProof(_executionSteps: PrivateExecutionStep[]): Promise<ChonkProofWithPublicInputs> {
243
267
  throw new Error('Not implemented');
244
268
  }
245
269
 
@@ -1,19 +1,17 @@
1
1
  import { runInDirectory } from '@aztec/foundation/fs';
2
2
  import { type Logger, createLogger } from '@aztec/foundation/log';
3
3
  import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
4
- import type { SimulationProvider } from '@aztec/simulator/server';
5
- import type { ClientIvcProof } from '@aztec/stdlib/proofs';
4
+ import type { CircuitSimulator } from '@aztec/simulator/server';
5
+ import { type PrivateExecutionStep, serializePrivateExecutionSteps } from '@aztec/stdlib/kernel';
6
+ import type { ChonkProofWithPublicInputs } from '@aztec/stdlib/proofs';
6
7
 
7
- import { encode } from '@msgpack/msgpack';
8
- import { serializeWitness } from '@noir-lang/noirc_abi';
9
- import type { WitnessMap } from '@noir-lang/types';
10
8
  import { promises as fs } from 'fs';
11
9
  import path from 'path';
12
10
 
13
- import { BB_RESULT, computeGateCountForCircuit, executeBbClientIvcProof } from '../bb/execute.js';
14
- import type { BBConfig } from '../config.js';
15
- import { BBPrivateKernelProver } from './bb_private_kernel_prover.js';
16
- import { readFromOutputDirectory } from './client_ivc_proof_utils.js';
11
+ import { BB_RESULT, computeGateCountForCircuit, executeBbChonkProof } from '../../../bb/execute.js';
12
+ import type { BBConfig } from '../../../config.js';
13
+ import { readChonkProofFromOutputDirectory } from '../../proof_utils.js';
14
+ import { BBPrivateKernelProver } from '../bb_private_kernel_prover.js';
17
15
 
18
16
  /**
19
17
  * This proof creator implementation uses the native bb binary.
@@ -23,51 +21,39 @@ export class BBNativePrivateKernelProver extends BBPrivateKernelProver {
23
21
  private bbBinaryPath: string,
24
22
  private bbWorkingDirectory: string,
25
23
  private skipCleanup: boolean,
26
- protected override simulationProvider: SimulationProvider,
24
+ protected override simulator: CircuitSimulator,
27
25
  protected override log = createLogger('bb-prover:native'),
28
26
  ) {
29
- super(new BundleArtifactProvider(), simulationProvider, log);
27
+ super(new BundleArtifactProvider(), simulator, log);
30
28
  }
31
29
 
32
- public static async new(config: BBConfig, simulationProvider: SimulationProvider, log?: Logger) {
30
+ public static async new(config: BBConfig, simulator: CircuitSimulator, log?: Logger) {
33
31
  await fs.mkdir(config.bbWorkingDirectory, { recursive: true });
34
32
  return new BBNativePrivateKernelProver(
35
33
  config.bbBinaryPath,
36
34
  config.bbWorkingDirectory,
37
35
  !!config.bbSkipCleanup,
38
- simulationProvider,
36
+ simulator,
39
37
  log,
40
38
  );
41
39
  }
42
40
 
43
- private async _createClientIvcProof(
41
+ private async _createChonkProof(
44
42
  directory: string,
45
- acirs: Buffer[],
46
- witnessStack: WitnessMap[],
47
- ): Promise<ClientIvcProof> {
48
- // TODO(#7371): Longer term we won't use this hacked together msgpack format
49
- // and instead properly create the bincode serialization from rust
50
- await fs.writeFile(path.join(directory, 'acir.msgpack'), encode(acirs));
51
- await fs.writeFile(
52
- path.join(directory, 'witnesses.msgpack'),
53
- encode(witnessStack.map(map => serializeWitness(map))),
54
- );
55
- const provingResult = await executeBbClientIvcProof(
56
- this.bbBinaryPath,
57
- directory,
58
- path.join(directory, 'acir.msgpack'),
59
- path.join(directory, 'witnesses.msgpack'),
60
- this.log.info,
61
- );
43
+ executionSteps: PrivateExecutionStep[],
44
+ ): Promise<ChonkProofWithPublicInputs> {
45
+ const inputsPath = path.join(directory, 'ivc-inputs.msgpack');
46
+ await fs.writeFile(inputsPath, serializePrivateExecutionSteps(executionSteps));
47
+ const provingResult = await executeBbChonkProof(this.bbBinaryPath, directory, inputsPath, this.log.info);
62
48
 
63
49
  if (provingResult.status === BB_RESULT.FAILURE) {
64
- this.log.error(`Failed to generate client ivc proof`);
50
+ this.log.error(`Failed to generate chonk proof`);
65
51
  throw new Error(provingResult.reason);
66
52
  }
67
53
 
68
- const proof = await readFromOutputDirectory(directory);
54
+ const proof = await readChonkProofFromOutputDirectory(directory);
69
55
 
70
- this.log.info(`Generated IVC proof`, {
56
+ this.log.info(`Generated Chonk proof`, {
71
57
  duration: provingResult.durationMs,
72
58
  eventName: 'circuit-proving',
73
59
  });
@@ -75,10 +61,10 @@ export class BBNativePrivateKernelProver extends BBPrivateKernelProver {
75
61
  return proof;
76
62
  }
77
63
 
78
- public override async createClientIvcProof(acirs: Buffer[], witnessStack: WitnessMap[]): Promise<ClientIvcProof> {
79
- this.log.info(`Generating Client IVC proof`);
64
+ public override async createChonkProof(executionSteps: PrivateExecutionStep[]): Promise<ChonkProofWithPublicInputs> {
65
+ this.log.info(`Generating Chonk proof`);
80
66
  const operation = async (directory: string) => {
81
- return await this._createClientIvcProof(directory, acirs, witnessStack);
67
+ return await this._createChonkProof(directory, executionSteps);
82
68
  };
83
69
  return await this.runInDirectory(operation);
84
70
  }
@@ -1,46 +1,49 @@
1
1
  import { AztecClientBackend } from '@aztec/bb.js';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
+ import { serializeWitness } from '@aztec/noir-noirc_abi';
4
5
  import type { ArtifactProvider } from '@aztec/noir-protocol-circuits-types/types';
5
- import type { SimulationProvider } from '@aztec/simulator/client';
6
- import { ClientIvcProof } from '@aztec/stdlib/proofs';
6
+ import type { CircuitSimulator } from '@aztec/simulator/client';
7
+ import type { PrivateExecutionStep } from '@aztec/stdlib/kernel';
8
+ import { ChonkProofWithPublicInputs } from '@aztec/stdlib/proofs';
7
9
 
8
- import { serializeWitness } from '@noir-lang/noirc_abi';
9
- import type { WitnessMap } from '@noir-lang/types';
10
10
  import { ungzip } from 'pako';
11
11
 
12
- import { BBPrivateKernelProver } from '../prover/bb_private_kernel_prover.js';
12
+ import { BBPrivateKernelProver } from '../bb_private_kernel_prover.js';
13
13
 
14
14
  export abstract class BBWASMPrivateKernelProver extends BBPrivateKernelProver {
15
15
  constructor(
16
16
  protected override artifactProvider: ArtifactProvider,
17
- protected override simulationProvider: SimulationProvider,
17
+ protected override simulator: CircuitSimulator,
18
18
  private threads: number = 1,
19
19
  protected override log = createLogger('bb-prover:wasm'),
20
20
  ) {
21
- super(artifactProvider, simulationProvider, log);
21
+ super(artifactProvider, simulator, log);
22
22
  }
23
23
 
24
- public override async createClientIvcProof(acirs: Buffer[], witnessStack: WitnessMap[]): Promise<ClientIvcProof> {
24
+ public override async createChonkProof(executionSteps: PrivateExecutionStep[]): Promise<ChonkProofWithPublicInputs> {
25
25
  const timer = new Timer();
26
- this.log.info(`Generating ClientIVC proof...`);
26
+ this.log.info(`Generating Chonk proof...`);
27
27
  const backend = new AztecClientBackend(
28
- acirs.map(acir => ungzip(acir)),
28
+ executionSteps.map(step => ungzip(step.bytecode)),
29
29
  { threads: this.threads, logger: this.log.verbose, wasmPath: process.env.BB_WASM_PATH },
30
30
  );
31
31
 
32
- const [proof, vk] = await backend.prove(witnessStack.map(witnessMap => ungzip(serializeWitness(witnessMap))));
32
+ const [proof] = await backend.prove(
33
+ executionSteps.map(step => ungzip(serializeWitness(step.witness))),
34
+ executionSteps.map(step => step.vk),
35
+ );
33
36
  await backend.destroy();
34
- this.log.info(`Generated ClientIVC proof`, {
35
- eventName: 'client-ivc-proof-generation',
37
+ this.log.info(`Generated Chonk proof`, {
38
+ eventName: 'chonk-proof-generation',
36
39
  duration: timer.ms(),
37
40
  proofSize: proof.length,
38
- vkSize: vk.length,
39
41
  });
40
- return new ClientIvcProof(Buffer.from(proof), Buffer.from(vk));
42
+ return ChonkProofWithPublicInputs.fromBufferArray(proof);
41
43
  }
42
44
 
43
45
  public override async computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
46
+ // Note we do not pass the vk to the backend. This is unneeded for gate counts.
44
47
  const backend = new AztecClientBackend([ungzip(_bytecode)], {
45
48
  threads: this.threads,
46
49
  logger: this.log.verbose,
@@ -1,11 +1,11 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
2
  import { BundleArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/bundle';
3
- import type { SimulationProvider } from '@aztec/simulator/client';
3
+ import type { CircuitSimulator } from '@aztec/simulator/client';
4
4
 
5
5
  import { BBWASMPrivateKernelProver } from './bb_wasm_private_kernel_prover.js';
6
6
 
7
7
  export class BBWASMBundlePrivateKernelProver extends BBWASMPrivateKernelProver {
8
- constructor(simulationProvider: SimulationProvider, threads = 1, log = createLogger('bb-prover:wasm:bundle')) {
9
- super(new BundleArtifactProvider(), simulationProvider, threads, log);
8
+ constructor(simulator: CircuitSimulator, threads = 16, log = createLogger('bb-prover:wasm:bundle')) {
9
+ super(new BundleArtifactProvider(), simulator, threads, log);
10
10
  }
11
11
  }
@@ -1,11 +1,11 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
2
  import { LazyArtifactProvider } from '@aztec/noir-protocol-circuits-types/client/lazy';
3
- import type { SimulationProvider } from '@aztec/simulator/client';
3
+ import type { CircuitSimulator } from '@aztec/simulator/client';
4
4
 
5
5
  import { BBWASMPrivateKernelProver } from './bb_wasm_private_kernel_prover.js';
6
6
 
7
7
  export class BBWASMLazyPrivateKernelProver extends BBWASMPrivateKernelProver {
8
- constructor(simulationProvider: SimulationProvider, threads = 1, log = createLogger('bb-prover:wasm:lazy')) {
9
- super(new LazyArtifactProvider(), simulationProvider, threads, log);
8
+ constructor(simulator: CircuitSimulator, threads = 16, log = createLogger('bb-prover:wasm:lazy')) {
9
+ super(new LazyArtifactProvider(), simulator, threads, log);
10
10
  }
11
11
  }
@@ -1,3 +1,2 @@
1
- export * from './bb_prover.js';
2
- export * from './bb_native_private_kernel_prover.js';
3
- export * from './client_ivc_proof_utils.js';
1
+ export * from './server/bb_prover.js';
2
+ export * from './proof_utils.js';
@@ -0,0 +1,115 @@
1
+ import {
2
+ CHONK_PROOF_LENGTH,
3
+ HIDING_KERNEL_IO_PUBLIC_INPUTS_SIZE,
4
+ IPA_CLAIM_SIZE,
5
+ NESTED_RECURSIVE_PROOF_LENGTH,
6
+ NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
7
+ PAIRING_POINTS_SIZE,
8
+ ULTRA_KECCAK_PROOF_LENGTH,
9
+ } from '@aztec/constants';
10
+ import { Fr } from '@aztec/foundation/fields';
11
+ import type { Logger } from '@aztec/foundation/log';
12
+ import { ChonkProofWithPublicInputs, Proof, RecursiveProof } from '@aztec/stdlib/proofs';
13
+ import type { VerificationKeyData } from '@aztec/stdlib/vks';
14
+
15
+ import assert from 'assert';
16
+ import { promises as fs } from 'fs';
17
+ import * as path from 'path';
18
+
19
+ import { PROOF_FILENAME, PUBLIC_INPUTS_FILENAME } from '../bb/execute.js';
20
+
21
+ /**
22
+ * Create a ChonkProof proof file.
23
+ *
24
+ * @param directory the directory to read the proof from.
25
+ * @returns the encapsulated chonk proof
26
+ */
27
+ export async function readChonkProofFromOutputDirectory(directory: string) {
28
+ const proofFilename = path.join(directory, PROOF_FILENAME);
29
+ const binaryProof = await fs.readFile(proofFilename);
30
+ const proofFields = splitBufferIntoFields(binaryProof);
31
+ return new ChonkProofWithPublicInputs(proofFields);
32
+ }
33
+
34
+ /**
35
+ * Serialize a ChonkProof to a proof file.
36
+ *
37
+ * @param proof the ChonkProof from object
38
+ * @param directory the directory to write in
39
+ */
40
+ export async function writeChonkProofToPath(chonkProof: ChonkProofWithPublicInputs, outputPath: string) {
41
+ // NB: Don't use chonkProof.toBuffer here because it will include the proof length.
42
+ const fieldsBuf = Buffer.concat(chonkProof.fieldsWithPublicInputs.map(field => field.toBuffer()));
43
+ await fs.writeFile(outputPath, fieldsBuf);
44
+ }
45
+
46
+ function getNumCustomPublicInputs(proofLength: number, vkData: VerificationKeyData) {
47
+ let numPublicInputs = vkData.numPublicInputs;
48
+ if (proofLength == CHONK_PROOF_LENGTH) {
49
+ numPublicInputs -= HIDING_KERNEL_IO_PUBLIC_INPUTS_SIZE;
50
+ } else {
51
+ numPublicInputs -= PAIRING_POINTS_SIZE;
52
+ if (proofLength == NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH) {
53
+ numPublicInputs -= IPA_CLAIM_SIZE;
54
+ }
55
+ }
56
+ return numPublicInputs;
57
+ }
58
+
59
+ function splitBufferIntoFields(buffer: Buffer): Fr[] {
60
+ const fields: Fr[] = [];
61
+ for (let i = 0; i < buffer.length / Fr.SIZE_IN_BYTES; i++) {
62
+ fields.push(Fr.fromBuffer(buffer.subarray(i * Fr.SIZE_IN_BYTES, (i + 1) * Fr.SIZE_IN_BYTES)));
63
+ }
64
+ return fields;
65
+ }
66
+
67
+ export async function readProofsFromOutputDirectory<PROOF_LENGTH extends number>(
68
+ directory: string,
69
+ vkData: VerificationKeyData,
70
+ proofLength: PROOF_LENGTH,
71
+ logger: Logger,
72
+ ): Promise<RecursiveProof<PROOF_LENGTH>> {
73
+ assert(
74
+ proofLength == CHONK_PROOF_LENGTH ||
75
+ proofLength == NESTED_RECURSIVE_PROOF_LENGTH ||
76
+ proofLength == NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH ||
77
+ proofLength == ULTRA_KECCAK_PROOF_LENGTH,
78
+ `Proof length must be one of the expected proof lengths, received ${proofLength}`,
79
+ );
80
+
81
+ const publicInputsFilename = path.join(directory, PUBLIC_INPUTS_FILENAME);
82
+ const proofFilename = path.join(directory, PROOF_FILENAME);
83
+
84
+ // Handle CHONK separately because bb outputs the proof fields with public inputs for CHONK.
85
+ const isChonk = proofLength == CHONK_PROOF_LENGTH;
86
+
87
+ const [binaryPublicInputs, binaryProof] = await Promise.all([
88
+ isChonk ? Buffer.alloc(0) : fs.readFile(publicInputsFilename),
89
+ fs.readFile(proofFilename),
90
+ ]);
91
+
92
+ const numPublicInputs = getNumCustomPublicInputs(proofLength, vkData);
93
+ let fieldsWithoutPublicInputs = splitBufferIntoFields(binaryProof);
94
+ if (isChonk) {
95
+ fieldsWithoutPublicInputs = fieldsWithoutPublicInputs.slice(numPublicInputs);
96
+ }
97
+
98
+ assert(
99
+ fieldsWithoutPublicInputs.length == proofLength,
100
+ `Proof fields length mismatch: ${fieldsWithoutPublicInputs.length} != ${proofLength}`,
101
+ );
102
+
103
+ // Concat binary public inputs and binary proof
104
+ // This buffer will have the form: [binary public inputs, binary proof]
105
+ const binaryProofWithPublicInputs = Buffer.concat([binaryPublicInputs, binaryProof]);
106
+ logger.debug(
107
+ `Circuit path: ${directory}, proof fields length: ${fieldsWithoutPublicInputs.length}, num public inputs: ${numPublicInputs}, circuit size: ${vkData.circuitSize}`,
108
+ );
109
+ return new RecursiveProof(
110
+ fieldsWithoutPublicInputs,
111
+ new Proof(binaryProofWithPublicInputs, numPublicInputs),
112
+ true,
113
+ proofLength,
114
+ );
115
+ }