Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
json_output.hpp
Go to the documentation of this file.
1#pragma once
2
7#include <iomanip>
8#include <sstream>
9#include <string>
10#include <vector>
11
12namespace bb {
13
17inline std::string bytes_to_hex_string(const std::vector<uint8_t>& bytes)
18{
19 std::stringstream ss;
20 ss << "0x" << std::hex << std::setfill('0');
21 for (const auto& byte : bytes) {
22 ss << std::setw(2) << static_cast<int>(byte);
23 }
24 return ss.str();
25}
26
30struct JsonOutput {
31 std::vector<std::string> fields;
32 std::string vk_hash; // Only for VK and proof (hash of VK the proof targets)
33 std::string file_kind; // "vk", "proof", or "public_inputs"
34 std::string bb_version;
35 std::string scheme;
36 std::string verifier_target; // Optional
37
39};
40
51template <typename T>
52std::string build_json_output(const std::vector<T>& fields,
53 const std::string& file_kind,
54 const API::Flags& flags,
55 const std::string& vk_hash = "")
56{
57 std::vector<std::string> hex_fields;
58 hex_fields.reserve(fields.size());
59 for (const auto& field : fields) {
60 std::stringstream ss;
61 ss << field; // T's operator<< outputs "0x" prefix
62 hex_fields.push_back(ss.str());
63 }
64
65 JsonOutput output{
66 .fields = std::move(hex_fields),
67 .vk_hash = vk_hash,
68 .file_kind = file_kind,
69 .bb_version = BB_VERSION,
70 .scheme = flags.scheme,
71 .verifier_target = flags.verifier_target,
72 };
73
74 msgpack::sbuffer buffer;
75 msgpack::pack(buffer, output);
76 msgpack::object_handle oh = msgpack::unpack(buffer.data(), buffer.size());
77
78 std::stringstream ss;
79 ss << oh.get();
80 return ss.str();
81}
82
83} // namespace bb
uint8_t buffer[RANDOM_BUFFER_SIZE]
Definition engine.cpp:34
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
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.
const char * BB_VERSION
Definition version.hpp:14
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
Definition tuple.hpp:13
std::string verifier_target
Definition api.hpp:20
std::string scheme
Definition api.hpp:18
Serializable structure for JSON output (msgpack-compatible)
MSGPACK_FIELDS(fields, vk_hash, file_kind, bb_version, scheme, verifier_target)
std::string bb_version
std::string file_kind
std::string scheme
std::vector< std::string > fields
std::string verifier_target
std::string vk_hash
General class for prime fields see Prime field documentation["field documentation"] for general imple...