@aztec/bb-prover 0.41.0 → 0.43.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 (59) hide show
  1. package/dest/bb/cli.d.ts.map +1 -1
  2. package/dest/bb/cli.js +24 -2
  3. package/dest/bb/execute.d.ts +30 -1
  4. package/dest/bb/execute.d.ts.map +1 -1
  5. package/dest/bb/execute.js +252 -60
  6. package/dest/config.d.ts +9 -0
  7. package/dest/config.d.ts.map +1 -0
  8. package/dest/config.js +2 -0
  9. package/dest/index.d.ts +2 -0
  10. package/dest/index.d.ts.map +1 -1
  11. package/dest/index.js +3 -1
  12. package/dest/mappings/mappings.d.ts +1 -0
  13. package/dest/mappings/mappings.d.ts.map +1 -1
  14. package/dest/mappings/mappings.js +27 -8
  15. package/dest/prover/bb_native_proof_creator.d.ts +2 -8
  16. package/dest/prover/bb_native_proof_creator.d.ts.map +1 -1
  17. package/dest/prover/bb_native_proof_creator.js +37 -79
  18. package/dest/prover/bb_prover.d.ts +33 -32
  19. package/dest/prover/bb_prover.d.ts.map +1 -1
  20. package/dest/prover/bb_prover.js +231 -162
  21. package/dest/stats.d.ts.map +1 -1
  22. package/dest/stats.js +8 -2
  23. package/dest/test/index.d.ts +1 -0
  24. package/dest/test/index.d.ts.map +1 -1
  25. package/dest/test/index.js +2 -1
  26. package/dest/test/test_circuit_prover.d.ts +9 -7
  27. package/dest/test/test_circuit_prover.d.ts.map +1 -1
  28. package/dest/test/test_circuit_prover.js +32 -16
  29. package/dest/test/test_verifier.d.ts +7 -0
  30. package/dest/test/test_verifier.d.ts.map +1 -0
  31. package/dest/test/test_verifier.js +10 -0
  32. package/dest/verification_key/verification_key_data.d.ts +8 -0
  33. package/dest/verification_key/verification_key_data.d.ts.map +1 -0
  34. package/dest/verification_key/verification_key_data.js +24 -0
  35. package/dest/verifier/bb_verifier.d.ts +18 -0
  36. package/dest/verifier/bb_verifier.d.ts.map +1 -0
  37. package/dest/verifier/bb_verifier.js +90 -0
  38. package/dest/verifier/index.d.ts +2 -0
  39. package/dest/verifier/index.d.ts.map +1 -0
  40. package/dest/verifier/index.js +2 -0
  41. package/package.json +6 -6
  42. package/src/bb/cli.ts +36 -1
  43. package/src/bb/execute.ts +340 -67
  44. package/src/config.ts +9 -0
  45. package/src/index.ts +2 -0
  46. package/src/mappings/mappings.ts +38 -12
  47. package/src/prover/bb_native_proof_creator.ts +49 -91
  48. package/src/prover/bb_prover.ts +396 -221
  49. package/src/stats.ts +7 -1
  50. package/src/test/index.ts +1 -0
  51. package/src/test/test_circuit_prover.ts +85 -23
  52. package/src/test/test_verifier.ts +12 -0
  53. package/src/verification_key/verification_key_data.ts +35 -0
  54. package/src/verifier/bb_verifier.ts +156 -0
  55. package/src/verifier/index.ts +1 -0
  56. package/dest/prover/verification_key_data.d.ts +0 -16
  57. package/dest/prover/verification_key_data.d.ts.map +0 -1
  58. package/dest/prover/verification_key_data.js +0 -5
  59. package/src/prover/verification_key_data.ts +0 -16
package/src/stats.ts CHANGED
@@ -55,7 +55,13 @@ export function mapProtocolArtifactNameToCircuitName(
55
55
  return 'private-kernel-reset-medium';
56
56
  case 'PrivateKernelResetSmallArtifact':
57
57
  return 'private-kernel-reset-small';
58
- default:
58
+ case 'EmptyNestedArtifact':
59
+ return 'empty-nested';
60
+ case 'PrivateKernelEmptyArtifact':
61
+ return 'private-kernel-empty';
62
+ default: {
63
+ const _foo: never = artifact;
59
64
  throw new Error(`Unknown circuit type: ${artifact}`);
65
+ }
60
66
  }
