@aztec/bb-prover 0.69.1 → 0.70.0

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 (60) hide show
  1. package/dest/bb/cli.d.ts +3 -0
  2. package/dest/bb/cli.d.ts.map +1 -1
  3. package/dest/bb/cli.js +7 -2
  4. package/dest/bb/execute.d.ts +14 -3
  5. package/dest/bb/execute.d.ts.map +1 -1
  6. package/dest/bb/execute.js +108 -10
  7. package/dest/honk.d.ts +8 -8
  8. package/dest/honk.d.ts.map +1 -1
  9. package/dest/honk.js +2 -7
  10. package/dest/prover/bb_native_private_kernel_prover.d.ts +25 -0
  11. package/dest/prover/bb_native_private_kernel_prover.d.ts.map +1 -0
  12. package/dest/prover/bb_native_private_kernel_prover.js +69 -0
  13. package/dest/prover/bb_private_kernel_prover.d.ts +26 -41
  14. package/dest/prover/bb_private_kernel_prover.d.ts.map +1 -1
  15. package/dest/prover/bb_private_kernel_prover.js +62 -118
  16. package/dest/prover/bb_prover.d.ts +4 -6
  17. package/dest/prover/bb_prover.d.ts.map +1 -1
  18. package/dest/prover/bb_prover.js +13 -34
  19. package/dest/prover/index.d.ts +1 -1
  20. package/dest/prover/index.d.ts.map +1 -1
  21. package/dest/prover/index.js +2 -2
  22. package/dest/stats.d.ts +3 -3
  23. package/dest/stats.d.ts.map +1 -1
  24. package/dest/stats.js +4 -7
  25. package/dest/test/test_avm.d.ts +1 -1
  26. package/dest/test/test_avm.d.ts.map +1 -1
  27. package/dest/test/test_circuit_prover.d.ts +5 -5
  28. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  29. package/dest/test/test_circuit_prover.js +13 -11
  30. package/dest/verifier/bb_verifier.d.ts +6 -6
  31. package/dest/verifier/bb_verifier.d.ts.map +1 -1
  32. package/dest/verifier/bb_verifier.js +5 -8
  33. package/dest/wasm/bb_wasm_private_kernel_prover.d.ts +16 -0
  34. package/dest/wasm/bb_wasm_private_kernel_prover.d.ts.map +1 -0
  35. package/dest/wasm/bb_wasm_private_kernel_prover.js +31 -0
  36. package/dest/wasm/bundle.d.ts +6 -0
  37. package/dest/wasm/bundle.d.ts.map +1 -0
  38. package/dest/wasm/bundle.js +9 -0
  39. package/dest/wasm/lazy.d.ts +6 -0
  40. package/dest/wasm/lazy.d.ts.map +1 -0
  41. package/dest/wasm/lazy.js +9 -0
  42. package/package.json +11 -10
  43. package/src/bb/cli.ts +9 -1
  44. package/src/bb/execute.ts +134 -11
  45. package/src/honk.ts +16 -21
  46. package/src/prover/bb_native_private_kernel_prover.ts +118 -0
  47. package/src/prover/bb_private_kernel_prover.ts +141 -202
  48. package/src/prover/bb_prover.ts +29 -77
  49. package/src/prover/index.ts +1 -1
  50. package/src/stats.ts +6 -11
  51. package/src/test/test_avm.ts +1 -1
  52. package/src/test/test_circuit_prover.ts +26 -41
  53. package/src/verifier/bb_verifier.ts +12 -15
  54. package/src/wasm/bb_wasm_private_kernel_prover.ts +42 -0
  55. package/src/wasm/bundle.ts +11 -0
  56. package/src/wasm/lazy.ts +11 -0
  57. package/dest/wasm/index.d.ts +0 -19
  58. package/dest/wasm/index.d.ts.map +0 -1
  59. package/dest/wasm/index.js +0 -74
  60. package/src/wasm/index.ts +0 -155
@@ -1,5 +1,5 @@
1
1
  import { type PrivateKernelProver, type PrivateKernelSimulateOutput } from '@aztec/circuit-types';
