@aztec/bb-prover 0.0.0-test.1 → 0.0.1-commit.001888fc
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/avm_proving_tests/avm_proving_tester.d.ts +15 -18
- package/dest/avm_proving_tests/avm_proving_tester.d.ts.map +1 -1
- package/dest/avm_proving_tests/avm_proving_tester.js +146 -79
- package/dest/bb/cli.d.ts +1 -1
- package/dest/bb/execute.d.ts +18 -50
- package/dest/bb/execute.d.ts.map +1 -1
- package/dest/bb/execute.js +150 -278
- package/dest/bb/index.d.ts +1 -1
- package/dest/config.d.ts +3 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/honk.d.ts +3 -3
- package/dest/honk.d.ts.map +1 -1
- package/dest/honk.js +3 -2
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/instrumentation.d.ts +3 -3
- package/dest/instrumentation.d.ts.map +1 -1
- package/dest/instrumentation.js +22 -46
- package/dest/prover/client/bb_private_kernel_prover.d.ts +38 -0
- package/dest/prover/client/bb_private_kernel_prover.d.ts.map +1 -0
- package/dest/prover/{bb_private_kernel_prover.js → client/bb_private_kernel_prover.js} +55 -21
- package/dest/prover/client/bundle.d.ts +6 -0
- package/dest/prover/client/bundle.d.ts.map +1 -0
- package/dest/prover/client/bundle.js +7 -0
- package/dest/prover/client/lazy.d.ts +6 -0
- package/dest/prover/client/lazy.d.ts.map +1 -0
- package/dest/prover/client/lazy.js +7 -0
- package/dest/prover/index.d.ts +3 -4
- package/dest/prover/index.d.ts.map +1 -1
- package/dest/prover/index.js +2 -3
- package/dest/prover/proof_utils.d.ts +19 -0
- package/dest/prover/proof_utils.d.ts.map +1 -0
- package/dest/prover/proof_utils.js +72 -0
- package/dest/prover/server/bb_prover.d.ts +97 -0
- package/dest/prover/server/bb_prover.d.ts.map +1 -0
- package/dest/prover/server/bb_prover.js +712 -0
- package/dest/test/delay_values.d.ts +1 -1
- package/dest/test/delay_values.d.ts.map +1 -1
- package/dest/test/delay_values.js +37 -23
- package/dest/test/index.d.ts +2 -1
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -0
- package/dest/test/test_circuit_prover.d.ts +27 -36
- package/dest/test/test_circuit_prover.d.ts.map +1 -1
- package/dest/test/test_circuit_prover.js +517 -88
- package/dest/test/test_verifier.d.ts +6 -3
- package/dest/test/test_verifier.d.ts.map +1 -1
- package/dest/test/test_verifier.js +23 -1
- package/dest/verification_key/verification_key_data.d.ts +1 -2
- package/dest/verification_key/verification_key_data.d.ts.map +1 -1
- package/dest/verification_key/verification_key_data.js +9 -34
- package/dest/verifier/bb_verifier.d.ts +6 -5
- package/dest/verifier/bb_verifier.d.ts.map +1 -1
- package/dest/verifier/bb_verifier.js +45 -27
- package/dest/verifier/index.d.ts +2 -1
- package/dest/verifier/index.d.ts.map +1 -1
- package/dest/verifier/index.js +1 -0
- package/dest/verifier/queued_chonk_verifier.d.ts +15 -0
- package/dest/verifier/queued_chonk_verifier.d.ts.map +1 -0
- package/dest/verifier/queued_chonk_verifier.js +101 -0
- package/package.json +35 -33
- package/src/avm_proving_tests/avm_proving_tester.ts +231 -113
- package/src/bb/execute.ts +125 -291
- package/src/config.ts +2 -0
- package/src/honk.ts +3 -2
- package/src/index.ts +1 -0
- package/src/instrumentation.ts +22 -47
- package/src/prover/{bb_private_kernel_prover.ts → client/bb_private_kernel_prover.ts} +95 -33
- package/src/prover/client/bundle.ts +10 -0
- package/src/prover/client/lazy.ts +10 -0
- package/src/prover/index.ts +2 -3
- package/src/prover/proof_utils.ts +115 -0
- package/src/prover/server/bb_prover.ts +718 -0
- package/src/test/delay_values.ts +38 -22
- package/src/test/index.ts +1 -0
- package/src/test/test_circuit_prover.ts +264 -154
- package/src/test/test_verifier.ts +15 -3
- package/src/verification_key/verification_key_data.ts +11 -31
- package/src/verifier/bb_verifier.ts +62 -35
- package/src/verifier/index.ts +1 -0
- package/src/verifier/queued_chonk_verifier.ts +109 -0
- package/dest/prover/bb_native_private_kernel_prover.d.ts +0 -25
- package/dest/prover/bb_native_private_kernel_prover.d.ts.map +0 -1
- package/dest/prover/bb_native_private_kernel_prover.js +0 -69
- package/dest/prover/bb_private_kernel_prover.d.ts +0 -32
- package/dest/prover/bb_private_kernel_prover.d.ts.map +0 -1
- package/dest/prover/bb_prover.d.ts +0 -120
- package/dest/prover/bb_prover.d.ts.map +0 -1
- package/dest/prover/bb_prover.js +0 -423
- package/dest/prover/client_ivc_proof_utils.d.ts +0 -25
- package/dest/prover/client_ivc_proof_utils.d.ts.map +0 -1
- package/dest/prover/client_ivc_proof_utils.js +0 -43
- package/dest/stats.d.ts +0 -5
- package/dest/stats.d.ts.map +0 -1
- package/dest/stats.js +0 -62
- package/dest/wasm/bb_wasm_private_kernel_prover.d.ts +0 -17
- package/dest/wasm/bb_wasm_private_kernel_prover.d.ts.map +0 -1
- package/dest/wasm/bb_wasm_private_kernel_prover.js +0 -46
- package/dest/wasm/bundle.d.ts +0 -6
- package/dest/wasm/bundle.d.ts.map +0 -1
- package/dest/wasm/bundle.js +0 -8
- package/dest/wasm/lazy.d.ts +0 -6
- package/dest/wasm/lazy.d.ts.map +0 -1
- package/dest/wasm/lazy.js +0 -8
- package/src/prover/bb_native_private_kernel_prover.ts +0 -119
- package/src/prover/bb_prover.ts +0 -781
- package/src/prover/client_ivc_proof_utils.ts +0 -42
- package/src/stats.ts +0 -64
- package/src/wasm/bb_wasm_private_kernel_prover.ts +0 -55
- package/src/wasm/bundle.ts +0 -11
- package/src/wasm/lazy.ts +0 -11
package/dest/bb/execute.js
CHANGED
|
@@ -1,52 +1,79 @@
|
|
|
1
|
-
import { sha256 } from '@aztec/foundation/crypto';
|
|
1
|
+
import { sha256 } from '@aztec/foundation/crypto/sha256';
|
|
2
2
|
import { Timer } from '@aztec/foundation/timer';
|
|
3
3
|
import * as proc from 'child_process';
|
|
4
4
|
import { promises as fs } from 'fs';
|
|
5
5
|
import { basename, dirname, join } from 'path';
|
|
6
|
-
import
|
|
6
|
+
import readline from 'readline';
|
|
7
7
|
export const VK_FILENAME = 'vk';
|
|
8
|
-
export const
|
|
8
|
+
export const PUBLIC_INPUTS_FILENAME = 'public_inputs';
|
|
9
9
|
export const PROOF_FILENAME = 'proof';
|
|
10
|
-
export const PROOF_FIELDS_FILENAME = 'proof_fields.json';
|
|
11
10
|
export const AVM_INPUTS_FILENAME = 'avm_inputs.bin';
|
|
12
11
|
export const AVM_BYTECODE_FILENAME = 'avm_bytecode.bin';
|
|
13
12
|
export const AVM_PUBLIC_INPUTS_FILENAME = 'avm_public_inputs.bin';
|
|
14
|
-
export const AVM_HINTS_FILENAME = 'avm_hints.bin';
|
|
15
13
|
export var BB_RESULT = /*#__PURE__*/ function(BB_RESULT) {
|
|
16
14
|
BB_RESULT[BB_RESULT["SUCCESS"] = 0] = "SUCCESS";
|
|
17
15
|
BB_RESULT[BB_RESULT["FAILURE"] = 1] = "FAILURE";
|
|
18
16
|
BB_RESULT[BB_RESULT["ALREADY_PRESENT"] = 2] = "ALREADY_PRESENT";
|
|
19
17
|
return BB_RESULT;
|
|
20
18
|
}({});
|
|
19
|
+
export const DEFAULT_BB_VERIFY_CONCURRENCY = 4;
|
|
21
20
|
/**
|
|
22
21
|
* Invokes the Barretenberg binary with the provided command and args
|
|
23
22
|
* @param pathToBB - The path to the BB binary
|
|
24
23
|
* @param command - The command to execute
|
|
25
24
|
* @param args - The arguments to pass
|
|
26
25
|
* @param logger - A log function
|
|
26
|
+
* @param timeout - An optional timeout before killing the BB process
|
|
27
27
|
* @param resultParser - An optional handler for detecting success or failure
|
|
28
28
|
* @returns The completed partial witness outputted from the circuit
|
|
29
|
-
*/ export function executeBB(pathToBB, command, args, logger, resultParser = (code)=>code === 0) {
|
|
29
|
+
*/ export function executeBB(pathToBB, command, args, logger, concurrency, timeout, resultParser = (code)=>code === 0) {
|
|
30
30
|
return new Promise((resolve)=>{
|
|
31
31
|
// spawn the bb process
|
|
32
32
|
const { HARDWARE_CONCURRENCY: _, ...envWithoutConcurrency } = process.env;
|
|
33
|
-
const env =
|
|
33
|
+
const env = envWithoutConcurrency;
|
|
34
|
+
// We prioritise the concurrency argument if provided and > 0
|
|
35
|
+
if (concurrency && concurrency > 0) {
|
|
36
|
+
env.HARDWARE_CONCURRENCY = concurrency.toString();
|
|
37
|
+
} else if (process.env.HARDWARE_CONCURRENCY) {
|
|
38
|
+
env.HARDWARE_CONCURRENCY = process.env.HARDWARE_CONCURRENCY;
|
|
39
|
+
}
|
|
40
|
+
logger(`BB concurrency: ${env.HARDWARE_CONCURRENCY}`);
|
|
34
41
|
logger(`Executing BB with: ${pathToBB} ${command} ${args.join(' ')}`);
|
|
35
42
|
const bb = proc.spawn(pathToBB, [
|
|
36
43
|
command,
|
|
37
44
|
...args
|
|
38
45
|
], {
|
|
46
|
+
stdio: [
|
|
47
|
+
'ignore',
|
|
48
|
+
'pipe',
|
|
49
|
+
'pipe'
|
|
50
|
+
],
|
|
39
51
|
env
|
|
40
52
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
let timeoutId;
|
|
54
|
+
if (timeout !== undefined) {
|
|
55
|
+
timeoutId = setTimeout(()=>{
|
|
56
|
+
logger(`BB execution timed out after ${timeout}ms, killing process`);
|
|
57
|
+
if (bb.pid) {
|
|
58
|
+
bb.kill('SIGKILL');
|
|
59
|
+
}
|
|
60
|
+
resolve({
|
|
61
|
+
status: 1,
|
|
62
|
+
exitCode: -1,
|
|
63
|
+
signal: 'TIMEOUT'
|
|
64
|
+
});
|
|
65
|
+
}, timeout);
|
|
66
|
+
}
|
|
67
|
+
readline.createInterface({
|
|
68
|
+
input: bb.stdout
|
|
69
|
+
}).on('line', logger);
|
|
70
|
+
readline.createInterface({
|
|
71
|
+
input: bb.stderr
|
|
72
|
+
}).on('line', logger);
|
|
49
73
|
bb.on('close', (exitCode, signal)=>{
|
|
74
|
+
if (timeoutId) {
|
|
75
|
+
clearTimeout(timeoutId);
|
|
76
|
+
}
|
|
50
77
|
if (resultParser(exitCode)) {
|
|
51
78
|
resolve({
|
|
52
79
|
status: 0,
|
|
@@ -67,12 +94,11 @@ export var BB_RESULT = /*#__PURE__*/ function(BB_RESULT) {
|
|
|
67
94
|
signal: undefined
|
|
68
95
|
}));
|
|
69
96
|
}
|
|
70
|
-
|
|
71
|
-
export async function executeBbClientIvcProof(pathToBB, workingDirectory, bytecodeStackPath, witnessStackPath, log) {
|
|
97
|
+
export async function executeBbChonkProof(pathToBB, workingDirectory, inputsPath, log, writeVk = false) {
|
|
72
98
|
// Check that the working directory exists
|
|
73
99
|
try {
|
|
74
100
|
await fs.access(workingDirectory);
|
|
75
|
-
} catch
|
|
101
|
+
} catch {
|
|
76
102
|
return {
|
|
77
103
|
status: 1,
|
|
78
104
|
reason: `Working directory ${workingDirectory} does not exist`
|
|
@@ -89,26 +115,23 @@ export async function executeBbClientIvcProof(pathToBB, workingDirectory, byteco
|
|
|
89
115
|
}
|
|
90
116
|
try {
|
|
91
117
|
// Write the bytecode to the working directory
|
|
92
|
-
log(`
|
|
93
|
-
|
|
118
|
+
log(`inputsPath ${inputsPath}`);
|
|
119
|
+
const timer = new Timer();
|
|
120
|
+
const logFunction = (message)=>{
|
|
121
|
+
log(`bb - ${message}`);
|
|
122
|
+
};
|
|
94
123
|
const args = [
|
|
95
124
|
'-o',
|
|
96
125
|
outputPath,
|
|
97
|
-
'
|
|
98
|
-
|
|
99
|
-
'-w',
|
|
100
|
-
witnessStackPath,
|
|
126
|
+
'--ivc_inputs_path',
|
|
127
|
+
inputsPath,
|
|
101
128
|
'-v',
|
|
102
129
|
'--scheme',
|
|
103
|
-
'
|
|
104
|
-
'--input_type',
|
|
105
|
-
'runtime_stack',
|
|
106
|
-
'--write_vk'
|
|
130
|
+
'chonk'
|
|
107
131
|
];
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
};
|
|
132
|
+
if (writeVk) {
|
|
133
|
+
args.push('--write_vk');
|
|
134
|
+
}
|
|
112
135
|
const result = await executeBB(pathToBB, 'prove', args, logFunction);
|
|
113
136
|
const durationMs = timer.ms();
|
|
114
137
|
if (result.status == 0) {
|
|
@@ -117,7 +140,7 @@ export async function executeBbClientIvcProof(pathToBB, workingDirectory, byteco
|
|
|
117
140
|
durationMs,
|
|
118
141
|
proofPath: `${outputPath}`,
|
|
119
142
|
pkPath: undefined,
|
|
120
|
-
|
|
143
|
+
vkDirectoryPath: `${outputPath}`
|
|
121
144
|
};
|
|
122
145
|
}
|
|
123
146
|
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
@@ -153,6 +176,15 @@ function getArgs(flavor) {
|
|
|
153
176
|
'keccak'
|
|
154
177
|
];
|
|
155
178
|
}
|
|
179
|
+
case 'ultra_starknet_honk':
|
|
180
|
+
{
|
|
181
|
+
return [
|
|
182
|
+
'--scheme',
|
|
183
|
+
'ultra_honk',
|
|
184
|
+
'--oracle_hash',
|
|
185
|
+
'starknet'
|
|
186
|
+
];
|
|
187
|
+
}
|
|
156
188
|
case 'ultra_rollup_honk':
|
|
157
189
|
{
|
|
158
190
|
return [
|
|
@@ -175,18 +207,19 @@ function getArgs(flavor) {
|
|
|
175
207
|
* @param inputWitnessFile - The circuit input witness
|
|
176
208
|
* @param log - A logging function
|
|
177
209
|
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
178
|
-
*/ export async function generateProof(pathToBB, workingDirectory, circuitName, bytecode,
|
|
210
|
+
*/ export async function generateProof(pathToBB, workingDirectory, circuitName, bytecode, verificationKey, inputWitnessFile, flavor, log) {
|
|
179
211
|
// Check that the working directory exists
|
|
180
212
|
try {
|
|
181
213
|
await fs.access(workingDirectory);
|
|
182
|
-
} catch
|
|
214
|
+
} catch {
|
|
183
215
|
return {
|
|
184
216
|
status: 1,
|
|
185
217
|
reason: `Working directory ${workingDirectory} does not exist`
|
|
186
218
|
};
|
|
187
219
|
}
|
|
188
|
-
// The bytecode is written to e.g. /workingDirectory/
|
|
220
|
+
// The bytecode is written to e.g. /workingDirectory/ParityBaseArtifact-bytecode
|
|
189
221
|
const bytecodePath = `${workingDirectory}/${circuitName}-bytecode`;
|
|
222
|
+
const vkPath = `${workingDirectory}/${circuitName}-vk`;
|
|
190
223
|
// The proof is written to e.g. /workingDirectory/ultra_honk/proof
|
|
191
224
|
const outputPath = `${workingDirectory}`;
|
|
192
225
|
const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
|
|
@@ -197,26 +230,30 @@ function getArgs(flavor) {
|
|
|
197
230
|
};
|
|
198
231
|
}
|
|
199
232
|
try {
|
|
200
|
-
// Write the bytecode to the working directory
|
|
201
|
-
await
|
|
233
|
+
// Write the bytecode and vk to the working directory
|
|
234
|
+
await Promise.all([
|
|
235
|
+
fs.writeFile(bytecodePath, bytecode),
|
|
236
|
+
fs.writeFile(vkPath, verificationKey)
|
|
237
|
+
]);
|
|
202
238
|
const args = getArgs(flavor).concat([
|
|
203
|
-
'--
|
|
204
|
-
'bytes_and_fields',
|
|
205
|
-
'--write_vk',
|
|
239
|
+
'--disable_zk',
|
|
206
240
|
'-o',
|
|
207
241
|
outputPath,
|
|
208
242
|
'-b',
|
|
209
243
|
bytecodePath,
|
|
244
|
+
'-k',
|
|
245
|
+
vkPath,
|
|
210
246
|
'-w',
|
|
211
247
|
inputWitnessFile,
|
|
212
248
|
'-v'
|
|
213
249
|
]);
|
|
214
|
-
|
|
215
|
-
|
|
250
|
+
const loggingArg = log.level === 'debug' || log.level === 'trace' ? '-d' : log.level === 'verbose' ? '-v' : '';
|
|
251
|
+
if (loggingArg !== '') {
|
|
252
|
+
args.push(loggingArg);
|
|
216
253
|
}
|
|
217
254
|
const timer = new Timer();
|
|
218
255
|
const logFunction = (message)=>{
|
|
219
|
-
log(`${circuitName} BB out - ${message}`);
|
|
256
|
+
log.info(`${circuitName} BB out - ${message}`);
|
|
220
257
|
};
|
|
221
258
|
const result = await executeBB(pathToBB, `prove`, args, logFunction);
|
|
222
259
|
const duration = timer.ms();
|
|
@@ -226,80 +263,7 @@ function getArgs(flavor) {
|
|
|
226
263
|
durationMs: duration,
|
|
227
264
|
proofPath: `${outputPath}`,
|
|
228
265
|
pkPath: undefined,
|
|
229
|
-
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
233
|
-
return {
|
|
234
|
-
status: 1,
|
|
235
|
-
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
236
|
-
retry: !!result.signal
|
|
237
|
-
};
|
|
238
|
-
} catch (error) {
|
|
239
|
-
return {
|
|
240
|
-
status: 1,
|
|
241
|
-
reason: `${error}`
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Used for generating proofs of the tube circuit
|
|
247
|
-
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
|
|
248
|
-
* @param pathToBB - The full path to the bb binary
|
|
249
|
-
* @param workingDirectory - A working directory for use by bb
|
|
250
|
-
* @param circuitName - An identifier for the circuit
|
|
251
|
-
* @param bytecode - The compiled circuit bytecode
|
|
252
|
-
* @param inputWitnessFile - The circuit input witness
|
|
253
|
-
* @param log - A logging function
|
|
254
|
-
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
255
|
-
*/ export async function generateTubeProof(pathToBB, workingDirectory, log) {
|
|
256
|
-
// Check that the working directory exists
|
|
257
|
-
try {
|
|
258
|
-
await fs.access(workingDirectory);
|
|
259
|
-
} catch (error) {
|
|
260
|
-
return {
|
|
261
|
-
status: 1,
|
|
262
|
-
reason: `Working directory ${workingDirectory} does not exist`
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
// // Paths for the inputs
|
|
266
|
-
const vkPath = join(workingDirectory, CLIENT_IVC_VK_FILE_NAME);
|
|
267
|
-
const proofPath = join(workingDirectory, CLIENT_IVC_PROOF_FILE_NAME);
|
|
268
|
-
// The proof is written to e.g. /workingDirectory/proof
|
|
269
|
-
const outputPath = workingDirectory;
|
|
270
|
-
const filePresent = async (file)=>await fs.access(file, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
|
|
271
|
-
const binaryPresent = await filePresent(pathToBB);
|
|
272
|
-
if (!binaryPresent) {
|
|
273
|
-
return {
|
|
274
|
-
status: 1,
|
|
275
|
-
reason: `Failed to find bb binary at ${pathToBB}`
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
try {
|
|
279
|
-
if (!await filePresent(vkPath) || !await filePresent(proofPath)) {
|
|
280
|
-
return {
|
|
281
|
-
status: 1,
|
|
282
|
-
reason: `Client IVC input files not present in ${workingDirectory}`
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
const args = [
|
|
286
|
-
'-o',
|
|
287
|
-
outputPath,
|
|
288
|
-
'-v'
|
|
289
|
-
];
|
|
290
|
-
const timer = new Timer();
|
|
291
|
-
const logFunction = (message)=>{
|
|
292
|
-
log(`TubeCircuit (prove) BB out - ${message}`);
|
|
293
|
-
};
|
|
294
|
-
const result = await executeBB(pathToBB, 'prove_tube', args, logFunction);
|
|
295
|
-
const durationMs = timer.ms();
|
|
296
|
-
if (result.status == 0) {
|
|
297
|
-
return {
|
|
298
|
-
status: 0,
|
|
299
|
-
durationMs,
|
|
300
|
-
proofPath: outputPath,
|
|
301
|
-
pkPath: undefined,
|
|
302
|
-
vkPath: outputPath
|
|
266
|
+
vkDirectoryPath: `${outputPath}`
|
|
303
267
|
};
|
|
304
268
|
}
|
|
305
269
|
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
@@ -321,13 +285,14 @@ function getArgs(flavor) {
|
|
|
321
285
|
* @param pathToBB - The full path to the bb binary
|
|
322
286
|
* @param workingDirectory - A working directory for use by bb
|
|
323
287
|
* @param input - The inputs for the public function to be proven
|
|
324
|
-
* @param
|
|
288
|
+
* @param logger - A logging function
|
|
289
|
+
* @param checkCircuitOnly - A boolean to toggle a "check-circuit only" operation instead of proving.
|
|
325
290
|
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
326
|
-
*/ export async function
|
|
291
|
+
*/ export async function generateAvmProof(pathToBB, workingDirectory, input, logger, checkCircuitOnly = false) {
|
|
327
292
|
// Check that the working directory exists
|
|
328
293
|
try {
|
|
329
294
|
await fs.access(workingDirectory);
|
|
330
|
-
} catch
|
|
295
|
+
} catch {
|
|
331
296
|
return {
|
|
332
297
|
status: 1,
|
|
333
298
|
reason: `Working directory ${workingDirectory} does not exist`
|
|
@@ -354,7 +319,10 @@ function getArgs(flavor) {
|
|
|
354
319
|
reason: `Could not write avm inputs to ${avmInputsPath}`
|
|
355
320
|
};
|
|
356
321
|
}
|
|
357
|
-
const args = [
|
|
322
|
+
const args = checkCircuitOnly ? [
|
|
323
|
+
'--avm-inputs',
|
|
324
|
+
avmInputsPath
|
|
325
|
+
] : [
|
|
358
326
|
'--avm-inputs',
|
|
359
327
|
avmInputsPath,
|
|
360
328
|
'-o',
|
|
@@ -365,93 +333,11 @@ function getArgs(flavor) {
|
|
|
365
333
|
args.push(loggingArg);
|
|
366
334
|
}
|
|
367
335
|
const timer = new Timer();
|
|
368
|
-
const
|
|
369
|
-
logger.verbose(`AvmCircuit (prove) BB out - ${message}`);
|
|
370
|
-
};
|
|
371
|
-
const result = await executeBB(pathToBB, 'avm2_prove', args, logFunction);
|
|
372
|
-
const duration = timer.ms();
|
|
373
|
-
if (result.status == 0) {
|
|
374
|
-
return {
|
|
375
|
-
status: 0,
|
|
376
|
-
durationMs: duration,
|
|
377
|
-
proofPath: join(outputPath, PROOF_FILENAME),
|
|
378
|
-
pkPath: undefined,
|
|
379
|
-
vkPath: outputPath
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
383
|
-
return {
|
|
384
|
-
status: 1,
|
|
385
|
-
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
386
|
-
retry: !!result.signal
|
|
387
|
-
};
|
|
388
|
-
} catch (error) {
|
|
389
|
-
return {
|
|
390
|
-
status: 1,
|
|
391
|
-
reason: `${error}`
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Used for generating AVM proofs (or doing check-circuit).
|
|
397
|
-
* It is assumed that the working directory is a temporary and/or random directory used solely for generating this proof.
|
|
398
|
-
* @param pathToBB - The full path to the bb binary
|
|
399
|
-
* @param workingDirectory - A working directory for use by bb
|
|
400
|
-
* @param bytecode - The AVM bytecode for the public function to be proven (expected to be decompressed)
|
|
401
|
-
* @param log - A logging function
|
|
402
|
-
* @returns An object containing a result indication, the location of the proof and the duration taken
|
|
403
|
-
*/ export async function generateAvmProof(pathToBB, workingDirectory, _input, logger, checkCircuitOnly = false) {
|
|
404
|
-
// Check that the working directory exists
|
|
405
|
-
try {
|
|
406
|
-
await fs.access(workingDirectory);
|
|
407
|
-
} catch (error) {
|
|
408
|
-
return {
|
|
409
|
-
status: 1,
|
|
410
|
-
reason: `Working directory ${workingDirectory} does not exist`
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
// Paths for the inputs
|
|
414
|
-
const publicInputsPath = join(workingDirectory, AVM_PUBLIC_INPUTS_FILENAME);
|
|
415
|
-
const avmHintsPath = join(workingDirectory, AVM_HINTS_FILENAME);
|
|
416
|
-
// The proof is written to e.g. /workingDirectory/proof
|
|
417
|
-
const outputPath = workingDirectory;
|
|
418
|
-
const filePresent = async (file)=>await fs.access(file, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
|
|
419
|
-
const binaryPresent = await filePresent(pathToBB);
|
|
420
|
-
if (!binaryPresent) {
|
|
421
|
-
return {
|
|
422
|
-
status: 1,
|
|
423
|
-
reason: `Failed to find bb binary at ${pathToBB}`
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
try {
|
|
427
|
-
// Write the inputs to the working directory.
|
|
428
|
-
// WARNING: Not writing the inputs since VM1 is disabled!
|
|
429
|
-
// await fs.writeFile(publicInputsPath, input.publicInputs.toBuffer());
|
|
430
|
-
// if (!(await filePresent(publicInputsPath))) {
|
|
431
|
-
// return { status: BB_RESULT.FAILURE, reason: `Could not write publicInputs at ${publicInputsPath}` };
|
|
432
|
-
// }
|
|
433
|
-
// await fs.writeFile(avmHintsPath, input.avmHints.toBuffer());
|
|
434
|
-
// if (!(await filePresent(avmHintsPath))) {
|
|
435
|
-
// return { status: BB_RESULT.FAILURE, reason: `Could not write avmHints at ${avmHintsPath}` };
|
|
436
|
-
// }
|
|
437
|
-
const args = [
|
|
438
|
-
'--avm-public-inputs',
|
|
439
|
-
publicInputsPath,
|
|
440
|
-
'--avm-hints',
|
|
441
|
-
avmHintsPath,
|
|
442
|
-
'-o',
|
|
443
|
-
outputPath
|
|
444
|
-
];
|
|
445
|
-
const loggingArg = logger.level === 'debug' || logger.level === 'trace' ? '-d' : logger.level === 'verbose' ? '-v' : '';
|
|
446
|
-
if (loggingArg !== '') {
|
|
447
|
-
args.push(loggingArg);
|
|
448
|
-
}
|
|
449
|
-
const timer = new Timer();
|
|
450
|
-
const cmd = checkCircuitOnly ? 'check_circuit' : 'prove';
|
|
336
|
+
const cmd = checkCircuitOnly ? 'avm_check_circuit' : 'avm_prove';
|
|
451
337
|
const logFunction = (message)=>{
|
|
452
338
|
logger.verbose(`AvmCircuit (${cmd}) BB out - ${message}`);
|
|
453
339
|
};
|
|
454
|
-
const result = await executeBB(pathToBB,
|
|
340
|
+
const result = await executeBB(pathToBB, cmd, args, logFunction);
|
|
455
341
|
const duration = timer.ms();
|
|
456
342
|
if (result.status == 0) {
|
|
457
343
|
return {
|
|
@@ -459,14 +345,14 @@ function getArgs(flavor) {
|
|
|
459
345
|
durationMs: duration,
|
|
460
346
|
proofPath: join(outputPath, PROOF_FILENAME),
|
|
461
347
|
pkPath: undefined,
|
|
462
|
-
|
|
348
|
+
vkDirectoryPath: undefined
|
|
463
349
|
};
|
|
464
350
|
}
|
|
465
351
|
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
466
352
|
return {
|
|
467
353
|
status: 1,
|
|
468
|
-
reason: `Failed to generate proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
469
|
-
retry:
|
|
354
|
+
reason: `Failed to generate proof. AVM proof for TX hash ${input.hints.tx.hash}. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
355
|
+
retry: result.signal === 'SIGKILL'
|
|
470
356
|
};
|
|
471
357
|
} catch (error) {
|
|
472
358
|
return {
|
|
@@ -480,22 +366,31 @@ function getArgs(flavor) {
|
|
|
480
366
|
* @param pathToBB - The full path to the bb binary
|
|
481
367
|
* @param proofFullPath - The full path to the proof to be verified
|
|
482
368
|
* @param verificationKeyPath - The full path to the circuit verification key
|
|
483
|
-
* @param
|
|
484
|
-
* @returns An object containing a result indication and duration taken
|
|
485
|
-
*/ export async function verifyProof(pathToBB, proofFullPath, verificationKeyPath, ultraHonkFlavor, log) {
|
|
486
|
-
return await verifyProofInternal(pathToBB, proofFullPath, verificationKeyPath, `verify`, log, getArgs(ultraHonkFlavor));
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Used for verifying proofs of the AVM
|
|
490
|
-
* @param pathToBB - The full path to the bb binary
|
|
491
|
-
* @param proofFullPath - The full path to the proof to be verified
|
|
492
|
-
* @param verificationKeyPath - The full path to the circuit verification key
|
|
493
|
-
* @param log - A logging function
|
|
369
|
+
* @param logger - A logger
|
|
494
370
|
* @returns An object containing a result indication and duration taken
|
|
495
|
-
*/ export async function
|
|
496
|
-
|
|
371
|
+
*/ export async function verifyProof(pathToBB, proofFullPath, verificationKeyPath, ultraHonkFlavor, logger) {
|
|
372
|
+
// Specify the public inputs path in the case of UH verification.
|
|
373
|
+
// Take proofFullPath and remove the suffix past the / to get the directory.
|
|
374
|
+
const proofDir = proofFullPath.substring(0, proofFullPath.lastIndexOf('/'));
|
|
375
|
+
const publicInputsFullPath = join(proofDir, '/public_inputs');
|
|
376
|
+
logger.debug(`public inputs path: ${publicInputsFullPath}`);
|
|
377
|
+
const args = [
|
|
378
|
+
'-p',
|
|
379
|
+
proofFullPath,
|
|
380
|
+
'-k',
|
|
381
|
+
verificationKeyPath,
|
|
382
|
+
'-i',
|
|
383
|
+
publicInputsFullPath,
|
|
384
|
+
'--disable_zk',
|
|
385
|
+
...getArgs(ultraHonkFlavor)
|
|
386
|
+
];
|
|
387
|
+
let concurrency = DEFAULT_BB_VERIFY_CONCURRENCY;
|
|
388
|
+
if (process.env.VERIFY_HARDWARE_CONCURRENCY) {
|
|
389
|
+
concurrency = parseInt(process.env.VERIFY_HARDWARE_CONCURRENCY, 10);
|
|
390
|
+
}
|
|
391
|
+
return await verifyProofInternal(pathToBB, `verify`, args, logger, concurrency);
|
|
497
392
|
}
|
|
498
|
-
export async function
|
|
393
|
+
export async function verifyAvmProof(pathToBB, workingDirectory, proofFullPath, publicInputs, logger) {
|
|
499
394
|
const inputsBuffer = publicInputs.serializeWithMessagePack();
|
|
500
395
|
// Write the inputs to the working directory.
|
|
501
396
|
const filePresent = async (file)=>await fs.access(file, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
|
|
@@ -507,19 +402,23 @@ export async function verifyAvmProofV2(pathToBB, workingDirectory, proofFullPath
|
|
|
507
402
|
reason: `Could not write avm inputs to ${avmInputsPath}`
|
|
508
403
|
};
|
|
509
404
|
}
|
|
510
|
-
|
|
405
|
+
const args = [
|
|
406
|
+
'-p',
|
|
407
|
+
proofFullPath,
|
|
511
408
|
'--avm-public-inputs',
|
|
512
409
|
avmInputsPath
|
|
513
|
-
]
|
|
410
|
+
];
|
|
411
|
+
return await verifyProofInternal(pathToBB, 'avm_verify', args, logger);
|
|
514
412
|
}
|
|
515
413
|
/**
|
|
516
|
-
* Verifies a
|
|
414
|
+
* Verifies a ChonkProof
|
|
517
415
|
* TODO(#7370) The verification keys should be supplied separately
|
|
518
416
|
* @param pathToBB - The full path to the bb binary
|
|
519
417
|
* @param targetPath - The path to the folder with the proof, accumulator, and verification keys
|
|
520
|
-
* @param
|
|
418
|
+
* @param logger - A logger
|
|
419
|
+
* @param concurrency - The number of threads to use for the verification
|
|
521
420
|
* @returns An object containing a result indication and duration taken
|
|
522
|
-
*/ export async function
|
|
421
|
+
*/ export async function verifyChonkProof(pathToBB, proofPath, keyPath, logger, concurrency = 1) {
|
|
523
422
|
const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
|
|
524
423
|
if (!binaryPresent) {
|
|
525
424
|
return {
|
|
@@ -527,47 +426,26 @@ export async function verifyAvmProofV2(pathToBB, workingDirectory, proofFullPath
|
|
|
527
426
|
reason: `Failed to find bb binary at ${pathToBB}`
|
|
528
427
|
};
|
|
529
428
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
const command = 'verify';
|
|
541
|
-
const result = await executeBB(pathToBB, command, args, log);
|
|
542
|
-
const duration = timer.ms();
|
|
543
|
-
if (result.status == 0) {
|
|
544
|
-
return {
|
|
545
|
-
status: 0,
|
|
546
|
-
durationMs: duration
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
550
|
-
return {
|
|
551
|
-
status: 1,
|
|
552
|
-
reason: `Failed to verify proof. Exit code ${result.exitCode}. Signal ${result.signal}.`,
|
|
553
|
-
retry: !!result.signal
|
|
554
|
-
};
|
|
555
|
-
} catch (error) {
|
|
556
|
-
return {
|
|
557
|
-
status: 1,
|
|
558
|
-
reason: `${error}`
|
|
559
|
-
};
|
|
560
|
-
}
|
|
429
|
+
const args = [
|
|
430
|
+
'--scheme',
|
|
431
|
+
'chonk',
|
|
432
|
+
'-p',
|
|
433
|
+
proofPath,
|
|
434
|
+
'-k',
|
|
435
|
+
keyPath,
|
|
436
|
+
'-v'
|
|
437
|
+
];
|
|
438
|
+
return await verifyProofInternal(pathToBB, 'verify', args, logger, concurrency);
|
|
561
439
|
}
|
|
562
440
|
/**
|
|
563
441
|
* Used for verifying proofs with BB
|
|
564
442
|
* @param pathToBB - The full path to the bb binary
|
|
565
|
-
* @param proofFullPath - The full path to the proof to be verified
|
|
566
|
-
* @param verificationKeyPath - The full path to the circuit verification key
|
|
567
443
|
* @param command - The BB command to execute (verify/avm_verify)
|
|
568
|
-
* @param
|
|
444
|
+
* @param args - The arguments to pass to the command
|
|
445
|
+
* @param logger - A logger
|
|
446
|
+
* @param concurrency - The number of threads to use for the verification
|
|
569
447
|
* @returns An object containing a result indication and duration taken
|
|
570
|
-
*/ async function verifyProofInternal(pathToBB,
|
|
448
|
+
*/ async function verifyProofInternal(pathToBB, command, args, logger, concurrency) {
|
|
571
449
|
const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
|
|
572
450
|
if (!binaryPresent) {
|
|
573
451
|
return {
|
|
@@ -579,19 +457,13 @@ export async function verifyAvmProofV2(pathToBB, workingDirectory, proofFullPath
|
|
|
579
457
|
logger.verbose(`bb-prover (verify) BB out - ${message}`);
|
|
580
458
|
};
|
|
581
459
|
try {
|
|
582
|
-
const args = [
|
|
583
|
-
'-p',
|
|
584
|
-
proofFullPath,
|
|
585
|
-
'-k',
|
|
586
|
-
verificationKeyPath,
|
|
587
|
-
...extraArgs
|
|
588
|
-
];
|
|
589
460
|
const loggingArg = logger.level === 'debug' || logger.level === 'trace' ? '-d' : logger.level === 'verbose' ? '-v' : '';
|
|
590
|
-
|
|
591
|
-
args
|
|
592
|
-
|
|
461
|
+
const finalArgs = loggingArg !== '' ? [
|
|
462
|
+
...args,
|
|
463
|
+
loggingArg
|
|
464
|
+
] : args;
|
|
593
465
|
const timer = new Timer();
|
|
594
|
-
const result = await executeBB(pathToBB, command,
|
|
466
|
+
const result = await executeBB(pathToBB, command, finalArgs, logFunction, concurrency);
|
|
595
467
|
const duration = timer.ms();
|
|
596
468
|
if (result.status == 0) {
|
|
597
469
|
return {
|
|
@@ -685,13 +557,13 @@ export async function generateContractForVerificationKey(pathToBB, vkFilePath, c
|
|
|
685
557
|
// Check that the working directory exists
|
|
686
558
|
try {
|
|
687
559
|
await fs.access(workingDirectory);
|
|
688
|
-
} catch
|
|
560
|
+
} catch {
|
|
689
561
|
return {
|
|
690
562
|
status: 1,
|
|
691
563
|
reason: `Working directory ${workingDirectory} does not exist`
|
|
692
564
|
};
|
|
693
565
|
}
|
|
694
|
-
// The bytecode is written to e.g. /workingDirectory/
|
|
566
|
+
// The bytecode is written to e.g. /workingDirectory/ParityBaseArtifact-bytecode
|
|
695
567
|
const bytecodePath = `${workingDirectory}/${circuitName}-bytecode`;
|
|
696
568
|
const binaryPresent = await fs.access(pathToBB, fs.constants.R_OK).then((_)=>true).catch((_)=>false);
|
|
697
569
|
if (!binaryPresent) {
|
|
@@ -712,7 +584,7 @@ export async function generateContractForVerificationKey(pathToBB, vkFilePath, c
|
|
|
712
584
|
const timer = new Timer();
|
|
713
585
|
const result = await executeBB(pathToBB, 'gates', [
|
|
714
586
|
'--scheme',
|
|
715
|
-
flavor === 'mega_honk' ? '
|
|
587
|
+
flavor === 'mega_honk' ? 'chonk' : 'ultra_honk',
|
|
716
588
|
'-b',
|
|
717
589
|
bytecodePath,
|
|
718
590
|
'-v'
|
|
@@ -772,7 +644,7 @@ async function fsCache(dir, expectedCacheKey, logger, force, action) {
|
|
|
772
644
|
}
|
|
773
645
|
try {
|
|
774
646
|
await fs.writeFile(cacheFilePath, expectedCacheKey);
|
|
775
|
-
} catch
|
|
647
|
+
} catch {
|
|
776
648
|
logger(`Couldn't write cache data to ${cacheFilePath}. Skipping cache...`);
|
|
777
649
|
// ignore
|
|
778
650
|
}
|
package/dest/bb/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --no-warnings
|
|
2
2
|
import 'source-map-support/register.js';
|
|
3
|
-
//# sourceMappingURL=
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBR0EsT0FBTyxnQ0FBZ0MsQ0FBQyJ9
|
package/dest/config.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export interface BBConfig {
|
|
|
3
3
|
bbWorkingDirectory: string;
|
|
4
4
|
/** Whether to skip tmp dir cleanup for debugging purposes */
|
|
5
5
|
bbSkipCleanup: boolean;
|
|
6
|
+
numConcurrentIVCVerifiers: number;
|
|
7
|
+
bbIVCConcurrency: number;
|
|
6
8
|
}
|
|
7
9
|
export interface ACVMConfig {
|
|
8
10
|
/** The path to the ACVM binary */
|
|
@@ -10,4 +12,4 @@ export interface ACVMConfig {
|
|
|
10
12
|
/** The working directory to use for simulation/proving */
|
|
11
13
|
acvmWorkingDirectory: string;
|
|
12
14
|
}
|
|
13
|
-
//# sourceMappingURL=
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE1BQU0sV0FBVyxRQUFRO0lBQ3ZCLFlBQVksRUFBRSxNQUFNLENBQUM7SUFDckIsa0JBQWtCLEVBQUUsTUFBTSxDQUFDO0lBQzNCLDZEQUE2RDtJQUM3RCxhQUFhLEVBQUUsT0FBTyxDQUFDO0lBQ3ZCLHlCQUF5QixFQUFFLE1BQU0sQ0FBQztJQUNsQyxnQkFBZ0IsRUFBRSxNQUFNLENBQUM7Q0FDMUI7QUFFRCxNQUFNLFdBQVcsVUFBVTtJQUN6QixrQ0FBa0M7SUFDbEMsY0FBYyxFQUFFLE1BQU0sQ0FBQztJQUN2QiwwREFBMEQ7SUFDMUQsb0JBQW9CLEVBQUUsTUFBTSxDQUFDO0NBQzlCIn0=
|