61
67
  }
package/src/test/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './test_circuit_prover.js';
2
+ export * from './test_verifier.js';
@@ -1,18 +1,22 @@
1
1
  import {
2
- type PublicInputsAndProof,
2
+ type ProofAndVerificationKey,
3
+ type PublicInputsAndRecursiveProof,
3
4
  type PublicKernelNonTailRequest,
4
5
  type PublicKernelTailRequest,
5
- PublicKernelType,
6
6
  type ServerCircuitProver,
7
- makePublicInputsAndProof,
7
+ makePublicInputsAndRecursiveProof,
8
8
  } from '@aztec/circuit-types';
9
9
  import {
10
+ type AvmCircuitInputs,
10
11
  type BaseOrMergeRollupPublicInputs,
11
12
  type BaseParityInputs,
12
13
  type BaseRollupInputs,
14
+ EmptyNestedData,
13
15
  type KernelCircuitPublicInputs,
14
16
  type MergeRollupInputs,
15
17
  NESTED_RECURSIVE_PROOF_LENGTH,
18
+ type PrivateKernelEmptyInputData,
19
+ PrivateKernelEmptyInputs,
16
20
  type Proof,
17
21
  type PublicKernelCircuitPublicInputs,
18
22
  RECURSIVE_PROOF_LENGTH,
@@ -21,7 +25,9 @@ import {
21
25
  type RootRollupInputs,
22
26
  type RootRollupPublicInputs,
23
27
  VerificationKeyAsFields,
28
+ VerificationKeyData,
24
29
  makeEmptyProof,
30
+ makeEmptyRecursiveProof,
25
31
  makeRecursiveProof,
26
32
  } from '@aztec/circuits.js';
27
33
  import { createDebugLogger } from '@aztec/foundation/log';
@@ -29,27 +35,30 @@ import { Timer } from '@aztec/foundation/timer';
29
35
  import {
30
36
  BaseParityArtifact,
31
37
  MergeRollupArtifact,
38
+ PrivateKernelEmptyArtifact,
32
39
  RootParityArtifact,
33
40
  RootRollupArtifact,
34
- ServerCircuitArtifacts,
35
41
  type ServerProtocolArtifact,
36
42
  SimulatedBaseRollupArtifact,
43
+ SimulatedServerCircuitArtifacts,
37
44
  convertBaseParityInputsToWitnessMap,
38
45
  convertBaseParityOutputsFromWitnessMap,
39
46
  convertMergeRollupInputsToWitnessMap,
40
47
  convertMergeRollupOutputsFromWitnessMap,
41
- convertPublicTailInputsToWitnessMap,
42
- convertPublicTailOutputFromWitnessMap,
48
+ convertPrivateKernelEmptyInputsToWitnessMap,
49
+ convertPrivateKernelEmptyOutputsFromWitnessMap,
43
50
  convertRootParityInputsToWitnessMap,
44
51
  convertRootParityOutputsFromWitnessMap,
45
52
  convertRootRollupInputsToWitnessMap,
46
53
  convertRootRollupOutputsFromWitnessMap,
47
54
  convertSimulatedBaseRollupInputsToWitnessMap,
48
55
  convertSimulatedBaseRollupOutputsFromWitnessMap,
56
+ convertSimulatedPublicTailInputsToWitnessMap,
57
+ convertSimulatedPublicTailOutputFromWitnessMap,
49
58
  } from '@aztec/noir-protocol-circuits-types';
50
59
  import { type SimulationProvider, WASMSimulator, emitCircuitSimulationStats } from '@aztec/simulator';
51
60
 
52
- import { PublicKernelArtifactMapping } from '../mappings/mappings.js';
61
+ import { SimulatedPublicKernelArtifactMapping } from '../mappings/mappings.js';
53
62
  import { mapPublicKernelToCircuitName } from '../stats.js';
54
63
 
55
64
  const VERIFICATION_KEYS: Record<ServerProtocolArtifact, VerificationKeyAsFields> = {
@@ -62,6 +71,8 @@ const VERIFICATION_KEYS: Record<ServerProtocolArtifact, VerificationKeyAsFields>
62
71
  BaseRollupArtifact: VerificationKeyAsFields.makeFake(),
63
72
  MergeRollupArtifact: VerificationKeyAsFields.makeFake(),
64
73
  RootRollupArtifact: VerificationKeyAsFields.makeFake(),
74
+ PrivateKernelEmptyArtifact: VerificationKeyAsFields.makeFake(),
75
+ EmptyNestedArtifact: VerificationKeyAsFields.makeFake(),
65
76
  };
66
77
 
67
78
  /**
@@ -76,6 +87,25 @@ export class TestCircuitProver implements ServerCircuitProver {
76
87
  private logger = createDebugLogger('aztec:test-prover'),
77
88
  ) {}
78
89
 
90
+ public async getEmptyPrivateKernelProof(
91
+ inputs: PrivateKernelEmptyInputData,
92
+ ): Promise<PublicInputsAndRecursiveProof<KernelCircuitPublicInputs>> {
93
+ const emptyNested = new EmptyNestedData(
94
+ makeRecursiveProof(RECURSIVE_PROOF_LENGTH),
95
+ VERIFICATION_KEYS['EmptyNestedArtifact'],
96
+ );
97
+ const kernelInputs = new PrivateKernelEmptyInputs(emptyNested, inputs.header, inputs.chainId, inputs.version);
98
+ const witnessMap = convertPrivateKernelEmptyInputsToWitnessMap(kernelInputs);
99
+ const witness = await this.wasmSimulator.simulateCircuit(witnessMap, PrivateKernelEmptyArtifact);
100
+ const result = convertPrivateKernelEmptyOutputsFromWitnessMap(witness);
101
+
102
+ return makePublicInputsAndRecursiveProof(
103
+ result,
104
+ makeRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH),
105
+ VerificationKeyData.makeFake(),
106
+ );
107
+ }
108
+
79
109
  /**
80
110
  * Simulates the base parity circuit from its inputs.
81
111
  * @param inputs - Inputs to the circuit.
@@ -146,7 +176,7 @@ export class TestCircuitProver implements ServerCircuitProver {
146
176
  */
147
177
  public async getBaseRollupProof(
148
178
  input: BaseRollupInputs,
149
- ): Promise<PublicInputsAndProof<BaseOrMergeRollupPublicInputs>> {
179
+ ): Promise<PublicInputsAndRecursiveProof<BaseOrMergeRollupPublicInputs>> {
150
180
  const timer = new Timer();
151
181
  const witnessMap = convertSimulatedBaseRollupInputsToWitnessMap(input);
152
182
 
@@ -162,7 +192,11 @@ export class TestCircuitProver implements ServerCircuitProver {
162
192
  result.toBuffer().length,
163
193
  this.logger,
164
194
  );
165
- return makePublicInputsAndProof(result, makeEmptyProof());
195
+ return makePublicInputsAndRecursiveProof(
196
+ result,
197
+ makeRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH),
198
+ VerificationKeyData.makeFake(),
199
+ );
166
200
  }
