17#pragma clang diagnostic push
18#pragma clang diagnostic ignored "-Wsign-conversion"
20#include <nlohmann/json.hpp>
22#pragma clang diagnostic pop
34 for (
const auto&
byte : bytes) {
35 ss << std::setw(2) << static_cast<int>(
byte);
49 for (
const auto&
byte : content) {
50 if (
std::isspace(
static_cast<unsigned char>(
byte)) != 0) {
61 std::string str(content.begin(), content.end());
62 return nlohmann::json::parse(str);
73 std::string str = hex_str;
75 if (str.size() >= 2 && str[0] ==
'0' && (str[1] ==
'x' || str[1] ==
'X')) {
79 if (str.size() < 64) {
80 str.insert(0, 64 - str.size(),
'0');
89 std::vector<std::string>
vk;
99 std::vector<std::string> hex_fields;
100 hex_fields.reserve(fields.size());
101 for (
const auto&
field : fields) {
102 std::stringstream ss;
104 hex_fields.push_back(ss.str());
110 msgpack::pack(
buffer, output);
111 msgpack::object_handle oh = msgpack::unpack(
buffer.data(),
buffer.size());
113 std::stringstream ss;
120 if (!json.contains(
"vk") || !json[
"vk"].is_array()) {
123 std::vector<uint8_t> result;
124 result.reserve(json[
"vk"].size() * 32);
125 for (
const auto&
field : json[
"vk"]) {
127 for (
int i = 3; i >= 0; --i) {
129 for (
int j = 7; j >= 0; --j) {
130 result.push_back(
static_cast<uint8_t
>((limb >> (j * 8)) & 0xFF));
149 template <
typename T>
152 std::vector<std::string> hex_fields;
153 hex_fields.reserve(fields.size());
154 for (
const auto&
field : fields) {
155 std::stringstream ss;
157 hex_fields.push_back(ss.str());
165 msgpack::pack(
buffer, output);
166 msgpack::object_handle oh = msgpack::unpack(
buffer.data(),
buffer.size());
168 std::stringstream ss;
175 if (!json.contains(
"proof") || !json[
"proof"].is_array()) {
179 result.reserve(json[
"proof"].size());
180 for (
const auto&
field : json[
"proof"]) {
199 std::vector<std::string> hex_fields;
200 hex_fields.reserve(fields.size());
201 for (
const auto&
field : fields) {
202 std::stringstream ss;
204 hex_fields.push_back(ss.str());
210 msgpack::pack(
buffer, output);
211 msgpack::object_handle oh = msgpack::unpack(
buffer.data(),
buffer.size());
213 std::stringstream ss;
220 if (!json.contains(
"public_inputs") || !json[
"public_inputs"].is_array()) {
224 result.reserve(json[
"public_inputs"].size());
225 for (
const auto&
field : json[
"public_inputs"]) {
std::unique_ptr< uint8_t[]> buffer
Entry point for Barretenberg command-line interface.
std::optional< nlohmann::json > try_parse_json(const std::vector< uint8_t > &content)
Try to parse file content as JSON.
uint256_t hex_string_to_uint256(const std::string &hex_str)
Parse a hex string (with or without 0x prefix) to uint256_t.
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
Serializable structure for proof JSON output (msgpack-compatible)
std::vector< std::string > proof
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)
MSGPACK_FIELDS(proof, vk_hash, bb_version, scheme)
Serializable structure for VK JSON output (msgpack-compatible)
MSGPACK_FIELDS(vk, hash, bb_version, scheme)
std::vector< std::string > vk
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)
General class for prime fields see Prime field documentation["field documentation"] for general imple...
void throw_or_abort(std::string const &err)