24void write_vk_outputs(
const bbapi::CircuitComputeVk::Response& vk_response,
25 const std::filesystem::path& output_dir,
26 const API::Flags& flags)
28 if (flags.output_format ==
"json") {
29 std::string json_content =
31 write_file(output_dir /
"vk.json", std::vector<uint8_t>(json_content.begin(), json_content.end()));
32 info(
"VK (JSON) saved to ", output_dir /
"vk.json");
34 write_file(output_dir /
"vk", vk_response.bytes);
35 info(
"VK saved to ", output_dir /
"vk");
36 write_file(output_dir /
"vk_hash", vk_response.hash);
37 info(
"VK Hash saved to ", output_dir /
"vk_hash");
41void write_proof_outputs(
const bbapi::CircuitProve::Response& prove_response,
42 const std::filesystem::path& output_dir,
43 const API::Flags& flags)
45 if (flags.output_format ==
"json") {
47 std::string proof_json =
build_json_output(prove_response.proof,
"proof", flags, vk_hash);
48 write_file(output_dir /
"proof.json", std::vector<uint8_t>(proof_json.begin(), proof_json.end()));
49 info(
"Proof (JSON) saved to ", output_dir /
"proof.json");
51 std::string pi_json =
build_json_output(prove_response.public_inputs,
"public_inputs", flags);
52 write_file(output_dir /
"public_inputs.json", std::vector<uint8_t>(pi_json.begin(), pi_json.end()));
53 info(
"Public inputs (JSON) saved to ", output_dir /
"public_inputs.json");
55 auto public_inputs_buf =
to_buffer(prove_response.public_inputs);
56 auto proof_buf =
to_buffer(prove_response.proof);
58 write_file(output_dir /
"public_inputs", public_inputs_buf);
60 info(
"Public inputs saved to ", output_dir /
"public_inputs");
61 info(
"Proof saved to ", output_dir /
"proof");
68 [[maybe_unused]]
const std::filesystem::path& bytecode_path,
69 [[maybe_unused]]
const std::filesystem::path& witness_path)
76 const std::filesystem::path& bytecode_path,
77 const std::filesystem::path& witness_path,
78 const std::filesystem::path& vk_path,
79 const std::filesystem::path& output_dir)
83 if (output_dir ==
"-") {
84 throw_or_abort(
"Stdout output is not supported. Please specify an output directory.");
97 std::vector<uint8_t> vk_bytes;
99 if (!vk_path.empty() && !flags.
write_vk) {
106 .verification_key =
std::move(vk_bytes) },
110 write_proof_outputs(response, output_dir, flags);
112 write_vk_outputs(response.vk, output_dir, flags);
117 const std::filesystem::path& public_inputs_path,
118 const std::filesystem::path& proof_path,
119 const std::filesystem::path& vk_path)
123 auto public_inputs = many_from_buffer<uint256_t>(
read_file(public_inputs_path));
124 auto proof = many_from_buffer<uint256_t>(
read_file(proof_path));
134 .public_inputs =
std::move(public_inputs),
136 .settings = settings }
139 return response.verified;
143 [[maybe_unused]]
const std::filesystem::path& bytecode_path,
144 [[maybe_unused]]
const std::filesystem::path& witness_path)
151 const std::filesystem::path& bytecode_path,
152 const std::filesystem::path& output_dir)
156 if (output_dir ==
"-") {
157 throw_or_abort(
"Stdout output is not supported. Please specify an output directory.");
169 .settings = settings }
172 write_vk_outputs(response, output_dir, flags);
176 [[maybe_unused]]
const std::filesystem::path& bytecode_path)
183 std::string functions_string =
"{\"functions\": [\n ";
189 .oracle_hash_type = flags.oracle_hash_type,
190 .disable_zk = flags.disable_zk };
194 .include_gates_per_opcode = flags.include_gates_per_opcode,
195 .settings = settings }
198 vinfo(
"Calculated circuit size in gate_count: ", response.num_gates);
201 std::string gates_per_opcode_str;
202 if (flags.include_gates_per_opcode) {
204 for (
size_t count : response.gates_per_opcode) {
206 gates_per_opcode_str +=
",";
215 auto result_string =
format(
216 "{\n \"acir_opcodes\": ",
217 response.num_acir_opcodes,
218 ",\n \"circuit_size\": ",
220 (flags.include_gates_per_opcode ?
format(
",\n \"gates_per_opcode\": [", gates_per_opcode_str,
"]") :
""),
223 functions_string =
format(functions_string, result_string);
228 const std::filesystem::path& output_path,
229 const std::filesystem::path& vk_path)
245 if (output_path ==
"-") {
248 write_file(output_path, { response.solidity_code.begin(), response.solidity_code.end() });
250 info(
"Honk solidity verifier saved to ", output_path);
252 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::string build_json_output(const std::vector< T > &fields, const std::string &file_kind, const API::Flags &flags, const std::string &vk_hash="")
Build JSON output string using msgpack serialization.
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::vector< uint8_t > read_file(const std::string &filename, size_t bytes=0)
void write_file(const std::string &filename, std::vector< uint8_t > const &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
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)