167
201
  /**
168
202
  * Simulates the merge rollup circuit from its inputs.
@@ -171,7 +205,7 @@ export class TestCircuitProver implements ServerCircuitProver {
171
205
  */
172
206
  public async getMergeRollupProof(
173
207
  input: MergeRollupInputs,
174
- ): Promise<PublicInputsAndProof<BaseOrMergeRollupPublicInputs>> {
208
+ ): Promise<PublicInputsAndRecursiveProof<BaseOrMergeRollupPublicInputs>> {
175
209
  const timer = new Timer();
176
210
  const witnessMap = convertMergeRollupInputsToWitnessMap(input);
177
211
 
@@ -187,7 +221,11 @@ export class TestCircuitProver implements ServerCircuitProver {
187
221
  result.toBuffer().length,
188
222
  this.logger,
189
223
  );
190
- return makePublicInputsAndProof(result, makeEmptyProof());
224
+ return makePublicInputsAndRecursiveProof(
225
+ result,
226
+ makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH),
227
+ VerificationKeyData.makeFake(),
228
+ );
191
229
  }
192
230
 
193
231
  /**
@@ -195,7 +233,9 @@ export class TestCircuitProver implements ServerCircuitProver {
195
233
  * @param input - Inputs to the circuit.
196
234
  * @returns The public inputs as outputs of the simulation.
197
235
  */
