From cb98db7c3e9fac87aed0e13f4e1877cab1c17585 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Sat, 26 Aug 2023 18:08:53 +0000 Subject: [PATCH 01/13] communication: - we now print raw bytes to stdout - we only print to stdout based on "-" --- .../cpp/src/barretenberg/bb/main.cpp | 78 ++++++++++++------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp index 506341e1849e..8575c534140b 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -1,4 +1,6 @@ #include "barretenberg/bb/get_crs.hpp" +#include "barretenberg/bb/vinfo.hpp" +#include "barretenberg/common/log.hpp" #include "get_bytecode.hpp" #include "get_witness.hpp" #include @@ -11,9 +13,9 @@ #include using namespace barretenberg; -// The maximum size that we can do in the browser is 2^19 +// The maximum size that we can do in the browser and node is 2^19 // based on memory constraints for UltraPlonk. -// However, since this will be ran natively, we can increase the +// However, since this CLI does not use WASM, we can increase the // size. uint32_t MAX_CIRCUIT_SIZE = 1 << 23; std::string CRS_PATH = "./crs"; @@ -59,9 +61,10 @@ bool proveAndVerify(const std::string& bytecodePath, const std::string& witnessP auto proof = acir_composer->create_proof(srs::get_crs_factory(), constraint_system, witness, recursive); auto verified = acir_composer->verify_proof(proof, recursive); - std::cout << verified << std::endl; + info("verified: ", verified); return verified; } + /** * @brief Creates a proof for an ACIR circuit * @@ -84,11 +87,15 @@ void prove(const std::string& bytecodePath, auto witness = get_witness(witnessPath); auto proof = acir_composer->create_proof(srs::get_crs_factory(), constraint_system, witness, recursive); - std::cout << proof << std::endl; - write_file(outputPath, proof); - - info("proof written to: ", outputPath); + if (outputPath == "-") { + writeRawBytesToStdout(proof); + info("proof written to stdout"); + } else { + write_file(outputPath, proof); + info("proof written to: ", outputPath); + } } + /** * @brief Computes the number of Barretenberg specific gates needed to create a proof for the specific ACIR circuit * @@ -103,8 +110,11 @@ void gateCount(const std::string& bytecodePath) auto constraint_system = get_constraint_system(bytecodePath); acir_composer->create_circuit(constraint_system); auto gate_count = acir_composer->get_total_circuit_size(); - std::cout << gate_count << std::endl; + + writeUint64AsRawBytesToStdout(static_cast(gate_count)); + info("gate count: ", gate_count); } + /** * @brief Verifies a proof for an ACIR circuit * @@ -112,7 +122,8 @@ void gateCount(const std::string& bytecodePath) * because this method uses the verification key to verify the proof. * * Communication: - * - stdout: A boolean value is printed to stdout indicating whether the proof is valid + * - proc_exit: A boolean value is returned indicating whether the proof is valid. + * an exit code of 0 will be returned for success and 1 for failure. * * @param proof_path Path to the file containing the serialized proof * @param recursive Whether to use recursive proof generation of non-recursive @@ -127,7 +138,8 @@ bool verify(const std::string& proof_path, bool recursive, const std::string& vk acir_composer->load_verification_key(barretenberg::srs::get_crs_factory(), std::move(vk_data)); auto verified = acir_composer->verify_proof(read_file(proof_path), recursive); - std::cout << verified << std::endl; + info("verified: ", verified); + return verified; } @@ -148,11 +160,13 @@ void writeVk(const std::string& bytecodePath, const std::string& outputPath) acir_composer->init_proving_key(srs::get_crs_factory(), constraint_system); auto vk = acir_composer->init_verification_key(); auto serialized_vk = to_buffer(*vk); - - std::cout << serialized_vk << std::endl; - write_file(outputPath, serialized_vk); - - info("vk written to: ", outputPath); + if (outputPath == "-") { + writeRawBytesToStdout(serialized_vk); + info("vk written to stdout"); + } else { + write_file(outputPath, serialized_vk); + info("vk written to: ", outputPath); + } } /** @@ -175,11 +189,15 @@ void contract(const std::string& output_path, const std::string& vk_path) acir_composer->load_verification_key(barretenberg::srs::get_crs_factory(), std::move(vk_data)); auto contract = acir_composer->get_solidity_verifier(); - std::cout << contract << std::endl; - write_file(output_path, { contract.begin(), contract.end() }); - - info("contract written to: ", output_path); + if (output_path == "-") { + writeStringToStdout(contract); + info("contract written to stdout"); + } else { + write_file(output_path, { contract.begin(), contract.end() }); + info("contract written to: ", output_path); + } } + /** * @brief Converts a proof from a byte array into a list of field elements * @@ -212,10 +230,13 @@ void proofAsFields(const std::string& proof_path, std::string const& vk_path, co auto data = acir_composer->serialize_proof_into_fields(read_file(proof_path), vk_data.num_public_inputs); auto json = format("[", join(map(data, [](auto fr) { return format("\"", fr, "\""); })), "]"); - std::cout << json << std::endl; - write_file(output_path, { json.begin(), json.end() }); - - info("proof as fields written to: ", output_path); + if (output_path == "-") { + writeStringToStdout(json); + info("proof as fields written to stdout"); + } else { + write_file(output_path, { json.begin(), json.end() }); + info("proof as fields written to: ", output_path); + } } /** @@ -242,11 +263,14 @@ void vkAsFields(const std::string& vk_path, const std::string& output_path) std::rotate(data.begin(), data.end() - 1, data.end()); auto json = format("[", join(map(data, [](auto fr) { return format("\"", fr, "\""); })), "]"); + if (output_path == "-") { + writeStringToStdout(json); + info("vk as fields written to stdout"); - std::cout << json << std::endl; - write_file(output_path, { json.begin(), json.end() }); - - info("vk as fields written to: ", output_path); + } else { + write_file(output_path, { json.begin(), json.end() }); + info("vk as fields written to: ", output_path); + } } bool flagPresent(std::vector& args, const std::string& flag) From e564651d0ad2f8e997bab2673abcb91b8cf2b0bf Mon Sep 17 00:00:00 2001 From: kevaundray Date: Sat, 26 Aug 2023 18:21:16 +0000 Subject: [PATCH 02/13] restore deleted file -- This adds the methods for writing to stdout --- .../cpp/src/barretenberg/bb/vinfo.hpp | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/vinfo.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/vinfo.hpp index 312512327623..d05085960e98 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/vinfo.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/vinfo.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include extern bool verbose; @@ -8,4 +9,57 @@ template inline void vinfo(Args... args) if (verbose) { info(args...); } +} +/** + * @brief Writes raw bytes of the vector to stdout + * + * Note: std::cout << byte is not being used here because that always prints the numerical value. + * << can also apply formatting and seems is not the appropriate way to write raw bytes to stdout. + * + * Example: + * + * uint8_t byte = 'A' + * std::cout << byte; // prints 65 + * std::cout.put(byte); // prints 'A' + * + * @param data The raw bytes that we want to write to stdout + */ +inline void writeRawBytesToStdout(const std::vector& data) +{ + for (auto byte : data) { + // Safety: a byte and a char occupy one byte + std::cout.put(static_cast(byte)); + } +} +/** + * @brief Writes a uint64_t to stdout in little endian format + * + * @param value The value to be written to stdout + */ +inline void writeUint64AsRawBytesToStdout(uint64_t value) +{ + // Convert the uint64_t to a vector of bytes, since std::cout.put + // only accepts a single byte. + // This is in little endian format + std::vector bytes; + bytes.reserve(sizeof(uint64_t)); + + for (size_t i = 0; i < sizeof(uint64_t); ++i) { + bytes.push_back(static_cast(value & 0xFF)); + value >>= 8; + } + + // Write the bytes to stdout + writeRawBytesToStdout(bytes); +} +/** + * @brief Writes a sting to stdout + * + * @param str The raw string to write to stdout + */ +inline void writeStringToStdout(const std::string& str) +{ + for (char ch : str) { + std::cout.put(ch); + } } \ No newline at end of file From 9730257c4c8541dda24a8fc53b884fde55f6788f Mon Sep 17 00:00:00 2001 From: kevaundray Date: Sat, 26 Aug 2023 18:24:12 +0000 Subject: [PATCH 03/13] rename vinfo.hpp to log.hpp --- .../barretenberg/cpp/src/barretenberg/bb/{vinfo.hpp => log.hpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename circuits/cpp/barretenberg/cpp/src/barretenberg/bb/{vinfo.hpp => log.hpp} (100%) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/vinfo.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp similarity index 100% rename from circuits/cpp/barretenberg/cpp/src/barretenberg/bb/vinfo.hpp rename to circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp From ba6626d2f1e1d025b1a97c2598d8ceca6f26aad0 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Sat, 26 Aug 2023 18:24:34 +0000 Subject: [PATCH 04/13] fix imports --- .../cpp/barretenberg/cpp/src/barretenberg/bb/get_crs.hpp | 2 +- circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_crs.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_crs.hpp index 4f9bc58192cc..808bb5a0f01e 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_crs.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/get_crs.hpp @@ -1,7 +1,7 @@ #pragma once #include "exec_pipe.hpp" #include "file_io.hpp" -#include "vinfo.hpp" +#include "log.hpp" #include #include #include diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp index 8575c534140b..09693ef24018 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -1,8 +1,7 @@ -#include "barretenberg/bb/get_crs.hpp" -#include "barretenberg/bb/vinfo.hpp" -#include "barretenberg/common/log.hpp" #include "get_bytecode.hpp" +#include "get_crs.hpp" #include "get_witness.hpp" +#include "log.hpp" #include #include #include From 1de1484be1682dd73afd13a985ee5d3c27e45224 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 28 Aug 2023 11:15:49 +0000 Subject: [PATCH 05/13] info -> vinfo --- .../cpp/src/barretenberg/bb/main.cpp | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp index 09693ef24018..988d039c3372 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -60,7 +60,7 @@ bool proveAndVerify(const std::string& bytecodePath, const std::string& witnessP auto proof = acir_composer->create_proof(srs::get_crs_factory(), constraint_system, witness, recursive); auto verified = acir_composer->verify_proof(proof, recursive); - info("verified: ", verified); + vinfo("verified: ", verified); return verified; } @@ -88,10 +88,10 @@ void prove(const std::string& bytecodePath, if (outputPath == "-") { writeRawBytesToStdout(proof); - info("proof written to stdout"); + vinfo("proof written to stdout"); } else { write_file(outputPath, proof); - info("proof written to: ", outputPath); + vinfo("proof written to: ", outputPath); } } @@ -111,7 +111,7 @@ void gateCount(const std::string& bytecodePath) auto gate_count = acir_composer->get_total_circuit_size(); writeUint64AsRawBytesToStdout(static_cast(gate_count)); - info("gate count: ", gate_count); + vinfo("gate count: ", gate_count); } /** @@ -137,7 +137,7 @@ bool verify(const std::string& proof_path, bool recursive, const std::string& vk acir_composer->load_verification_key(barretenberg::srs::get_crs_factory(), std::move(vk_data)); auto verified = acir_composer->verify_proof(read_file(proof_path), recursive); - info("verified: ", verified); + vinfo("verified: ", verified); return verified; } @@ -161,10 +161,10 @@ void writeVk(const std::string& bytecodePath, const std::string& outputPath) auto serialized_vk = to_buffer(*vk); if (outputPath == "-") { writeRawBytesToStdout(serialized_vk); - info("vk written to stdout"); + vinfo("vk written to stdout"); } else { write_file(outputPath, serialized_vk); - info("vk written to: ", outputPath); + vinfo("vk written to: ", outputPath); } } @@ -190,10 +190,10 @@ void contract(const std::string& output_path, const std::string& vk_path) if (output_path == "-") { writeStringToStdout(contract); - info("contract written to stdout"); + vinfo("contract written to stdout"); } else { write_file(output_path, { contract.begin(), contract.end() }); - info("contract written to: ", output_path); + vinfo("contract written to: ", output_path); } } @@ -231,10 +231,10 @@ void proofAsFields(const std::string& proof_path, std::string const& vk_path, co if (output_path == "-") { writeStringToStdout(json); - info("proof as fields written to stdout"); + vinfo("proof as fields written to stdout"); } else { write_file(output_path, { json.begin(), json.end() }); - info("proof as fields written to: ", output_path); + vinfo("proof as fields written to: ", output_path); } } @@ -264,11 +264,10 @@ void vkAsFields(const std::string& vk_path, const std::string& output_path) auto json = format("[", join(map(data, [](auto fr) { return format("\"", fr, "\""); })), "]"); if (output_path == "-") { writeStringToStdout(json); - info("vk as fields written to stdout"); - + vinfo("vk as fields written to stdout"); } else { write_file(output_path, { json.begin(), json.end() }); - info("vk as fields written to: ", output_path); + vinfo("vk as fields written to: ", output_path); } } From 533d52ab9a537b59d0f5d69500c625f48038d487 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 28 Aug 2023 12:21:27 +0100 Subject: [PATCH 06/13] Update circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp --- circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp index d05085960e98..ae094e17908a 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp @@ -49,7 +49,6 @@ inline void writeUint64AsRawBytesToStdout(uint64_t value) value >>= 8; } - // Write the bytes to stdout writeRawBytesToStdout(bytes); } /** From b3c079c211013170f73acba5dc88e77fe2ecc188 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 28 Aug 2023 12:21:34 +0100 Subject: [PATCH 07/13] Update circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp --- circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp index ae094e17908a..35b80d4a989b 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp @@ -40,7 +40,6 @@ inline void writeUint64AsRawBytesToStdout(uint64_t value) { // Convert the uint64_t to a vector of bytes, since std::cout.put // only accepts a single byte. - // This is in little endian format std::vector bytes; bytes.reserve(sizeof(uint64_t)); From 830399cd6071a672569281fb73f4fc030a8cec26 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 28 Aug 2023 11:22:06 +0000 Subject: [PATCH 08/13] formatting --- circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp index 35b80d4a989b..8c378b71ee29 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/log.hpp @@ -10,6 +10,7 @@ template inline void vinfo(Args... args) info(args...); } } + /** * @brief Writes raw bytes of the vector to stdout * @@ -31,6 +32,7 @@ inline void writeRawBytesToStdout(const std::vector& data) std::cout.put(static_cast(byte)); } } + /** * @brief Writes a uint64_t to stdout in little endian format * @@ -50,6 +52,7 @@ inline void writeUint64AsRawBytesToStdout(uint64_t value) writeRawBytesToStdout(bytes); } + /** * @brief Writes a sting to stdout * From 90e7995574cd3db3c0372c4a4fb038eee74d869a Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 28 Aug 2023 11:23:42 +0000 Subject: [PATCH 09/13] document proc_exit for prove_and_verify --- circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp index 988d039c3372..1f2ae5c1654e 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -44,7 +44,8 @@ acir_format::acir_format get_constraint_system(std::string const& bytecode_path) * @brief Proves and Verifies an ACIR circuit * * Communication: - * - stdout: A boolean value is printed to stdout indicating whether the proof is valid + * - proc_exit: A boolean value is returned indicating whether the proof is valid. + * an exit code of 0 will be returned for success and 1 for failure. * * @param bytecodePath Path to the file containing the serialized circuit * @param witnessPath Path to the file containing the serialized witness From 9a467c07870e4d221991a7f3b79130eff5f14d1d Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 28 Aug 2023 11:38:37 +0000 Subject: [PATCH 10/13] add small readme --- .../cpp/src/barretenberg/bb/readme.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 circuits/cpp/barretenberg/cpp/src/barretenberg/bb/readme.md diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/readme.md b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/readme.md new file mode 100644 index 000000000000..8b72d2c49774 --- /dev/null +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/readme.md @@ -0,0 +1,16 @@ +# BB + +## Why is this needed? + +Barretenberg is a library that allows one to create and verify proofs. One way to specify the circuit that one will use to create and verify +proofs over is to use the Barretenberg standard library. Another way, which pertains to this module is to supply the circuit description using +an IR called [ACIR](https://github.com/noir-lang/acvm). This binary will take as input ACIR and witness values described in the IR to create proofs. + + +## FilePath vs Stdout + +For commands which allow you to send the output to a file using `-o {filePath}`, there is also the option to send the output to stdout by using `-o -`. + +## Maximum Circuit Size + +Currently the binary downloads an SRS that ca be used to prove the maximum circuit size. This maximum circuit size parameter is a constant in the code and has been set to $2^{23}$ as of writing. This maximum circuit size differs from the maximum circuit size that one can prove in the browser, due to WASM limits. \ No newline at end of file From 6fb93c511a3c1a06659a728161d5ef04ca896a10 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 28 Aug 2023 12:42:31 +0000 Subject: [PATCH 11/13] modify ts code to match cpp code --- circuits/cpp/barretenberg/ts/src/main.ts | 56 +++++++++++++++++------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/circuits/cpp/barretenberg/ts/src/main.ts b/circuits/cpp/barretenberg/ts/src/main.ts index eecda39aa0aa..a6b30b107b69 100755 --- a/circuits/cpp/barretenberg/ts/src/main.ts +++ b/circuits/cpp/barretenberg/ts/src/main.ts @@ -85,7 +85,7 @@ export async function proveAndVerify(bytecodePath: string, witnessPath: string, debug(`verifying...`); const verified = await api.acirVerifyProof(acirComposer, proof, isRecursive); - process.stdout.write(`${verified}`); + debug(`verified: ${verified}`); return verified; } finally { await api.destroy(); @@ -107,10 +107,14 @@ export async function prove( const proof = await api.acirCreateProof(acirComposer, bytecode, witness, isRecursive); debug(`done.`); - process.stdout.write(proof); - writeFileSync(outputPath, proof); + if (outputPath === '-') { + process.stdout.write(proof); + debug(`proof written to stdout`); + } else { + writeFileSync(outputPath, proof); + debug(`proof written to: ${outputPath}`); + } - debug(`proof written to: ${outputPath}`); } finally { await api.destroy(); } @@ -130,8 +134,7 @@ export async function verify(proofPath: string, isRecursive: boolean, vkPath: st try { await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath))); const verified = await api.acirVerifyProof(acirComposer, readFileSync(proofPath), isRecursive); - - process.stdout.write(`${verified}`); + debug(`verified: ${verified}`); return verified; } finally { await api.destroy(); @@ -144,10 +147,14 @@ export async function contract(outputPath: string, vkPath: string) { await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath))); const contract = await api.acirGetSolidityVerifier(acirComposer); - process.stdout.write(contract); - writeFileSync(outputPath, contract); + if (outputPath === '-') { + process.stdout.write(contract); + debug(`contract written to stdout`); + } else { + writeFileSync(outputPath, contract); + debug(`contract written to: ${outputPath}`); + } - debug(`contract written to: ${outputPath}`); } finally { await api.destroy(); } @@ -163,10 +170,14 @@ export async function writeVk(bytecodePath: string, crsPath: string, outputPath: debug('initing verification key...'); const vk = await api.acirGetVerificationKey(acirComposer); - process.stdout.write(vk); - writeFileSync(outputPath, vk); + if (outputPath === '-') { + process.stdout.write(vk); + debug(`vk written to stdout`); + } else { + writeFileSync(outputPath, vk); + debug(`vk written to: ${outputPath}`); + } - debug(`vk written to: ${outputPath}`); } finally { await api.destroy(); } @@ -184,8 +195,14 @@ export async function proofAsFields(proofPath: string, numInnerPublicInputs: num ); const jsonProofAsFields = JSON.stringify(proofAsFields.map(f => f.toString())); - process.stdout.write(jsonProofAsFields); - writeFileSync(outputPath, jsonProofAsFields); + + if (outputPath === '-') { + process.stdout.write(jsonProofAsFields); + debug(`proofAsFields written to stdout`); + } else { + writeFileSync(outputPath, jsonProofAsFields); + debug(`proofAsFields written to: ${outputPath}`); + } debug('done.'); } finally { @@ -203,8 +220,13 @@ export async function vkAsFields(vkPath: string, vkeyOutputPath: string) { const output = [vkHash, ...vkAsFields].map(f => f.toString()); const jsonVKAsFields = JSON.stringify(output); - process.stdout.write(jsonVKAsFields); - writeFileSync(vkeyOutputPath, jsonVKAsFields); + if (vkeyOutputPath === '-') { + process.stdout.write(jsonVKAsFields); + debug(`vkAsFields written to stdout`); + } else { + writeFileSync(vkeyOutputPath, jsonVKAsFields); + debug(`vkAsFields written to: ${vkeyOutputPath}`); + } debug('done.'); } finally { @@ -272,7 +294,7 @@ program .command('contract') .description('Output solidity verification key contract.') .option('-b, --bytecode-path ', 'Specify the bytecode path', './target/main.bytecode') - .option('-o, --output-path ', 'Specify the path to write the contract', '-') + .option('-o, --output-path ', 'Specify the path to write the contract', './target/contract.sol') .requiredOption('-k, --vk ', 'path to a verification key. avoids recomputation.') .action(async ({ outputPath, vk }) => { handleGlobalOptions(); From c60029ffeba50a122d2e49819464377b039bc590 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 28 Aug 2023 13:16:12 +0000 Subject: [PATCH 12/13] prettier --- circuits/cpp/barretenberg/ts/src/main.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/circuits/cpp/barretenberg/ts/src/main.ts b/circuits/cpp/barretenberg/ts/src/main.ts index a6b30b107b69..ba78dda40a07 100755 --- a/circuits/cpp/barretenberg/ts/src/main.ts +++ b/circuits/cpp/barretenberg/ts/src/main.ts @@ -107,14 +107,13 @@ export async function prove( const proof = await api.acirCreateProof(acirComposer, bytecode, witness, isRecursive); debug(`done.`); - if (outputPath === '-') { + if (outputPath === '-') { process.stdout.write(proof); debug(`proof written to stdout`); } else { writeFileSync(outputPath, proof); debug(`proof written to: ${outputPath}`); } - } finally { await api.destroy(); } @@ -147,14 +146,13 @@ export async function contract(outputPath: string, vkPath: string) { await api.acirLoadVerificationKey(acirComposer, new RawBuffer(readFileSync(vkPath))); const contract = await api.acirGetSolidityVerifier(acirComposer); - if (outputPath === '-') { + if (outputPath === '-') { process.stdout.write(contract); debug(`contract written to stdout`); } else { writeFileSync(outputPath, contract); debug(`contract written to: ${outputPath}`); } - } finally { await api.destroy(); } @@ -170,14 +168,13 @@ export async function writeVk(bytecodePath: string, crsPath: string, outputPath: debug('initing verification key...'); const vk = await api.acirGetVerificationKey(acirComposer); - if (outputPath === '-') { + if (outputPath === '-') { process.stdout.write(vk); debug(`vk written to stdout`); } else { writeFileSync(outputPath, vk); debug(`vk written to: ${outputPath}`); } - } finally { await api.destroy(); } @@ -195,8 +192,7 @@ export async function proofAsFields(proofPath: string, numInnerPublicInputs: num ); const jsonProofAsFields = JSON.stringify(proofAsFields.map(f => f.toString())); - - if (outputPath === '-') { + if (outputPath === '-') { process.stdout.write(jsonProofAsFields); debug(`proofAsFields written to stdout`); } else { @@ -220,7 +216,7 @@ export async function vkAsFields(vkPath: string, vkeyOutputPath: string) { const output = [vkHash, ...vkAsFields].map(f => f.toString()); const jsonVKAsFields = JSON.stringify(output); - if (vkeyOutputPath === '-') { + if (vkeyOutputPath === '-') { process.stdout.write(jsonVKAsFields); debug(`vkAsFields written to stdout`); } else { From b5d06a7914ac85d2fb59a78ac2176328049c4db1 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 28 Aug 2023 17:48:33 +0100 Subject: [PATCH 13/13] Update circuits/cpp/barretenberg/cpp/src/barretenberg/bb/readme.md Co-authored-by: Maxim Vezenov --- circuits/cpp/barretenberg/cpp/src/barretenberg/bb/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/readme.md b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/readme.md index 8b72d2c49774..ea265a3a8c1f 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/readme.md +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/bb/readme.md @@ -13,4 +13,4 @@ For commands which allow you to send the output to a file using `-o {filePath}`, ## Maximum Circuit Size -Currently the binary downloads an SRS that ca be used to prove the maximum circuit size. This maximum circuit size parameter is a constant in the code and has been set to $2^{23}$ as of writing. This maximum circuit size differs from the maximum circuit size that one can prove in the browser, due to WASM limits. \ No newline at end of file +Currently the binary downloads an SRS that can be used to prove the maximum circuit size. This maximum circuit size parameter is a constant in the code and has been set to $2^{23}$ as of writing. This maximum circuit size differs from the maximum circuit size that one can prove in the browser, due to WASM limits. \ No newline at end of file