@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
|
@@ -1,51 +1,34 @@
|
|
|
1
1
|
import { Tx } from '@aztec/circuit-types';
|
|
2
2
|
import { runInDirectory } from '@aztec/foundation/fs';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import {
|
|
4
|
+
import { ServerCircuitVks } from '@aztec/noir-protocol-circuits-types/vks';
|
|
5
5
|
import { promises as fs } from 'fs';
|
|
6
6
|
import * as path from 'path';
|
|
7
|
-
import { BB_RESULT, PROOF_FILENAME, VK_FILENAME,
|
|
7
|
+
import { BB_RESULT, PROOF_FILENAME, VK_FILENAME, verifyClientIvcProof, verifyProof } from '../bb/execute.js';
|
|
8
8
|
import { getUltraHonkFlavorForCircuit } from '../honk.js';
|
|
9
9
|
import { writeToOutputDirectory } from '../prover/client_ivc_proof_utils.js';
|
|
10
|
-
import {
|
|
11
|
-
import { extractVkData } from '../verification_key/verification_key_data.js';
|
|
10
|
+
import { mapProtocolArtifactNameToCircuitName } from '../stats.js';
|
|
12
11
|
export class BBCircuitVerifier {
|
|
13
|
-
constructor(config,
|
|
12
|
+
constructor(config, logger) {
|
|
14
13
|
this.config = config;
|
|
15
|
-
this.verificationKeys = verificationKeys;
|
|
16
14
|
this.logger = logger;
|
|
17
15
|
}
|
|
18
|
-
static async new(config,
|
|
16
|
+
static async new(config, logger = createLogger('bb-prover:verifier')) {
|
|
19
17
|
await fs.mkdir(config.bbWorkingDirectory, { recursive: true });
|
|
20
|
-
|
|
21
|
-
for (const circuit of initialCircuits) {
|
|
22
|
-
const vkData = await this.generateVerificationKey(circuit, config.bbBinaryPath, config.bbWorkingDirectory, logger.debug);
|
|
23
|
-
keys.set(circuit, Promise.resolve(vkData));
|
|
24
|
-
}
|
|
25
|
-
return new BBCircuitVerifier(config, keys, logger);
|
|
26
|
-
}
|
|
27
|
-
static async generateVerificationKey(circuit, bbPath, workingDirectory, logFn) {
|
|
28
|
-
return await generateKeyForNoirCircuit(bbPath, workingDirectory, circuit, ServerCircuitArtifacts[circuit], isProtocolArtifactRecursive(circuit), getUltraHonkFlavorForCircuit(circuit), logFn).then(result => {
|
|
29
|
-
if (result.status === BB_RESULT.FAILURE) {
|
|
30
|
-
throw new Error(`Failed to created verification key for ${circuit}, ${result.reason}`);
|
|
31
|
-
}
|
|
32
|
-
return extractVkData(result.vkPath);
|
|
33
|
-
});
|
|
18
|
+
return new BBCircuitVerifier(config, logger);
|
|
34
19
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
20
|
+
getVerificationKeyData(circuitType) {
|
|
21
|
+
const vk = ServerCircuitVks[circuitType];
|
|
22
|
+
if (vk === undefined) {
|
|
23
|
+
throw new Error('Could not find VK for server artifact ' + circuitType);
|
|
39
24
|
}
|
|
40
|
-
|
|
41
|
-
const vk = await promise;
|
|
42
|
-
return vk.clone();
|
|
25
|
+
return vk;
|
|
43
26
|
}
|
|
44
27
|
async verifyProofForCircuit(circuit, proof) {
|
|
45
28
|
const operation = async (bbWorkingDirectory) => {
|
|
46
29
|
const proofFileName = path.join(bbWorkingDirectory, PROOF_FILENAME);
|
|
47
30
|
const verificationKeyPath = path.join(bbWorkingDirectory, VK_FILENAME);
|
|
48
|
-
const verificationKey =
|
|
31
|
+
const verificationKey = this.getVerificationKeyData(circuit);
|
|
49
32
|
this.logger.debug(`${circuit} Verifying with key: ${verificationKey.keyAsFields.hash.toString()}`);
|
|
50
33
|
await fs.writeFile(proofFileName, proof.buffer);
|
|
51
34
|
await fs.writeFile(verificationKeyPath, verificationKey.keyAsBytes);
|
|
@@ -63,13 +46,6 @@ export class BBCircuitVerifier {
|
|
|
63
46
|
};
|
|
64
47
|
await runInDirectory(this.config.bbWorkingDirectory, operation, this.config.bbSkipCleanup);
|
|
65
48
|
}
|
|
66
|
-
async generateSolidityContract(circuit, contractName) {
|
|
67
|
-
const result = await generateContractForCircuit(this.config.bbBinaryPath, this.config.bbWorkingDirectory, circuit, ServerCircuitArtifacts[circuit], contractName, this.logger.debug);
|
|
68
|
-
if (result.status === BB_RESULT.FAILURE) {
|
|
69
|
-
throw new Error(`Failed to create verifier contract for ${circuit}, ${result.reason}`);
|
|
70
|
-
}
|
|
71
|
-
return fs.readFile(result.contractPath, 'utf-8');
|
|
72
|
-
}
|
|
73
49
|
async verifyProof(tx) {
|
|
74
50
|
try {
|
|
75
51
|
// TODO(#7370) The verification keys should be supplied separately and based on the expectedCircuit
|
|
@@ -107,4 +83,4 @@ export class BBCircuitVerifier {
|
|
|
107
83
|
}
|
|
108
84
|
}
|
|
109
85
|
}
|
|
110
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
86
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmJfdmVyaWZpZXIuanMiLCJzb3VyY2VSb290IjoiIiw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DakMsU0FBUyxFQUFFLFlBQVk7aUJBQ1csQ0FBQyxDQUFDO1lBQ3hDLENBQUMsQ0FBQztZQUNGLE1BQU0sY0FBYyxDQUFDLElBQUksQ0FBQyxNQUFNLENBQUMsa0JBQWtCLEVBQUUsU0FBUyxFQUFFLElBQUksQ0FBQyxNQUFNLENBQUMsYUFBYSxDQUFDLENBQUM7WUFDM0YsT0FBTyxJQUFJLENBQUM7UUFDZCxDQUFDO1FBQUMsT0FBTyxHQUFHLEVBQUUsQ0FBQztZQUNiLElBQUksQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLDJDQUEyQyxFQUFFLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQyxLQUFLLE1BQU0sQ0FBQyxHQUFHLENBQUMsRUFBRSxDQUFDLENBQUM7WUFDOUYsT0FBTyxLQUFLLENBQUM7UUFDZixDQUFDO0lBQ0gsQ0FBQztDQUNGIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/bb-prover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.72.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -67,14 +67,14 @@
|
|
|
67
67
|
]
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@aztec/bb.js": "0.
|
|
71
|
-
"@aztec/circuit-types": "0.
|
|
72
|
-
"@aztec/circuits.js": "0.
|
|
73
|
-
"@aztec/foundation": "0.
|
|
74
|
-
"@aztec/noir-protocol-circuits-types": "0.
|
|
75
|
-
"@aztec/simulator": "0.
|
|
76
|
-
"@aztec/telemetry-client": "0.
|
|
77
|
-
"@aztec/world-state": "0.
|
|
70
|
+
"@aztec/bb.js": "0.72.1",
|
|
71
|
+
"@aztec/circuit-types": "0.72.1",
|
|
72
|
+
"@aztec/circuits.js": "0.72.1",
|
|
73
|
+
"@aztec/foundation": "0.72.1",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.72.1",
|
|
75
|
+
"@aztec/simulator": "0.72.1",
|
|
76
|
+
"@aztec/telemetry-client": "0.72.1",
|
|
77
|
+
"@aztec/world-state": "0.72.1",
|
|
78
78
|
"@msgpack/msgpack": "^3.0.0-beta2",
|
|
79
79
|
"@noir-lang/noirc_abi": "portal:../../noir/packages/noirc_abi",
|
|
80
80
|
"@noir-lang/types": "portal:../../noir/packages/types",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"jest-mock-extended": "^3.0.3",
|
|
97
97
|
"ts-node": "^10.9.1",
|
|
98
98
|
"typescript": "^5.0.4",
|
|
99
|
-
"viem": "
|
|
99
|
+
"viem": "2.22.8"
|
|
100
100
|
},
|
|
101
101
|
"files": [
|
|
102
102
|
"dest",
|
package/src/bb/cli.ts
CHANGED
|
@@ -5,11 +5,6 @@ import { type ProtocolArtifact } from '@aztec/noir-protocol-circuits-types/types
|
|
|
5
5
|
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
6
6
|
|
|
7
7
|
import { Command } from 'commander';
|
|
8
|
-
import { promises as fs } from 'fs';
|
|
9
|
-
|
|
10
|
-
import { generateContractForCircuit, generateKeyForNoirCircuit } from './execute.js';
|
|
11
|
-
|
|
12
|
-
const { BB_WORKING_DIRECTORY, BB_BINARY_PATH } = process.env;
|
|
13
8
|
|
|
14
9
|
export const ProtocolCircuitArtifacts: Record<ProtocolArtifact, NoirCompiledCircuit> = {
|
|
15
10
|
...ClientCircuitArtifacts,
|
|
@@ -33,76 +28,5 @@ export function getProgram(log: LogFn): Command {
|
|
|
33
28
|
log(Object.keys(ProtocolCircuitArtifacts).reduce((prev: string, x: string) => prev.concat(`\n${x}`)));
|
|
34
29
|
});
|
|
35
30
|
|
|
36
|
-
program
|
|
37
|
-
.command('write-vk')
|
|
38
|
-
.description('Generates the verification key for the specified circuit')
|
|
39
|
-
.requiredOption(
|
|
40
|
-
'-w, --working-directory <string>',
|
|
41
|
-
'A directory to use for storing input/output files',
|
|
42
|
-
BB_WORKING_DIRECTORY,
|
|
43
|
-
)
|
|
44
|
-
.requiredOption('-b, --bb-path <string>', 'The path to the BB binary', BB_BINARY_PATH)
|
|
45
|
-
.requiredOption('-c, --circuit <string>', 'The name of a protocol circuit')
|
|
46
|
-
.requiredOption('-f, --flavor <string>', 'The name of the verification key flavor', 'ultra_honk')
|
|
47
|
-
.option('-r, --recursive', 'Whether a SNARK friendly key should be generated', false)
|
|
48
|
-
.action(async options => {
|
|
49
|
-
const compiledCircuit = ProtocolCircuitArtifacts[options.circuit as ProtocolArtifact];
|
|
50
|
-
if (!compiledCircuit) {
|
|
51
|
-
log(`Failed to find circuit ${options.circuit}`);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
try {
|
|
55
|
-
await fs.access(options.workingDirectory, fs.constants.W_OK);
|
|
56
|
-
} catch (error) {
|
|
57
|
-
log(`Working directory does not exist`);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
await generateKeyForNoirCircuit(
|
|
61
|
-
options.bbPath,
|
|
62
|
-
options.workingDirectory,
|
|
63
|
-
options.circuit,
|
|
64
|
-
compiledCircuit,
|
|
65
|
-
options.recursive,
|
|
66
|
-
options.flavor,
|
|
67
|
-
// (options.circuit as ServerProtocolArtifact) === 'RootRollupArtifact' ? 'ultra_keccak_honk' : 'ultra_honk',
|
|
68
|
-
log,
|
|
69
|
-
);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
program
|
|
73
|
-
.command('write-contract')
|
|
74
|
-
.description('Generates the verification contract for the specified circuit')
|
|
75
|
-
.requiredOption(
|
|
76
|
-
'-w, --working-directory <string>',
|
|
77
|
-
'A directory to use for storing input/output files',
|
|
78
|
-
BB_WORKING_DIRECTORY,
|
|
79
|
-
)
|
|
80
|
-
.requiredOption('-b, --bb-path <string>', 'The path to the BB binary', BB_BINARY_PATH)
|
|
81
|
-
.requiredOption('-c, --circuit <string>', 'The name of a protocol circuit')
|
|
82
|
-
.requiredOption('-n --contract-name <string>', 'The name of the contract to generate', 'contract.sol')
|
|
83
|
-
.action(async options => {
|
|
84
|
-
const compiledCircuit = ProtocolCircuitArtifacts[options.circuit as ProtocolArtifact];
|
|
85
|
-
if (!compiledCircuit) {
|
|
86
|
-
log(`Failed to find circuit ${options.circuit}`);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
await fs.access(options.workingDirectory, fs.constants.W_OK);
|
|
91
|
-
} catch (error) {
|
|
92
|
-
log(`Working directory does not exist`);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
await generateContractForCircuit(
|
|
97
|
-
options.bbPath,
|
|
98
|
-
options.workingDirectory,
|
|
99
|
-
options.circuit,
|
|
100
|
-
compiledCircuit,
|
|
101
|
-
options.contractName,
|
|
102
|
-
log,
|
|
103
|
-
/*force= */ true,
|
|
104
|
-
);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
31
|
return program;
|
|
108
32
|
}
|
package/src/bb/execute.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { type AvmCircuitInputs, serializeWithMessagePack } from '@aztec/circuits
|
|
|
2
2
|
import { sha256 } from '@aztec/foundation/crypto';
|
|
3
3
|
import { type LogFn, type Logger } from '@aztec/foundation/log';
|
|
4
4
|
import { Timer } from '@aztec/foundation/timer';
|
|
5
|
-
import { type NoirCompiledCircuit } from '@aztec/types/noir';
|
|
6
5
|
|
|
7
6
|
import * as proc from 'child_process';
|
|
8
7
|
import { promises as fs } from 'fs';
|
|
@@ -97,103 +96,6 @@ export function executeBB(
|
|
|
97
96
|
}).catch(_ => ({ status: BB_RESULT.FAILURE, exitCode: -1, signal: undefined }));
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
const bytecodeFilename = 'bytecode';
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Used for generating either a proving or verification key, will exit early if the key already exists
|
|
104
|
-
* It assumes the provided working directory is one where the caller wishes to maintain a permanent set of keys
|
|
105
|
-
* It is not considered a temporary directory
|
|
106
|
-
* @param pathToBB - The full path to the bb binary
|
|
107
|
-
* @param workingDirectory - The directory into which the key should be created
|
|
108
|
-
* @param circuitName - An identifier for the circuit
|
|
109
|
-
* @param compiledCircuit - The compiled circuit
|
|
110
|
-
* @param key - The type of key, either 'pk' or 'vk'
|
|
111
|
-
* @param log - A logging function
|
|
112
|
-
* @param force - Force the key to be regenerated even if it already exists
|
|
113
|
-
* @returns An instance of BBResult
|
|
114
|
-
*/
|
|
115
|
-
export async function generateKeyForNoirCircuit(
|
|
116
|
-
pathToBB: string,
|
|
117
|
-
workingDirectory: string,
|
|
118
|
-
circuitName: string,
|
|
119
|
-
compiledCircuit: NoirCompiledCircuit,
|
|
120
|
-
recursive: boolean,
|
|
121
|
-
flavor: UltraHonkFlavor,
|
|
122
|
-
log: LogFn,
|
|
123
|
-
force = false,
|
|
124
|
-
): Promise<BBSuccess | BBFailure> {
|
|
125
|
-
const bytecode = Buffer.from(compiledCircuit.bytecode, 'base64');
|
|
126
|
-
|
|
127
|
-
// The key generation is written to e.g. /workingDirectory/pk/BaseParityArtifact/pk
|
|
128
|
-
// The bytecode hash file is also written here as /workingDirectory/pk/BaseParityArtifact/bytecode-hash
|
|
129
|
-
// The bytecode is written to e.g. /workingDirectory/pk/BaseParityArtifact/bytecode
|
|
130
|
-
// The bytecode is removed after the key is generated, leaving just the hash file
|
|
131
|
-
const circuitOutputDirectory = `${workingDirectory}/vk/${circuitName}`;
|
|
132
|
-
const outputPath = `${circuitOutputDirectory}`;
|
|
133
|
-
const bytecodeHash = sha256(bytecode);
|
|
134
|
-
|
|
135
|
-
// ensure the directory exists
|
|
136
|
-
await fs.mkdir(circuitOutputDirectory, { recursive: true });
|
|
137
|
-
|
|
138
|
-
const res = await fsCache<BBSuccess | BBFailure>(circuitOutputDirectory, bytecodeHash, log, force, async () => {
|
|
139
|
-
const binaryPresent = await fs
|
|
140
|
-
.access(pathToBB, fs.constants.R_OK)
|
|
141
|
-
.then(_ => true)
|
|
142
|
-
.catch(_ => false);
|
|
143
|
-
if (!binaryPresent) {
|
|
144
|
-
return { status: BB_RESULT.FAILURE, reason: `Failed to find bb binary at ${pathToBB}` };
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// We are now going to generate the key
|
|
148
|
-
try {
|
|
149
|
-
const bytecodePath = `${circuitOutputDirectory}/${bytecodeFilename}`;
|
|
150
|
-
// Write the bytecode to the working directory
|
|
151
|
-
await fs.writeFile(bytecodePath, bytecode);
|
|
152
|
-
|
|
153
|
-
// args are the output path and the input bytecode path
|
|
154
|
-
const args = ['-o', `${outputPath}/${VK_FILENAME}`, '-b', bytecodePath, recursive ? '--recursive' : ''];
|
|
155
|
-
const timer = new Timer();
|
|
156
|
-
let result = await executeBB(pathToBB, `write_vk_${flavor}`, args, log);
|
|
157
|
-
|
|
158
|
-
// If we succeeded and the type of key if verification, have bb write the 'fields' version too
|
|
159
|
-
if (result.status == BB_RESULT.SUCCESS) {
|
|
160
|
-
const asFieldsArgs = ['-k', `${outputPath}/${VK_FILENAME}`, '-o', `${outputPath}/${VK_FIELDS_FILENAME}`, '-v'];
|
|
161
|
-
result = await executeBB(pathToBB, `vk_as_fields_${flavor}`, asFieldsArgs, log);
|
|
162
|
-
}
|
|
163
|
-
const duration = timer.ms();
|
|
164
|
-
|
|
165
|
-
if (result.status == BB_RESULT.SUCCESS) {
|
|
166
|
-
return {
|
|
167
|
-
status: BB_RESULT.SUCCESS,
|
|
168
|
-
durationMs: duration,
|
|
169
|
-
pkPath: undefined,
|
|
170
|
-
vkPath: outputPath,
|
|
171
|
-
proofPath: undefined,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
// Not a great error message here but it is difficult to decipher what comes from bb
|
|
175
|
-
return {
|
|
176
|
-
status: BB_RESULT.FAILURE,
|
|
177
|
-
reason: `Failed to generate key. Exit code: ${result.exitCode}. Signal ${result.signal}.`,
|
|
178
|
-
retry: !!result.signal,
|
|
179
|
-
};
|
|
180
|
-
} catch (error) {
|
|
181
|
-
return { status: BB_RESULT.FAILURE, reason: `${error}` };
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
if (!res) {
|
|
186
|
-
return {
|
|
187
|
-
status: BB_RESULT.ALREADY_PRESENT,
|
|
188
|
-
durationMs: 0,
|
|
189
|
-
pkPath: undefined,
|
|
190
|
-
vkPath: outputPath,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return res;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
99
|
// TODO(#7369) comment this etc (really just take inspiration from this and rewrite it all O:))
|
|
198
100
|
export async function executeBbClientIvcProof(
|
|
199
101
|
pathToBB: string,
|
|
@@ -960,43 +862,6 @@ export async function generateContractForVerificationKey(
|
|
|
960
862
|
return res;
|
|
961
863
|
}
|
|
962
864
|
|
|
963
|
-
export async function generateContractForCircuit(
|
|
964
|
-
pathToBB: string,
|
|
965
|
-
workingDirectory: string,
|
|
966
|
-
circuitName: string,
|
|
967
|
-
compiledCircuit: NoirCompiledCircuit,
|
|
968
|
-
contractName: string,
|
|
969
|
-
log: LogFn,
|
|
970
|
-
force = false,
|
|
971
|
-
) {
|
|
972
|
-
// Verifier contracts are never recursion friendly, because non-recursive proofs are generated using the keccak256 hash function.
|
|
973
|
-
// We need to use the same hash function during verification so proofs generated using keccak256 are cheap to verify on ethereum
|
|
974
|
-
// (where the verifier contract would be deployed) whereas if we want to verify the proof within a snark (for recursion) we want
|
|
975
|
-
// to use a snark-friendly hash function.
|
|
976
|
-
const recursive = false;
|
|
977
|
-
|
|
978
|
-
const vkResult = await generateKeyForNoirCircuit(
|
|
979
|
-
pathToBB,
|
|
980
|
-
workingDirectory,
|
|
981
|
-
circuitName,
|
|
982
|
-
compiledCircuit,
|
|
983
|
-
recursive,
|
|
984
|
-
'ultra_keccak_honk',
|
|
985
|
-
log,
|
|
986
|
-
force,
|
|
987
|
-
);
|
|
988
|
-
if (vkResult.status === BB_RESULT.FAILURE) {
|
|
989
|
-
return vkResult;
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
return generateContractForVerificationKey(
|
|
993
|
-
pathToBB,
|
|
994
|
-
join(vkResult.vkPath!, VK_FILENAME),
|
|
995
|
-
join(workingDirectory, 'contract', circuitName, contractName),
|
|
996
|
-
log,
|
|
997
|
-
);
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
865
|
/**
|
|
1001
866
|
* Compute bb gate count for a given circuit
|
|
1002
867
|
* @param pathToBB - The full path to the bb binary
|