198
- public async getRootRollupProof(input: RootRollupInputs): Promise<PublicInputsAndProof<RootRollupPublicInputs>> {
236
+ public async getRootRollupProof(
237
+ input: RootRollupInputs,
238
+ ): Promise<PublicInputsAndRecursiveProof<RootRollupPublicInputs>> {
199
239
  const timer = new Timer();
200
240
  const witnessMap = convertRootRollupInputsToWitnessMap(input);
201
241
 
@@ -211,20 +251,27 @@ export class TestCircuitProver implements ServerCircuitProver {
211
251
  result.toBuffer().length,
212
252
  this.logger,
213
253
  );
214
- return makePublicInputsAndProof(result, makeEmptyProof());
254
+ return makePublicInputsAndRecursiveProof(
255
+ result,
256
+ makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH),
257
+ VerificationKeyData.makeFake(),
258
+ );
215
259
  }
216
260
 
217
261
  public async getPublicKernelProof(
218
262
  kernelRequest: PublicKernelNonTailRequest,
219
- ): Promise<PublicInputsAndProof<PublicKernelCircuitPublicInputs>> {
263
+ ): Promise<PublicInputsAndRecursiveProof<PublicKernelCircuitPublicInputs>> {
220
264
  const timer = new Timer();
221
- const kernelOps = PublicKernelArtifactMapping[kernelRequest.type];
265
+ const kernelOps = SimulatedPublicKernelArtifactMapping[kernelRequest.type];
222
266
  if (kernelOps === undefined) {
223
- throw new Error(`Unable to prove for kernel type ${PublicKernelType[kernelRequest.type]}`);
267
+ throw new Error(`Unable to prove for kernel type ${kernelRequest.type}`);
224
268
  }
225
269
  const witnessMap = kernelOps.convertInputs(kernelRequest.inputs);
226
270
 
227
- const witness = await this.wasmSimulator.simulateCircuit(witnessMap, ServerCircuitArtifacts[kernelOps.artifact]);
271
+ const witness = await this.wasmSimulator.simulateCircuit(
272
+ witnessMap,
273
+ SimulatedServerCircuitArtifacts[kernelOps.artifact],
274
+ );
228
275
 
229
276
  const result = kernelOps.convertOutputs(witness);
230
277
  emitCircuitSimulationStats(
@@ -235,21 +282,25 @@ export class TestCircuitProver implements ServerCircuitProver {
235
282
  this.logger,
236
283
  );
237
284
 
238
- return makePublicInputsAndProof(result, makeEmptyProof());
285
+ return makePublicInputsAndRecursiveProof(
286
+ result,
287
+ makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH),
288
+ VerificationKeyData.makeFake(),
289
+ );
239
290
  }
240
291
 
241
292
  public async getPublicTailProof(
242
293
  kernelRequest: PublicKernelTailRequest,
243
- ): Promise<PublicInputsAndProof<KernelCircuitPublicInputs>> {
294
+ ): Promise<PublicInputsAndRecursiveProof<KernelCircuitPublicInputs>> {
244
295
  const timer = new Timer();
245
- const witnessMap = convertPublicTailInputsToWitnessMap(kernelRequest.inputs);
296
+ const witnessMap = convertSimulatedPublicTailInputsToWitnessMap(kernelRequest.inputs);
246
297
  // use WASM here as it is faster for small circuits
247
298
  const witness = await this.wasmSimulator.simulateCircuit(
248
299
  witnessMap,
249
- ServerCircuitArtifacts['PublicKernelTailArtifact'],
300
+ SimulatedServerCircuitArtifacts['PublicKernelTailArtifact'],
250
301
  );
251
302
 
252
- const result = convertPublicTailOutputFromWitnessMap(witness);
303
+ const result = convertSimulatedPublicTailOutputFromWitnessMap(witness);
253
304
  emitCircuitSimulationStats(
254
305
  'public-kernel-tail',
255
306
  timer.ms(),
@@ -258,7 +309,18 @@ export class TestCircuitProver implements ServerCircuitProver {
258
309
  this.logger,
259
310
  );
260
311
 
261
- return makePublicInputsAndProof(result, makeEmptyProof());
312
+ return makePublicInputsAndRecursiveProof(
313
+ result,
314
+ makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH),
315
+ VerificationKeyData.makeFake(),
316
+ );
317
+ }
318
+
319
+ getAvmProof(_inputs: AvmCircuitInputs): Promise<ProofAndVerificationKey> {
320
+ // We can't simulate the AVM because we don't have enough context to do so (e.g., DBs).
321
+ // We just return an empty proof and VK data.
322
+ this.logger.debug('Skipping AVM simulation in TestCircuitProver.');
323
+ return Promise.resolve({ proof: makeEmptyProof(), verificationKey: VerificationKeyData.makeFake() });
262
324
  }
