From 9b9eacadb34f2a7c190769ed24f3e302f1f23ed8 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Thu, 17 Aug 2023 17:23:56 +0000 Subject: [PATCH 1/6] fix leaky preprocessed_program abstraction --- circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh | 6 +++--- .../barretenberg/cpp/src/barretenberg/bb/get_bytecode.hpp | 4 +--- circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh b/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh index f80da051b99..e8b33da494c 100755 --- a/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh +++ b/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh @@ -40,7 +40,7 @@ function test() { return fi - if [[ ! -f ./$1/target/$dir_name.json || ! -f ./$1/target/witness.tr ]]; then + if [[ ! -f ./$1/target/$dir_name.bytecode || ! -f ./$1/target/witness.tr ]]; then echo -e "\033[33mSKIPPED\033[0m (uncompiled)" return fi @@ -49,9 +49,9 @@ function test() { set +e if [ -n "$VERBOSE" ]; then - $BB prove_and_verify -v -c $CRS_PATH -j ./target/$dir_name.json + $BB prove_and_verify -v -c $CRS_PATH -j ./target/$dir_name.bytecode else - $BB prove_and_verify -c $CRS_PATH -j ./target/$dir_name.json > /dev/null 2>&1 + $BB prove_and_verify -c $CRS_PATH -j ./target/$dir_name.bytecode > /dev/null 2>&1 fi result=$? set -e diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_bytecode.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_bytecode.hpp index 4c27c7bcb47..9a898b3146b 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_bytecode.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_bytecode.hpp @@ -3,11 +3,9 @@ /** * We can assume for now we're running on a unix like system and use the following to extract the bytecode. - * Maybe we should consider bytecode being output into its own independent file alongside the JSON? */ inline std::vector get_bytecode(const std::string& jsonPath) { - std::string command = - "awk -F'\"bytecode\":' '{print $2}' " + jsonPath + " | awk -F'\"' '{print $2}' | base64 -d | gunzip"; + std::string command = "base64 -d " + jsonPath + " | gunzip"; return exec_pipe(command); } \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp index b6661560e8e..30fb42f7a95 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -148,7 +148,7 @@ int main(int argc, char* argv[]) std::string command = args[0]; - std::string json_path = getOption(args, "-j", "./target/main.json"); + std::string json_path = getOption(args, "-j", "./target/main.bytecode"); std::string witness_path = getOption(args, "-w", "./target/witness.tr"); std::string proof_path = getOption(args, "-p", "./proofs/proof"); std::string vk_path = getOption(args, "-k", "./target/vk"); From adcc0b282bfdf18fde7df3b221d580103f30f99c Mon Sep 17 00:00:00 2001 From: kevaundray Date: Thu, 17 Aug 2023 21:30:45 +0000 Subject: [PATCH 2/6] modify main.ts to use bytecode --- circuits/cpp/barretenberg/ts/src/main.ts | 27 ++++++------------------ 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/circuits/cpp/barretenberg/ts/src/main.ts b/circuits/cpp/barretenberg/ts/src/main.ts index a62afc048a2..7ba2bbd6b46 100755 --- a/circuits/cpp/barretenberg/ts/src/main.ts +++ b/circuits/cpp/barretenberg/ts/src/main.ts @@ -11,28 +11,15 @@ const debug = createDebug('bb.js'); // Maximum we support. const MAX_CIRCUIT_SIZE = 2 ** 19; -function getJsonData(jsonPath: string) { - const json = readFileSync(jsonPath, 'utf-8'); - const parsed = JSON.parse(json); - return parsed; -} - function getBytecode(jsonPath: string) { - const parsed = getJsonData(jsonPath); - const buffer = Buffer.from(parsed.bytecode, 'base64'); + const encodedCircuit = readFileSync(jsonPath, 'utf-8'); + const buffer = Buffer.from(encodedCircuit, 'base64'); const decompressed = gunzipSync(buffer); return decompressed; } -async function getGates(jsonPath: string, api: BarretenbergApiAsync) { - const parsed = getJsonData(jsonPath); - if (parsed.gates) { - return +parsed.gates; - } +async function getGates(jsonPath: string, api: BarretenbergApiAsync) { const { total } = await computeCircuitSize(jsonPath, api); - const jsonData = getJsonData(jsonPath); - jsonData.gates = total; - writeFileSync(jsonPath, JSON.stringify(jsonData)); return total; } @@ -231,7 +218,7 @@ function handleGlobalOptions() { program .command('prove_and_verify') .description('Generate a proof and verify it. Process exits with success or failure code.') - .option('-j, --json-path ', 'Specify the JSON path', './target/main.json') + .option('-j, --json-path ', 'Specify the JSON path', './target/main.bytecode') .option('-w, --witness-path ', 'Specify the witness path', './target/witness.tr') .option('-r, --recursive', 'prove and verify using recursive prover and verifier', false) .action(async ({ jsonPath, witnessPath, recursive, crsPath }) => { @@ -243,7 +230,7 @@ program program .command('prove') .description('Generate a proof and write it to a file.') - .option('-j, --json-path ', 'Specify the JSON path', './target/main.json') + .option('-j, --json-path ', 'Specify the JSON path', './target/main.bytecode') .option('-w, --witness-path ', 'Specify the witness path', './target/witness.tr') .option('-r, --recursive', 'prove using recursive prover', false) .option('-o, --output-path ', 'Specify the proof output path', './proofs/proof') @@ -255,7 +242,7 @@ program program .command('gates') .description('Print gate count to standard output.') - .option('-j, --json-path ', 'Specify the JSON path', './target/main.json') + .option('-j, --json-path ', 'Specify the JSON path', './target/main.bytecode') .action(async ({ jsonPath }) => { handleGlobalOptions(); await gateCount(jsonPath); @@ -276,7 +263,7 @@ program program .command('contract') .description('Output solidity verification key contract.') - .option('-j, --json-path ', 'Specify the JSON path', './target/main.json') + .option('-j, --json-path ', 'Specify the JSON path', './target/main.bytecode') .option('-o, --output-path ', 'Specify the path to write the contract', '-') .requiredOption('-k, --vk ', 'path to a verification key. avoids recomputation.') .action(async ({ outputPath, vk }) => { From 43dfacb4d13d755f2f92b127af31ae3449828120 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Thu, 17 Aug 2023 21:35:46 +0000 Subject: [PATCH 3/6] formatting --- circuits/cpp/barretenberg/ts/src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuits/cpp/barretenberg/ts/src/main.ts b/circuits/cpp/barretenberg/ts/src/main.ts index 7ba2bbd6b46..a4eb0d89d19 100755 --- a/circuits/cpp/barretenberg/ts/src/main.ts +++ b/circuits/cpp/barretenberg/ts/src/main.ts @@ -18,7 +18,7 @@ function getBytecode(jsonPath: string) { return decompressed; } -async function getGates(jsonPath: string, api: BarretenbergApiAsync) { +async function getGates(jsonPath: string, api: BarretenbergApiAsync) { const { total } = await computeCircuitSize(jsonPath, api); return total; } From ae54d144fb3e0bedc7d0d9135549f8efac550bae Mon Sep 17 00:00:00 2001 From: kevaundray Date: Fri, 18 Aug 2023 20:43:08 +0000 Subject: [PATCH 4/6] add main.bytecode --- circuits/cpp/barretenberg/ts/bin-test/target/main.bytecode | 1 + circuits/cpp/barretenberg/ts/bin-test/target/main.json | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 circuits/cpp/barretenberg/ts/bin-test/target/main.bytecode delete mode 100644 circuits/cpp/barretenberg/ts/bin-test/target/main.json diff --git a/circuits/cpp/barretenberg/ts/bin-test/target/main.bytecode b/circuits/cpp/barretenberg/ts/bin-test/target/main.bytecode new file mode 100644 index 00000000000..fee406537ed --- /dev/null +++ b/circuits/cpp/barretenberg/ts/bin-test/target/main.bytecode @@ -0,0 +1 @@ +H4sIAAAAAAAA/+3YY4xkaRhA4e6xp8e2bavHtj2ztjG2bdu2bWttjm3P9uyp9OnNZP/uJrOb9E2enNxblU5V3qrvVn8dg4OCYgaFH9HtB5aHgqIgKqL5eIyg8OfHQmzEQVzEQ3wkQEKEIBESIwmSIhmSIwVSIhVSIw3SIh3SIwMyIhMyIwuyIhuyIwdyIhdyIw/yIh/yowAKohAKowiKohiKowRKohRKowz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2rx8gFXlGJVRGFVRFNVRHDdRELdRGHdRFPdRHg8gbX+SNz4bayBtfeP9rN77Tnp+xZ+05e95esBftJXvZXrFX7TV73d6wN+0te9vesXftPXvfPrAP7SP72D6xEf+ARHhqAwtQoME2io1qo9noNoaNaWPZ2DaOjWvj2fg2gU1oQ2wim9gmsUltMpvcprApbSqb2qaxaW06m95msBltJpvZZrFZbTab3eawOW0um9vmsXltPpvfFrAFbSFb2BaxRW0xW9yWsCVtKVvalrFlbTlb3lawoRHzDwo//n7jC372xhe4UMlWtlVsVVvNVrc1bE1by9a2dWxdW8/Wtw0iPii+joacN0JjNEFTNENztEBLtEJrtEFbtEN7dAgOf8N+7iN374L+/7t3kbt1z2e3LrBQBBaJf7ojF7kD93x24CKOf2td/ROKWJ6DKhkAAA== \ No newline at end of file diff --git a/circuits/cpp/barretenberg/ts/bin-test/target/main.json b/circuits/cpp/barretenberg/ts/bin-test/target/main.json deleted file mode 100644 index 776e0007598..00000000000 --- a/circuits/cpp/barretenberg/ts/bin-test/target/main.json +++ /dev/null @@ -1 +0,0 @@ -{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"verification_key","type":{"kind":"array","length":114,"type":{"kind":"field"}},"visibility":"private"},{"name":"proof","type":{"kind":"array","length":94,"type":{"kind":"field"}},"visibility":"private"},{"name":"public_inputs","type":{"kind":"array","length":1,"type":{"kind":"field"}},"visibility":"private"},{"name":"key_hash","type":{"kind":"field"},"visibility":"private"},{"name":"input_aggregation_object","type":{"kind":"array","length":16,"type":{"kind":"field"}},"visibility":"private"},{"name":"proof_b","type":{"kind":"array","length":94,"type":{"kind":"field"}},"visibility":"private"}],"param_witnesses":{"input_aggregation_object":[211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226],"key_hash":[210],"proof":[115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208],"proof_b":[227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320],"public_inputs":[209],"verification_key":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114]},"return_type":{"kind":"array","length":16,"type":{"kind":"field"}},"return_witnesses":[337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352]},"bytecode":"H4sIAAAAAAAA/+3YY4xkaRhA4e6xp8e2bavHtj2ztjG2bdu2bWttjm3P9uyp9OnNZP/uJrOb9E2enNxblU5V3qrvVn8dg4OCYgaFH9HtB5aHgqIgKqL5eIyg8OfHQmzEQVzEQ3wkQEKEIBESIwmSIhmSIwVSIhVSIw3SIh3SIwMyIhMyIwuyIhuyIwdyIhdyIw/yIh/yowAKohAKowiKohiKowRKohRKowzKohzKowJCURGVUBlVUBXVUB01UBO1UBt1UBf1UB8N0BCN0BhN0BTN0Bwt0BKt0Bpt0Bbt0B4d0BEv4EW8hJfxCl7Fa3gdb+BNvIW38Q7exXt431lGd5btnOuH+Agf4xN8ik7ojC7oim7ojh7oiV7ojT7oi37ojwEYiEEYjCEYimEYjhEYiVEYjTEYi3EYjwmYiEmYjCmYimmYjhmYiVmYjTmYi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msXltPpvfFrAFbSFb2BaxRW0xW9yWsCVtKVvalrFlbTlb3lawoRHzDwo//n7jC372xhe4UMlWtlVsVVvNVrc1bE1by9a2dWxdW8/Wtw0iPii+joacN0JjNEFTNENztEBLtEJrtEFbtEN7dAgOf8N+7iN374L+/7t3kbt1z2e3LrBQBBaJf7ojF7kD93x24CKOf2td/ROKWJ6DKhkAAA==","proving_key":null,"verification_key":null,"gates":505505} \ No newline at end of file From 4329a20c846f63f219d5dd3b872db8b4385c34fa Mon Sep 17 00:00:00 2001 From: kevaundray Date: Fri, 18 Aug 2023 20:51:25 +0000 Subject: [PATCH 5/6] change .json to .bytecode --- circuits/cpp/barretenberg/ts/src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuits/cpp/barretenberg/ts/src/main.ts b/circuits/cpp/barretenberg/ts/src/main.ts index a4eb0d89d19..1df93f6856f 100755 --- a/circuits/cpp/barretenberg/ts/src/main.ts +++ b/circuits/cpp/barretenberg/ts/src/main.ts @@ -274,7 +274,7 @@ program program .command('write_vk') .description('Output verification key.') - .option('-j, --json-path ', 'Specify the JSON path', './target/main.json') + .option('-j, --json-path ', 'Specify the JSON path', './target/main.bytecode') .requiredOption('-o, --output-path ', 'Specify the path to write the key') .action(async ({ jsonPath, outputPath, crsPath }) => { handleGlobalOptions(); From 1515576162288b7fe26acd985103e3945aed0880 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Fri, 18 Aug 2023 21:12:58 +0000 Subject: [PATCH 6/6] use -b and rename jsonPath to bytecodePath --- .../barretenberg/acir_tests/run_acir_tests.sh | 4 +- .../cpp/src/barretenberg/bb/get_bytecode.hpp | 4 +- .../cpp/src/barretenberg/bb/main.cpp | 33 +++++----- circuits/cpp/barretenberg/ts/src/main.ts | 64 +++++++++---------- 4 files changed, 54 insertions(+), 51 deletions(-) diff --git a/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh b/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh index e8b33da494c..e9e509f6fae 100755 --- a/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh +++ b/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh @@ -49,9 +49,9 @@ function test() { set +e if [ -n "$VERBOSE" ]; then - $BB prove_and_verify -v -c $CRS_PATH -j ./target/$dir_name.bytecode + $BB prove_and_verify -v -c $CRS_PATH -b ./target/$dir_name.bytecode else - $BB prove_and_verify -c $CRS_PATH -j ./target/$dir_name.bytecode > /dev/null 2>&1 + $BB prove_and_verify -c $CRS_PATH -b ./target/$dir_name.bytecode > /dev/null 2>&1 fi result=$? set -e diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_bytecode.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_bytecode.hpp index 9a898b3146b..61de3910974 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_bytecode.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_bytecode.hpp @@ -4,8 +4,8 @@ /** * We can assume for now we're running on a unix like system and use the following to extract the bytecode. */ -inline std::vector get_bytecode(const std::string& jsonPath) +inline std::vector get_bytecode(const std::string& bytecodePath) { - std::string command = "base64 -d " + jsonPath + " | gunzip"; + std::string command = "base64 -d " + bytecodePath + " | gunzip"; return exec_pipe(command); } \ No newline at end of file diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp index 30fb42f7a95..bd6c9c79bf1 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -30,16 +30,16 @@ acir_format::WitnessVector get_witness(std::string const& witness_path) return acir_format::witness_buf_to_witness_data(witness_data); } -acir_format::acir_format get_constraint_system(std::string const& json_path) +acir_format::acir_format get_constraint_system(std::string const& bytecode_path) { - auto bytecode = get_bytecode(json_path); + auto bytecode = get_bytecode(bytecode_path); return acir_format::circuit_buf_to_acir_format(bytecode); } -bool proveAndVerify(const std::string& jsonPath, const std::string& witnessPath, bool recursive) +bool proveAndVerify(const std::string& bytecodePath, const std::string& witnessPath, bool recursive) { auto acir_composer = new acir_proofs::AcirComposer(MAX_CIRCUIT_SIZE, verbose); - auto constraint_system = get_constraint_system(jsonPath); + auto constraint_system = get_constraint_system(bytecodePath); auto witness = get_witness(witnessPath); auto proof = acir_composer->create_proof(srs::get_crs_factory(), constraint_system, witness, recursive); auto verified = acir_composer->verify_proof(proof, recursive); @@ -47,20 +47,23 @@ bool proveAndVerify(const std::string& jsonPath, const std::string& witnessPath, return verified; } -void prove(const std::string& jsonPath, const std::string& witnessPath, bool recursive, const std::string& outputPath) +void prove(const std::string& bytecodePath, + const std::string& witnessPath, + bool recursive, + const std::string& outputPath) { auto acir_composer = new acir_proofs::AcirComposer(MAX_CIRCUIT_SIZE, verbose); - auto constraint_system = get_constraint_system(jsonPath); + auto constraint_system = get_constraint_system(bytecodePath); auto witness = get_witness(witnessPath); auto proof = acir_composer->create_proof(srs::get_crs_factory(), constraint_system, witness, recursive); write_file(outputPath, proof); info("proof written to: ", outputPath); } -void gateCount(const std::string& jsonPath) +void gateCount(const std::string& bytecodePath) { auto acir_composer = new acir_proofs::AcirComposer(MAX_CIRCUIT_SIZE, verbose); - auto constraint_system = get_constraint_system(jsonPath); + auto constraint_system = get_constraint_system(bytecodePath); acir_composer->create_circuit(constraint_system); info("gates: ", acir_composer->get_total_circuit_size()); } @@ -75,10 +78,10 @@ bool verify(const std::string& proof_path, bool recursive, const std::string& vk return verified; } -void writeVk(const std::string& jsonPath, const std::string& outputPath) +void writeVk(const std::string& bytecodePath, const std::string& outputPath) { auto acir_composer = new acir_proofs::AcirComposer(MAX_CIRCUIT_SIZE, verbose); - auto constraint_system = get_constraint_system(jsonPath); + auto constraint_system = get_constraint_system(bytecodePath); acir_composer->init_proving_key(srs::get_crs_factory(), constraint_system); auto vk = acir_composer->init_verification_key(); write_file(outputPath, to_buffer(*vk)); @@ -148,7 +151,7 @@ int main(int argc, char* argv[]) std::string command = args[0]; - std::string json_path = getOption(args, "-j", "./target/main.bytecode"); + std::string bytecode_path = getOption(args, "-b", "./target/main.bytecode"); std::string witness_path = getOption(args, "-w", "./target/witness.tr"); std::string proof_path = getOption(args, "-p", "./proofs/proof"); std::string vk_path = getOption(args, "-k", "./target/vk"); @@ -157,12 +160,12 @@ int main(int argc, char* argv[]) init(); if (command == "prove_and_verify") { - return proveAndVerify(json_path, witness_path, recursive) ? 0 : 1; + return proveAndVerify(bytecode_path, witness_path, recursive) ? 0 : 1; } else if (command == "prove") { std::string output_path = getOption(args, "-o", "./proofs/proof"); - prove(json_path, witness_path, recursive, output_path); + prove(bytecode_path, witness_path, recursive, output_path); } else if (command == "gates") { - gateCount(json_path); + gateCount(bytecode_path); } else if (command == "verify") { verify(proof_path, recursive, vk_path); } else if (command == "contract") { @@ -170,7 +173,7 @@ int main(int argc, char* argv[]) contract(output_path, vk_path); } else if (command == "write_vk") { std::string output_path = getOption(args, "-o", "./target/vk"); - writeVk(json_path, output_path); + writeVk(bytecode_path, output_path); } else if (command == "proof_as_fields") { std::string output_path = getOption(args, "-o", proof_path + "_fields.json"); proofAsFields(proof_path, vk_path, output_path); diff --git a/circuits/cpp/barretenberg/ts/src/main.ts b/circuits/cpp/barretenberg/ts/src/main.ts index 1df93f6856f..a83f14aac30 100755 --- a/circuits/cpp/barretenberg/ts/src/main.ts +++ b/circuits/cpp/barretenberg/ts/src/main.ts @@ -11,15 +11,15 @@ const debug = createDebug('bb.js'); // Maximum we support. const MAX_CIRCUIT_SIZE = 2 ** 19; -function getBytecode(jsonPath: string) { - const encodedCircuit = readFileSync(jsonPath, 'utf-8'); +function getBytecode(bytecodePath: string) { + const encodedCircuit = readFileSync(bytecodePath, 'utf-8'); const buffer = Buffer.from(encodedCircuit, 'base64'); const decompressed = gunzipSync(buffer); return decompressed; } -async function getGates(jsonPath: string, api: BarretenbergApiAsync) { - const { total } = await computeCircuitSize(jsonPath, api); +async function getGates(bytecodePath: string, api: BarretenbergApiAsync) { + const { total } = await computeCircuitSize(bytecodePath, api); return total; } @@ -29,17 +29,17 @@ function getWitness(witnessPath: string) { return decompressed; } -async function computeCircuitSize(jsonPath: string, api: BarretenbergApiAsync) { +async function computeCircuitSize(bytecodePath: string, api: BarretenbergApiAsync) { debug(`computing circuit size...`); - const bytecode = getBytecode(jsonPath); + const bytecode = getBytecode(bytecodePath); const [exact, total, subgroup] = await api.acirGetCircuitSizes(bytecode); return { exact, total, subgroup }; } -async function init(jsonPath: string, crsPath: string) { +async function init(bytecodePath: string, crsPath: string) { const api = await newBarretenbergApiAsync(); - const circuitSize = await getGates(jsonPath, api); + const circuitSize = await getGates(bytecodePath, api); const subgroupSize = Math.pow(2, Math.ceil(Math.log2(circuitSize))); if (subgroupSize > MAX_CIRCUIT_SIZE) { throw new Error(`Circuit size of ${subgroupSize} exceeds max supported of ${MAX_CIRCUIT_SIZE}`); @@ -75,11 +75,11 @@ async function initLite() { return { api, acirComposer }; } -export async function proveAndVerify(jsonPath: string, witnessPath: string, crsPath: string, isRecursive: boolean) { - const { api, acirComposer } = await init(jsonPath, crsPath); +export async function proveAndVerify(bytecodePath: string, witnessPath: string, crsPath: string, isRecursive: boolean) { + const { api, acirComposer } = await init(bytecodePath, crsPath); try { debug(`creating proof...`); - const bytecode = getBytecode(jsonPath); + const bytecode = getBytecode(bytecodePath); const witness = getWitness(witnessPath); const proof = await api.acirCreateProof(acirComposer, bytecode, witness, isRecursive); @@ -93,16 +93,16 @@ export async function proveAndVerify(jsonPath: string, witnessPath: string, crsP } export async function prove( - jsonPath: string, + bytecodePath: string, witnessPath: string, crsPath: string, isRecursive: boolean, outputPath: string, ) { - const { api, acirComposer } = await init(jsonPath, crsPath); + const { api, acirComposer } = await init(bytecodePath, crsPath); try { debug(`creating proof...`); - const bytecode = getBytecode(jsonPath); + const bytecode = getBytecode(bytecodePath); const witness = getWitness(witnessPath); const proof = await api.acirCreateProof(acirComposer, bytecode, witness, isRecursive); debug(`done.`); @@ -114,10 +114,10 @@ export async function prove( } } -export async function gateCount(jsonPath: string) { +export async function gateCount(bytecodePath: string) { const api = await newBarretenbergApiAsync(1); try { - console.log(`gates: ${await getGates(jsonPath, api)}`); + console.log(`gates: ${await getGates(bytecodePath, api)}`); } finally { await api.destroy(); } @@ -151,11 +151,11 @@ export async function contract(outputPath: string, vkPath: string) { } } -export async function writeVk(jsonPath: string, crsPath: string, outputPath: string) { - const { api, acirComposer } = await init(jsonPath, crsPath); +export async function writeVk(bytecodePath: string, crsPath: string, outputPath: string) { + const { api, acirComposer } = await init(bytecodePath, crsPath); try { debug('initing proving key...'); - const bytecode = getBytecode(jsonPath); + const bytecode = getBytecode(bytecodePath); await api.acirInitProvingKey(acirComposer, bytecode); debug('initing verification key...'); @@ -218,34 +218,34 @@ function handleGlobalOptions() { program .command('prove_and_verify') .description('Generate a proof and verify it. Process exits with success or failure code.') - .option('-j, --json-path ', 'Specify the JSON path', './target/main.bytecode') + .option('-b, --bytecode-path ', 'Specify the bytecode path', './target/main.bytecode') .option('-w, --witness-path ', 'Specify the witness path', './target/witness.tr') .option('-r, --recursive', 'prove and verify using recursive prover and verifier', false) - .action(async ({ jsonPath, witnessPath, recursive, crsPath }) => { + .action(async ({ bytecodePath, witnessPath, recursive, crsPath }) => { handleGlobalOptions(); - const result = await proveAndVerify(jsonPath, witnessPath, crsPath, recursive); + const result = await proveAndVerify(bytecodePath, witnessPath, crsPath, recursive); process.exit(result ? 0 : 1); }); program .command('prove') .description('Generate a proof and write it to a file.') - .option('-j, --json-path ', 'Specify the JSON path', './target/main.bytecode') + .option('-b, --bytecode-path ', 'Specify the bytecode path', './target/main.bytecode') .option('-w, --witness-path ', 'Specify the witness path', './target/witness.tr') .option('-r, --recursive', 'prove using recursive prover', false) .option('-o, --output-path ', 'Specify the proof output path', './proofs/proof') - .action(async ({ jsonPath, witnessPath, recursive, outputPath, crsPath }) => { + .action(async ({ bytecodePath, witnessPath, recursive, outputPath, crsPath }) => { handleGlobalOptions(); - await prove(jsonPath, witnessPath, crsPath, recursive, outputPath); + await prove(bytecodePath, witnessPath, crsPath, recursive, outputPath); }); program .command('gates') .description('Print gate count to standard output.') - .option('-j, --json-path ', 'Specify the JSON path', './target/main.bytecode') - .action(async ({ jsonPath }) => { + .option('-b, --bytecode-path ', 'Specify the bytecode path', './target/main.bytecode') + .action(async ({ bytecodePath: bytecodePath }) => { handleGlobalOptions(); - await gateCount(jsonPath); + await gateCount(bytecodePath); }); program @@ -263,7 +263,7 @@ program program .command('contract') .description('Output solidity verification key contract.') - .option('-j, --json-path ', 'Specify the JSON path', './target/main.bytecode') + .option('-b, --bytecode-path ', 'Specify the bytecode path', './target/main.bytecode') .option('-o, --output-path ', 'Specify the path to write the contract', '-') .requiredOption('-k, --vk ', 'path to a verification key. avoids recomputation.') .action(async ({ outputPath, vk }) => { @@ -274,11 +274,11 @@ program program .command('write_vk') .description('Output verification key.') - .option('-j, --json-path ', 'Specify the JSON path', './target/main.bytecode') + .option('-b, --bytecode-path ', 'Specify the bytecode path', './target/main.bytecode') .requiredOption('-o, --output-path ', 'Specify the path to write the key') - .action(async ({ jsonPath, outputPath, crsPath }) => { + .action(async ({ bytecodePath, outputPath, crsPath }) => { handleGlobalOptions(); - await writeVk(jsonPath, crsPath, outputPath); + await writeVk(bytecodePath, crsPath, outputPath); }); program