@aztec/bb-prover 0.52.0 → 0.53.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.
- package/dest/bb/cli.d.ts.map +1 -1
- package/dest/bb/cli.js +5 -23
- package/dest/bb/execute.d.ts +5 -4
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +20 -20
- package/dest/honk.d.ts +10 -0
- package/dest/honk.d.ts.map +1 -0
- package/dest/honk.js +8 -0
- package/dest/prover/bb_private_kernel_prover.d.ts.map +1 -1
- package/dest/prover/bb_private_kernel_prover.js +6 -5
- package/dest/prover/bb_prover.d.ts +2 -1
- package/dest/prover/bb_prover.d.ts.map +1 -1
- package/dest/prover/bb_prover.js +19 -28
- package/dest/verification_key/verification_key_data.d.ts.map +1 -1
- package/dest/verification_key/verification_key_data.js +3 -5
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +4 -3
- package/package.json +10 -8
- package/src/bb/cli.ts +3 -33
- package/src/bb/execute.ts +22 -17
- package/src/honk.ts +18 -0
- package/src/prover/bb_private_kernel_prover.ts +17 -3
- package/src/prover/bb_prover.ts +26 -40
- package/src/verification_key/verification_key_data.ts +2 -6
- package/src/verifier/bb_verifier.ts +9 -2
package/src/bb/execute.ts
CHANGED
|
@@ -8,6 +8,8 @@ import * as proc from 'child_process';
|
|
|
8
8
|
import * as fs from 'fs/promises';
|
|
9
9
|
import { basename, dirname, join } from 'path';
|
|
10
10
|
|
|
11
|
+
import { type UltraHonkFlavor } from '../honk.js';
|
|
12
|
+
|
|
11
13
|
export const VK_FILENAME = 'vk';
|
|
12
14
|
export const VK_FIELDS_FILENAME = 'vk_fields.json';
|
|
13
15
|
export const PROOF_FILENAME = 'proof';
|
|
@@ -113,7 +115,7 @@ export async function generateKeyForNoirCircuit(
|
|
|
113
115
|
workingDirectory: string,
|
|
114
116
|
circuitName: string,
|
|
115
117
|
compiledCircuit: NoirCompiledCircuit,
|
|
116
|
-
|
|
118
|
+
flavor: UltraHonkFlavor,
|
|
117
119
|
log: LogFn,
|
|
118
120
|
force = false,
|
|
119
121
|
): Promise<BBSuccess | BBFailure> {
|
|
@@ -123,7 +125,7 @@ export async function generateKeyForNoirCircuit(
|
|
|
123
125
|
// The bytecode hash file is also written here as /workingDirectory/pk/BaseParityArtifact/bytecode-hash
|
|
124
126
|
// The bytecode is written to e.g. /workingDirectory/pk/BaseParityArtifact/bytecode
|
|
125
127
|
// The bytecode is removed after the key is generated, leaving just the hash file
|
|
126
|
-
const circuitOutputDirectory = `${workingDirectory}/${
|
|
128
|
+
const circuitOutputDirectory = `${workingDirectory}/vk/${circuitName}`;
|
|
127
129
|
const outputPath = `${circuitOutputDirectory}`;
|
|
128
130
|
const bytecodeHash = sha256(bytecode);
|
|
129
131
|
|
|
@@ -148,11 +150,11 @@ export async function generateKeyForNoirCircuit(
|
|
|
148
150
|
// args are the output path and the input bytecode path
|
|
149
151
|
const args = ['-o', `${outputPath}/${VK_FILENAME}`, '-b', bytecodePath];
|
|
150
152
|
const timer = new Timer();
|
|
151
|
-
let result = await executeBB(pathToBB, `
|
|
153
|
+
let result = await executeBB(pathToBB, `write_vk_${flavor}`, args, log);
|
|
152
154
|
// If we succeeded and the type of key if verification, have bb write the 'fields' version too
|
|
153
|
-
if (result.status == BB_RESULT.SUCCESS
|
|
155
|
+
if (result.status == BB_RESULT.SUCCESS) {
|
|
154
156
|
const asFieldsArgs = ['-k', `${outputPath}/${VK_FILENAME}`, '-o', `${outputPath}/${VK_FIELDS_FILENAME}`, '-v'];
|
|
155
|
-
result = await executeBB(pathToBB, `
|
|
157
|
+
result = await executeBB(pathToBB, `vk_as_fields_${flavor}`, asFieldsArgs, log);
|
|
156
158
|
}
|
|
157
159
|
const duration = timer.ms();
|
|
158
160
|
|
|
@@ -160,8 +162,8 @@ export async function generateKeyForNoirCircuit(
|
|
|
160
162
|
return {
|
|
161
163
|
status: BB_RESULT.SUCCESS,
|
|
162
164
|
durationMs: duration,
|
|
163
|
-
pkPath:
|
|
164
|
-
vkPath:
|
|
165
|
+
pkPath: undefined,
|
|
166
|
+
vkPath: outputPath,
|
|
165
167
|
proofPath: undefined,
|
|
166
168
|
};
|
|
167
169
|
}
|
|
@@ -179,8 +181,8 @@ export async function generateKeyForNoirCircuit(
|
|
|
179
181
|
return {
|
|
180
182
|
status: BB_RESULT.ALREADY_PRESENT,
|
|
181
183
|
durationMs: 0,
|
|
182
|
-
pkPath:
|
|
183
|
-
vkPath:
|
|
184
|
+
pkPath: undefined,
|
|
185
|
+
vkPath: outputPath,
|
|
184
186
|
};
|
|
185
187
|
}
|
|
186
188
|
|
|
@@ -261,6 +263,7 @@ export async function computeVerificationKey(
|
|
|
261
263
|
workingDirectory: string,
|
|
262
264
|
circuitName: string,
|
|
263
265
|
bytecode: Buffer,
|
|
266
|
+
flavor: UltraHonkFlavor,
|
|
264
267
|
log: LogFn,
|
|
265
268
|
): Promise<BBFailure | BBSuccess> {
|
|
266
269
|
// Check that the working directory exists
|
|
@@ -293,7 +296,7 @@ export async function computeVerificationKey(
|
|
|
293
296
|
};
|
|
294
297
|
let result = await executeBB(
|
|
295
298
|
pathToBB,
|
|
296
|
-
|
|
299
|
+
`write_vk_${flavor}`,
|
|
297
300
|
['-o', outputPath, '-b', bytecodePath, '-v'],
|
|
298
301
|
logFunction,
|
|
299
302
|
);
|
|
@@ -302,7 +305,7 @@ export async function computeVerificationKey(
|
|
|
302
305
|
}
|
|
303
306
|
result = await executeBB(
|
|
304
307
|
pathToBB,
|
|
305
|
-
|
|
308
|
+
`vk_as_fields_${flavor}`,
|
|
306
309
|
['-o', outputPath + '_fields.json', '-k', outputPath, '-v'],
|
|
307
310
|
logFunction,
|
|
308
311
|
);
|
|
@@ -343,6 +346,7 @@ export async function generateProof(
|
|
|
343
346
|
circuitName: string,
|
|
344
347
|
bytecode: Buffer,
|
|
345
348
|
inputWitnessFile: string,
|
|
349
|
+
flavor: UltraHonkFlavor,
|
|
346
350
|
log: LogFn,
|
|
347
351
|
): Promise<BBFailure | BBSuccess> {
|
|
348
352
|
// Check that the working directory exists
|
|
@@ -355,7 +359,7 @@ export async function generateProof(
|
|
|
355
359
|
// The bytecode is written to e.g. /workingDirectory/BaseParityArtifact-bytecode
|
|
356
360
|
const bytecodePath = `${workingDirectory}/${circuitName}-bytecode`;
|
|
357
361
|
|
|
358
|
-
// The proof is written to e.g. /workingDirectory/proof
|
|
362
|
+
// The proof is written to e.g. /workingDirectory/ultra_honk/proof
|
|
359
363
|
const outputPath = `${workingDirectory}`;
|
|
360
364
|
|
|
361
365
|
const binaryPresent = await fs
|
|
@@ -374,7 +378,7 @@ export async function generateProof(
|
|
|
374
378
|
const logFunction = (message: string) => {
|
|
375
379
|
log(`${circuitName} BB out - ${message}`);
|
|
376
380
|
};
|
|
377
|
-
const result = await executeBB(pathToBB,
|
|
381
|
+
const result = await executeBB(pathToBB, `prove_${flavor}_output_all`, args, logFunction);
|
|
378
382
|
const duration = timer.ms();
|
|
379
383
|
|
|
380
384
|
if (result.status == BB_RESULT.SUCCESS) {
|
|
@@ -420,7 +424,7 @@ export async function generateTubeProof(
|
|
|
420
424
|
}
|
|
421
425
|
|
|
422
426
|
// // Paths for the inputs
|
|
423
|
-
const vkPath = join(workingDirectory, '
|
|
427
|
+
const vkPath = join(workingDirectory, 'final_decider_vk.bin'); // the vk of the last instance
|
|
424
428
|
const accPath = join(workingDirectory, 'pg_acc.bin');
|
|
425
429
|
const proofPath = join(workingDirectory, 'client_ivc_proof.bin');
|
|
426
430
|
const translatorVkPath = join(workingDirectory, 'translator_vk.bin');
|
|
@@ -599,9 +603,10 @@ export async function verifyProof(
|
|
|
599
603
|
pathToBB: string,
|
|
600
604
|
proofFullPath: string,
|
|
601
605
|
verificationKeyPath: string,
|
|
606
|
+
ultraHonkFlavor: UltraHonkFlavor,
|
|
602
607
|
log: LogFn,
|
|
603
608
|
): Promise<BBFailure | BBSuccess> {
|
|
604
|
-
return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath,
|
|
609
|
+
return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, `verify_${ultraHonkFlavor}`, log);
|
|
605
610
|
}
|
|
606
611
|
|
|
607
612
|
/**
|
|
@@ -674,7 +679,7 @@ async function verifyProofInternal(
|
|
|
674
679
|
pathToBB: string,
|
|
675
680
|
proofFullPath: string,
|
|
676
681
|
verificationKeyPath: string,
|
|
677
|
-
command: 'verify_ultra_honk' | 'avm_verify',
|
|
682
|
+
command: 'verify_ultra_honk' | 'verify_ultra_keccak_honk' | 'avm_verify',
|
|
678
683
|
log: LogFn,
|
|
679
684
|
): Promise<BBFailure | BBSuccess> {
|
|
680
685
|
const binaryPresent = await fs
|
|
@@ -851,7 +856,7 @@ export async function generateContractForCircuit(
|
|
|
851
856
|
workingDirectory,
|
|
852
857
|
circuitName,
|
|
853
858
|
compiledCircuit,
|
|
854
|
-
'
|
|
859
|
+
'ultra_keccak_honk',
|
|
855
860
|
log,
|
|
856
861
|
force,
|
|
857
862
|
);
|
package/src/honk.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ProtocolArtifact } from '@aztec/noir-protocol-circuits-types';
|
|
2
|
+
|
|
3
|
+
export type UltraHonkFlavor = 'ultra_honk' | 'ultra_keccak_honk';
|
|
4
|
+
|
|
5
|
+
const UltraKeccakHonkCircuits = ['BlockRootRollupArtifact'] as const;
|
|
6
|
+
type UltraKeccakHonkCircuits = (typeof UltraKeccakHonkCircuits)[number];
|
|
7
|
+
type UltraHonkCircuits = Exclude<ProtocolArtifact, UltraKeccakHonkCircuits>;
|
|
8
|
+
|
|
9
|
+
export function getUltraHonkFlavorForCircuit(artifact: UltraKeccakHonkCircuits): 'ultra_keccak_honk';
|
|
10
|
+
export function getUltraHonkFlavorForCircuit(artifact: UltraHonkCircuits): 'ultra_honk';
|
|
11
|
+
export function getUltraHonkFlavorForCircuit(artifact: ProtocolArtifact): UltraHonkFlavor;
|
|
12
|
+
export function getUltraHonkFlavorForCircuit(artifact: ProtocolArtifact): UltraHonkFlavor {
|
|
13
|
+
return isUltraKeccakHonkCircuit(artifact) ? 'ultra_keccak_honk' : 'ultra_honk';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function isUltraKeccakHonkCircuit(artifact: ProtocolArtifact): artifact is UltraKeccakHonkCircuits {
|
|
17
|
+
return UltraKeccakHonkCircuits.includes(artifact as UltraKeccakHonkCircuits);
|
|
18
|
+
}
|
|
@@ -58,6 +58,7 @@ import {
|
|
|
58
58
|
verifyProof,
|
|
59
59
|
} from '../bb/execute.js';
|
|
60
60
|
import { type BBConfig } from '../config.js';
|
|
61
|
+
import { type UltraHonkFlavor, getUltraHonkFlavorForCircuit } from '../honk.js';
|
|
61
62
|
import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
62
63
|
import { extractVkData } from '../verification_key/verification_key_data.js';
|
|
63
64
|
|
|
@@ -213,7 +214,12 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
|
|
|
213
214
|
this.log.debug(`${circuitType} BB out - ${message}`);
|
|
214
215
|
};
|
|
215
216
|
|
|
216
|
-
const result = await this.verifyProofFromKey(
|
|
217
|
+
const result = await this.verifyProofFromKey(
|
|
218
|
+
getUltraHonkFlavorForCircuit(circuitType),
|
|
219
|
+
verificationKey.keyAsBytes,
|
|
220
|
+
proof,
|
|
221
|
+
logFunction,
|
|
222
|
+
);
|
|
217
223
|
|
|
218
224
|
if (result.status === BB_RESULT.FAILURE) {
|
|
219
225
|
const errorMessage = `Failed to verify ${circuitType} proof!`;
|
|
@@ -224,6 +230,7 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
|
|
|
224
230
|
}
|
|
225
231
|
|
|
226
232
|
private async verifyProofFromKey(
|
|
233
|
+
flavor: UltraHonkFlavor,
|
|
227
234
|
verificationKey: Buffer,
|
|
228
235
|
proof: Proof,
|
|
229
236
|
logFunction: (message: string) => void = () => {},
|
|
@@ -234,7 +241,7 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
|
|
|
234
241
|
|
|
235
242
|
await fs.writeFile(proofFileName, proof.buffer);
|
|
236
243
|
await fs.writeFile(verificationKeyPath, verificationKey);
|
|
237
|
-
return await verifyProof(this.bbBinaryPath, proofFileName, verificationKeyPath!, logFunction);
|
|
244
|
+
return await verifyProof(this.bbBinaryPath, proofFileName, verificationKeyPath!, flavor, logFunction);
|
|
238
245
|
};
|
|
239
246
|
return await this.runInDirectory(operation);
|
|
240
247
|
}
|
|
@@ -301,7 +308,14 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
|
|
|
301
308
|
|
|
302
309
|
const timer = new Timer();
|
|
303
310
|
|
|
304
|
-
const vkResult = await computeVerificationKey(
|
|
311
|
+
const vkResult = await computeVerificationKey(
|
|
312
|
+
this.bbBinaryPath,
|
|
313
|
+
directory,
|
|
314
|
+
circuitType,
|
|
315
|
+
bytecode,
|
|
316
|
+
circuitType === 'App' ? 'ultra_honk' : getUltraHonkFlavorForCircuit(circuitType),
|
|
317
|
+
this.log.debug,
|
|
318
|
+
);
|
|
305
319
|
|
|
306
320
|
if (vkResult.status === BB_RESULT.FAILURE) {
|
|
307
321
|
this.log.error(`Failed to generate proof for ${circuitType}${dbgCircuitName}: ${vkResult.reason}`);
|
package/src/prover/bb_prover.ts
CHANGED
|
@@ -77,12 +77,12 @@ import * as fs from 'fs/promises';
|
|
|
77
77
|
import * as path from 'path';
|
|
78
78
|
|
|
79
79
|
import {
|
|
80
|
+
type BBFailure,
|
|
80
81
|
type BBSuccess,
|
|
81
82
|
BB_RESULT,
|
|
82
83
|
PROOF_FIELDS_FILENAME,
|
|
83
84
|
PROOF_FILENAME,
|
|
84
85
|
VK_FILENAME,
|
|
85
|
-
type VerificationFunction,
|
|
86
86
|
generateAvmProof,
|
|
87
87
|
generateKeyForNoirCircuit,
|
|
88
88
|
generateProof,
|
|
@@ -92,6 +92,7 @@ import {
|
|
|
92
92
|
writeProofAsFields,
|
|
93
93
|
} from '../bb/execute.js';
|
|
94
94
|
import type { ACVMConfig, BBConfig } from '../config.js';
|
|
95
|
+
import { type UltraHonkFlavor, getUltraHonkFlavorForCircuit } from '../honk.js';
|
|
95
96
|
import { ProverInstrumentation } from '../instrumentation.js';
|
|
96
97
|
import { PublicKernelArtifactMapping } from '../mappings/mappings.js';
|
|
97
98
|
import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
@@ -99,11 +100,6 @@ import { extractAvmVkData, extractVkData } from '../verification_key/verificatio
|
|
|
99
100
|
|
|
100
101
|
const logger = createDebugLogger('aztec:bb-prover');
|
|
101
102
|
|
|
102
|
-
const CIRCUITS_WITHOUT_AGGREGATION: Set<ServerProtocolArtifact> = new Set([
|
|
103
|
-
'BaseParityArtifact',
|
|
104
|
-
'EmptyNestedArtifact',
|
|
105
|
-
]);
|
|
106
|
-
|
|
107
103
|
export interface BBProverConfig extends BBConfig, ACVMConfig {
|
|
108
104
|
// list of circuits supported by this prover. defaults to all circuits if empty
|
|
109
105
|
circuitFilter?: ServerProtocolArtifact[];
|
|
@@ -113,8 +109,8 @@ export interface BBProverConfig extends BBConfig, ACVMConfig {
|
|
|
113
109
|
* Prover implementation that uses barretenberg native proving
|
|
114
110
|
*/
|
|
115
111
|
export class BBNativeRollupProver implements ServerCircuitProver {
|
|
116
|
-
private verificationKeys
|
|
117
|
-
ServerProtocolArtifact
|
|
112
|
+
private verificationKeys = new Map<
|
|
113
|
+
`ultra${'_keccak_' | '_'}honk_${ServerProtocolArtifact}`,
|
|
118
114
|
Promise<VerificationKeyData>
|
|
119
115
|
>();
|
|
120
116
|
|
|
@@ -235,6 +231,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
235
231
|
);
|
|
236
232
|
|
|
237
233
|
await this.verifyWithKey(
|
|
234
|
+
getUltraHonkFlavorForCircuit(kernelOps.artifact),
|
|
238
235
|
kernelRequest.inputs.previousKernel.vk,
|
|
239
236
|
kernelRequest.inputs.previousKernel.proof.binaryProof,
|
|
240
237
|
);
|
|
@@ -539,6 +536,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
539
536
|
circuitType,
|
|
540
537
|
Buffer.from(artifact.bytecode, 'base64'),
|
|
541
538
|
outputWitnessFile,
|
|
539
|
+
getUltraHonkFlavorForCircuit(circuitType),
|
|
542
540
|
logger.debug,
|
|
543
541
|
);
|
|
544
542
|
|
|
@@ -682,9 +680,8 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
682
680
|
this.instrumentation.recordSize('circuitSize', 'tubeCircuit', tubeVK.circuitSize);
|
|
683
681
|
|
|
684
682
|
// Sanity check the tube proof (can be removed later)
|
|
685
|
-
await this.verifyWithKey(tubeVK, tubeProof.binaryProof);
|
|
683
|
+
await this.verifyWithKey('ultra_honk', tubeVK, tubeProof.binaryProof);
|
|
686
684
|
|
|
687
|
-
// TODO(#7369): properly time tube construction
|
|
688
685
|
logger.info(
|
|
689
686
|
`Generated proof for tubeCircuit in ${Math.ceil(provingResult.durationMs)} ms, size: ${
|
|
690
687
|
tubeProof.proof.length
|
|
@@ -762,22 +759,25 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
762
759
|
*/
|
|
763
760
|
public async verifyProof(circuitType: ServerProtocolArtifact, proof: Proof) {
|
|
764
761
|
const verificationKey = await this.getVerificationKeyDataForCircuit(circuitType);
|
|
765
|
-
|
|
766
|
-
return await this.verifyWithKey(verificationKey, proof);
|
|
762
|
+
return await this.verifyWithKey(getUltraHonkFlavorForCircuit(circuitType), verificationKey, proof);
|
|
767
763
|
}
|
|
768
764
|
|
|
769
765
|
public async verifyAvmProof(proof: Proof, verificationKey: AvmVerificationKeyData) {
|
|
770
|
-
return await this.verifyWithKeyInternal(proof, verificationKey,
|
|
766
|
+
return await this.verifyWithKeyInternal(proof, verificationKey, (proofPath, vkPath) =>
|
|
767
|
+
verifyAvmProof(this.config.bbBinaryPath, proofPath, vkPath, logger.debug),
|
|
768
|
+
);
|
|
771
769
|
}
|
|
772
770
|
|
|
773
|
-
public async verifyWithKey(verificationKey: VerificationKeyData, proof: Proof) {
|
|
774
|
-
return await this.verifyWithKeyInternal(proof, verificationKey,
|
|
771
|
+
public async verifyWithKey(flavor: UltraHonkFlavor, verificationKey: VerificationKeyData, proof: Proof) {
|
|
772
|
+
return await this.verifyWithKeyInternal(proof, verificationKey, (proofPath, vkPath) =>
|
|
773
|
+
verifyProof(this.config.bbBinaryPath, proofPath, vkPath, flavor, logger.debug),
|
|
774
|
+
);
|
|
775
775
|
}
|
|
776
776
|
|
|
777
777
|
private async verifyWithKeyInternal(
|
|
778
778
|
proof: Proof,
|
|
779
779
|
verificationKey: { keyAsBytes: Buffer },
|
|
780
|
-
verificationFunction:
|
|
780
|
+
verificationFunction: (proofPath: string, vkPath: string) => Promise<BBFailure | BBSuccess>,
|
|
781
781
|
) {
|
|
782
782
|
const operation = async (bbWorkingDirectory: string) => {
|
|
783
783
|
const proofFileName = path.join(bbWorkingDirectory, PROOF_FILENAME);
|
|
@@ -786,16 +786,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
786
786
|
await fs.writeFile(proofFileName, proof.buffer);
|
|
787
787
|
await fs.writeFile(verificationKeyPath, verificationKey.keyAsBytes);
|
|
788
788
|
|
|
789
|
-
const
|
|
790
|
-
logger.verbose(`BB out - ${message}`);
|
|
791
|
-
};
|
|
792
|
-
|
|
793
|
-
const result = await verificationFunction(
|
|
794
|
-
this.config.bbBinaryPath,
|
|
795
|
-
proofFileName,
|
|
796
|
-
verificationKeyPath!,
|
|
797
|
-
logFunction,
|
|
798
|
-
);
|
|
789
|
+
const result = await verificationFunction(proofFileName, verificationKeyPath!);
|
|
799
790
|
|
|
800
791
|
if (result.status === BB_RESULT.FAILURE) {
|
|
801
792
|
const errorMessage = `Failed to verify proof from key!`;
|
|
@@ -886,14 +877,15 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
886
877
|
* @returns The verification key data
|
|
887
878
|
*/
|
|
888
879
|
private async getVerificationKeyDataForCircuit(circuitType: ServerProtocolArtifact): Promise<VerificationKeyData> {
|
|
889
|
-
|
|
880
|
+
const flavor = getUltraHonkFlavorForCircuit(circuitType);
|
|
881
|
+
let promise = this.verificationKeys.get(`${flavor}_${circuitType}`);
|
|
890
882
|
if (!promise) {
|
|
891
883
|
promise = generateKeyForNoirCircuit(
|
|
892
884
|
this.config.bbBinaryPath,
|
|
893
885
|
this.config.bbWorkingDirectory,
|
|
894
886
|
circuitType,
|
|
895
887
|
ServerCircuitArtifacts[circuitType],
|
|
896
|
-
|
|
888
|
+
flavor,
|
|
897
889
|
logger.debug,
|
|
898
890
|
).then(result => {
|
|
899
891
|
if (result.status === BB_RESULT.FAILURE) {
|
|
@@ -901,7 +893,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
901
893
|
}
|
|
902
894
|
return extractVkData(result.vkPath!);
|
|
903
895
|
});
|
|
904
|
-
this.verificationKeys.set(circuitType
|
|
896
|
+
this.verificationKeys.set(`${flavor}_${circuitType}`, promise);
|
|
905
897
|
}
|
|
906
898
|
const vk = await promise;
|
|
907
899
|
return vk.clone();
|
|
@@ -916,10 +908,11 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
916
908
|
filePath: string,
|
|
917
909
|
circuitType: ServerProtocolArtifact,
|
|
918
910
|
): Promise<VerificationKeyData> {
|
|
919
|
-
|
|
911
|
+
const flavor = getUltraHonkFlavorForCircuit(circuitType);
|
|
912
|
+
let promise = this.verificationKeys.get(`${flavor}_${circuitType}`);
|
|
920
913
|
if (!promise) {
|
|
921
914
|
promise = extractVkData(filePath);
|
|
922
|
-
this.verificationKeys.set(circuitType
|
|
915
|
+
this.verificationKeys.set(`${flavor}_${circuitType}`, promise);
|
|
923
916
|
}
|
|
924
917
|
return promise;
|
|
925
918
|
}
|
|
@@ -943,20 +936,13 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
943
936
|
fs.readFile(proofFieldsFilename, { encoding: 'utf-8' }),
|
|
944
937
|
]);
|
|
945
938
|
const json = JSON.parse(proofString);
|
|
946
|
-
const vkData = await this.
|
|
947
|
-
if (!vkData) {
|
|
948
|
-
throw new Error(`Invalid verification key for ${circuitType}`);
|
|
949
|
-
}
|
|
939
|
+
const vkData = await this.getVerificationKeyDataForCircuit(circuitType);
|
|
950
940
|
const numPublicInputs = vkData.numPublicInputs - AGGREGATION_OBJECT_LENGTH;
|
|
951
941
|
const fieldsWithoutPublicInputs = json
|
|
952
942
|
.slice(0, 3)
|
|
953
943
|
.map(Fr.fromString)
|
|
954
944
|
.concat(json.slice(3 + numPublicInputs).map(Fr.fromString));
|
|
955
|
-
logger.debug(
|
|
956
|
-
`num pub inputs ${vkData.numPublicInputs} and without aggregation ${CIRCUITS_WITHOUT_AGGREGATION.has(
|
|
957
|
-
circuitType,
|
|
958
|
-
)}`,
|
|
959
|
-
);
|
|
945
|
+
logger.debug(`num pub inputs ${vkData.numPublicInputs} circuit=${circuitType}`);
|
|
960
946
|
|
|
961
947
|
const proof = new RecursiveProof<PROOF_LENGTH>(
|
|
962
948
|
fieldsWithoutPublicInputs,
|
|
@@ -3,11 +3,9 @@ import {
|
|
|
3
3
|
AvmVerificationKeyAsFields,
|
|
4
4
|
AvmVerificationKeyData,
|
|
5
5
|
Fr,
|
|
6
|
-
VERIFICATION_KEY_LENGTH_IN_FIELDS,
|
|
7
6
|
VerificationKeyAsFields,
|
|
8
7
|
VerificationKeyData,
|
|
9
8
|
} from '@aztec/circuits.js';
|
|
10
|
-
import { type Tuple } from '@aztec/foundation/serialize';
|
|
11
9
|
|
|
12
10
|
import { strict as assert } from 'assert';
|
|
13
11
|
import * as fs from 'fs/promises';
|
|
@@ -29,10 +27,8 @@ export async function extractVkData(vkDirectoryPath: string): Promise<Verificati
|
|
|
29
27
|
const fields = fieldsJson.map(Fr.fromString);
|
|
30
28
|
// The first item is the hash, this is not part of the actual VK
|
|
31
29
|
const vkHash = fields[0];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const vk = new VerificationKeyData(vkAsFields, rawBinary);
|
|
35
|
-
return vk;
|
|
30
|
+
const vkAsFields = new VerificationKeyAsFields(fields, vkHash);
|
|
31
|
+
return new VerificationKeyData(vkAsFields, rawBinary);
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
// TODO: This was adapted from the above function. A refactor might be needed.
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
verifyProof,
|
|
23
23
|
} from '../bb/execute.js';
|
|
24
24
|
import { type BBConfig } from '../config.js';
|
|
25
|
+
import { getUltraHonkFlavorForCircuit } from '../honk.js';
|
|
25
26
|
import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
26
27
|
import { extractVkData } from '../verification_key/verification_key_data.js';
|
|
27
28
|
|
|
@@ -62,7 +63,7 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
62
63
|
workingDirectory,
|
|
63
64
|
circuit,
|
|
64
65
|
ProtocolCircuitArtifacts[circuit],
|
|
65
|
-
|
|
66
|
+
getUltraHonkFlavorForCircuit(circuit),
|
|
66
67
|
logFn,
|
|
67
68
|
).then(result => {
|
|
68
69
|
if (result.status === BB_RESULT.FAILURE) {
|
|
@@ -103,7 +104,13 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
103
104
|
this.logger.debug(`${circuit} BB out - ${message}`);
|
|
104
105
|
};
|
|
105
106
|
|
|
106
|
-
const result = await verifyProof(
|
|
107
|
+
const result = await verifyProof(
|
|
108
|
+
this.config.bbBinaryPath,
|
|
109
|
+
proofFileName,
|
|
110
|
+
verificationKeyPath!,
|
|
111
|
+
getUltraHonkFlavorForCircuit(circuit),
|
|
112
|
+
logFunction,
|
|
113
|
+
);
|
|
107
114
|
|
|
108
115
|
if (result.status === BB_RESULT.FAILURE) {
|
|
109
116
|
const errorMessage = `Failed to verify ${circuit} proof!`;
|