@aztec/bb-prover 0.70.0 → 0.72.1
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 +1 -52
- package/dest/bb/execute.d.ts +0 -16
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +1 -91
- package/dest/prover/bb_prover.d.ts +3 -16
- package/dest/prover/bb_prover.d.ts.map +1 -1
- package/dest/prover/bb_prover.js +27 -59
- package/dest/test/test_avm.d.ts.map +1 -1
- package/dest/test/test_avm.js +3 -3
- package/dest/test/test_circuit_prover.d.ts +2 -2
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +3 -3
- package/dest/verifier/bb_verifier.d.ts +2 -6
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +13 -37
- package/package.json +10 -10
- package/src/bb/cli.ts +0 -76
- package/src/bb/execute.ts +0 -135
- package/src/prover/bb_prover.ts +38 -91
- package/src/test/test_avm.ts +3 -3
- package/src/test/test_circuit_prover.ts +2 -2
- package/src/verifier/bb_verifier.ts +16 -94
package/src/prover/bb_prover.ts
CHANGED
|
@@ -23,7 +23,6 @@ import {
|
|
|
23
23
|
RecursiveProof,
|
|
24
24
|
type RootParityInputs,
|
|
25
25
|
TUBE_PROOF_LENGTH,
|
|
26
|
-
type VerificationKeyAsFields,
|
|
27
26
|
type VerificationKeyData,
|
|
28
27
|
makeRecursiveProofFromBinary,
|
|
29
28
|
} from '@aztec/circuits.js';
|
|
@@ -69,8 +68,9 @@ import {
|
|
|
69
68
|
convertSingleTxBlockRootRollupInputsToWitnessMap,
|
|
70
69
|
convertSingleTxBlockRootRollupOutputsFromWitnessMap,
|
|
71
70
|
} from '@aztec/noir-protocol-circuits-types/server';
|
|
71
|
+
import { ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/vks';
|
|
72
72
|
import { NativeACVMSimulator } from '@aztec/simulator/server';
|
|
73
|
-
import { Attributes, type TelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
73
|
+
import { Attributes, type TelemetryClient, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
74
74
|
|
|
75
75
|
import { type WitnessMap } from '@noir-lang/types';
|
|
76
76
|
import { assert } from 'console';
|
|
@@ -86,7 +86,6 @@ import {
|
|
|
86
86
|
PROOF_FILENAME,
|
|
87
87
|
VK_FILENAME,
|
|
88
88
|
generateAvmProof,
|
|
89
|
-
generateKeyForNoirCircuit,
|
|
90
89
|
generateProof,
|
|
91
90
|
generateTubeProof,
|
|
92
91
|
verifyAvmProof,
|
|
@@ -114,11 +113,6 @@ export interface BBProverConfig extends BBConfig, ACVMConfig {
|
|
|
114
113
|
* Prover implementation that uses barretenberg native proving
|
|
115
114
|
*/
|
|
116
115
|
export class BBNativeRollupProver implements ServerCircuitProver {
|
|
117
|
-
private verificationKeys = new Map<
|
|
118
|
-
`ultra${'_keccak_' | '_' | '_rollup_'}honk_${ServerProtocolArtifact}`,
|
|
119
|
-
Promise<VerificationKeyData>
|
|
120
|
-
>();
|
|
121
|
-
|
|
122
116
|
private instrumentation: ProverInstrumentation;
|
|
123
117
|
|
|
124
118
|
constructor(private config: BBProverConfig, telemetry: TelemetryClient) {
|
|
@@ -129,7 +123,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
129
123
|
return this.instrumentation.tracer;
|
|
130
124
|
}
|
|
131
125
|
|
|
132
|
-
static async new(config: BBProverConfig, telemetry: TelemetryClient) {
|
|
126
|
+
static async new(config: BBProverConfig, telemetry: TelemetryClient = getTelemetryClient()) {
|
|
133
127
|
await fs.access(config.acvmBinaryPath, fs.constants.R_OK);
|
|
134
128
|
await fs.mkdir(config.acvmWorkingDirectory, { recursive: true });
|
|
135
129
|
await fs.access(config.bbBinaryPath, fs.constants.R_OK);
|
|
@@ -157,7 +151,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
157
151
|
convertBaseParityOutputsFromWitnessMap,
|
|
158
152
|
);
|
|
159
153
|
|
|
160
|
-
const verificationKey =
|
|
154
|
+
const verificationKey = this.getVerificationKeyDataForCircuit('BaseParityArtifact');
|
|
161
155
|
await this.verifyProof('BaseParityArtifact', proof.binaryProof);
|
|
162
156
|
|
|
163
157
|
return makePublicInputsAndRecursiveProof(circuitOutput, proof, verificationKey);
|
|
@@ -180,7 +174,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
180
174
|
convertRootParityOutputsFromWitnessMap,
|
|
181
175
|
);
|
|
182
176
|
|
|
183
|
-
const verificationKey =
|
|
177
|
+
const verificationKey = this.getVerificationKeyDataForCircuit('RootParityArtifact');
|
|
184
178
|
await this.verifyProof('RootParityArtifact', proof.binaryProof);
|
|
185
179
|
|
|
186
180
|
return makePublicInputsAndRecursiveProof(circuitOutput, proof, verificationKey);
|
|
@@ -222,7 +216,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
222
216
|
convertPrivateBaseRollupOutputsFromWitnessMap,
|
|
223
217
|
);
|
|
224
218
|
|
|
225
|
-
const verificationKey =
|
|
219
|
+
const verificationKey = this.getVerificationKeyDataForCircuit(artifactName);
|
|
226
220
|
|
|
227
221
|
await this.verifyProof(artifactName, proof.binaryProof);
|
|
228
222
|
|
|
@@ -249,7 +243,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
249
243
|
convertPublicBaseRollupOutputsFromWitnessMap,
|
|
250
244
|
);
|
|
251
245
|
|
|
252
|
-
const verificationKey =
|
|
246
|
+
const verificationKey = this.getVerificationKeyDataForCircuit(artifactName);
|
|
253
247
|
|
|
254
248
|
await this.verifyProof(artifactName, proof.binaryProof);
|
|
255
249
|
|
|
@@ -274,7 +268,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
274
268
|
convertMergeRollupOutputsFromWitnessMap,
|
|
275
269
|
);
|
|
276
270
|
|
|
277
|
-
const verificationKey =
|
|
271
|
+
const verificationKey = this.getVerificationKeyDataForCircuit('MergeRollupArtifact');
|
|
278
272
|
|
|
279
273
|
await this.verifyProof('MergeRollupArtifact', proof.binaryProof);
|
|
280
274
|
|
|
@@ -299,7 +293,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
299
293
|
convertBlockRootRollupOutputsFromWitnessMap,
|
|
300
294
|
);
|
|
301
295
|
|
|
302
|
-
const verificationKey =
|
|
296
|
+
const verificationKey = this.getVerificationKeyDataForCircuit('BlockRootRollupArtifact');
|
|
303
297
|
|
|
304
298
|
await this.verifyProof('BlockRootRollupArtifact', proof.binaryProof);
|
|
305
299
|
|
|
@@ -319,7 +313,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
319
313
|
convertSingleTxBlockRootRollupOutputsFromWitnessMap,
|
|
320
314
|
);
|
|
321
315
|
|
|
322
|
-
const verificationKey =
|
|
316
|
+
const verificationKey = this.getVerificationKeyDataForCircuit('SingleTxBlockRootRollupArtifact');
|
|
323
317
|
|
|
324
318
|
await this.verifyProof('SingleTxBlockRootRollupArtifact', proof.binaryProof);
|
|
325
319
|
|
|
@@ -344,7 +338,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
344
338
|
convertEmptyBlockRootRollupOutputsFromWitnessMap,
|
|
345
339
|
);
|
|
346
340
|
|
|
347
|
-
const verificationKey =
|
|
341
|
+
const verificationKey = this.getVerificationKeyDataForCircuit('EmptyBlockRootRollupArtifact');
|
|
348
342
|
|
|
349
343
|
await this.verifyProof('EmptyBlockRootRollupArtifact', proof.binaryProof);
|
|
350
344
|
|
|
@@ -369,7 +363,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
369
363
|
convertBlockMergeRollupOutputsFromWitnessMap,
|
|
370
364
|
);
|
|
371
365
|
|
|
372
|
-
const verificationKey =
|
|
366
|
+
const verificationKey = this.getVerificationKeyDataForCircuit('BlockMergeRollupArtifact');
|
|
373
367
|
|
|
374
368
|
await this.verifyProof('BlockMergeRollupArtifact', proof.binaryProof);
|
|
375
369
|
|
|
@@ -393,7 +387,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
393
387
|
|
|
394
388
|
const recursiveProof = makeRecursiveProofFromBinary(proof, NESTED_RECURSIVE_PROOF_LENGTH);
|
|
395
389
|
|
|
396
|
-
const verificationKey =
|
|
390
|
+
const verificationKey = this.getVerificationKeyDataForCircuit('RootRollupArtifact');
|
|
397
391
|
|
|
398
392
|
await this.verifyProof('RootRollupArtifact', proof);
|
|
399
393
|
|
|
@@ -409,7 +403,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
409
403
|
convertInput: (input: Input) => WitnessMap,
|
|
410
404
|
convertOutput: (outputWitness: WitnessMap) => Output,
|
|
411
405
|
workingDirectory: string,
|
|
412
|
-
): Promise<{ circuitOutput: Output;
|
|
406
|
+
): Promise<{ circuitOutput: Output; provingResult: BBSuccess }> {
|
|
413
407
|
// Have the ACVM write the partial witness here
|
|
414
408
|
const outputWitnessFile = path.join(workingDirectory, 'partial-witness.gz');
|
|
415
409
|
|
|
@@ -462,12 +456,8 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
462
456
|
throw new ProvingError(provingResult.reason, provingResult, provingResult.retry);
|
|
463
457
|
}
|
|
464
458
|
|
|
465
|
-
// Ensure our vk cache is up to date
|
|
466
|
-
const vkData = await this.updateVerificationKeyAfterProof(provingResult.vkPath!, circuitType);
|
|
467
|
-
|
|
468
459
|
return {
|
|
469
460
|
circuitOutput: output,
|
|
470
|
-
vkData,
|
|
471
461
|
provingResult,
|
|
472
462
|
};
|
|
473
463
|
}
|
|
@@ -479,15 +469,17 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
479
469
|
convertOutput: (outputWitness: WitnessMap) => Output,
|
|
480
470
|
): Promise<{ circuitOutput: Output; proof: Proof }> {
|
|
481
471
|
const operation = async (bbWorkingDirectory: string) => {
|
|
482
|
-
const {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
472
|
+
const { provingResult, circuitOutput: output } = await this.generateProofWithBB(
|
|
473
|
+
input,
|
|
474
|
+
circuitType,
|
|
475
|
+
convertInput,
|
|
476
|
+
convertOutput,
|
|
477
|
+
bbWorkingDirectory,
|
|
478
|
+
);
|
|
487
479
|
|
|
488
480
|
// Read the binary proof
|
|
489
481
|
const rawProof = await fs.readFile(`${provingResult.proofPath!}/${PROOF_FILENAME}`);
|
|
490
|
-
|
|
482
|
+
const vkData = this.getVerificationKeyDataForCircuit(circuitType);
|
|
491
483
|
const proof = new Proof(rawProof, vkData.numPublicInputs);
|
|
492
484
|
const circuitName = mapProtocolArtifactNameToCircuitName(circuitType);
|
|
493
485
|
|
|
@@ -581,12 +573,12 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
581
573
|
}
|
|
582
574
|
|
|
583
575
|
public async getTubeProof(input: TubeInputs): Promise<ProofAndVerificationKey<typeof TUBE_PROOF_LENGTH>> {
|
|
584
|
-
// this probably is gonna need to call client ivc
|
|
585
576
|
const operation = async (bbWorkingDirectory: string) => {
|
|
586
577
|
logger.debug(`createTubeProof: ${bbWorkingDirectory}`);
|
|
587
578
|
const provingResult = await this.generateTubeProofWithBB(bbWorkingDirectory, input);
|
|
588
579
|
|
|
589
580
|
// Read the proof as fields
|
|
581
|
+
// TODO(AD): this is the only remaining use of extractVkData.
|
|
590
582
|
const tubeVK = await extractVkData(provingResult.vkPath!);
|
|
591
583
|
const tubeProof = await this.readProofAsFields(provingResult.proofPath!, tubeVK, TUBE_PROOF_LENGTH);
|
|
592
584
|
|
|
@@ -631,12 +623,15 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
631
623
|
): Promise<{ circuitOutput: CircuitOutputType; proof: RecursiveProof<PROOF_LENGTH> }> {
|
|
632
624
|
// this probably is gonna need to call client ivc
|
|
633
625
|
const operation = async (bbWorkingDirectory: string) => {
|
|
634
|
-
const {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
626
|
+
const { provingResult, circuitOutput: output } = await this.generateProofWithBB(
|
|
627
|
+
input,
|
|
628
|
+
circuitType,
|
|
629
|
+
convertInput,
|
|
630
|
+
convertOutput,
|
|
631
|
+
bbWorkingDirectory,
|
|
632
|
+
);
|
|
639
633
|
|
|
634
|
+
const vkData = this.getVerificationKeyDataForCircuit(circuitType);
|
|
640
635
|
// Read the proof as fields
|
|
641
636
|
const proof = await this.readProofAsFields(provingResult.proofPath!, vkData, proofLength);
|
|
642
637
|
|
|
@@ -674,7 +669,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
674
669
|
* @param proof - The proof to be verified
|
|
675
670
|
*/
|
|
676
671
|
public async verifyProof(circuitType: ServerProtocolArtifact, proof: Proof) {
|
|
677
|
-
const verificationKey =
|
|
672
|
+
const verificationKey = this.getVerificationKeyDataForCircuit(circuitType);
|
|
678
673
|
return await this.verifyWithKey(getUltraHonkFlavorForCircuit(circuitType), verificationKey, proof);
|
|
679
674
|
}
|
|
680
675
|
|
|
@@ -715,16 +710,6 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
715
710
|
await this.runInDirectory(operation);
|
|
716
711
|
}
|
|
717
712
|
|
|
718
|
-
/**
|
|
719
|
-
* Returns the verification key for a circuit, will generate it if not cached internally
|
|
720
|
-
* @param circuitType - The type of circuit for which the verification key is required
|
|
721
|
-
* @returns The verification key
|
|
722
|
-
*/
|
|
723
|
-
public async getVerificationKeyForCircuit(circuitType: ServerProtocolArtifact): Promise<VerificationKeyAsFields> {
|
|
724
|
-
const vkData = await this.getVerificationKeyDataForCircuit(circuitType);
|
|
725
|
-
return vkData.clone().keyAsFields;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
713
|
/**
|
|
729
714
|
* Will check a recursive proof argument for validity of it's 'fields' format of proof and convert if required
|
|
730
715
|
* @param proof - The input proof that may need converting
|
|
@@ -789,54 +774,16 @@ export class BBNativeRollupProver implements ServerCircuitProver {
|
|
|
789
774
|
}
|
|
790
775
|
|
|
791
776
|
/**
|
|
792
|
-
* Returns the verification key data for a circuit
|
|
777
|
+
* Returns the verification key data for a circuit.
|
|
793
778
|
* @param circuitType - The type of circuit for which the verification key is required
|
|
794
779
|
* @returns The verification key data
|
|
795
780
|
*/
|
|
796
|
-
private
|
|
797
|
-
const
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
promise = generateKeyForNoirCircuit(
|
|
801
|
-
this.config.bbBinaryPath,
|
|
802
|
-
this.config.bbWorkingDirectory,
|
|
803
|
-
circuitType,
|
|
804
|
-
ServerCircuitArtifacts[circuitType],
|
|
805
|
-
SERVER_CIRCUIT_RECURSIVE,
|
|
806
|
-
flavor,
|
|
807
|
-
logger.debug,
|
|
808
|
-
).then(result => {
|
|
809
|
-
if (result.status === BB_RESULT.FAILURE) {
|
|
810
|
-
throw new ProvingError(
|
|
811
|
-
`Failed to generate verification key for ${circuitType}, ${result.reason}`,
|
|
812
|
-
result,
|
|
813
|
-
result.retry,
|
|
814
|
-
);
|
|
815
|
-
}
|
|
816
|
-
return extractVkData(result.vkPath!);
|
|
817
|
-
});
|
|
818
|
-
this.verificationKeys.set(`${flavor}_${circuitType}`, promise);
|
|
819
|
-
}
|
|
820
|
-
const vk = await promise;
|
|
821
|
-
return vk.clone();
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
/**
|
|
825
|
-
* Ensures our verification key cache includes the key data located at the specified directory
|
|
826
|
-
* @param filePath - The directory containing the verification key data files
|
|
827
|
-
* @param circuitType - The type of circuit to which the verification key corresponds
|
|
828
|
-
*/
|
|
829
|
-
private async updateVerificationKeyAfterProof(
|
|
830
|
-
filePath: string,
|
|
831
|
-
circuitType: ServerProtocolArtifact,
|
|
832
|
-
): Promise<VerificationKeyData> {
|
|
833
|
-
const flavor = getUltraHonkFlavorForCircuit(circuitType);
|
|
834
|
-
let promise = this.verificationKeys.get(`${flavor}_${circuitType}`);
|
|
835
|
-
if (!promise) {
|
|
836
|
-
promise = extractVkData(filePath);
|
|
837
|
-
this.verificationKeys.set(`${flavor}_${circuitType}`, promise);
|
|
781
|
+
private getVerificationKeyDataForCircuit(circuitType: ServerProtocolArtifact): VerificationKeyData {
|
|
782
|
+
const vk = ServerCircuitVks[circuitType];
|
|
783
|
+
if (vk === undefined) {
|
|
784
|
+
throw new Error('Could not find VK for server artifact ' + circuitType);
|
|
838
785
|
}
|
|
839
|
-
return
|
|
786
|
+
return vk;
|
|
840
787
|
}
|
|
841
788
|
|
|
842
789
|
private async readProofAsFields<PROOF_LENGTH extends number>(
|
package/src/test/test_avm.ts
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
Gas,
|
|
7
7
|
GlobalVariables,
|
|
8
8
|
L2ToL1Message,
|
|
9
|
-
LogHash,
|
|
10
9
|
MAX_ENQUEUED_CALLS_PER_CALL,
|
|
11
10
|
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
|
|
12
11
|
MAX_L2_TO_L1_MSGS_PER_CALL,
|
|
@@ -17,11 +16,12 @@ import {
|
|
|
17
16
|
MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
|
|
18
17
|
MAX_PUBLIC_DATA_READS_PER_CALL,
|
|
19
18
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
20
|
-
|
|
19
|
+
MAX_PUBLIC_LOGS_PER_CALL,
|
|
21
20
|
NoteHash,
|
|
22
21
|
Nullifier,
|
|
23
22
|
PublicCircuitPublicInputs,
|
|
24
23
|
PublicInnerCallRequest,
|
|
24
|
+
PublicLog,
|
|
25
25
|
ReadRequest,
|
|
26
26
|
RevertCode,
|
|
27
27
|
TreeLeafReadRequest,
|
|
@@ -73,7 +73,7 @@ export function getPublicInputs(result: PublicFunctionCallResult): PublicCircuit
|
|
|
73
73
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
74
74
|
),
|
|
75
75
|
publicCallRequests: padArrayEnd([], PublicInnerCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_CALL),
|
|
76
|
-
|
|
76
|
+
publicLogs: padArrayEnd(result.publicLogs, PublicLog.empty(), MAX_PUBLIC_LOGS_PER_CALL),
|
|
77
77
|
historicalHeader: BlockHeader.empty(),
|
|
78
78
|
globalVariables: GlobalVariables.empty(),
|
|
79
79
|
startGasLeft: Gas.from(result.startGasLeft),
|
|
@@ -64,7 +64,7 @@ import {
|
|
|
64
64
|
} from '@aztec/noir-protocol-circuits-types/server';
|
|
65
65
|
import { ProtocolCircuitVks } from '@aztec/noir-protocol-circuits-types/vks';
|
|
66
66
|
import { type SimulationProvider, WASMSimulatorWithBlobs, emitCircuitSimulationStats } from '@aztec/simulator/server';
|
|
67
|
-
import { type TelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
67
|
+
import { type TelemetryClient, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
68
68
|
|
|
69
69
|
import { type WitnessMap } from '@noir-lang/types';
|
|
70
70
|
|
|
@@ -81,9 +81,9 @@ export class TestCircuitProver implements ServerCircuitProver {
|
|
|
81
81
|
private logger = createLogger('bb-prover:test-prover');
|
|
82
82
|
|
|
83
83
|
constructor(
|
|
84
|
-
telemetry: TelemetryClient,
|
|
85
84
|
private simulationProvider?: SimulationProvider,
|
|
86
85
|
private opts: { proverTestDelayMs: number } = { proverTestDelayMs: 0 },
|
|
86
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
87
87
|
) {
|
|
88
88
|
this.instrumentation = new ProverInstrumentation(telemetry, 'TestCircuitProver');
|
|
89
89
|
}
|
|
@@ -2,101 +2,40 @@ import { type ClientProtocolCircuitVerifier, Tx } from '@aztec/circuit-types';
|
|
|
2
2
|
import { type CircuitVerificationStats } from '@aztec/circuit-types/stats';
|
|
3
3
|
import { type Proof, type VerificationKeyData } from '@aztec/circuits.js';
|
|
4
4
|
import { runInDirectory } from '@aztec/foundation/fs';
|
|
5
|
-
import { type
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
type ClientProtocolArtifact,
|
|
9
|
-
type ProtocolArtifact,
|
|
10
|
-
type ServerProtocolArtifact,
|
|
11
|
-
} from '@aztec/noir-protocol-circuits-types/types';
|
|
5
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { type ClientProtocolArtifact, type ServerProtocolArtifact } from '@aztec/noir-protocol-circuits-types/types';
|
|
7
|
+
import { ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/vks';
|
|
12
8
|
|
|
13
9
|
import { promises as fs } from 'fs';
|
|
14
10
|
import * as path from 'path';
|
|
15
11
|
|
|
16
|
-
import {
|
|
17
|
-
BB_RESULT,
|
|
18
|
-
PROOF_FILENAME,
|
|
19
|
-
VK_FILENAME,
|
|
20
|
-
generateContractForCircuit,
|
|
21
|
-
generateKeyForNoirCircuit,
|
|
22
|
-
verifyClientIvcProof,
|
|
23
|
-
verifyProof,
|
|
24
|
-
} from '../bb/execute.js';
|
|
12
|
+
import { BB_RESULT, PROOF_FILENAME, VK_FILENAME, verifyClientIvcProof, verifyProof } from '../bb/execute.js';
|
|
25
13
|
import { type BBConfig } from '../config.js';
|
|
26
|
-
import {
|
|
14
|
+
import { getUltraHonkFlavorForCircuit } from '../honk.js';
|
|
27
15
|
import { writeToOutputDirectory } from '../prover/client_ivc_proof_utils.js';
|
|
28
|
-
import {
|
|
29
|
-
import { extractVkData } from '../verification_key/verification_key_data.js';
|
|
16
|
+
import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
30
17
|
|
|
31
18
|
export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
32
|
-
private constructor(
|
|
33
|
-
private config: BBConfig,
|
|
34
|
-
private verificationKeys = new Map<ProtocolArtifact, Promise<VerificationKeyData>>(),
|
|
35
|
-
private logger: Logger,
|
|
36
|
-
) {}
|
|
37
|
-
|
|
38
|
-
public static async new(
|
|
39
|
-
config: BBConfig,
|
|
40
|
-
initialCircuits: ServerProtocolArtifact[] = [],
|
|
41
|
-
logger = createLogger('bb-prover:verifier'),
|
|
42
|
-
) {
|
|
43
|
-
await fs.mkdir(config.bbWorkingDirectory, { recursive: true });
|
|
44
|
-
const keys = new Map<ProtocolArtifact, Promise<VerificationKeyData>>();
|
|
45
|
-
for (const circuit of initialCircuits) {
|
|
46
|
-
const vkData = await this.generateVerificationKey(
|
|
47
|
-
circuit,
|
|
48
|
-
config.bbBinaryPath,
|
|
49
|
-
config.bbWorkingDirectory,
|
|
50
|
-
logger.debug,
|
|
51
|
-
);
|
|
52
|
-
keys.set(circuit, Promise.resolve(vkData));
|
|
53
|
-
}
|
|
54
|
-
return new BBCircuitVerifier(config, keys, logger);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private static async generateVerificationKey(
|
|
58
|
-
circuit: ServerProtocolArtifact,
|
|
59
|
-
bbPath: string,
|
|
60
|
-
workingDirectory: string,
|
|
61
|
-
logFn: LogFn,
|
|
62
|
-
) {
|
|
63
|
-
return await generateKeyForNoirCircuit(
|
|
64
|
-
bbPath,
|
|
65
|
-
workingDirectory,
|
|
66
|
-
circuit,
|
|
67
|
-
ServerCircuitArtifacts[circuit],
|
|
68
|
-
isProtocolArtifactRecursive(circuit),
|
|
69
|
-
getUltraHonkFlavorForCircuit(circuit),
|
|
70
|
-
logFn,
|
|
71
|
-
).then(result => {
|
|
72
|
-
if (result.status === BB_RESULT.FAILURE) {
|
|
73
|
-
throw new Error(`Failed to created verification key for ${circuit}, ${result.reason}`);
|
|
74
|
-
}
|
|
19
|
+
private constructor(private config: BBConfig, private logger: Logger) {}
|
|
75
20
|
|
|
76
|
-
|
|
77
|
-
});
|
|
21
|
+
public static async new(config: BBConfig, logger = createLogger('bb-prover:verifier')) {
|
|
22
|
+
await fs.mkdir(config.bbWorkingDirectory, { recursive: true });
|
|
23
|
+
return new BBCircuitVerifier(config, logger);
|
|
78
24
|
}
|
|
79
25
|
|
|
80
|
-
public
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
circuit,
|
|
85
|
-
this.config.bbBinaryPath,
|
|
86
|
-
this.config.bbWorkingDirectory,
|
|
87
|
-
this.logger.debug,
|
|
88
|
-
);
|
|
26
|
+
public getVerificationKeyData(circuitType: ServerProtocolArtifact): VerificationKeyData {
|
|
27
|
+
const vk = ServerCircuitVks[circuitType];
|
|
28
|
+
if (vk === undefined) {
|
|
29
|
+
throw new Error('Could not find VK for server artifact ' + circuitType);
|
|
89
30
|
}
|
|
90
|
-
|
|
91
|
-
const vk = await promise;
|
|
92
|
-
return vk.clone();
|
|
31
|
+
return vk;
|
|
93
32
|
}
|
|
94
33
|
|
|
95
34
|
public async verifyProofForCircuit(circuit: ServerProtocolArtifact, proof: Proof) {
|
|
96
35
|
const operation = async (bbWorkingDirectory: string) => {
|
|
97
36
|
const proofFileName = path.join(bbWorkingDirectory, PROOF_FILENAME);
|
|
98
37
|
const verificationKeyPath = path.join(bbWorkingDirectory, VK_FILENAME);
|
|
99
|
-
const verificationKey =
|
|
38
|
+
const verificationKey = this.getVerificationKeyData(circuit);
|
|
100
39
|
|
|
101
40
|
this.logger.debug(`${circuit} Verifying with key: ${verificationKey.keyAsFields.hash.toString()}`);
|
|
102
41
|
|
|
@@ -126,23 +65,6 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
|
|
|
126
65
|
await runInDirectory(this.config.bbWorkingDirectory, operation, this.config.bbSkipCleanup);
|
|
127
66
|
}
|
|
128
67
|
|
|
129
|
-
public async generateSolidityContract(circuit: UltraKeccakHonkServerProtocolArtifact, contractName: string) {
|
|
130
|
-
const result = await generateContractForCircuit(
|
|
131
|
-
this.config.bbBinaryPath,
|
|
132
|
-
this.config.bbWorkingDirectory,
|
|
133
|
-
circuit,
|
|
134
|
-
ServerCircuitArtifacts[circuit],
|
|
135
|
-
contractName,
|
|
136
|
-
this.logger.debug,
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
if (result.status === BB_RESULT.FAILURE) {
|
|
140
|
-
throw new Error(`Failed to create verifier contract for ${circuit}, ${result.reason}`);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return fs.readFile(result.contractPath!, 'utf-8');
|
|
144
|
-
}
|
|
145
|
-
|
|
146
68
|
public async verifyProof(tx: Tx): Promise<boolean> {
|
|
147
69
|
try {
|
|
148
70
|
// TODO(#7370) The verification keys should be supplied separately and based on the expectedCircuit
|