@aztec/bb-prover 0.40.1 → 0.42.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 +24 -2
- package/dest/bb/execute.d.ts +37 -2
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +276 -75
- package/dest/config.d.ts +9 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +2 -0
- package/dest/index.d.ts +2 -0
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -1
- package/dest/mappings/mappings.d.ts +1 -0
- package/dest/mappings/mappings.d.ts.map +1 -1
- package/dest/mappings/mappings.js +27 -8
- package/dest/prover/bb_native_proof_creator.d.ts +4 -9
- package/dest/prover/bb_native_proof_creator.d.ts.map +1 -1
- package/dest/prover/bb_native_proof_creator.js +77 -101
- package/dest/prover/bb_prover.d.ts +35 -23
- package/dest/prover/bb_prover.d.ts.map +1 -1
- package/dest/prover/bb_prover.js +247 -155
- package/dest/stats.d.ts +2 -5
- package/dest/stats.d.ts.map +1 -1
- package/dest/stats.js +27 -26
- package/dest/test/index.d.ts +1 -0
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +2 -1
- package/dest/test/test_circuit_prover.d.ts +9 -7
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +31 -15
- package/dest/test/test_verifier.d.ts +7 -0
- package/dest/test/test_verifier.d.ts.map +1 -0
- package/dest/test/test_verifier.js +10 -0
- package/dest/verification_key/verification_key_data.d.ts +8 -0
- package/dest/verification_key/verification_key_data.d.ts.map +1 -0
- package/dest/verification_key/verification_key_data.js +24 -0
- package/dest/verifier/bb_verifier.d.ts +18 -0
- package/dest/verifier/bb_verifier.d.ts.map +1 -0
- package/dest/verifier/bb_verifier.js +90 -0
- package/dest/verifier/index.d.ts +2 -0
- package/dest/verifier/index.d.ts.map +1 -0
- package/dest/verifier/index.js +2 -0
- package/package.json +6 -6
- package/src/bb/cli.ts +36 -1
- package/src/bb/execute.ts +371 -83
- package/src/config.ts +9 -0
- package/src/index.ts +2 -0
- package/src/mappings/mappings.ts +38 -12
- package/src/prover/bb_native_proof_creator.ts +139 -119
- package/src/prover/bb_prover.ts +454 -242
- package/src/stats.ts +30 -45
- package/src/test/index.ts +1 -0
- package/src/test/test_circuit_prover.ts +84 -21
- package/src/test/test_verifier.ts +12 -0
- package/src/verification_key/verification_key_data.ts +35 -0
- package/src/verifier/bb_verifier.ts +156 -0
- package/src/verifier/index.ts +1 -0
- package/dest/prover/verification_key_data.d.ts +0 -16
- package/dest/prover/verification_key_data.d.ts.map +0 -1
- package/dest/prover/verification_key_data.js +0 -5
- package/src/prover/verification_key_data.ts +0 -16
|
@@ -1,36 +1,42 @@
|
|
|
1
1
|
import { type AppCircuitProofOutput, type KernelProofOutput, type ProofCreator } from '@aztec/circuit-types';
|
|
2
|
+
import { type CircuitProvingStats, type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats';
|
|
2
3
|
import {
|
|
4
|
+
AGGREGATION_OBJECT_LENGTH,
|
|
3
5
|
Fr,
|
|
4
6
|
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
5
7
|
type PrivateCircuitPublicInputs,
|
|
6
8
|
type PrivateKernelCircuitPublicInputs,
|
|
7
9
|
type PrivateKernelInitCircuitPrivateInputs,
|
|
8
10
|
type PrivateKernelInnerCircuitPrivateInputs,
|
|
11
|
+
type PrivateKernelResetCircuitPrivateInputsVariants,
|
|
9
12
|
type PrivateKernelTailCircuitPrivateInputs,
|
|
10
13
|
type PrivateKernelTailCircuitPublicInputs,
|
|
11
14
|
Proof,
|
|
12
15
|
RECURSIVE_PROOF_LENGTH,
|
|
13
16
|
RecursiveProof,
|
|
14
|
-
type
|
|
15
|
-
|
|
17
|
+
type VerificationKeyAsFields,
|
|
18
|
+
type VerificationKeyData,
|
|
16
19
|
} from '@aztec/circuits.js';
|
|
17
20
|
import { siloNoteHash } from '@aztec/circuits.js/hash';
|
|
18
|
-
import {
|
|
21
|
+
import { runInDirectory } from '@aztec/foundation/fs';
|
|
19
22
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
20
|
-
import {
|
|
23
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
21
24
|
import {
|
|
22
25
|
ClientCircuitArtifacts,
|
|
23
26
|
type ClientProtocolArtifact,
|
|
27
|
+
PrivateResetTagToArtifactName,
|
|
24
28
|
convertPrivateKernelInitInputsToWitnessMap,
|
|
25
29
|
convertPrivateKernelInitOutputsFromWitnessMap,
|
|
26
30
|
convertPrivateKernelInnerInputsToWitnessMap,
|
|
27
31
|
convertPrivateKernelInnerOutputsFromWitnessMap,
|
|
32
|
+
convertPrivateKernelResetInputsToWitnessMap,
|
|
33
|
+
convertPrivateKernelResetOutputsFromWitnessMap,
|
|
28
34
|
convertPrivateKernelTailForPublicOutputsFromWitnessMap,
|
|
29
35
|
convertPrivateKernelTailInputsToWitnessMap,
|
|
30
36
|
convertPrivateKernelTailOutputsFromWitnessMap,
|
|
31
37
|
convertPrivateKernelTailToPublicInputsToWitnessMap,
|
|
32
38
|
} from '@aztec/noir-protocol-circuits-types';
|
|
33
|
-
import {
|
|
39
|
+
import { WASMSimulator } from '@aztec/simulator';
|
|
34
40
|
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
35
41
|
|
|
36
42
|
import { serializeWitness } from '@noir-lang/noirc_abi';
|
|
@@ -41,38 +47,12 @@ import {
|
|
|
41
47
|
BB_RESULT,
|
|
42
48
|
PROOF_FIELDS_FILENAME,
|
|
43
49
|
PROOF_FILENAME,
|
|
44
|
-
VK_FIELDS_FILENAME,
|
|
45
|
-
VK_FILENAME,
|
|
46
50
|
generateKeyForNoirCircuit,
|
|
47
51
|
generateProof,
|
|
48
52
|
verifyProof,
|
|
49
53
|
} from '../bb/execute.js';
|
|
50
|
-
import {
|
|
51
|
-
|
|
52
|
-
CIRCUIT_PUBLIC_INPUTS_INDEX,
|
|
53
|
-
CIRCUIT_RECURSIVE_INDEX,
|
|
54
|
-
CIRCUIT_SIZE_INDEX,
|
|
55
|
-
type VerificationKeyData,
|
|
56
|
-
} from './verification_key_data.js';
|
|
57
|
-
|
|
58
|
-
type PrivateKernelProvingOps = {
|
|
59
|
-
convertOutputs: (outputs: WitnessMap) => PrivateKernelCircuitPublicInputs | PrivateKernelTailCircuitPublicInputs;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const PrivateKernelArtifactMapping: Record<ClientProtocolArtifact, PrivateKernelProvingOps> = {
|
|
63
|
-
PrivateKernelInitArtifact: {
|
|
64
|
-
convertOutputs: convertPrivateKernelInitOutputsFromWitnessMap,
|
|
65
|
-
},
|
|
66
|
-
PrivateKernelInnerArtifact: {
|
|
67
|
-
convertOutputs: convertPrivateKernelInnerOutputsFromWitnessMap,
|
|
68
|
-
},
|
|
69
|
-
PrivateKernelTailArtifact: {
|
|
70
|
-
convertOutputs: convertPrivateKernelTailOutputsFromWitnessMap,
|
|
71
|
-
},
|
|
72
|
-
PrivateKernelTailToPublicArtifact: {
|
|
73
|
-
convertOutputs: convertPrivateKernelTailForPublicOutputsFromWitnessMap,
|
|
74
|
-
},
|
|
75
|
-
};
|
|
54
|
+
import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
55
|
+
import { extractVkData } from '../verification_key/verification_key_data.js';
|
|
76
56
|
|
|
77
57
|
/**
|
|
78
58
|
* This proof creator implementation uses the native bb binary.
|
|
@@ -103,38 +83,63 @@ export class BBNativeProofCreator implements ProofCreator {
|
|
|
103
83
|
public async createProofInit(
|
|
104
84
|
inputs: PrivateKernelInitCircuitPrivateInputs,
|
|
105
85
|
): Promise<KernelProofOutput<PrivateKernelCircuitPublicInputs>> {
|
|
106
|
-
|
|
107
|
-
|
|
86
|
+
return await this.createSafeProof(
|
|
87
|
+
inputs,
|
|
88
|
+
'PrivateKernelInitArtifact',
|
|
89
|
+
convertPrivateKernelInitInputsToWitnessMap,
|
|
90
|
+
convertPrivateKernelInitOutputsFromWitnessMap,
|
|
91
|
+
);
|
|
108
92
|
}
|
|
109
93
|
|
|
110
94
|
public async createProofInner(
|
|
111
95
|
inputs: PrivateKernelInnerCircuitPrivateInputs,
|
|
112
96
|
): Promise<KernelProofOutput<PrivateKernelCircuitPublicInputs>> {
|
|
113
|
-
|
|
114
|
-
|
|
97
|
+
return await this.createSafeProof(
|
|
98
|
+
inputs,
|
|
99
|
+
'PrivateKernelInnerArtifact',
|
|
100
|
+
convertPrivateKernelInnerInputsToWitnessMap,
|
|
101
|
+
convertPrivateKernelInnerOutputsFromWitnessMap,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public async createProofReset(
|
|
106
|
+
inputs: PrivateKernelResetCircuitPrivateInputsVariants,
|
|
107
|
+
): Promise<KernelProofOutput<PrivateKernelCircuitPublicInputs>> {
|
|
108
|
+
return await this.createSafeProof(
|
|
109
|
+
inputs,
|
|
110
|
+
PrivateResetTagToArtifactName[inputs.sizeTag],
|
|
111
|
+
convertPrivateKernelResetInputsToWitnessMap,
|
|
112
|
+
output => convertPrivateKernelResetOutputsFromWitnessMap(output, inputs.sizeTag),
|
|
113
|
+
);
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
public async createProofTail(
|
|
118
117
|
inputs: PrivateKernelTailCircuitPrivateInputs,
|
|
119
118
|
): Promise<KernelProofOutput<PrivateKernelTailCircuitPublicInputs>> {
|
|
120
119
|
if (!inputs.isForPublic()) {
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
return await this.createSafeProof(
|
|
121
|
+
inputs,
|
|
122
|
+
'PrivateKernelTailArtifact',
|
|
123
|
+
convertPrivateKernelTailInputsToWitnessMap,
|
|
124
|
+
convertPrivateKernelTailOutputsFromWitnessMap,
|
|
125
|
+
);
|
|
123
126
|
}
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
return await this.createSafeProof(
|
|
128
|
+
inputs,
|
|
129
|
+
'PrivateKernelTailToPublicArtifact',
|
|
130
|
+
convertPrivateKernelTailToPublicInputsToWitnessMap,
|
|
131
|
+
convertPrivateKernelTailForPublicOutputsFromWitnessMap,
|
|
132
|
+
);
|
|
126
133
|
}
|
|
127
134
|
|
|
128
135
|
public async createAppCircuitProof(
|
|
129
|
-
partialWitness:
|
|
136
|
+
partialWitness: WitnessMap,
|
|
130
137
|
bytecode: Buffer,
|
|
138
|
+
appCircuitName?: string,
|
|
131
139
|
): Promise<AppCircuitProofOutput> {
|
|
132
|
-
const
|
|
133
|
-
await fs.mkdir(directory, { recursive: true });
|
|
134
|
-
this.log.debug(`Created directory: ${directory}`);
|
|
135
|
-
try {
|
|
140
|
+
const operation = async (directory: string) => {
|
|
136
141
|
this.log.debug(`Proving app circuit`);
|
|
137
|
-
const proofOutput = await this.createProof(directory, partialWitness, bytecode, 'App');
|
|
142
|
+
const proofOutput = await this.createProof(directory, partialWitness, bytecode, 'App', appCircuitName);
|
|
138
143
|
if (proofOutput.proof.proof.length != RECURSIVE_PROOF_LENGTH) {
|
|
139
144
|
throw new Error(`Incorrect proof length`);
|
|
140
145
|
}
|
|
@@ -144,10 +149,9 @@ export class BBNativeProofCreator implements ProofCreator {
|
|
|
144
149
|
verificationKey: proofOutput.verificationKey,
|
|
145
150
|
};
|
|
146
151
|
return output;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
return await runInDirectory(this.bbWorkingDirectory, operation);
|
|
151
155
|
}
|
|
152
156
|
|
|
153
157
|
/**
|
|
@@ -158,7 +162,7 @@ export class BBNativeProofCreator implements ProofCreator {
|
|
|
158
162
|
public async verifyProofForProtocolCircuit(circuitType: ClientProtocolArtifact, proof: Proof) {
|
|
159
163
|
const verificationKey = await this.getVerificationKeyDataForCircuit(circuitType);
|
|
160
164
|
|
|
161
|
-
this.log.debug(`Verifying with key: ${verificationKey.hash.toString()}`);
|
|
165
|
+
this.log.debug(`Verifying with key: ${verificationKey.keyAsFields.hash.toString()}`);
|
|
162
166
|
|
|
163
167
|
const logFunction = (message: string) => {
|
|
164
168
|
this.log.debug(`${circuitType} BB out - ${message}`);
|
|
@@ -179,21 +183,15 @@ export class BBNativeProofCreator implements ProofCreator {
|
|
|
179
183
|
proof: Proof,
|
|
180
184
|
logFunction: (message: string) => void = () => {},
|
|
181
185
|
) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const proofFileName = `${bbWorkingDirectory}/proof`;
|
|
187
|
-
const verificationKeyPath = `${bbWorkingDirectory}/vk`;
|
|
186
|
+
const operation = async (bbWorkingDirectory: string) => {
|
|
187
|
+
const proofFileName = `${bbWorkingDirectory}/proof`;
|
|
188
|
+
const verificationKeyPath = `${bbWorkingDirectory}/vk`;
|
|
188
189
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
try {
|
|
190
|
+
await fs.writeFile(proofFileName, proof.buffer);
|
|
191
|
+
await fs.writeFile(verificationKeyPath, verificationKey);
|
|
193
192
|
return await verifyProof(this.bbBinaryPath, proofFileName, verificationKeyPath!, logFunction);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
}
|
|
193
|
+
};
|
|
194
|
+
return await runInDirectory(this.bbWorkingDirectory, operation);
|
|
197
195
|
}
|
|
198
196
|
|
|
199
197
|
/**
|
|
@@ -215,39 +213,13 @@ export class BBNativeProofCreator implements ProofCreator {
|
|
|
215
213
|
if (result.status === BB_RESULT.FAILURE) {
|
|
216
214
|
throw new Error(`Failed to generate verification key for ${circuitType}, ${result.reason}`);
|
|
217
215
|
}
|
|
218
|
-
return
|
|
216
|
+
return extractVkData(result.vkPath!);
|
|
219
217
|
});
|
|
220
218
|
this.verificationKeys.set(circuitType, promise);
|
|
221
219
|
}
|
|
222
220
|
return await promise;
|
|
223
221
|
}
|
|
224
222
|
|
|
225
|
-
/**
|
|
226
|
-
* Reads the verification key data stored at the specified location and parses into a VerificationKeyData
|
|
227
|
-
* @param filePath - The directory containing the verification key data files
|
|
228
|
-
* @returns The verification key data
|
|
229
|
-
*/
|
|
230
|
-
private async convertVk(filePath: string): Promise<VerificationKeyData> {
|
|
231
|
-
const [rawFields, rawBinary] = await Promise.all([
|
|
232
|
-
fs.readFile(`${filePath}/${VK_FIELDS_FILENAME}`, { encoding: 'utf-8' }),
|
|
233
|
-
fs.readFile(`${filePath}/${VK_FILENAME}`),
|
|
234
|
-
]);
|
|
235
|
-
const fieldsJson = JSON.parse(rawFields);
|
|
236
|
-
const fields = fieldsJson.map(Fr.fromString);
|
|
237
|
-
// The first item is the hash, this is not part of the actual VK
|
|
238
|
-
const vkHash = fields[0];
|
|
239
|
-
const actualVk = fields.slice(1);
|
|
240
|
-
const vk: VerificationKeyData = {
|
|
241
|
-
hash: vkHash,
|
|
242
|
-
keyAsFields: actualVk as Tuple<Fr, typeof VERIFICATION_KEY_LENGTH_IN_FIELDS>,
|
|
243
|
-
keyAsBytes: rawBinary,
|
|
244
|
-
numPublicInputs: Number(actualVk[CIRCUIT_PUBLIC_INPUTS_INDEX]),
|
|
245
|
-
circuitSize: Number(actualVk[CIRCUIT_SIZE_INDEX]),
|
|
246
|
-
isRecursive: actualVk[CIRCUIT_RECURSIVE_INDEX] == Fr.ONE,
|
|
247
|
-
};
|
|
248
|
-
return vk;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
223
|
/**
|
|
252
224
|
* Ensures our verification key cache includes the key data located at the specified directory
|
|
253
225
|
* @param filePath - The directory containing the verification key data files
|
|
@@ -256,41 +228,50 @@ export class BBNativeProofCreator implements ProofCreator {
|
|
|
256
228
|
private async updateVerificationKeyAfterProof(filePath: string, circuitType: ClientProtocolArtifact) {
|
|
257
229
|
let promise = this.verificationKeys.get(circuitType);
|
|
258
230
|
if (!promise) {
|
|
259
|
-
promise =
|
|
231
|
+
promise = extractVkData(filePath);
|
|
260
232
|
this.log.debug(`Updated verification key for circuit: ${circuitType}`);
|
|
261
233
|
this.verificationKeys.set(circuitType, promise);
|
|
262
234
|
}
|
|
263
235
|
return await promise;
|
|
264
236
|
}
|
|
265
237
|
|
|
266
|
-
private async createSafeProof<
|
|
267
|
-
inputs:
|
|
238
|
+
private async createSafeProof<I extends { toBuffer: () => Buffer }, O extends { toBuffer: () => Buffer }>(
|
|
239
|
+
inputs: I,
|
|
268
240
|
circuitType: ClientProtocolArtifact,
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
277
|
-
this.log.debug(`Deleted directory: ${directory}`);
|
|
278
|
-
}
|
|
241
|
+
convertInputs: (inputs: I) => WitnessMap,
|
|
242
|
+
convertOutputs: (outputs: WitnessMap) => O,
|
|
243
|
+
): Promise<KernelProofOutput<O>> {
|
|
244
|
+
const operation = async (directory: string) => {
|
|
245
|
+
return await this.generateWitnessAndCreateProof(inputs, circuitType, directory, convertInputs, convertOutputs);
|
|
246
|
+
};
|
|
247
|
+
return await runInDirectory(this.bbWorkingDirectory, operation);
|
|
279
248
|
}
|
|
280
249
|
|
|
281
|
-
private async generateWitnessAndCreateProof<
|
|
282
|
-
|
|
250
|
+
private async generateWitnessAndCreateProof<
|
|
251
|
+
I extends { toBuffer: () => Buffer },
|
|
252
|
+
O extends { toBuffer: () => Buffer },
|
|
253
|
+
>(
|
|
254
|
+
inputs: I,
|
|
283
255
|
circuitType: ClientProtocolArtifact,
|
|
284
256
|
directory: string,
|
|
285
|
-
|
|
257
|
+
convertInputs: (inputs: I) => WitnessMap,
|
|
258
|
+
convertOutputs: (outputs: WitnessMap) => O,
|
|
259
|
+
): Promise<KernelProofOutput<O>> {
|
|
286
260
|
this.log.debug(`Generating witness for ${circuitType}`);
|
|
287
261
|
const compiledCircuit: NoirCompiledCircuit = ClientCircuitArtifacts[circuitType];
|
|
288
262
|
|
|
289
|
-
const
|
|
263
|
+
const witnessMap = convertInputs(inputs);
|
|
264
|
+
const timer = new Timer();
|
|
265
|
+
const outputWitness = await this.simulator.simulateCircuit(witnessMap, compiledCircuit);
|
|
266
|
+
const output = convertOutputs(outputWitness);
|
|
290
267
|
|
|
291
|
-
this.log.debug(`Generated witness for ${circuitType}
|
|
292
|
-
|
|
293
|
-
|
|
268
|
+
this.log.debug(`Generated witness for ${circuitType}`, {
|
|
269
|
+
eventName: 'circuit-witness-generation',
|
|
270
|
+
circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
|
|
271
|
+
duration: timer.ms(),
|
|
272
|
+
inputSize: inputs.toBuffer().length,
|
|
273
|
+
outputSize: output.toBuffer().length,
|
|
274
|
+
} satisfies CircuitWitnessGenerationStats);
|
|
294
275
|
|
|
295
276
|
const proofOutput = await this.createProof(
|
|
296
277
|
directory,
|
|
@@ -303,8 +284,8 @@ export class BBNativeProofCreator implements ProofCreator {
|
|
|
303
284
|
}
|
|
304
285
|
const nestedProof = proofOutput.proof as RecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>;
|
|
305
286
|
|
|
306
|
-
const kernelOutput: KernelProofOutput<
|
|
307
|
-
publicInputs,
|
|
287
|
+
const kernelOutput: KernelProofOutput<O> = {
|
|
288
|
+
publicInputs: output,
|
|
308
289
|
proof: nestedProof,
|
|
309
290
|
verificationKey: proofOutput.verificationKey,
|
|
310
291
|
};
|
|
@@ -316,6 +297,7 @@ export class BBNativeProofCreator implements ProofCreator {
|
|
|
316
297
|
partialWitness: WitnessMap,
|
|
317
298
|
bytecode: Buffer,
|
|
318
299
|
circuitType: ClientProtocolArtifact | 'App',
|
|
300
|
+
appCircuitName?: string,
|
|
319
301
|
): Promise<{
|
|
320
302
|
proof: RecursiveProof<typeof RECURSIVE_PROOF_LENGTH> | RecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>;
|
|
321
303
|
verificationKey: VerificationKeyAsFields;
|
|
@@ -328,6 +310,10 @@ export class BBNativeProofCreator implements ProofCreator {
|
|
|
328
310
|
|
|
329
311
|
this.log.debug(`Written ${inputsWitnessFile}`);
|
|
330
312
|
|
|
313
|
+
this.log.info(`Proving ${circuitType} circuit...`);
|
|
314
|
+
|
|
315
|
+
const timer = new Timer();
|
|
316
|
+
|
|
331
317
|
const provingResult = await generateProof(
|
|
332
318
|
this.bbBinaryPath,
|
|
333
319
|
directory,
|
|
@@ -342,15 +328,45 @@ export class BBNativeProofCreator implements ProofCreator {
|
|
|
342
328
|
throw new Error(provingResult.reason);
|
|
343
329
|
}
|
|
344
330
|
|
|
331
|
+
this.log.info(
|
|
332
|
+
`Generated ${circuitType === 'App' ? appCircuitName : circuitType} circuit proof in ${timer.ms()} ms`,
|
|
333
|
+
);
|
|
334
|
+
|
|
345
335
|
if (circuitType === 'App') {
|
|
346
|
-
const vkData = await
|
|
336
|
+
const vkData = await extractVkData(directory);
|
|
347
337
|
const proof = await this.readProofAsFields<typeof RECURSIVE_PROOF_LENGTH>(directory, circuitType, vkData);
|
|
348
|
-
|
|
338
|
+
|
|
339
|
+
this.log.debug(`Generated proof`, {
|
|
340
|
+
eventName: 'circuit-proving',
|
|
341
|
+
circuitName: 'app-circuit',
|
|
342
|
+
duration: provingResult.duration,
|
|
343
|
+
inputSize: compressedBincodedWitness.length,
|
|
344
|
+
proofSize: proof.binaryProof.buffer.length,
|
|
345
|
+
appCircuitName,
|
|
346
|
+
circuitSize: vkData.circuitSize,
|
|
347
|
+
numPublicInputs: vkData.numPublicInputs,
|
|
348
|
+
} as CircuitProvingStats);
|
|
349
|
+
|
|
350
|
+
return { proof, verificationKey: vkData.keyAsFields };
|
|
349
351
|
}
|
|
350
352
|
|
|
351
353
|
const vkData = await this.updateVerificationKeyAfterProof(directory, circuitType);
|
|
354
|
+
|
|
352
355
|
const proof = await this.readProofAsFields<typeof NESTED_RECURSIVE_PROOF_LENGTH>(directory, circuitType, vkData);
|
|
353
|
-
|
|
356
|
+
|
|
357
|
+
await this.verifyProofForProtocolCircuit(circuitType, proof.binaryProof);
|
|
358
|
+
|
|
359
|
+
this.log.debug(`Generated proof`, {
|
|
360
|
+
circuitName: mapProtocolArtifactNameToCircuitName(circuitType),
|
|
361
|
+
duration: provingResult.duration,
|
|
362
|
+
eventName: 'circuit-proving',
|
|
363
|
+
inputSize: compressedBincodedWitness.length,
|
|
364
|
+
proofSize: proof.binaryProof.buffer.length,
|
|
365
|
+
circuitSize: vkData.circuitSize,
|
|
366
|
+
numPublicInputs: vkData.numPublicInputs,
|
|
367
|
+
} as CircuitProvingStats);
|
|
368
|
+
|
|
369
|
+
return { proof, verificationKey: vkData.keyAsFields };
|
|
354
370
|
}
|
|
355
371
|
|
|
356
372
|
/**
|
|
@@ -371,12 +387,16 @@ export class BBNativeProofCreator implements ProofCreator {
|
|
|
371
387
|
const json = JSON.parse(proofString);
|
|
372
388
|
const fields = json.map(Fr.fromString);
|
|
373
389
|
const numPublicInputs =
|
|
374
|
-
circuitType === 'App' ? vkData.numPublicInputs : vkData.numPublicInputs -
|
|
390
|
+
circuitType === 'App' ? vkData.numPublicInputs : vkData.numPublicInputs - AGGREGATION_OBJECT_LENGTH;
|
|
375
391
|
const fieldsWithoutPublicInputs = fields.slice(numPublicInputs);
|
|
376
392
|
this.log.debug(
|
|
377
393
|
`Circuit type: ${circuitType}, complete proof length: ${fields.length}, without public inputs: ${fieldsWithoutPublicInputs.length}, num public inputs: ${numPublicInputs}, circuit size: ${vkData.circuitSize}, is recursive: ${vkData.isRecursive}, raw length: ${binaryProof.length}`,
|
|
378
394
|
);
|
|
379
|
-
const proof = new RecursiveProof<PROOF_LENGTH>(
|
|
395
|
+
const proof = new RecursiveProof<PROOF_LENGTH>(
|
|
396
|
+
fieldsWithoutPublicInputs,
|
|
397
|
+
new Proof(binaryProof, vkData.numPublicInputs),
|
|
398
|
+
true,
|
|
399
|
+
);
|
|
380
400
|
return proof;
|
|
381
401
|
}
|
|
382
402
|
}
|