@aztec/bb-prover 0.46.2 → 0.46.3
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 +22 -1
- package/dest/bb/execute.d.ts +25 -0
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +185 -7
- package/dest/prover/bb_private_kernel_prover.d.ts +49 -0
- package/dest/prover/bb_private_kernel_prover.d.ts.map +1 -0
- package/dest/prover/bb_private_kernel_prover.js +201 -0
- package/dest/prover/bb_prover.d.ts +20 -5
- package/dest/prover/bb_prover.d.ts.map +1 -1
- package/dest/prover/bb_prover.js +118 -15
- package/dest/prover/index.d.ts +1 -1
- package/dest/prover/index.d.ts.map +1 -1
- package/dest/prover/index.js +2 -2
- package/dest/stats.d.ts.map +1 -1
- package/dest/stats.js +3 -1
- package/dest/test/test_circuit_prover.d.ts +6 -1
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +17 -3
- package/dest/verification_key/verification_key_data.d.ts.map +1 -1
- package/dest/verification_key/verification_key_data.js +2 -3
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +8 -7
- package/package.json +8 -7
- package/src/bb/cli.ts +32 -0
- package/src/bb/execute.ts +227 -7
- package/src/prover/{bb_native_proof_creator.ts → bb_private_kernel_prover.ts} +114 -114
- package/src/prover/bb_prover.ts +167 -17
- package/src/prover/index.ts +1 -1
- package/src/stats.ts +2 -0
- package/src/test/test_circuit_prover.ts +42 -0
- package/src/verification_key/verification_key_data.ts +1 -5
- package/src/verifier/bb_verifier.ts +7 -6
- package/dest/prover/bb_native_proof_creator.d.ts +0 -47
- package/dest/prover/bb_native_proof_creator.d.ts.map +0 -1
- package/dest/prover/bb_native_proof_creator.js +0 -198
|
@@ -64,19 +64,20 @@ export class BBCircuitVerifier {
|
|
|
64
64
|
}
|
|
65
65
|
return fs.readFile(result.contractPath, 'utf-8');
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
const expectedCircuit = data.forPublic
|
|
67
|
+
verifyProof(tx) {
|
|
68
|
+
const expectedCircuit = tx.data.forPublic
|
|
70
69
|
? 'PrivateKernelTailToPublicArtifact'
|
|
71
70
|
: 'PrivateKernelTailArtifact';
|
|
72
71
|
try {
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1050) we need a proper verify flow for clientIvcProof
|
|
73
|
+
// For now we handle only the trivial blank data case
|
|
74
|
+
// await this.verifyProofForCircuit(expectedCircuit, proof);
|
|
75
|
+
return Promise.resolve(!tx.clientIvcProof.isEmpty());
|
|
75
76
|
}
|
|
76
77
|
catch (err) {
|
|
77
78
|
this.logger.warn(`Failed to verify ${expectedCircuit} proof for tx ${Tx.getHash(tx)}: ${String(err)}`);
|
|
78
|
-
return false;
|
|
79
|
+
return Promise.resolve(false);
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
83
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmJfdmVyaWZpZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdmVyaWZpZXIvYmJfdmVyaWZpZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFzQyxFQUFFLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUU5RSxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFDdEQsT0FBTyxFQUFnQyxpQkFBaUIsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQ3hGLE9BQU8sRUFHTCx3QkFBd0IsR0FDekIsTUFBTSxxQ0FBcUMsQ0FBQztBQUU3QyxPQUFPLEtBQ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UssTUFBTSxDQUFDLE1BQU0sRUFBRSxDQUFDLENBQUM7UUFDekYsQ0FBQztRQUVELE9BQU8sRUFBRSxDQUFDLFFBQVEsQ0FBQyxNQUFNLENBQUMsWUFBYSxFQUFFLE9BQU8sQ0FBQyxDQUFDO0lBQ3BELENBQUM7SUFFRCxXQUFXLENBQUMsRUFBTTtRQUNoQixNQUFNLGVBQWUsR0FBMkIsRUFBRSxDQUFDLElBQUksQ0FBQyxTQUFTO1lBQy9ELENBQUMsQ0FBQyxtQ0FBbUM7WUFDckMsQ0FBQyxDQUFDLDJCQUEyQixDQUFDO1FBRWhDLElBQUksQ0FBQztZQUNILGtIQUFrSDtZQUNsSCxxREFBcUQ7WUFDckQsNERBQTREO1lBQzVELE9BQU8sT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQUFDLEVBQUUsQ0FBQyxjQUFjLENBQUMsT0FBTyxFQUFFLENBQUMsQ0FBQztRQUN2RCxDQUFDO1FBQUMsT0FBTyxHQUFHLEVBQUUsQ0FBQztZQUNiLElBQUksQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLG9CQUFvQixlQUFlLGlCQUFpQixFQUFFLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQyxLQUFLLE1BQU0sQ0FBQyxHQUFHLENBQUMsRUFBRSxDQUFDLENBQUM7WUFDdkcsT0FBTyxPQUFPLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFDO1FBQ2hDLENBQUM7SUFDSCxDQUFDO0NBQ0YifQ==
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/bb-prover",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js"
|
|
@@ -59,12 +59,13 @@
|
|
|
59
59
|
]
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@aztec/circuit-types": "0.46.
|
|
63
|
-
"@aztec/circuits.js": "0.46.
|
|
64
|
-
"@aztec/foundation": "0.46.
|
|
65
|
-
"@aztec/noir-protocol-circuits-types": "0.46.
|
|
66
|
-
"@aztec/simulator": "0.46.
|
|
67
|
-
"@aztec/telemetry-client": "0.46.
|
|
62
|
+
"@aztec/circuit-types": "0.46.3",
|
|
63
|
+
"@aztec/circuits.js": "0.46.3",
|
|
64
|
+
"@aztec/foundation": "0.46.3",
|
|
65
|
+
"@aztec/noir-protocol-circuits-types": "0.46.3",
|
|
66
|
+
"@aztec/simulator": "0.46.3",
|
|
67
|
+
"@aztec/telemetry-client": "0.46.3",
|
|
68
|
+
"@msgpack/msgpack": "^3.0.0-beta2",
|
|
68
69
|
"@noir-lang/noirc_abi": "portal:../../noir/packages/noirc_abi",
|
|
69
70
|
"@noir-lang/types": "portal:../../noir/packages/types",
|
|
70
71
|
"commander": "^9.0.0",
|
package/src/bb/cli.ts
CHANGED
|
@@ -89,6 +89,38 @@ export function getProgram(log: LogFn): Command {
|
|
|
89
89
|
);
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
+
program
|
|
93
|
+
.command('write-vk')
|
|
94
|
+
.description('Generates the verification key for the specified circuit')
|
|
95
|
+
.requiredOption(
|
|
96
|
+
'-w, --working-directory <string>',
|
|
97
|
+
'A directory to use for storing input/output files',
|
|
98
|
+
BB_WORKING_DIRECTORY,
|
|
99
|
+
)
|
|
100
|
+
.requiredOption('-b, --bb-path <string>', 'The path to the BB binary', BB_BINARY_PATH)
|
|
101
|
+
.requiredOption('-c, --circuit <string>', 'The name of a protocol circuit')
|
|
102
|
+
.action(async options => {
|
|
103
|
+
const compiledCircuit = ProtocolCircuitArtifacts[options.circuit as ProtocolArtifact];
|
|
104
|
+
if (!compiledCircuit) {
|
|
105
|
+
log(`Failed to find circuit ${options.circuit}`);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
await fs.access(options.workingDirectory, fs.constants.W_OK);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
log(`Working directory does not exist`);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
await generateKeyForNoirCircuit(
|
|
115
|
+
options.bbPath,
|
|
116
|
+
options.workingDirectory,
|
|
117
|
+
options.circuit,
|
|
118
|
+
compiledCircuit,
|
|
119
|
+
'vk',
|
|
120
|
+
log,
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
92
124
|
program
|
|
93
125
|
.command('write-contract')
|
|
94
126
|
.description('Generates the verification contract for the specified circuit')
|
package/src/bb/execute.ts
CHANGED
|
@@ -148,11 +148,11 @@ export async function generateKeyForNoirCircuit(
|
|
|
148
148
|
// args are the output path and the input bytecode path
|
|
149
149
|
const args = ['-o', `${outputPath}/${VK_FILENAME}`, '-b', bytecodePath];
|
|
150
150
|
const timer = new Timer();
|
|
151
|
-
let result = await executeBB(pathToBB, `write_${key}`, args, log);
|
|
151
|
+
let result = await executeBB(pathToBB, `write_${key}_ultra_honk`, args, log);
|
|
152
152
|
// If we succeeded and the type of key if verification, have bb write the 'fields' version too
|
|
153
153
|
if (result.status == BB_RESULT.SUCCESS && key === 'vk') {
|
|
154
154
|
const asFieldsArgs = ['-k', `${outputPath}/${VK_FILENAME}`, '-o', `${outputPath}/${VK_FIELDS_FILENAME}`, '-v'];
|
|
155
|
-
result = await executeBB(pathToBB, `
|
|
155
|
+
result = await executeBB(pathToBB, `vk_as_fields_ultra_honk`, asFieldsArgs, log);
|
|
156
156
|
}
|
|
157
157
|
const duration = timer.ms();
|
|
158
158
|
|
|
@@ -187,6 +187,145 @@ export async function generateKeyForNoirCircuit(
|
|
|
187
187
|
return res;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
// TODO(#7369) comment this etc (really just take inspiration from this and rewrite it all O:))
|
|
191
|
+
export async function executeBbClientIvcProof(
|
|
192
|
+
pathToBB: string,
|
|
193
|
+
workingDirectory: string,
|
|
194
|
+
bytecodeStackPath: string,
|
|
195
|
+
witnessStackPath: string,
|
|
196
|
+
log: LogFn,
|
|
197
|
+
): Promise<BBFailure | BBSuccess> {
|
|
198
|
+
// Check that the working directory exists
|
|
199
|
+
try {
|
|
200
|
+
await fs.access(workingDirectory);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
return { status: BB_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// The proof is written to e.g. /workingDirectory/proof
|
|
206
|
+
const outputPath = `${workingDirectory}`;
|
|
207
|
+
|
|
208
|
+
const binaryPresent = await fs
|
|
209
|
+
.access(pathToBB, fs.constants.R_OK)
|
|
210
|
+
.then(_ => true)
|
|
211
|
+
.catch(_ => false);
|
|
212
|
+
if (!binaryPresent) {
|
|
213
|
+
return { status: BB_RESULT.FAILURE, reason: `Failed to find bb binary at ${pathToBB}` };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
try {
|
|
217
|
+
// Write the bytecode to the working directory
|
|
218
|
+
log(`bytecodePath ${bytecodeStackPath}`);
|
|
219
|
+
log(`outputPath ${outputPath}`);
|
|
220
|
+
const args = ['-o', outputPath, '-b', bytecodeStackPath, '-w', witnessStackPath, '-v'];
|
|
221
|
+
const timer = new Timer();
|
|
222
|
+
const logFunction = (message: string) => {
|
|
223
|
+
log(`client ivc proof BB out - ${message}`);
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const result = await executeBB(pathToBB, 'client_ivc_prove_output_all_msgpack', args, logFunction);
|
|
227
|
+
const durationMs = timer.ms();
|
|
228
|
+
|
|
229
|
+
if (result.status == BB_RESULT.SUCCESS) {
|
|
230
|
+
return {
|
|
231
|
+
status: BB_RESULT.SUCCESS,
|
|
232
|
+
durationMs,
|
|
233
|
+
proofPath: `${outputPath}`,
|
|
234
|
+
pkPath: undefined,
|
|
235
|
+
vkPath: `${outputPath}`,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
239
|
+
return {
|
|
240
|
+
status: BB_RESULT.FAILURE,
|
|
241
|
+
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
242
|
+
};
|
|
243
|
+
} catch (error) {
|
|
244
|
+
return { status: BB_RESULT.FAILURE, reason: `${error}` };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Used for generating verification keys of noir circuits.
|
|
250
|
+
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this VK.
|
|
251
|
+
* @param pathToBB - The full path to the bb binary
|
|
252
|
+
* @param workingDirectory - A working directory for use by bb
|
|
253
|
+
* @param circuitName - An identifier for the circuit
|
|
254
|
+
* @param bytecode - The compiled circuit bytecode
|
|
255
|
+
* @param inputWitnessFile - The circuit input witness
|
|
256
|
+
* @param log - A logging function
|
|
257
|
+
* @returns An object containing a result indication, the location of the VK and the duration taken
|
|
258
|
+
*/
|
|
259
|
+
export async function computeVerificationKey(
|
|
260
|
+
pathToBB: string,
|
|
261
|
+
workingDirectory: string,
|
|
262
|
+
circuitName: string,
|
|
263
|
+
bytecode: Buffer,
|
|
264
|
+
log: LogFn,
|
|
265
|
+
): Promise<BBFailure | BBSuccess> {
|
|
266
|
+
// Check that the working directory exists
|
|
267
|
+
try {
|
|
268
|
+
await fs.access(workingDirectory);
|
|
269
|
+
} catch (error) {
|
|
270
|
+
return { status: BB_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// The bytecode is written to e.g. /workingDirectory/BaseParityArtifact-bytecode
|
|
274
|
+
const bytecodePath = `${workingDirectory}/${circuitName}-bytecode`;
|
|
275
|
+
|
|
276
|
+
// The verification key is written to this path
|
|
277
|
+
const outputPath = `${workingDirectory}/vk`;
|
|
278
|
+
|
|
279
|
+
const binaryPresent = await fs
|
|
280
|
+
.access(pathToBB, fs.constants.R_OK)
|
|
281
|
+
.then(_ => true)
|
|
282
|
+
.catch(_ => false);
|
|
283
|
+
if (!binaryPresent) {
|
|
284
|
+
return { status: BB_RESULT.FAILURE, reason: `Failed to find bb binary at ${pathToBB}` };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
try {
|
|
288
|
+
// Write the bytecode to the working directory
|
|
289
|
+
await fs.writeFile(bytecodePath, bytecode);
|
|
290
|
+
const timer = new Timer();
|
|
291
|
+
const logFunction = (message: string) => {
|
|
292
|
+
log(`computeVerificationKey(${circuitName}) BB out - ${message}`);
|
|
293
|
+
};
|
|
294
|
+
let result = await executeBB(
|
|
295
|
+
pathToBB,
|
|
296
|
+
'write_vk_ultra_honk',
|
|
297
|
+
['-o', outputPath, '-b', bytecodePath, '-v'],
|
|
298
|
+
logFunction,
|
|
299
|
+
);
|
|
300
|
+
if (result.status == BB_RESULT.FAILURE) {
|
|
301
|
+
return { status: BB_RESULT.FAILURE, reason: 'Failed writing VK.' };
|
|
302
|
+
}
|
|
303
|
+
result = await executeBB(
|
|
304
|
+
pathToBB,
|
|
305
|
+
'vk_as_fields_ultra_honk',
|
|
306
|
+
['-o', outputPath + '_fields.json', '-k', outputPath, '-v'],
|
|
307
|
+
logFunction,
|
|
308
|
+
);
|
|
309
|
+
const duration = timer.ms();
|
|
310
|
+
|
|
311
|
+
if (result.status == BB_RESULT.SUCCESS) {
|
|
312
|
+
return {
|
|
313
|
+
status: BB_RESULT.SUCCESS,
|
|
314
|
+
durationMs: duration,
|
|
315
|
+
pkPath: undefined,
|
|
316
|
+
vkPath: `${outputPath}`,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
320
|
+
return {
|
|
321
|
+
status: BB_RESULT.FAILURE,
|
|
322
|
+
reason: `Failed to write VK. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
323
|
+
};
|
|
324
|
+
} catch (error) {
|
|
325
|
+
return { status: BB_RESULT.FAILURE, reason: `${error}` };
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
190
329
|
/**
|
|
191
330
|
* Used for generating proofs of noir circuits.
|
|
192
331
|
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
|
|
@@ -235,7 +374,7 @@ export async function generateProof(
|
|
|
235
374
|
const logFunction = (message: string) => {
|
|
236
375
|
log(`${circuitName} BB out - ${message}`);
|
|
237
376
|
};
|
|
238
|
-
const result = await executeBB(pathToBB, '
|
|
377
|
+
const result = await executeBB(pathToBB, 'prove_ultra_honk_output_all', args, logFunction);
|
|
239
378
|
const duration = timer.ms();
|
|
240
379
|
|
|
241
380
|
if (result.status == BB_RESULT.SUCCESS) {
|
|
@@ -257,6 +396,87 @@ export async function generateProof(
|
|
|
257
396
|
}
|
|
258
397
|
}
|
|
259
398
|
|
|
399
|
+
/**
|
|
400
|
+
* Used for generating proofs of the tube circuit
|
|
401
|
+
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
|
|
402
|
+
* @param pathToBB - The full path to the bb binary
|
|
403
|
+
* @param workingDirectory - A working directory for use by bb
|
|
404
|
+
* @param circuitName - An identifier for the circuit
|
|
405
|
+
* @param bytecode - The compiled circuit bytecode
|
|
406
|
+
* @param inputWitnessFile - The circuit input witness
|
|
407
|
+
* @param log - A logging function
|
|
408
|
+
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
409
|
+
*/
|
|
410
|
+
export async function generateTubeProof(
|
|
411
|
+
pathToBB: string,
|
|
412
|
+
workingDirectory: string,
|
|
413
|
+
log: LogFn,
|
|
414
|
+
): Promise<BBFailure | BBSuccess> {
|
|
415
|
+
// Check that the working directory exists
|
|
416
|
+
try {
|
|
417
|
+
await fs.access(workingDirectory);
|
|
418
|
+
} catch (error) {
|
|
419
|
+
return { status: BB_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// // Paths for the inputs
|
|
423
|
+
const vkPath = join(workingDirectory, 'inst_vk.bin'); // the vk of the last instance
|
|
424
|
+
const accPath = join(workingDirectory, 'pg_acc.bin');
|
|
425
|
+
const proofPath = join(workingDirectory, 'client_ivc_proof.bin');
|
|
426
|
+
const translatorVkPath = join(workingDirectory, 'translator_vk.bin');
|
|
427
|
+
const eccVkPath = join(workingDirectory, 'ecc_vk.bin');
|
|
428
|
+
|
|
429
|
+
// The proof is written to e.g. /workingDirectory/proof
|
|
430
|
+
const outputPath = workingDirectory;
|
|
431
|
+
const filePresent = async (file: string) =>
|
|
432
|
+
await fs
|
|
433
|
+
.access(file, fs.constants.R_OK)
|
|
434
|
+
.then(_ => true)
|
|
435
|
+
.catch(_ => false);
|
|
436
|
+
|
|
437
|
+
const binaryPresent = await filePresent(pathToBB);
|
|
438
|
+
if (!binaryPresent) {
|
|
439
|
+
return { status: BB_RESULT.FAILURE, reason: `Failed to find bb binary at ${pathToBB}` };
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
try {
|
|
443
|
+
if (
|
|
444
|
+
!filePresent(vkPath) ||
|
|
445
|
+
!filePresent(accPath) ||
|
|
446
|
+
!filePresent(proofPath) ||
|
|
447
|
+
!filePresent(translatorVkPath) ||
|
|
448
|
+
!filePresent(eccVkPath)
|
|
449
|
+
) {
|
|
450
|
+
return { status: BB_RESULT.FAILURE, reason: `Client IVC input files not present in ${workingDirectory}` };
|
|
451
|
+
}
|
|
452
|
+
const args = ['-o', outputPath, '-v'];
|
|
453
|
+
|
|
454
|
+
const timer = new Timer();
|
|
455
|
+
const logFunction = (message: string) => {
|
|
456
|
+
log(`TubeCircuit (prove) BB out - ${message}`);
|
|
457
|
+
};
|
|
458
|
+
const result = await executeBB(pathToBB, 'prove_tube', args, logFunction);
|
|
459
|
+
const durationMs = timer.ms();
|
|
460
|
+
|
|
461
|
+
if (result.status == BB_RESULT.SUCCESS) {
|
|
462
|
+
return {
|
|
463
|
+
status: BB_RESULT.SUCCESS,
|
|
464
|
+
durationMs,
|
|
465
|
+
proofPath: outputPath,
|
|
466
|
+
pkPath: undefined,
|
|
467
|
+
vkPath: outputPath,
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
471
|
+
return {
|
|
472
|
+
status: BB_RESULT.FAILURE,
|
|
473
|
+
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
474
|
+
};
|
|
475
|
+
} catch (error) {
|
|
476
|
+
return { status: BB_RESULT.FAILURE, reason: `${error}` };
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
260
480
|
/**
|
|
261
481
|
* Used for generating AVM proofs.
|
|
262
482
|
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
|
|
@@ -381,7 +601,7 @@ export async function verifyProof(
|
|
|
381
601
|
verificationKeyPath: string,
|
|
382
602
|
log: LogFn,
|
|
383
603
|
): Promise<BBFailure | BBSuccess> {
|
|
384
|
-
return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, '
|
|
604
|
+
return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, 'verify_ultra_honk', log);
|
|
385
605
|
}
|
|
386
606
|
|
|
387
607
|
/**
|
|
@@ -414,7 +634,7 @@ async function verifyProofInternal(
|
|
|
414
634
|
pathToBB: string,
|
|
415
635
|
proofFullPath: string,
|
|
416
636
|
verificationKeyPath: string,
|
|
417
|
-
command: '
|
|
637
|
+
command: 'verify_ultra_honk' | 'avm_verify',
|
|
418
638
|
log: LogFn,
|
|
419
639
|
): Promise<BBFailure | BBSuccess> {
|
|
420
640
|
const binaryPresent = await fs
|
|
@@ -468,7 +688,7 @@ export async function writeVkAsFields(
|
|
|
468
688
|
try {
|
|
469
689
|
const args = ['-k', `${verificationKeyPath}/${verificationKeyFilename}`, '-v'];
|
|
470
690
|
const timer = new Timer();
|
|
471
|
-
const result = await executeBB(pathToBB, '
|
|
691
|
+
const result = await executeBB(pathToBB, 'vk_as_fields_ultra_honk', args, log);
|
|
472
692
|
const duration = timer.ms();
|
|
473
693
|
if (result.status == BB_RESULT.SUCCESS) {
|
|
474
694
|
return { status: BB_RESULT.SUCCESS, durationMs: duration, vkPath: verificationKeyPath };
|
|
@@ -510,7 +730,7 @@ export async function writeProofAsFields(
|
|
|
510
730
|
try {
|
|
511
731
|
const args = ['-p', `${proofPath}/${proofFileName}`, '-k', vkFilePath, '-v'];
|
|
512
732
|
const timer = new Timer();
|
|
513
|
-
const result = await executeBB(pathToBB, '
|
|
733
|
+
const result = await executeBB(pathToBB, 'proof_as_fields_honk', args, log);
|
|
514
734
|
const duration = timer.ms();
|
|
515
735
|
if (result.status == BB_RESULT.SUCCESS) {
|
|
516
736
|
return { status: BB_RESULT.SUCCESS, durationMs: duration, proofPath: proofPath };
|