2
- import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats';
2
+ import { type CircuitSimulationStats, type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats';
3
3
  import {
4
4
  type ClientIvcProof,
5
5
  type PrivateKernelCircuitPublicInputs,
@@ -8,264 +8,196 @@ import {
8
8
  type PrivateKernelResetCircuitPrivateInputs,
9
9
  type PrivateKernelTailCircuitPrivateInputs,
10
10
  type PrivateKernelTailCircuitPublicInputs,
11
- type Proof,
12
- type VerificationKeyData,
13
11
  } from '@aztec/circuits.js';
14
- import { runInDirectory } from '@aztec/foundation/fs';
15
- import { type Logger, createLogger } from '@aztec/foundation/log';
12
+ import { createLogger } from '@aztec/foundation/log';
16
13
  import { Timer } from '@aztec/foundation/timer';
17
14
  import {
18
- ClientCircuitArtifacts,
19
- ClientCircuitVks,
20
- type ClientProtocolArtifact,
21
- ProtocolCircuitVks,
22
- convertPrivateKernelInitInputsToWitnessMap,
23
- convertPrivateKernelInitOutputsFromWitnessMap,
24
- convertPrivateKernelInnerInputsToWitnessMap,
25
- convertPrivateKernelInnerOutputsFromWitnessMap,
26
- convertPrivateKernelResetInputsToWitnessMap,
27
- convertPrivateKernelResetOutputsFromWitnessMap,
28
- convertPrivateKernelTailForPublicOutputsFromWitnessMap,
29
- convertPrivateKernelTailInputsToWitnessMap,
30
- convertPrivateKernelTailOutputsFromWitnessMap,
31
- convertPrivateKernelTailToPublicInputsToWitnessMap,
15
+ convertPrivateKernelInitInputsToWitnessMapWithAbi,
16
+ convertPrivateKernelInitOutputsFromWitnessMapWithAbi,
17
+ convertPrivateKernelInnerInputsToWitnessMapWithAbi,
18
+ convertPrivateKernelInnerOutputsFromWitnessMapWithAbi,
19
+ convertPrivateKernelResetInputsToWitnessMapWithAbi,
20
+ convertPrivateKernelResetOutputsFromWitnessMapWithAbi,
21
+ convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
22
+ convertPrivateKernelTailInputsToWitnessMapWithAbi,
23
+ convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
24
+ convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
32
25
  getPrivateKernelResetArtifactName,
33
- } from '@aztec/noir-protocol-circuits-types';
34
- import { WASMSimulatorWithBlobs } from '@aztec/simulator';
26
+ updateResetCircuitSampleInputs,
27
+ } from '@aztec/noir-protocol-circuits-types/client';
28
+ import { type ArtifactProvider, type ClientProtocolArtifact } from '@aztec/noir-protocol-circuits-types/types';
29
+ import { ClientCircuitVks } from '@aztec/noir-protocol-circuits-types/vks';
30
+ import { type SimulationProvider } from '@aztec/simulator/client';
35
31
  import { type NoirCompiledCircuit } from '@aztec/types/noir';
36
32
 
37
- import { encode } from '@msgpack/msgpack';
38
- import { serializeWitness } from '@noir-lang/noirc_abi';
39
- import { type WitnessMap } from '@noir-lang/types';
40
- import { promises as fs } from 'fs';
41
- import path from 'path';
33
+ import { type Abi, type WitnessMap } from '@noir-lang/types';
42
34
 
43
- import { BB_RESULT, computeGateCountForCircuit, executeBbClientIvcProof, verifyProof } from '../bb/execute.js';
44
- import { type BBConfig } from '../config.js';
45
- import { type UltraHonkFlavor, getUltraHonkFlavorForCircuit } from '../honk.js';
46
35
  import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
47
- import { extractVkData } from '../verification_key/verification_key_data.js';
48
- import { readFromOutputDirectory } from './client_ivc_proof_utils.js';
49
36
 
50
- /**
51
- * This proof creator implementation uses the native bb binary.
52
- * This is a temporary implementation until we make the WASM version work.
53
- * TODO(#7368): this class grew 'organically' aka it could use a look at its resposibilities
54
- */
55
- export class BBNativePrivateKernelProver implements PrivateKernelProver {
56
- private simulator = new WASMSimulatorWithBlobs();
57
-
58
- private verificationKeys: Map<ClientProtocolArtifact, Promise<VerificationKeyData>> = new Map<
59
- ClientProtocolArtifact,
60
- Promise<VerificationKeyData>
61
- >();
62
-
63
- private constructor(
64
- private bbBinaryPath: string,
65
- private bbWorkingDirectory: string,
66
- private skipCleanup: boolean,
67
- private log = createLogger('bb-prover:native'),
37
+ export abstract class BBPrivateKernelProver implements PrivateKernelProver {
38
+ constructor(
39
+ protected artifactProvider: ArtifactProvider,
40
+ protected simulationProvider: SimulationProvider,
41
+ protected log = createLogger('bb-prover'),
68
42
  ) {}
69
43
 
70
- public static async new(config: BBConfig, log?: Logger) {
71
- await fs.mkdir(config.bbWorkingDirectory, { recursive: true });
72
- return new BBNativePrivateKernelProver(config.bbBinaryPath, config.bbWorkingDirectory, !!config.bbSkipCleanup, log);
73
- }
74
-
75
- private async _createClientIvcProof(
76
- directory: string,
77
- acirs: Buffer[],
78
- witnessStack: WitnessMap[],
79
- ): Promise<ClientIvcProof> {
80
- // TODO(#7371): Longer term we won't use this hacked together msgpack format
81
- // and instead properly create the bincode serialization from rust
82
- await fs.writeFile(path.join(directory, 'acir.msgpack'), encode(acirs));
83
- await fs.writeFile(
84
- path.join(directory, 'witnesses.msgpack'),
85
- encode(witnessStack.map(map => serializeWitness(map))),
86
- );
87
- const provingResult = await executeBbClientIvcProof(
88
- this.bbBinaryPath,
89
- directory,
90
- path.join(directory, 'acir.msgpack'),
91
- path.join(directory, 'witnesses.msgpack'),
92
- this.log.info,
44
+ public async generateInitOutput(
45
+ inputs: PrivateKernelInitCircuitPrivateInputs,
46
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
47
+ return await this.generateCircuitOutput(
48
+ inputs,
49
+ 'PrivateKernelInitArtifact',
50
+ convertPrivateKernelInitInputsToWitnessMapWithAbi,
51
+ convertPrivateKernelInitOutputsFromWitnessMapWithAbi,
93
52
  );
94
-
95
- if (provingResult.status === BB_RESULT.FAILURE) {
96
- this.log.error(`Failed to generate client ivc proof`);
97
- throw new Error(provingResult.reason);
98
- }
99
-
100
- const proof = await readFromOutputDirectory(directory);
101
-
102
- this.log.info(`Generated IVC proof`, {
103
- duration: provingResult.durationMs,
104
- eventName: 'circuit-proving',
105
- });
106
-
107
- return proof;
108
53
  }
109
54
 
110
- async createClientIvcProof(acirs: Buffer[], witnessStack: WitnessMap[]): Promise<ClientIvcProof> {
111
- this.log.info(`Generating Client IVC proof`);
112
- const operation = async (directory: string) => {
113
- return await this._createClientIvcProof(directory, acirs, witnessStack);
114
- };
115
- return await this.runInDirectory(operation);
116
- }
117
-
118
- public async simulateProofInit(
55
+ public async simulateInit(
119
56
  inputs: PrivateKernelInitCircuitPrivateInputs,
120
57
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
121
- return await this.simulate(
58
+ return await this.simulateCircuitOutput(
122
59
  inputs,
123
60
  'PrivateKernelInitArtifact',
124
- convertPrivateKernelInitInputsToWitnessMap,
125
- convertPrivateKernelInitOutputsFromWitnessMap,
61
+ convertPrivateKernelInitInputsToWitnessMapWithAbi,
62
+ convertPrivateKernelInitOutputsFromWitnessMapWithAbi,
63
+ );
64
+ }
65
+
66
+ public async generateInnerOutput(
67
+ inputs: PrivateKernelInnerCircuitPrivateInputs,
68
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
69
+ return await this.generateCircuitOutput(
70
+ inputs,
71
+ 'PrivateKernelInnerArtifact',
72
+ convertPrivateKernelInnerInputsToWitnessMapWithAbi,
73
+ convertPrivateKernelInnerOutputsFromWitnessMapWithAbi,
126
74
  );
127
75
  }
128
76
 
129
- public async simulateProofInner(
77
+ public async simulateInner(
130
78
  inputs: PrivateKernelInnerCircuitPrivateInputs,
131
79
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
132
- return await this.simulate(
80
+ return await this.simulateCircuitOutput(
133
81
  inputs,
134
82
  'PrivateKernelInnerArtifact',
135
- convertPrivateKernelInnerInputsToWitnessMap,
136
- convertPrivateKernelInnerOutputsFromWitnessMap,
83
+ convertPrivateKernelInnerInputsToWitnessMapWithAbi,
84
+ convertPrivateKernelInnerOutputsFromWitnessMapWithAbi,
137
85
  );
138
86
  }
139
87
 
140
- public async simulateProofReset(
88
+ public async generateResetOutput(
141
89
  inputs: PrivateKernelResetCircuitPrivateInputs,
142
90
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
143
91
  const variantInputs = inputs.trimToSizes();
144
92
  const artifactName = getPrivateKernelResetArtifactName(inputs.dimensions);
145
- return await this.simulate(
93
+ return await this.generateCircuitOutput(
146
94
  variantInputs,
147
95
  artifactName,
148
- variantInputs => convertPrivateKernelResetInputsToWitnessMap(variantInputs, artifactName),
149
- output => convertPrivateKernelResetOutputsFromWitnessMap(output, artifactName),
96
+ convertPrivateKernelResetInputsToWitnessMapWithAbi,
97
+ convertPrivateKernelResetOutputsFromWitnessMapWithAbi,
150
98
  );
151
99
  }
152
100
 
153
- public async simulateProofTail(
101
+ public async simulateReset(
102
+ inputs: PrivateKernelResetCircuitPrivateInputs,
103
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelCircuitPublicInputs>> {
104
+ updateResetCircuitSampleInputs(inputs);
105
+ const variantInputs = inputs.trimToSizes();
106
+ const artifactName = getPrivateKernelResetArtifactName(inputs.dimensions);
107
+ return await this.simulateCircuitOutput(
108
+ variantInputs,
109
+ artifactName,
110
+ convertPrivateKernelResetInputsToWitnessMapWithAbi,
111
+ convertPrivateKernelResetOutputsFromWitnessMapWithAbi,
112
+ );
113
+ }
114
+
115
+ public async generateTailOutput(
154
116
  inputs: PrivateKernelTailCircuitPrivateInputs,
155
117
  ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
156
118
  if (!inputs.isForPublic()) {
157
- return await this.simulate(
119
+ return await this.generateCircuitOutput(
158
120
  inputs,
159
121
  'PrivateKernelTailArtifact',
160
- convertPrivateKernelTailInputsToWitnessMap,
161
- convertPrivateKernelTailOutputsFromWitnessMap,
122
+ convertPrivateKernelTailInputsToWitnessMapWithAbi,
123
+ convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
162
124
  );
163
125
  }
164
- return await this.simulate(
126
+ return await this.generateCircuitOutput(
165
127
  inputs,
166
128
  'PrivateKernelTailToPublicArtifact',
167
- convertPrivateKernelTailToPublicInputsToWitnessMap,
168
- convertPrivateKernelTailForPublicOutputsFromWitnessMap,
129
+ convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
130
+ convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
169
131
  );
170
132
  }
171
133
 
172
- /**
173
- * Verifies a proof, will generate the verification key if one is not cached internally
174
- * @param circuitType - The type of circuit whose proof is to be verified
175
- * @param proof - The proof to be verified
176
- */
177
- public async verifyProofForProtocolCircuit(circuitType: ClientProtocolArtifact, proof: Proof) {
178
- const verificationKey = ProtocolCircuitVks[circuitType];
179
-
180
- this.log.debug(`Verifying with key: ${verificationKey.keyAsFields.hash.toString()}`);
181
-
182
- const logFunction = (message: string) => {
183
- this.log.debug(`${circuitType} BB out - ${message}`);
184
- };
185
-
186
- const result = await this.verifyProofFromKey(
187
- getUltraHonkFlavorForCircuit(circuitType),
188
- verificationKey.keyAsBytes,
189
- proof,
190
- logFunction,
191
- );
192
-
193
- if (result.status === BB_RESULT.FAILURE) {
194
- const errorMessage = `Failed to verify ${circuitType} proof!`;
195
- throw new Error(errorMessage);
134
+ public async simulateTail(
135
+ inputs: PrivateKernelTailCircuitPrivateInputs,
136
+ ): Promise<PrivateKernelSimulateOutput<PrivateKernelTailCircuitPublicInputs>> {
137
+ if (!inputs.isForPublic()) {
138
+ return await this.simulateCircuitOutput(
139
+ inputs,
140
+ 'PrivateKernelTailArtifact',
141
+ convertPrivateKernelTailInputsToWitnessMapWithAbi,
142
+ convertPrivateKernelTailOutputsFromWitnessMapWithAbi,
143
+ );
196
144
  }
197
-
198
- this.log.info(`Successfully verified ${circuitType} proof in ${Math.ceil(result.durationMs)} ms`);
145
+ return await this.simulateCircuitOutput(
146
+ inputs,
147
+ 'PrivateKernelTailToPublicArtifact',
148
+ convertPrivateKernelTailToPublicInputsToWitnessMapWithAbi,
149
+ convertPrivateKernelTailForPublicOutputsFromWitnessMapWithAbi,
150
+ );
199
151
  }
200
152
 
201
- public async computeGateCountForCircuit(bytecode: Buffer, circuitName: string): Promise<number> {
202
- const logFunction = (message: string) => {
203
- this.log.debug(`$bb gates ${circuitName} - ${message}`);
204
- };
205
-
206
- const result = await computeGateCountForCircuit(
207
- this.bbBinaryPath,
208
- this.bbWorkingDirectory,
209
- circuitName,
210
- bytecode,
211
- 'mega_honk',
212
- logFunction,
153
+ public async simulateCircuitOutput<
154
+ I extends { toBuffer: () => Buffer },
155
+ O extends PrivateKernelCircuitPublicInputs | PrivateKernelTailCircuitPublicInputs,
156
+ >(
157
+ inputs: I,
158
+ circuitType: ClientProtocolArtifact,
159
+ convertInputs: (inputs: I, abi: Abi) => WitnessMap,
160
+ convertOutputs: (outputs: WitnessMap, abi: Abi) => O,
161
+ ): Promise<PrivateKernelSimulateOutput<O>> {
162
+ const compiledCircuit: NoirCompiledCircuit = await this.artifactProvider.getSimulatedClientCircuitArtifactByName(
163
+ circuitType,
213
164
  );
214
- if (result.status === BB_RESULT.FAILURE) {
215
- throw new Error(result.reason);
216
- }
217
165
 
218
- return result.circuitSize as number;
219
- }
166
+ const witnessMap = convertInputs(inputs, compiledCircuit.abi);
220
167
 
221
- private async verifyProofFromKey(
222
- flavor: UltraHonkFlavor,
223
- verificationKey: Buffer,
224
- proof: Proof,
225
- logFunction: (message: string) => void = () => {},
226
- ) {
227
- const operation = async (bbWorkingDirectory: string) => {
228
- const proofFileName = `${bbWorkingDirectory}/proof`;
229
- const verificationKeyPath = `${bbWorkingDirectory}/vk`;
168
+ const timer = new Timer();
169
+ const outputWitness = await this.simulationProvider.executeProtocolCircuit(witnessMap, compiledCircuit);
170
+ const output = convertOutputs(outputWitness, compiledCircuit.abi);
230
171
 
231
- await fs.writeFile(proofFileName, proof.buffer);
232
- await fs.writeFile(verificationKeyPath, verificationKey);
233
- return await verifyProof(this.bbBinaryPath, proofFileName, verificationKeyPath!, flavor, logFunction);
234
- };
235
- return await this.runInDirectory(operation);
236
- }
172
+ this.log.debug(`Simulated ${circuitType}`, {
173
+ eventName: 'circuit-simulation',
174
+ circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
175
+ duration: timer.ms(),
176
+ inputSize: inputs.toBuffer().length,
177
+ outputSize: output.toBuffer().length,
178
+ } satisfies CircuitSimulationStats);
237
179
 
238
- /**
239
- * Ensures our verification key cache includes the key data located at the specified directory
240
- * @param filePath - The directory containing the verification key data files
241
- * @param circuitType - The type of circuit to which the verification key corresponds
242
- */
243
- private async updateVerificationKeyAfterSimulation(filePath: string, circuitType: ClientProtocolArtifact) {
244
- let promise = this.verificationKeys.get(circuitType);
245
- if (!promise) {
246
- promise = extractVkData(filePath);
247
- this.log.debug(`Updated verification key for circuit: ${circuitType}`);
248
- this.verificationKeys.set(circuitType, promise);
249
- }
250
- return await promise;
180
+ return this.makeEmptyKernelSimulateOutput<O>(output, circuitType);
251
181
  }
252
182
 
253
- private async simulate<
183
+ public async generateCircuitOutput<
254
184
  I extends { toBuffer: () => Buffer },
255
185
  O extends PrivateKernelCircuitPublicInputs | PrivateKernelTailCircuitPublicInputs,
256
186
  >(
257
187
  inputs: I,
258
188
  circuitType: ClientProtocolArtifact,
259
- convertInputs: (inputs: I) => WitnessMap,
260
- convertOutputs: (outputs: WitnessMap) => O,
189
+ convertInputs: (inputs: I, abi: Abi) => WitnessMap,
190
+ convertOutputs: (outputs: WitnessMap, abi: Abi) => O,
261
191
  ): Promise<PrivateKernelSimulateOutput<O>> {
262
192
  this.log.debug(`Generating witness for ${circuitType}`);
263
- const compiledCircuit: NoirCompiledCircuit = ClientCircuitArtifacts[circuitType];
193
+ const compiledCircuit: NoirCompiledCircuit = await this.artifactProvider.getClientCircuitArtifactByName(
194
+ circuitType,
195
+ );
264
196
 
265
- const witnessMap = convertInputs(inputs);
197
+ const witnessMap = convertInputs(inputs, compiledCircuit.abi);
266
198
  const timer = new Timer();
267
- const outputWitness = await this.simulator.simulateCircuit(witnessMap, compiledCircuit);
268
- const output = convertOutputs(outputWitness);
199
+ const outputWitness = await this.simulationProvider.executeProtocolCircuit(witnessMap, compiledCircuit);
200
+ const output = convertOutputs(outputWitness, compiledCircuit.abi);
269
201
 
270
202
  this.log.debug(`Generated witness for ${circuitType}`, {
271
203
  eventName: 'circuit-witness-generation',
@@ -287,16 +219,23 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
287
219
  return kernelOutput;
288
220
  }
289
221
 
290
- private runInDirectory<T>(fn: (dir: string) => Promise<T>) {
291
- const log = this.log;
292
- return runInDirectory(
293
- this.bbWorkingDirectory,
294
- (dir: string) =>
295
- fn(dir).catch(err => {
296
- log.error(`Error running operation at ${dir}: ${err}`);
297
- throw err;
298
- }),
299
- this.skipCleanup,
300
- );
222
+ public makeEmptyKernelSimulateOutput<
223
+ PublicInputsType extends PrivateKernelTailCircuitPublicInputs | PrivateKernelCircuitPublicInputs,
224
+ >(publicInputs: PublicInputsType, circuitType: ClientProtocolArtifact) {
225
+ const kernelProofOutput: PrivateKernelSimulateOutput<PublicInputsType> = {
226
+ publicInputs,
227
+ verificationKey: ClientCircuitVks[circuitType].keyAsFields,
228
+ outputWitness: new Map(),
229
+ bytecode: Buffer.from([]),
230
+ };
231
+ return kernelProofOutput;
232
+ }
233
+
234
+ public createClientIvcProof(_acirs: Buffer[], _witnessStack: WitnessMap[]): Promise<ClientIvcProof> {
235
+ throw new Error('Not implemented');
236
+ }
237
+
238
+ public computeGateCountForCircuit(_bytecode: Buffer, _circuitName: string): Promise<number> {
239
+ throw new Error('Not implemented');
301
240
  }
302
241
  }
@@ -13,19 +13,13 @@ import {
13
13
  AVM_PROOF_LENGTH_IN_FIELDS,
14
14
  type AvmCircuitInputs,
15
15
  type BaseParityInputs,
16
- EmptyNestedCircuitInputs,
17
- EmptyNestedData,
18
16
  Fr,
19
17
  IPA_CLAIM_LENGTH,
20
18
  NESTED_RECURSIVE_PROOF_LENGTH,
21
19
  NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
22
20
  type ParityPublicInputs,
23
- type PrivateKernelEmptyInputData,
24
- PrivateKernelEmptyInputs,
25
- type PrivateToRollupKernelCircuitPublicInputs,
26
21
  Proof,
27
22
  RECURSIVE_PROOF_LENGTH,
28
- RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
29
23
  RecursiveProof,
30
24
  type RootParityInputs,
31
25
  TUBE_PROOF_LENGTH,
@@ -44,6 +38,7 @@ import {
44
38
  type PublicBaseRollupInputs,
45
39
  type RootRollupInputs,
46
40
  type RootRollupPublicInputs,
41
+ type SingleTxBlockRootRollupInputs,
47
42
  type TubeInputs,
48
43
  } from '@aztec/circuits.js/rollup';
49
44
  import { runInDirectory } from '@aztec/foundation/fs';
@@ -51,7 +46,6 @@ import { createLogger } from '@aztec/foundation/log';
51
46
  import { BufferReader } from '@aztec/foundation/serialize';
52
47
  import { Timer } from '@aztec/foundation/timer';
53
48
  import {
54
- ProtocolCircuitVks,
55
49
  ServerCircuitArtifacts,
56
50
  type ServerProtocolArtifact,
57
51
  convertBaseParityInputsToWitnessMap,
@@ -66,20 +60,19 @@ import {
66
60
  convertMergeRollupOutputsFromWitnessMap,
67
61
  convertPrivateBaseRollupInputsToWitnessMap,
68
62
  convertPrivateBaseRollupOutputsFromWitnessMap,
69
- convertPrivateKernelEmptyInputsToWitnessMap,
70
- convertPrivateKernelEmptyOutputsFromWitnessMap,
71
63
  convertPublicBaseRollupInputsToWitnessMap,
72
64
  convertPublicBaseRollupOutputsFromWitnessMap,
73
65
  convertRootParityInputsToWitnessMap,
74
66
  convertRootParityOutputsFromWitnessMap,
75
67
  convertRootRollupInputsToWitnessMap,
76
68
  convertRootRollupOutputsFromWitnessMap,
77
- } from '@aztec/noir-protocol-circuits-types';
78
- import { NativeACVMSimulator } from '@aztec/simulator';
69
+ convertSingleTxBlockRootRollupInputsToWitnessMap,
70
+ convertSingleTxBlockRootRollupOutputsFromWitnessMap,
71
+ } from '@aztec/noir-protocol-circuits-types/server';
72
+ import { NativeACVMSimulator } from '@aztec/simulator/server';
79
73
  import { Attributes, type TelemetryClient, trackSpan } from '@aztec/telemetry-client';
80
74
 
81
- import { abiEncode } from '@noir-lang/noirc_abi';
82
- import { type Abi, type WitnessMap } from '@noir-lang/types';
75
+ import { type WitnessMap } from '@noir-lang/types';
83
76
  import { assert } from 'console';
84
77
  import crypto from 'crypto';
85
78
  import { promises as fs } from 'fs';
@@ -313,6 +306,26 @@ export class BBNativeRollupProver implements ServerCircuitProver {
313
306
  return makePublicInputsAndRecursiveProof(circuitOutput, proof, verificationKey);
314
307
  }
315
308
 
309
+ public async getSingleTxBlockRootRollupProof(
310
+ input: SingleTxBlockRootRollupInputs,
311
+ ): Promise<
312
+ PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
313
+ > {
314
+ const { circuitOutput, proof } = await this.createRecursiveProof(
315
+ input,
316
+ 'SingleTxBlockRootRollupArtifact',
317
+ NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
318
+ convertSingleTxBlockRootRollupInputsToWitnessMap,
319
+ convertSingleTxBlockRootRollupOutputsFromWitnessMap,
320
+ );
321
+
322
+ const verificationKey = await this.getVerificationKeyDataForCircuit('SingleTxBlockRootRollupArtifact');
323
+
324
+ await this.verifyProof('SingleTxBlockRootRollupArtifact', proof.binaryProof);
325
+
326
+ return makePublicInputsAndRecursiveProof(circuitOutput, proof, verificationKey);
327
+ }
328
+
316
329
  /**
317
330
  * Simulates the empty block root rollup circuit from its inputs.
318
331
  * @param input - Inputs to the circuit.
@@ -387,67 +400,6 @@ export class BBNativeRollupProver implements ServerCircuitProver {
387
400
  return makePublicInputsAndRecursiveProof(circuitOutput, recursiveProof, verificationKey);
388
401
  }
389
402
 
390
- public async getEmptyPrivateKernelProof(
391
- inputs: PrivateKernelEmptyInputData,
392
- ): Promise<
393
- PublicInputsAndRecursiveProof<
394
- PrivateToRollupKernelCircuitPublicInputs,
395
- typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
396
- >
397
- > {
398
- const emptyNested = await this.getEmptyNestedProof();
399
- const emptyPrivateKernelProof = await this.getEmptyPrivateKernelProofFromEmptyNested(
400
- PrivateKernelEmptyInputs.from({
401
- ...inputs,
402
- emptyNested,
403
- }),
404
- );
405
-
406
- return emptyPrivateKernelProof;
407
- }
408
-
409
- private async getEmptyNestedProof(): Promise<EmptyNestedData> {
410
- const inputs = new EmptyNestedCircuitInputs();
411
- const { proof } = await this.createRecursiveProof(
412
- inputs,
413
- 'EmptyNestedArtifact',
414
- RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
415
- (nothing: any) => abiEncode(ServerCircuitArtifacts.EmptyNestedArtifact.abi as Abi, { _inputs: nothing as any }),
416
- () => new EmptyNestedCircuitInputs(),
417
- );
418
-
419
- const verificationKey = await this.getVerificationKeyDataForCircuit('EmptyNestedArtifact');
420
- await this.verifyProof('EmptyNestedArtifact', proof.binaryProof);
421
- // logger.debug(`EmptyNestedData proof size: ${proof.proof.length}`);
422
- // logger.debug(`EmptyNestedData proof: ${proof.proof}`);
423
- // logger.debug(`EmptyNestedData vk size: ${verificationKey.keyAsFields.key.length}`);
424
- // logger.debug(`EmptyNestedData vk: ${verificationKey.keyAsFields.key}`);
425
-
426
- return new EmptyNestedData(proof, verificationKey.keyAsFields);
427
- }
428
-
429
- private async getEmptyPrivateKernelProofFromEmptyNested(
430
- inputs: PrivateKernelEmptyInputs,
431
- ): Promise<
432
- PublicInputsAndRecursiveProof<
433
- PrivateToRollupKernelCircuitPublicInputs,
434
- typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
435
- >
436
- > {
437
- const { circuitOutput, proof } = await this.createRecursiveProof(
438
- inputs,
439
- 'PrivateKernelEmptyArtifact',
440
- NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
441
- convertPrivateKernelEmptyInputsToWitnessMap,
442
- convertPrivateKernelEmptyOutputsFromWitnessMap,
443
- );
444
- //info(`proof: ${proof.proof}`);
445
- const verificationKey = ProtocolCircuitVks['PrivateKernelEmptyArtifact'];
446
- await this.verifyProof('PrivateKernelEmptyArtifact', proof.binaryProof);
447
-
448
- return makePublicInputsAndRecursiveProof(circuitOutput, proof, verificationKey);
449
- }
450
-
451
403
  private async generateProofWithBB<
452
404
  Input extends { toBuffer: () => Buffer },
453
405
  Output extends { toBuffer: () => Buffer },
@@ -475,7 +427,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
475
427
 
476
428
  const inputWitness = convertInput(input);
477
429
  const timer = new Timer();
478
- const outputWitness = await simulator.simulateCircuit(inputWitness, artifact);
430
+ const outputWitness = await simulator.executeProtocolCircuit(inputWitness, artifact);
479
431
  const output = convertOutput(outputWitness);
480
432
 
481
433
  const circuitName = mapProtocolArtifactNameToCircuitName(circuitType);
@@ -728,13 +680,13 @@ export class BBNativeRollupProver implements ServerCircuitProver {
728
680
 
729
681
  public async verifyAvmProof(proof: Proof, verificationKey: VerificationKeyData) {
730
682
  return await this.verifyWithKeyInternal(proof, verificationKey, (proofPath, vkPath) =>
731
- verifyAvmProof(this.config.bbBinaryPath, proofPath, vkPath, logger.debug),
683
+ verifyAvmProof(this.config.bbBinaryPath, proofPath, vkPath, logger),
732
684
  );
733
685
  }
734
686
 
735
687
  public async verifyWithKey(flavor: UltraHonkFlavor, verificationKey: VerificationKeyData, proof: Proof) {
736
688
  return await this.verifyWithKeyInternal(proof, verificationKey, (proofPath, vkPath) =>
737
- verifyProof(this.config.bbBinaryPath, proofPath, vkPath, flavor, logger.debug),
689
+ verifyProof(this.config.bbBinaryPath, proofPath, vkPath, flavor, logger),
738
690
  );
739
691
  }
740
692
 
@@ -1,3 +1,3 @@
1
1
  export * from './bb_prover.js';
2
- export * from './bb_private_kernel_prover.js';
2
+ export * from './bb_native_private_kernel_prover.js';
3
3
  export * from './client_ivc_proof_utils.js';
package/src/stats.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import type { CircuitName } from '@aztec/circuit-types/stats';
2
- import { type ClientProtocolArtifact, type ServerProtocolArtifact } from '@aztec/noir-protocol-circuits-types';
2
+ import { type ProtocolArtifact } from '@aztec/noir-protocol-circuits-types/types';
3
3
 
4
- export function mapProtocolArtifactNameToCircuitName(
5
- artifact: ServerProtocolArtifact | ClientProtocolArtifact,
6
- ): CircuitName {
4
+ export function mapProtocolArtifactNameToCircuitName(artifact: ProtocolArtifact): CircuitName {
7
5
  switch (artifact) {
8
6
  case 'BaseParityArtifact':
9
7
  return 'base-parity';
@@ -17,6 +15,8 @@ export function mapProtocolArtifactNameToCircuitName(
17
15
  return 'merge-rollup';
18
16
  case 'BlockRootRollupArtifact':
19
17
  return 'block-root-rollup';
18
+ case 'SingleTxBlockRootRollupArtifact':
19
+ return 'single-tx-block-root-rollup';
20
20
  case 'EmptyBlockRootRollupArtifact':
21
21
  return 'empty-block-root-rollup';
22
22
  case 'BlockMergeRollupArtifact':
@@ -31,10 +31,6 @@ export function mapProtocolArtifactNameToCircuitName(
31
31
  return 'private-kernel-tail';
32
32
  case 'PrivateKernelTailToPublicArtifact':
33
33
  return 'private-kernel-tail-to-public';
34
- case 'EmptyNestedArtifact':
35
- return 'empty-nested';
36
- case 'PrivateKernelEmptyArtifact':
37
- return 'private-kernel-empty';
38
34
  default: {
39
35
  if (artifact.startsWith('PrivateKernelReset')) {
40
36
  return 'private-kernel-reset';
@@ -44,16 +40,15 @@ export function mapProtocolArtifactNameToCircuitName(
44
40
  }
45
41
  }
46
42
 
47
- export function isProtocolArtifactRecursive(artifact: ServerProtocolArtifact | ClientProtocolArtifact): boolean {
43
+ export function isProtocolArtifactRecursive(artifact: ProtocolArtifact): boolean {
48
44
  switch (artifact) {
49
- case 'EmptyNestedArtifact':
50
- case 'PrivateKernelEmptyArtifact':
51
45
  case 'BaseParityArtifact':
52
46
  case 'RootParityArtifact':
53
47
  case 'PrivateBaseRollupArtifact':
54
48
  case 'PublicBaseRollupArtifact':
55
49
  case 'MergeRollupArtifact':
56
50
  case 'BlockRootRollupArtifact':
51
+ case 'SingleTxBlockRootRollupArtifact':
57
52
  case 'EmptyBlockRootRollupArtifact':
58
53
  case 'BlockMergeRollupArtifact':
59
54
  case 'RootRollupArtifact':