24void write_vk_outputs(
const bbapi::CircuitComputeVk::Response& vk_response,
25 const std::string& output_format,
26 const std::filesystem::path& output_dir)
28 if (output_format ==
"bytes" || output_format ==
"bytes_and_fields") {
29 write_file(output_dir /
"vk", vk_response.bytes);
30 info(
"VK saved to ", output_dir /
"vk");
31 write_file(output_dir /
"vk_hash", vk_response.hash);
32 info(
"VK Hash saved to ", output_dir /
"vk_hash");
35 if (output_format ==
"fields" || output_format ==
"bytes_and_fields") {
38 write_file(output_dir /
"vk_fields.json", { vk_json.begin(), vk_json.end() });
39 info(
"VK fields saved to ", output_dir /
"vk_fields.json");
42 auto vk_hash_fr = from_buffer<fr>(vk_response.hash);
43 std::string vk_hash_json =
format(
"\"", vk_hash_fr,
"\"");
44 write_file(output_dir /
"vk_hash_fields.json", { vk_hash_json.begin(), vk_hash_json.end() });
45 info(
"VK Hash fields saved to ", output_dir /
"vk_hash_fields.json");
49void write_proof_outputs(
const bbapi::CircuitProve::Response& prove_response,
50 const std::string& output_format,
51 const std::filesystem::path& output_dir)
53 if (output_format ==
"bytes" || output_format ==
"bytes_and_fields") {
54 auto public_inputs_buf =
to_buffer(prove_response.public_inputs);
55 auto proof_buf =
to_buffer(prove_response.proof);
57 write_file(output_dir /
"public_inputs", public_inputs_buf);
59 info(
"Public inputs saved to ", output_dir /
"public_inputs");
60 info(
"Proof saved to ", output_dir /
"proof");
63 if (output_format ==
"fields" || output_format ==
"bytes_and_fields") {
67 write_file(output_dir /
"public_inputs_fields.json", { public_inputs_json.begin(), public_inputs_json.end() });
68 write_file(output_dir /
"proof_fields.json", { proof_json.begin(), proof_json.end() });
69 info(
"Public inputs fields saved to ", output_dir /
"public_inputs_fields.json");
70 info(
"Proof fields saved to ", output_dir /
"proof_fields.json");
76 [[maybe_unused]]
const std::filesystem::path& bytecode_path,
77 [[maybe_unused]]
const std::filesystem::path& witness_path)
84 const std::filesystem::path& bytecode_path,
85 const std::filesystem::path& witness_path,
86 const std::filesystem::path& vk_path,
87 const std::filesystem::path& output_dir)
90 if (output_dir ==
"-") {
91 throw_or_abort(
"Stdout output is not supported. Please specify an output directory.");
99 std::vector<uint8_t> vk_bytes;
100 if (!vk_path.empty() && !flags.
write_vk) {
107 .verification_key =
std::move(vk_bytes) },
113 write_proof_outputs(response, flags.
output_format, output_dir);
115 write_vk_outputs(response.vk, flags.
output_format, output_dir);
120 const std::filesystem::path& public_inputs_path,
121 const std::filesystem::path& proof_path,
122 const std::filesystem::path& vk_path)
125 auto public_inputs = many_from_buffer<uint256_t>(
read_file(public_inputs_path));
126 auto proof = many_from_buffer<uint256_t>(
read_file(proof_path));
136 .public_inputs =
std::move(public_inputs),
138 .settings = settings }
141 return response.verified;
145 [[maybe_unused]]
const std::filesystem::path& bytecode_path,
146 [[maybe_unused]]
const std::filesystem::path& witness_path)
153 const std::filesystem::path& bytecode_path,
154 const std::filesystem::path& output_dir)
157 if (output_dir ==
"-") {
158 throw_or_abort(
"Stdout output is not supported. Please specify an output directory.");
171 .settings = settings }
179 [[maybe_unused]]
const std::filesystem::path& bytecode_path)
185 std::string functions_string =
"{\"functions\": [\n ";
191 .oracle_hash_type = flags.oracle_hash_type,
192 .disable_zk = flags.disable_zk };
196 .include_gates_per_opcode = flags.include_gates_per_opcode,
197 .settings = settings }
200 vinfo(
"Calculated circuit size in gate_count: ", response.num_gates);
203 std::string gates_per_opcode_str;
204 if (flags.include_gates_per_opcode) {
206 for (
size_t count : response.gates_per_opcode) {
208 gates_per_opcode_str +=
",";
217 auto result_string =
format(
218 "{\n \"acir_opcodes\": ",
219 response.num_acir_opcodes,
220 ",\n \"circuit_size\": ",
222 (flags.include_gates_per_opcode ?
format(
",\n \"gates_per_opcode\": [", gates_per_opcode_str,
"]") :
""),
225 functions_string =
format(functions_string, result_string);
230 const std::filesystem::path& output_path,
231 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);
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_file(const std::string &filename, size_t bytes=0)
void write_file(const std::string &filename, std::vector< uint8_t > const &data)
std::string field_elements_to_json(const std::vector< Fr > &fields)
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)
std::string oracle_hash_type
std::string output_format
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)