16void write_vk_outputs(
const bbapi::CircuitComputeVk::Response& vk_response,
17 const std::filesystem::path& output_dir,
18 const API::Flags& flags)
20 if (flags.output_format ==
"json") {
21 std::string json_content =
23 write_file(output_dir /
"vk.json", std::vector<uint8_t>(json_content.begin(), json_content.end()));
24 info(
"VK (JSON) saved to ", output_dir /
"vk.json");
26 write_file(output_dir /
"vk", vk_response.bytes);
27 info(
"VK saved to ", output_dir /
"vk");
28 write_file(output_dir /
"vk_hash", vk_response.hash);
29 info(
"VK Hash saved to ", output_dir /
"vk_hash");
33void write_proof_outputs(
const bbapi::CircuitProve::Response& prove_response,
34 const std::filesystem::path& output_dir,
35 const API::Flags& flags)
37 if (flags.output_format ==
"json") {
39 std::string proof_json =
ProofJson::build(prove_response.proof, vk_hash, flags.scheme);
40 write_file(output_dir /
"proof.json", std::vector<uint8_t>(proof_json.begin(), proof_json.end()));
41 info(
"Proof (JSON) saved to ", output_dir /
"proof.json");
44 write_file(output_dir /
"public_inputs.json", std::vector<uint8_t>(pi_json.begin(), pi_json.end()));
45 info(
"Public inputs (JSON) saved to ", output_dir /
"public_inputs.json");
47 auto public_inputs_buf =
to_buffer(prove_response.public_inputs);
48 auto proof_buf =
to_buffer(prove_response.proof);
50 write_file(output_dir /
"public_inputs", public_inputs_buf);
52 info(
"Public inputs saved to ", output_dir /
"public_inputs");
53 info(
"Proof saved to ", output_dir /
"proof");
60 [[maybe_unused]]
const std::filesystem::path& bytecode_path,
61 [[maybe_unused]]
const std::filesystem::path& witness_path)
68 const std::filesystem::path& bytecode_path,
69 const std::filesystem::path& witness_path,
70 const std::filesystem::path& vk_path,
71 const std::filesystem::path& output_dir)
75 if (output_dir ==
"-") {
76 throw_or_abort(
"Stdout output is not supported. Please specify an output directory.");
89 std::vector<uint8_t> vk_bytes;
91 if (!vk_path.empty() && !flags.
write_vk) {
98 .verification_key =
std::move(vk_bytes) },
102 write_proof_outputs(response, output_dir, flags);
104 write_vk_outputs(response.vk, output_dir, flags);
109 const std::filesystem::path& public_inputs_path,
110 const std::filesystem::path& proof_path,
111 const std::filesystem::path& vk_path)
118 std::vector<uint8_t> vk_bytes;
120 auto public_inputs_content =
read_file(public_inputs_path);
124 public_inputs = many_from_buffer<uint256_t>(public_inputs_content);
127 auto proof_content =
read_file(proof_path);
131 proof = many_from_buffer<uint256_t>(proof_content);
148 .public_inputs =
std::move(public_inputs),
150 .settings = settings }
153 return response.verified;
157 [[maybe_unused]]
const std::filesystem::path& bytecode_path,
158 [[maybe_unused]]
const std::filesystem::path& witness_path)
165 const std::filesystem::path& bytecode_path,
166 const std::filesystem::path& output_dir)
170 if (output_dir ==
"-") {
171 throw_or_abort(
"Stdout output is not supported. Please specify an output directory.");
183 .settings = settings }
186 write_vk_outputs(response, output_dir, flags);
190 [[maybe_unused]]
const std::filesystem::path& bytecode_path)
197 std::string functions_string =
"{\"functions\": [\n ";
202 .oracle_hash_type = flags.oracle_hash_type,
203 .disable_zk = flags.disable_zk };
207 .include_gates_per_opcode = flags.include_gates_per_opcode,
208 .settings = settings }
211 vinfo(
"Calculated circuit size in gate_count: ", response.num_gates);
214 std::string gates_per_opcode_str;
215 if (flags.include_gates_per_opcode) {
217 for (
size_t count : response.gates_per_opcode) {
219 gates_per_opcode_str +=
",";
228 auto result_string =
format(
229 "{\n \"acir_opcodes\": ",
230 response.num_acir_opcodes,
231 ",\n \"circuit_size\": ",
233 (flags.include_gates_per_opcode ?
format(
",\n \"gates_per_opcode\": [", gates_per_opcode_str,
"]") :
""),
236 functions_string =
format(functions_string, result_string);
241 const std::filesystem::path& output_path,
242 const std::filesystem::path& vk_path)
258 if (output_path ==
"-") {
263 response.solidity_code.size()));
265 info(
"Honk solidity verifier saved to ", output_path);
267 info(
"ZK Honk solidity verifier saved to ", output_path);
std::shared_ptr< Napi::ThreadSafeFunction > bytecode
#define BB_BENCH_NAME(name)
UltraHonk-specific command definitions for the Barretenberg RPC API.
void prove(const Flags &flags, const std::filesystem::path &bytecode_path, const std::filesystem::path &witness_path, const std::filesystem::path &vk_path, const std::filesystem::path &output_dir)
void write_vk(const Flags &flags, const std::filesystem::path &bytecode_path, const std::filesystem::path &output_path) override
bool verify(const Flags &flags, const std::filesystem::path &public_inputs_path, const std::filesystem::path &proof_path, const std::filesystem::path &vk_path) override
bool check(const Flags &flags, const std::filesystem::path &bytecode_path, const std::filesystem::path &witness_path) override
bool prove_and_verify(const Flags &flags, const std::filesystem::path &bytecode_path, const std::filesystem::path &witness_path)
void gates(const Flags &flags, const std::filesystem::path &bytecode_path) override
void write_solidity_verifier(const Flags &flags, const std::filesystem::path &output_path, const std::filesystem::path &vk_path) override
std::string format(Args... args)
std::vector< uint8_t > get_bytecode(const std::string &bytecodePath)
Entry point for Barretenberg command-line interface.
std::vector< uint8_t > read_vk_file(const std::filesystem::path &vk_path)
Read a verification key file with an actionable error message if not found.
std::optional< nlohmann::json > try_parse_json(const std::vector< uint8_t > &content)
Try to parse file content as JSON.
std::vector< uint8_t > read_file(const std::string &filename, size_t bytes=0)
void write_file(const std::string &filename, std::span< const uint8_t > data)
std::string bytes_to_hex_string(const std::vector< uint8_t > &bytes)
Convert bytes to a hex string with 0x prefix.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)
std::vector< uint8_t > to_buffer(T const &value)
bool optimized_solidity_verifier
std::string oracle_hash_type
static std::vector< uint256_t > parse(const nlohmann::json &json)
static std::string build(const std::vector< T > &fields, const std::string &vk_hash, const std::string &scheme)
static std::vector< uint8_t > parse_to_bytes(const nlohmann::json &json)
static std::string build(const std::vector< T > &fields, const std::string &hash, const std::string &scheme)
Represents a request to generate a proof. Currently, UltraHonk is the only proving system supported b...
Consolidated command for retrieving circuit information. Combines gate count, circuit size,...
Verify a proof against a verification key and public inputs.
std::vector< uint8_t > verification_key
Command to generate Solidity verifier contract.
std::vector< uint8_t > verification_key
bool ipa_accumulation
Optional flag to indicate if the proof should be generated with IPA accumulation (i....
void throw_or_abort(std::string const &err)