263
325
 
264
326
  // Not implemented for test circuits
@@ -0,0 +1,12 @@
1
+ import { type ClientProtocolCircuitVerifier, type Tx } from '@aztec/circuit-types';
2
+ import { type VerificationKeys, getMockVerificationKeys } from '@aztec/circuits.js';
3
+
4
+ export class TestCircuitVerifier implements ClientProtocolCircuitVerifier {
5
+ verifyProof(_tx: Tx): Promise<boolean> {
6
+ return Promise.resolve(true);
7
+ }
8
+
9
+ getVerificationKeys(): Promise<VerificationKeys> {
10
+ return Promise.resolve(getMockVerificationKeys());
11
+ }
12
+ }
@@ -0,0 +1,35 @@
1
+ import {
2
+ Fr,
3
+ type VERIFICATION_KEY_LENGTH_IN_FIELDS,
4
+ VerificationKeyAsFields,
5
+ VerificationKeyData,
6
+ } from '@aztec/circuits.js';
7
+ import { type Tuple } from '@aztec/foundation/serialize';
8
+
9
+ import * as fs from 'fs/promises';
10
+ import * as path from 'path';
11
+
12
+ import { VK_FIELDS_FILENAME, VK_FILENAME } from '../bb/execute.js';
13
+
14
+ /**
15
+ * Reads the verification key data stored at the specified location and parses into a VerificationKeyData
16
+ * @param vkDirectoryPath - The directory containing the verification key data files
17
+ * @returns The verification key data
18
+ */
19
+ export async function extractVkData(vkDirectoryPath: string): Promise<VerificationKeyData> {
20
+ const [rawFields, rawBinary] = await Promise.all([
21
+ fs.readFile(path.join(vkDirectoryPath, VK_FIELDS_FILENAME), { encoding: 'utf-8' }),
22
+ fs.readFile(path.join(vkDirectoryPath, VK_FILENAME)),
23
+ ]);
24
+ const fieldsJson = JSON.parse(rawFields);
25
+ const fields = fieldsJson.map(Fr.fromString);
26
+ // The first item is the hash, this is not part of the actual VK
27
+ const vkHash = fields[0];
28
+ const actualVk = fields.slice(1);
29
+ const vkAsFields = new VerificationKeyAsFields(
30
+ actualVk as Tuple<Fr, typeof VERIFICATION_KEY_LENGTH_IN_FIELDS>,
31
+ vkHash,
32
+ );
33
+ const vk = new VerificationKeyData(vkAsFields, rawBinary);
34
+ return vk;
35
+ }
@@ -0,0 +1,156 @@
1
+ import { type ClientProtocolCircuitVerifier, Tx } from '@aztec/circuit-types';
2
+ import { type Proof, type VerificationKeyData, type VerificationKeys } from '@aztec/circuits.js';
3
+ import { runInDirectory } from '@aztec/foundation/fs';
4
+ import { type DebugLogger, type LogFn, createDebugLogger } from '@aztec/foundation/log';
5
+ import {
6
+ type ClientProtocolArtifact,
7
+ type ProtocolArtifact,
8
+ ProtocolCircuitArtifacts,
9
+ } from '@aztec/noir-protocol-circuits-types';
10
+
11
+ import * as fs from 'fs/promises';
12
+ import * as path from 'path';
13
+
14
+ import {
15
+ BB_RESULT,
16
+ PROOF_FILENAME,
17
+ VK_FILENAME,
18
+ generateContractForCircuit,
19
+ generateKeyForNoirCircuit,
20
+ verifyProof,
21
+ } from '../bb/execute.js';
22
+ import { type BBConfig } from '../config.js';
23
+ import { extractVkData } from '../verification_key/verification_key_data.js';
24
+
25
+ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
26
+ private constructor(
27
+ private config: BBConfig,
28
+ private verificationKeys = new Map<ProtocolArtifact, Promise<VerificationKeyData>>(),
29
+ private logger: DebugLogger,
30
+ ) {}
31
+
32
+ public static async new(
33
+ config: BBConfig,
34
+ initialCircuits: ProtocolArtifact[] = [],
35
+ logger = createDebugLogger('aztec:bb-verifier'),
36
+ ) {
37
+ const keys = new Map<ProtocolArtifact, Promise<VerificationKeyData>>();
38
+ for (const circuit of initialCircuits) {
39
+ const vkData = await this.generateVerificationKey(
40
+ circuit,
41
+ config.bbBinaryPath,
42
+ config.bbWorkingDirectory,
43
+ logger.debug,
44
+ );
45
+ keys.set(circuit, Promise.resolve(vkData));
46
+ }
47
+ return new BBCircuitVerifier(config, keys, logger);
48
+ }
49
+
50
+ private static async generateVerificationKey(
51
+ circuit: ProtocolArtifact,
52
+ bbPath: string,
53
+ workingDirectory: string,
54
+ logFn: LogFn,
55
+ ) {
56
+ return await generateKeyForNoirCircuit(
57
+ bbPath,
58
+ workingDirectory,
59
+ circuit,
60
+ ProtocolCircuitArtifacts[circuit],
61
+ 'vk',
62
+ logFn,
63
+ ).then(result => {
64
+ if (result.status === BB_RESULT.FAILURE) {
65
+ throw new Error(`Failed to created verification key for ${circuit}, ${result.reason}`);
66
+ }
67
+
68
+ return extractVkData(result.vkPath!);
69
+ });
70
+ }
71
+
72
+ public async getVerificationKeyData(circuit: ProtocolArtifact) {
73
+ let promise = this.verificationKeys.get(circuit);
74
+ if (!promise) {
75
+ promise = BBCircuitVerifier.generateVerificationKey(
76
+ circuit,
77
+ this.config.bbBinaryPath,
78
+ this.config.bbWorkingDirectory,
79
+ this.logger.debug,
80
+ );
81
+ }
82
+ this.verificationKeys.set(circuit, promise);
83
+ const vk = await promise;
84
+ return vk.clone();
85
+ }
86
+
87
+ public async verifyProofForCircuit(circuit: ProtocolArtifact, proof: Proof) {
88
+ const operation = async (bbWorkingDirectory: string) => {
89
+ const proofFileName = path.join(bbWorkingDirectory, PROOF_FILENAME);
90
+ const verificationKeyPath = path.join(bbWorkingDirectory, VK_FILENAME);
91
+ const verificationKey = await this.getVerificationKeyData(circuit);
92
+
93
+ this.logger.debug(`${circuit} Verifying with key: ${verificationKey.keyAsFields.hash.toString()}`);
94
+
95
+ await fs.writeFile(proofFileName, proof.buffer);
96
+ await fs.writeFile(verificationKeyPath, verificationKey.keyAsBytes);
97
+
98
+ const logFunction = (message: string) => {
99
+ this.logger.debug(`${circuit} BB out - ${message}`);
100
+ };
101
+
102
+ const result = await verifyProof(this.config.bbBinaryPath, proofFileName, verificationKeyPath!, logFunction);
103
+
104
+ if (result.status === BB_RESULT.FAILURE) {
105
+ const errorMessage = `Failed to verify ${circuit} proof!`;
106
+ throw new Error(errorMessage);
107
+ }
108
+
109
+ this.logger.debug(`${circuit} verification successful`);
110
+ };
111
+ await runInDirectory(this.config.bbWorkingDirectory, operation);
112
+ }
113
+
114
+ public async generateSolidityContract(circuit: ProtocolArtifact, contractName: string) {
115
+ const result = await generateContractForCircuit(
116
+ this.config.bbBinaryPath,
117
+ this.config.bbWorkingDirectory,
118
+ circuit,
119
+ ProtocolCircuitArtifacts[circuit],
120
+ contractName,
121
+ this.logger.debug,
122
+ );
123
+
124
+ if (result.status === BB_RESULT.FAILURE) {
125
+ throw new Error(`Failed to create verifier contract for ${circuit}, ${result.reason}`);
126
+ }
127
+
128
+ return fs.readFile(result.contractPath!, 'utf-8');
129
+ }
130
+
131
+ async verifyProof(tx: Tx): Promise<boolean> {
132
+ const { proof, enqueuedPublicFunctionCalls } = tx;
133
+ const expectedCircuit: ClientProtocolArtifact =
134
+ enqueuedPublicFunctionCalls.length > 0 ? 'PrivateKernelTailToPublicArtifact' : 'PrivateKernelTailArtifact';
135
+
136
+ try {
137
+ await this.verifyProofForCircuit(expectedCircuit, proof);
138
+ return true;
139
+ } catch (err) {
140
+ this.logger.warn(`Failed to verify ${expectedCircuit} proof for tx ${Tx.getHash(tx)}: ${String(err)}`);
141
+ return false;
142
+ }
143
+ }
144
+
145
+ async getVerificationKeys(): Promise<VerificationKeys> {
146
+ const [privateKernelCircuit, privateKernelToPublicCircuit] = await Promise.all([
147
+ this.getVerificationKeyData('PrivateKernelTailArtifact'),
148
+ this.getVerificationKeyData('PrivateKernelTailToPublicArtifact'),
149
+ ]);
150
+
151
+ return {
152
+ privateKernelCircuit,
153
+ privateKernelToPublicCircuit,
154
+ };
155
+ }
156
+ }
@@ -0,0 +1 @@
1
+ export * from './bb_verifier.js';
@@ -1,16 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { type Fr, type VERIFICATION_KEY_LENGTH_IN_FIELDS } from '@aztec/circuits.js';
3
- import { type Tuple } from '@aztec/foundation/serialize';
4
- export declare const AGGREGATION_OBJECT_SIZE = 16;
5
- export declare const CIRCUIT_SIZE_INDEX = 3;
6
- export declare const CIRCUIT_PUBLIC_INPUTS_INDEX = 4;
7
- export declare const CIRCUIT_RECURSIVE_INDEX = 5;
8
- export type VerificationKeyData = {
9
- hash: Fr;
10
- keyAsFields: Tuple<Fr, typeof VERIFICATION_KEY_LENGTH_IN_FIELDS>;
11
- keyAsBytes: Buffer;
12
- numPublicInputs: number;
13
- circuitSize: number;
14
- isRecursive: boolean;
15
- };
16
- //# sourceMappingURL=verification_key_data.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"verification_key_data.d.ts","sourceRoot":"","sources":["../../src/prover/verification_key_data.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAEzD,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAC7C,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,EAAE,CAAC;IACT,WAAW,EAAE,KAAK,CAAC,EAAE,EAAE,OAAO,iCAAiC,CAAC,CAAC;IACjE,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC"}
@@ -1,5 +0,0 @@
1
- export const AGGREGATION_OBJECT_SIZE = 16;
2
- export const CIRCUIT_SIZE_INDEX = 3;
3
- export const CIRCUIT_PUBLIC_INPUTS_INDEX = 4;
4
- export const CIRCUIT_RECURSIVE_INDEX = 5;
5
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmVyaWZpY2F0aW9uX2tleV9kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3Byb3Zlci92ZXJpZmljYXRpb25fa2V5X2RhdGEudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR0EsTUFBTSxDQUFDLE1BQU0sdUJBQXVCLEdBQUcsRUFBRSxDQUFDO0FBQzFDLE1BQU0sQ0FBQyxNQUFNLGtCQUFrQixHQUFHLENBQUMsQ0FBQztBQUNwQyxNQUFNLENBQUMsTUFBTSwyQkFBMkIsR0FBRyxDQUFDLENBQUM7QUFDN0MsTUFBTSxDQUFDLE1BQU0sdUJBQXVCLEdBQUcsQ0FBQyxDQUFDIn0=
@@ -1,16 +0,0 @@
1
- import { type Fr, type VERIFICATION_KEY_LENGTH_IN_FIELDS } from '@aztec/circuits.js';
2
- import { type Tuple } from '@aztec/foundation/serialize';
3
-
4
- export const AGGREGATION_OBJECT_SIZE = 16;
5
- export const CIRCUIT_SIZE_INDEX = 3;
6
- export const CIRCUIT_PUBLIC_INPUTS_INDEX = 4;
7
- export const CIRCUIT_RECURSIVE_INDEX = 5;
8
-
9
- export type VerificationKeyData = {
10
- hash: Fr;
11
- keyAsFields: Tuple<Fr, typeof VERIFICATION_KEY_LENGTH_IN_FIELDS>;
12
- keyAsBytes: Buffer;
13
- numPublicInputs: number;
14
- circuitSize: number;
15
- isRecursive: boolean;
16
- };