From 5d95bb4f2a2c358f58d9223535876c545cb50371 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Mon, 17 Mar 2025 10:39:02 +0000 Subject: [PATCH 01/36] Commands to copy and format generated files --- barretenberg/cpp/src/barretenberg/dsl/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/dsl/README.md b/barretenberg/cpp/src/barretenberg/dsl/README.md index 9b0ecc0cb843..440eec6c4a8b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/README.md +++ b/barretenberg/cpp/src/barretenberg/dsl/README.md @@ -17,6 +17,15 @@ You will have to update a couple things in the new `acir.hpp`: The same can then be done for any breaking changes introduced to `witness_stack.hpp`. +The steps described above can be executed like so: + +```shell +cd noir/noir-repo && NOIR_CODEGEN_OVERWRITE=1 cargo test -p acir cpp_codegen && cd - +cp noir/noir-repo/acvm-repo/acir/codegen/acir.cpp barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +cp noir/noir-repo/acvm-repo/acir/codegen/witness.cpp barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp +cd barretenberg/cpp && ./format.sh changed && cd - +``` + 2. Full Breaking Change This type of breaking change is rarely expected to happen, however, due to its nature there are multiple consumers of the pre-existing serialization you should be aware of if you ever need to make this change. From c1bdb0dcfd518e02170607abfea9677634e8d0d6 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 18 Mar 2025 11:10:32 +0000 Subject: [PATCH 02/36] Set noir to the feature branch --- noir/noir-repo-ref | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noir/noir-repo-ref b/noir/noir-repo-ref index 025d5572874b..8cda881454fb 100644 --- a/noir/noir-repo-ref +++ b/noir/noir-repo-ref @@ -1 +1 @@ -nightly-2025-03-18 +af/msgpack-codegen From f99c869564899e8ad66cfb078db2a4486360f733 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 18 Mar 2025 12:58:59 +0000 Subject: [PATCH 03/36] Change C++ codegen for serde/msgpack --- .../acir_format/acir_to_constraint_buf.cpp | 98 +- .../dsl/acir_format/serde/acir.hpp | 3734 ++++++++++++----- .../dsl/acir_format/serde/witness_stack.hpp | 66 +- 3 files changed, 2738 insertions(+), 1160 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 7a0921b55270..c582220ef956 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -20,10 +20,10 @@ using namespace bb; * * @param arg acir representation of an 3-wire arithmetic operation * @return poly_triple - * @note In principle Program::Expression can accommodate arbitrarily many quadratic and linear terms but in practice + * @note In principle Acir::Expression can accommodate arbitrarily many quadratic and linear terms but in practice * the ones processed here have a max of 1 and 3 respectively, in accordance with the standard width-3 arithmetic gate. */ -poly_triple serialize_arithmetic_gate(Program::Expression const& arg) +poly_triple serialize_arithmetic_gate(Acir::Expression const& arg) { poly_triple pt{ .a = 0, @@ -129,7 +129,7 @@ void assign_linear_term(mul_quad_& gate, int index, uint32_t witness_index, } /// Accumulate the input expression into a serie of quad gates -std::vector> split_into_mul_quad_gates(Program::Expression const& arg) +std::vector> split_into_mul_quad_gates(Acir::Expression const& arg) { std::vector> result; auto current_mul_term = arg.mul_terms.begin(); @@ -230,7 +230,7 @@ std::vector> split_into_mul_quad_gates(Program::Expression const& return result; } -mul_quad_ serialize_mul_quad_gate(Program::Expression const& arg) +mul_quad_ serialize_mul_quad_gate(Acir::Expression const& arg) { mul_quad_ quad{ .a = 0, .b = 0, @@ -301,7 +301,7 @@ mul_quad_ serialize_mul_quad_gate(Program::Expression const& arg) return quad; } -void constrain_witnesses(Program::Opcode::AssertZero const& arg, AcirFormat& af) +void constrain_witnesses(Acir::Opcode::AssertZero const& arg, AcirFormat& af) { for (const auto& linear_term : arg.value.linear_combinations) { uint32_t witness_idx = std::get<1>(linear_term).value; @@ -315,7 +315,7 @@ void constrain_witnesses(Program::Opcode::AssertZero const& arg, AcirFormat& af) } } -std::pair is_assert_equal(Program::Opcode::AssertZero const& arg, +std::pair is_assert_equal(Acir::Opcode::AssertZero const& arg, poly_triple const& pt, AcirFormat const& af) { @@ -331,7 +331,7 @@ std::pair is_assert_equal(Program::Opcode::AssertZero const& return { 0, 0 }; } -void handle_arithmetic(Program::Opcode::AssertZero const& arg, AcirFormat& af, size_t opcode_index) +void handle_arithmetic(Acir::Opcode::AssertZero const& arg, AcirFormat& af, size_t opcode_index) { // If the expression fits in a polytriple, we use it. if (arg.value.linear_combinations.size() <= 3 && arg.value.mul_terms.size() <= 1) { @@ -409,24 +409,24 @@ void handle_arithmetic(Program::Opcode::AssertZero const& arg, AcirFormat& af, s } constrain_witnesses(arg, af); } -uint32_t get_witness_from_function_input(Program::FunctionInput input) +uint32_t get_witness_from_function_input(Acir::FunctionInput input) { - auto input_witness = std::get(input.input.value); + auto input_witness = std::get(input.input.value); return input_witness.value.value; } -WitnessOrConstant parse_input(Program::FunctionInput input) +WitnessOrConstant parse_input(Acir::FunctionInput input) { WitnessOrConstant result = std::visit( [&](auto&& e) { using T = std::decay_t; - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { return WitnessOrConstant{ .index = e.value.value, .value = bb::fr::zero(), .is_constant = false, }; - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { return WitnessOrConstant{ .index = 0, .value = uint256_t(e.value), @@ -445,7 +445,7 @@ WitnessOrConstant parse_input(Program::FunctionInput input) return result; } -void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, +void handle_blackbox_func_call(Acir::Opcode::BlackBoxFuncCall const& arg, AcirFormat& af, uint32_t honk_recursion, size_t opcode_index) @@ -453,7 +453,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, std::visit( [&](auto&& arg) { using T = std::decay_t; - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { auto lhs_input = parse_input(arg.lhs); auto rhs_input = parse_input(arg.rhs); af.logic_constraints.push_back(LogicConstraint{ @@ -465,7 +465,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, }); af.constrained_witness.insert(af.logic_constraints.back().result); af.original_opcode_indices.logic_constraints.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { auto lhs_input = parse_input(arg.lhs); auto rhs_input = parse_input(arg.rhs); af.logic_constraints.push_back(LogicConstraint{ @@ -477,7 +477,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, }); af.constrained_witness.insert(af.logic_constraints.back().result); af.original_opcode_indices.logic_constraints.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { auto witness_input = get_witness_from_function_input(arg.input); af.range_constraints.push_back(RangeConstraint{ .witness = witness_input, @@ -491,7 +491,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, } else { af.minimal_range[witness_input] = arg.input.num_bits; } - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.aes128_constraints.push_back(AES128Constraint{ .inputs = map(arg.inputs, [](auto& e) { return parse_input(e); }), .iv = map(arg.iv, [](auto& e) { return parse_input(e); }), @@ -502,7 +502,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, af.constrained_witness.insert(output); } af.original_opcode_indices.aes128_constraints.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.sha256_compression.push_back(Sha256Compression{ .inputs = map(arg.inputs, [](auto& e) { return parse_input(e); }), .hash_values = map(arg.hash_values, [](auto& e) { return parse_input(e); }), @@ -512,7 +512,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, af.constrained_witness.insert(output); } af.original_opcode_indices.sha256_compression.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.blake2s_constraints.push_back(Blake2sConstraint{ .inputs = map(arg.inputs, [](auto& e) { @@ -527,7 +527,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, af.constrained_witness.insert(output); } af.original_opcode_indices.blake2s_constraints.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.blake3_constraints.push_back(Blake3Constraint{ .inputs = map(arg.inputs, [](auto& e) { @@ -542,7 +542,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, af.constrained_witness.insert(output); } af.original_opcode_indices.blake3_constraints.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.ecdsa_k1_constraints.push_back(EcdsaSecp256k1Constraint{ .hashed_message = map(arg.hashed_message, [](auto& e) { return get_witness_from_function_input(e); }), @@ -553,7 +553,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, }); af.constrained_witness.insert(af.ecdsa_k1_constraints.back().result); af.original_opcode_indices.ecdsa_k1_constraints.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.ecdsa_r1_constraints.push_back(EcdsaSecp256r1Constraint{ .hashed_message = map(arg.hashed_message, [](auto& e) { return get_witness_from_function_input(e); }), @@ -564,7 +564,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, }); af.constrained_witness.insert(af.ecdsa_r1_constraints.back().result); af.original_opcode_indices.ecdsa_r1_constraints.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.multi_scalar_mul_constraints.push_back(MultiScalarMul{ .points = map(arg.points, [](auto& e) { return parse_input(e); }), .scalars = map(arg.scalars, [](auto& e) { return parse_input(e); }), @@ -576,7 +576,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, af.constrained_witness.insert(af.multi_scalar_mul_constraints.back().out_point_y); af.constrained_witness.insert(af.multi_scalar_mul_constraints.back().out_point_is_infinite); af.original_opcode_indices.multi_scalar_mul_constraints.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { auto input_1_x = parse_input(arg.input1[0]); auto input_1_y = parse_input(arg.input1[1]); auto input_1_infinite = parse_input(arg.input1[2]); @@ -599,7 +599,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, af.constrained_witness.insert(af.ec_add_constraints.back().result_y); af.constrained_witness.insert(af.ec_add_constraints.back().result_infinite); af.original_opcode_indices.ec_add_constraints.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.keccak_permutations.push_back(Keccakf1600{ .state = map(arg.inputs, [](auto& e) { return parse_input(e); }), .result = map(arg.outputs, [](auto& e) { return e.value; }), @@ -608,7 +608,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, af.constrained_witness.insert(output); } af.original_opcode_indices.keccak_permutations.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { auto input_key = get_witness_from_function_input(arg.key_hash); @@ -658,14 +658,14 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, info("Invalid PROOF_TYPE in RecursionConstraint!"); ASSERT(false); } - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.bigint_from_le_bytes_constraints.push_back(BigIntFromLeBytes{ .inputs = map(arg.inputs, [](auto& e) { return get_witness_from_function_input(e); }), .modulus = map(arg.modulus, [](auto& e) -> uint32_t { return e; }), .result = arg.output, }); af.original_opcode_indices.bigint_from_le_bytes_constraints.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.bigint_to_le_bytes_constraints.push_back(BigIntToLeBytes{ .input = arg.input, .result = map(arg.outputs, [](auto& e) { return e.value; }), @@ -674,7 +674,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, af.constrained_witness.insert(output); } af.original_opcode_indices.bigint_to_le_bytes_constraints.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.bigint_operations.push_back(BigIntOperation{ .lhs = arg.lhs, .rhs = arg.rhs, @@ -682,7 +682,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, .opcode = BigIntOperationType::Add, }); af.original_opcode_indices.bigint_operations.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.bigint_operations.push_back(BigIntOperation{ .lhs = arg.lhs, .rhs = arg.rhs, @@ -690,7 +690,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, .opcode = BigIntOperationType::Sub, }); af.original_opcode_indices.bigint_operations.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.bigint_operations.push_back(BigIntOperation{ .lhs = arg.lhs, .rhs = arg.rhs, @@ -698,7 +698,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, .opcode = BigIntOperationType::Mul, }); af.original_opcode_indices.bigint_operations.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.bigint_operations.push_back(BigIntOperation{ .lhs = arg.lhs, .rhs = arg.rhs, @@ -706,7 +706,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, .opcode = BigIntOperationType::Div, }); af.original_opcode_indices.bigint_operations.push_back(opcode_index); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { af.poseidon2_constraints.push_back(Poseidon2Constraint{ .state = map(arg.inputs, [](auto& e) { return parse_input(e); }), .result = map(arg.outputs, [](auto& e) { return e.value; }), @@ -721,7 +721,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, arg.value.value); } -BlockConstraint handle_memory_init(Program::Opcode::MemoryInit const& mem_init) +BlockConstraint handle_memory_init(Acir::Opcode::MemoryInit const& mem_init) { BlockConstraint block{ .init = {}, .trace = {}, .type = BlockType::ROM }; std::vector init; @@ -743,23 +743,23 @@ BlockConstraint handle_memory_init(Program::Opcode::MemoryInit const& mem_init) // Databus is only supported for Goblin, non Goblin builders will treat call_data and return_data as normal // array. - if (std::holds_alternative(mem_init.block_type.value)) { + if (std::holds_alternative(mem_init.block_type.value)) { block.type = BlockType::CallData; - block.calldata_id = std::get(mem_init.block_type.value).value; - } else if (std::holds_alternative(mem_init.block_type.value)) { + block.calldata_id = std::get(mem_init.block_type.value).value; + } else if (std::holds_alternative(mem_init.block_type.value)) { block.type = BlockType::ReturnData; } return block; } -bool is_rom(Program::MemOp const& mem_op) +bool is_rom(Acir::MemOp const& mem_op) { return mem_op.operation.mul_terms.size() == 0 && mem_op.operation.linear_combinations.size() == 0 && uint256_t(mem_op.operation.q_c) == 0; } -void handle_memory_op(Program::Opcode::MemoryOp const& mem_op, BlockConstraint& block) +void handle_memory_op(Acir::Opcode::MemoryOp const& mem_op, BlockConstraint& block) { uint8_t access_type = 1; if (is_rom(mem_op.op)) { @@ -777,7 +777,7 @@ void handle_memory_op(Program::Opcode::MemoryOp const& mem_op, BlockConstraint& block.trace.push_back(acir_mem_op); } -AcirFormat circuit_serde_to_acir_format(Program::Circuit const& circuit, uint32_t honk_recursion) +AcirFormat circuit_serde_to_acir_format(Acir::Circuit const& circuit, uint32_t honk_recursion) { AcirFormat af; // `varnum` is the true number of variables, thus we add one to the index which starts at zero @@ -792,16 +792,16 @@ AcirFormat circuit_serde_to_acir_format(Program::Circuit const& circuit, uint32_ std::visit( [&](auto&& arg) { using T = std::decay_t; - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v) { handle_arithmetic(arg, af, i); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { handle_blackbox_func_call(arg, af, honk_recursion, i); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { auto block = handle_memory_init(arg); uint32_t block_id = arg.block_id.value; std::vector opcode_indices = { i }; block_id_to_block_constraint[block_id] = std::make_pair(block, opcode_indices); - } else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v) { auto block = block_id_to_block_constraint.find(arg.block_id.value); if (block == block_id_to_block_constraint.end()) { throw_or_abort("unitialized MemoryOp"); @@ -828,7 +828,7 @@ AcirFormat circuit_buf_to_acir_format(std::vector const& buf, uint32_t // TODO(https://github.com/AztecProtocol/barretenberg/issues/927): Move to using just // `program_buf_to_acir_format` once Honk fully supports all ACIR test flows For now the backend still expects // to work with a single ACIR function - auto circuit = Program::Program::bincodeDeserialize(buf).functions[0]; + auto circuit = Acir::Program::bincodeDeserialize(buf).functions[0]; return circuit_serde_to_acir_format(circuit, honk_recursion); } @@ -841,7 +841,7 @@ AcirFormat circuit_buf_to_acir_format(std::vector const& buf, uint32_t * @note This transformation results in all unassigned witnesses within the `WitnessMap` being assigned the value 0. * Converting the `WitnessVector` back to a `WitnessMap` is unlikely to return the exact same `WitnessMap`. */ -WitnessVector witness_map_to_witness_vector(WitnessStack::WitnessMap const& witness_map) +WitnessVector witness_map_to_witness_vector(Witnesses::WitnessMap const& witness_map) { WitnessVector wv; size_t index = 0; @@ -872,7 +872,7 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) // TODO(https://github.com/AztecProtocol/barretenberg/issues/927): Move to using just // `witness_buf_to_witness_stack` once Honk fully supports all ACIR test flows. For now the backend still // expects to work with the stop of the `WitnessStack`. - auto witness_stack = WitnessStack::WitnessStack::bincodeDeserialize(buf); + auto witness_stack = Witnesses::WitnessStack::bincodeDeserialize(buf); auto w = witness_stack.stack[witness_stack.stack.size() - 1].witness; return witness_map_to_witness_vector(w); @@ -880,7 +880,7 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) std::vector program_buf_to_acir_format(std::vector const& buf, uint32_t honk_recursion) { - auto program = Program::Program::bincodeDeserialize(buf); + auto program = Acir::Program::bincodeDeserialize(buf); std::vector constraint_systems; constraint_systems.reserve(program.functions.size()); @@ -893,7 +893,7 @@ std::vector program_buf_to_acir_format(std::vector const& b WitnessVectorStack witness_buf_to_witness_stack(std::vector const& buf) { - auto witness_stack = WitnessStack::WitnessStack::bincodeDeserialize(buf); + auto witness_stack = Witnesses::WitnessStack::bincodeDeserialize(buf); WitnessVectorStack witness_vector_stack; witness_vector_stack.reserve(witness_stack.stack.size()); for (auto const& stack_item : witness_stack.stack) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index 5d9d94d25e38..dcdc6dbd79f4 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -1,9 +1,10 @@ #pragma once #include "bincode.hpp" +#include "msgpack.hpp" #include "serde.hpp" -namespace Program { +namespace Acir { struct BinaryFieldOp { @@ -11,48 +12,72 @@ struct BinaryFieldOp { friend bool operator==(const Add&, const Add&); std::vector bincodeSerialize() const; static Add bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Sub { friend bool operator==(const Sub&, const Sub&); std::vector bincodeSerialize() const; static Sub bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Mul { friend bool operator==(const Mul&, const Mul&); std::vector bincodeSerialize() const; static Mul bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Div { friend bool operator==(const Div&, const Div&); std::vector bincodeSerialize() const; static Div bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct IntegerDiv { friend bool operator==(const IntegerDiv&, const IntegerDiv&); std::vector bincodeSerialize() const; static IntegerDiv bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Equals { friend bool operator==(const Equals&, const Equals&); std::vector bincodeSerialize() const; static Equals bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct LessThan { friend bool operator==(const LessThan&, const LessThan&); std::vector bincodeSerialize() const; static LessThan bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct LessThanEquals { friend bool operator==(const LessThanEquals&, const LessThanEquals&); std::vector bincodeSerialize() const; static LessThanEquals bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; std::variant value; @@ -60,6 +85,90 @@ struct BinaryFieldOp { friend bool operator==(const BinaryFieldOp&, const BinaryFieldOp&); std::vector bincodeSerialize() const; static BinaryFieldOp bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "Add"; + break; + case 1: + tag = "Sub"; + break; + case 2: + tag = "Mul"; + break; + case 3: + tag = "Div"; + break; + case 4: + tag = "IntegerDiv"; + break; + case 5: + tag = "Equals"; + break; + case 6: + tag = "LessThan"; + break; + case 7: + tag = "LessThanEquals"; + break; + default: + throw_or_abort("unknown 'BinaryFieldOp' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "Add") { + Add v; + obj.convert(v); + value = v; + } else if (tag == "Sub") { + Sub v; + obj.convert(v); + value = v; + } else if (tag == "Mul") { + Mul v; + obj.convert(v); + value = v; + } else if (tag == "Div") { + Div v; + obj.convert(v); + value = v; + } else if (tag == "IntegerDiv") { + IntegerDiv v; + obj.convert(v); + value = v; + } else if (tag == "Equals") { + Equals v; + obj.convert(v); + value = v; + } else if (tag == "LessThan") { + LessThan v; + obj.convert(v); + value = v; + } else if (tag == "LessThanEquals") { + LessThanEquals v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'BinaryFieldOp' enum variant: " + tag); + } + } }; struct BinaryIntOp { @@ -68,72 +177,108 @@ struct BinaryIntOp { friend bool operator==(const Add&, const Add&); std::vector bincodeSerialize() const; static Add bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Sub { friend bool operator==(const Sub&, const Sub&); std::vector bincodeSerialize() const; static Sub bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Mul { friend bool operator==(const Mul&, const Mul&); std::vector bincodeSerialize() const; static Mul bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Div { friend bool operator==(const Div&, const Div&); std::vector bincodeSerialize() const; static Div bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Equals { friend bool operator==(const Equals&, const Equals&); std::vector bincodeSerialize() const; static Equals bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct LessThan { friend bool operator==(const LessThan&, const LessThan&); std::vector bincodeSerialize() const; static LessThan bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct LessThanEquals { friend bool operator==(const LessThanEquals&, const LessThanEquals&); std::vector bincodeSerialize() const; static LessThanEquals bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct And { friend bool operator==(const And&, const And&); std::vector bincodeSerialize() const; static And bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Or { friend bool operator==(const Or&, const Or&); std::vector bincodeSerialize() const; static Or bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Xor { friend bool operator==(const Xor&, const Xor&); std::vector bincodeSerialize() const; static Xor bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Shl { friend bool operator==(const Shl&, const Shl&); std::vector bincodeSerialize() const; static Shl bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Shr { friend bool operator==(const Shr&, const Shr&); std::vector bincodeSerialize() const; static Shr bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; std::variant value; @@ -141,6 +286,118 @@ struct BinaryIntOp { friend bool operator==(const BinaryIntOp&, const BinaryIntOp&); std::vector bincodeSerialize() const; static BinaryIntOp bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "Add"; + break; + case 1: + tag = "Sub"; + break; + case 2: + tag = "Mul"; + break; + case 3: + tag = "Div"; + break; + case 4: + tag = "Equals"; + break; + case 5: + tag = "LessThan"; + break; + case 6: + tag = "LessThanEquals"; + break; + case 7: + tag = "And"; + break; + case 8: + tag = "Or"; + break; + case 9: + tag = "Xor"; + break; + case 10: + tag = "Shl"; + break; + case 11: + tag = "Shr"; + break; + default: + throw_or_abort("unknown 'BinaryIntOp' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "Add") { + Add v; + obj.convert(v); + value = v; + } else if (tag == "Sub") { + Sub v; + obj.convert(v); + value = v; + } else if (tag == "Mul") { + Mul v; + obj.convert(v); + value = v; + } else if (tag == "Div") { + Div v; + obj.convert(v); + value = v; + } else if (tag == "Equals") { + Equals v; + obj.convert(v); + value = v; + } else if (tag == "LessThan") { + LessThan v; + obj.convert(v); + value = v; + } else if (tag == "LessThanEquals") { + LessThanEquals v; + obj.convert(v); + value = v; + } else if (tag == "And") { + And v; + obj.convert(v); + value = v; + } else if (tag == "Or") { + Or v; + obj.convert(v); + value = v; + } else if (tag == "Xor") { + Xor v; + obj.convert(v); + value = v; + } else if (tag == "Shl") { + Shl v; + obj.convert(v); + value = v; + } else if (tag == "Shr") { + Shr v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'BinaryIntOp' enum variant: " + tag); + } + } }; struct IntegerBitSize { @@ -149,36 +406,54 @@ struct IntegerBitSize { friend bool operator==(const U1&, const U1&); std::vector bincodeSerialize() const; static U1 bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct U8 { friend bool operator==(const U8&, const U8&); std::vector bincodeSerialize() const; static U8 bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct U16 { friend bool operator==(const U16&, const U16&); std::vector bincodeSerialize() const; static U16 bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct U32 { friend bool operator==(const U32&, const U32&); std::vector bincodeSerialize() const; static U32 bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct U64 { friend bool operator==(const U64&, const U64&); std::vector bincodeSerialize() const; static U64 bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct U128 { friend bool operator==(const U128&, const U128&); std::vector bincodeSerialize() const; static U128 bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; std::variant value; @@ -186,6 +461,76 @@ struct IntegerBitSize { friend bool operator==(const IntegerBitSize&, const IntegerBitSize&); std::vector bincodeSerialize() const; static IntegerBitSize bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "U1"; + break; + case 1: + tag = "U8"; + break; + case 2: + tag = "U16"; + break; + case 3: + tag = "U32"; + break; + case 4: + tag = "U64"; + break; + case 5: + tag = "U128"; + break; + default: + throw_or_abort("unknown 'IntegerBitSize' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "U1") { + U1 v; + obj.convert(v); + value = v; + } else if (tag == "U8") { + U8 v; + obj.convert(v); + value = v; + } else if (tag == "U16") { + U16 v; + obj.convert(v); + value = v; + } else if (tag == "U32") { + U32 v; + obj.convert(v); + value = v; + } else if (tag == "U64") { + U64 v; + obj.convert(v); + value = v; + } else if (tag == "U128") { + U128 v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'IntegerBitSize' enum variant: " + tag); + } + } }; struct BitSize { @@ -194,14 +539,20 @@ struct BitSize { friend bool operator==(const Field&, const Field&); std::vector bincodeSerialize() const; static Field bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Integer { - Program::IntegerBitSize value; + Acir::IntegerBitSize value; friend bool operator==(const Integer&, const Integer&); std::vector bincodeSerialize() const; static Integer bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; std::variant value; @@ -209,6 +560,48 @@ struct BitSize { friend bool operator==(const BitSize&, const BitSize&); std::vector bincodeSerialize() const; static BitSize bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "Field"; + break; + case 1: + tag = "Integer"; + break; + default: + throw_or_abort("unknown 'BitSize' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "Field") { + Field v; + obj.convert(v); + value = v; + } else if (tag == "Integer") { + Integer v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'BitSize' enum variant: " + tag); + } + } }; struct MemoryAddress { @@ -219,6 +612,9 @@ struct MemoryAddress { friend bool operator==(const Direct&, const Direct&); std::vector bincodeSerialize() const; static Direct bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct Relative { @@ -227,6 +623,9 @@ struct MemoryAddress { friend bool operator==(const Relative&, const Relative&); std::vector bincodeSerialize() const; static Relative bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; std::variant value; @@ -234,203 +633,283 @@ struct MemoryAddress { friend bool operator==(const MemoryAddress&, const MemoryAddress&); std::vector bincodeSerialize() const; static MemoryAddress bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "Direct"; + break; + case 1: + tag = "Relative"; + break; + default: + throw_or_abort("unknown 'MemoryAddress' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "Direct") { + Direct v; + obj.convert(v); + value = v; + } else if (tag == "Relative") { + Relative v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'MemoryAddress' enum variant: " + tag); + } + } }; struct HeapArray { - Program::MemoryAddress pointer; + Acir::MemoryAddress pointer; uint64_t size; friend bool operator==(const HeapArray&, const HeapArray&); std::vector bincodeSerialize() const; static HeapArray bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(pointer, size); }; struct HeapVector { - Program::MemoryAddress pointer; - Program::MemoryAddress size; + Acir::MemoryAddress pointer; + Acir::MemoryAddress size; friend bool operator==(const HeapVector&, const HeapVector&); std::vector bincodeSerialize() const; static HeapVector bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(pointer, size); }; struct BlackBoxOp { struct AES128Encrypt { - Program::HeapVector inputs; - Program::HeapArray iv; - Program::HeapArray key; - Program::HeapVector outputs; + Acir::HeapVector inputs; + Acir::HeapArray iv; + Acir::HeapArray key; + Acir::HeapVector outputs; friend bool operator==(const AES128Encrypt&, const AES128Encrypt&); std::vector bincodeSerialize() const; static AES128Encrypt bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(inputs, iv, key, outputs); }; struct Blake2s { - Program::HeapVector message; - Program::HeapArray output; + Acir::HeapVector message; + Acir::HeapArray output; friend bool operator==(const Blake2s&, const Blake2s&); std::vector bincodeSerialize() const; static Blake2s bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(message, output); }; struct Blake3 { - Program::HeapVector message; - Program::HeapArray output; + Acir::HeapVector message; + Acir::HeapArray output; friend bool operator==(const Blake3&, const Blake3&); std::vector bincodeSerialize() const; static Blake3 bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(message, output); }; struct Keccakf1600 { - Program::HeapArray input; - Program::HeapArray output; + Acir::HeapArray input; + Acir::HeapArray output; friend bool operator==(const Keccakf1600&, const Keccakf1600&); std::vector bincodeSerialize() const; static Keccakf1600 bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(input, output); }; struct EcdsaSecp256k1 { - Program::HeapVector hashed_msg; - Program::HeapArray public_key_x; - Program::HeapArray public_key_y; - Program::HeapArray signature; - Program::MemoryAddress result; + Acir::HeapVector hashed_msg; + Acir::HeapArray public_key_x; + Acir::HeapArray public_key_y; + Acir::HeapArray signature; + Acir::MemoryAddress result; friend bool operator==(const EcdsaSecp256k1&, const EcdsaSecp256k1&); std::vector bincodeSerialize() const; static EcdsaSecp256k1 bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(hashed_msg, public_key_x, public_key_y, signature, result); }; struct EcdsaSecp256r1 { - Program::HeapVector hashed_msg; - Program::HeapArray public_key_x; - Program::HeapArray public_key_y; - Program::HeapArray signature; - Program::MemoryAddress result; + Acir::HeapVector hashed_msg; + Acir::HeapArray public_key_x; + Acir::HeapArray public_key_y; + Acir::HeapArray signature; + Acir::MemoryAddress result; friend bool operator==(const EcdsaSecp256r1&, const EcdsaSecp256r1&); std::vector bincodeSerialize() const; static EcdsaSecp256r1 bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(hashed_msg, public_key_x, public_key_y, signature, result); }; struct MultiScalarMul { - Program::HeapVector points; - Program::HeapVector scalars; - Program::HeapArray outputs; + Acir::HeapVector points; + Acir::HeapVector scalars; + Acir::HeapArray outputs; friend bool operator==(const MultiScalarMul&, const MultiScalarMul&); std::vector bincodeSerialize() const; static MultiScalarMul bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(points, scalars, outputs); }; struct EmbeddedCurveAdd { - Program::MemoryAddress input1_x; - Program::MemoryAddress input1_y; - Program::MemoryAddress input1_infinite; - Program::MemoryAddress input2_x; - Program::MemoryAddress input2_y; - Program::MemoryAddress input2_infinite; - Program::HeapArray result; + Acir::MemoryAddress input1_x; + Acir::MemoryAddress input1_y; + Acir::MemoryAddress input1_infinite; + Acir::MemoryAddress input2_x; + Acir::MemoryAddress input2_y; + Acir::MemoryAddress input2_infinite; + Acir::HeapArray result; friend bool operator==(const EmbeddedCurveAdd&, const EmbeddedCurveAdd&); std::vector bincodeSerialize() const; static EmbeddedCurveAdd bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(input1_x, input1_y, input1_infinite, input2_x, input2_y, input2_infinite, result); }; struct BigIntAdd { - Program::MemoryAddress lhs; - Program::MemoryAddress rhs; - Program::MemoryAddress output; + Acir::MemoryAddress lhs; + Acir::MemoryAddress rhs; + Acir::MemoryAddress output; friend bool operator==(const BigIntAdd&, const BigIntAdd&); std::vector bincodeSerialize() const; static BigIntAdd bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntSub { - Program::MemoryAddress lhs; - Program::MemoryAddress rhs; - Program::MemoryAddress output; + Acir::MemoryAddress lhs; + Acir::MemoryAddress rhs; + Acir::MemoryAddress output; friend bool operator==(const BigIntSub&, const BigIntSub&); std::vector bincodeSerialize() const; static BigIntSub bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntMul { - Program::MemoryAddress lhs; - Program::MemoryAddress rhs; - Program::MemoryAddress output; + Acir::MemoryAddress lhs; + Acir::MemoryAddress rhs; + Acir::MemoryAddress output; friend bool operator==(const BigIntMul&, const BigIntMul&); std::vector bincodeSerialize() const; static BigIntMul bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntDiv { - Program::MemoryAddress lhs; - Program::MemoryAddress rhs; - Program::MemoryAddress output; + Acir::MemoryAddress lhs; + Acir::MemoryAddress rhs; + Acir::MemoryAddress output; friend bool operator==(const BigIntDiv&, const BigIntDiv&); std::vector bincodeSerialize() const; static BigIntDiv bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntFromLeBytes { - Program::HeapVector inputs; - Program::HeapVector modulus; - Program::MemoryAddress output; + Acir::HeapVector inputs; + Acir::HeapVector modulus; + Acir::MemoryAddress output; friend bool operator==(const BigIntFromLeBytes&, const BigIntFromLeBytes&); std::vector bincodeSerialize() const; static BigIntFromLeBytes bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(inputs, modulus, output); }; struct BigIntToLeBytes { - Program::MemoryAddress input; - Program::HeapVector output; + Acir::MemoryAddress input; + Acir::HeapVector output; friend bool operator==(const BigIntToLeBytes&, const BigIntToLeBytes&); std::vector bincodeSerialize() const; static BigIntToLeBytes bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(input, output); }; struct Poseidon2Permutation { - Program::HeapVector message; - Program::HeapArray output; - Program::MemoryAddress len; + Acir::HeapVector message; + Acir::HeapArray output; + Acir::MemoryAddress len; friend bool operator==(const Poseidon2Permutation&, const Poseidon2Permutation&); std::vector bincodeSerialize() const; static Poseidon2Permutation bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(message, output, len); }; struct Sha256Compression { - Program::HeapArray input; - Program::HeapArray hash_values; - Program::HeapArray output; + Acir::HeapArray input; + Acir::HeapArray hash_values; + Acir::HeapArray output; friend bool operator==(const Sha256Compression&, const Sha256Compression&); std::vector bincodeSerialize() const; static Sha256Compression bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(input, hash_values, output); }; struct ToRadix { - Program::MemoryAddress input; - Program::MemoryAddress radix; - Program::MemoryAddress output_pointer; - Program::MemoryAddress num_limbs; - Program::MemoryAddress output_bits; + Acir::MemoryAddress input; + Acir::MemoryAddress radix; + Acir::MemoryAddress output_pointer; + Acir::MemoryAddress num_limbs; + Acir::MemoryAddress output_bits; friend bool operator==(const ToRadix&, const ToRadix&); std::vector bincodeSerialize() const; static ToRadix bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(input, radix, output_pointer, num_limbs, output_bits); }; std::variant bincodeSerialize() const; static BlackBoxOp bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "AES128Encrypt"; + break; + case 1: + tag = "Blake2s"; + break; + case 2: + tag = "Blake3"; + break; + case 3: + tag = "Keccakf1600"; + break; + case 4: + tag = "EcdsaSecp256k1"; + break; + case 5: + tag = "EcdsaSecp256r1"; + break; + case 6: + tag = "MultiScalarMul"; + break; + case 7: + tag = "EmbeddedCurveAdd"; + break; + case 8: + tag = "BigIntAdd"; + break; + case 9: + tag = "BigIntSub"; + break; + case 10: + tag = "BigIntMul"; + break; + case 11: + tag = "BigIntDiv"; + break; + case 12: + tag = "BigIntFromLeBytes"; + break; + case 13: + tag = "BigIntToLeBytes"; + break; + case 14: + tag = "Poseidon2Permutation"; + break; + case 15: + tag = "Sha256Compression"; + break; + case 16: + tag = "ToRadix"; + break; + default: + throw_or_abort("unknown 'BlackBoxOp' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "AES128Encrypt") { + AES128Encrypt v; + obj.convert(v); + value = v; + } else if (tag == "Blake2s") { + Blake2s v; + obj.convert(v); + value = v; + } else if (tag == "Blake3") { + Blake3 v; + obj.convert(v); + value = v; + } else if (tag == "Keccakf1600") { + Keccakf1600 v; + obj.convert(v); + value = v; + } else if (tag == "EcdsaSecp256k1") { + EcdsaSecp256k1 v; + obj.convert(v); + value = v; + } else if (tag == "EcdsaSecp256r1") { + EcdsaSecp256r1 v; + obj.convert(v); + value = v; + } else if (tag == "MultiScalarMul") { + MultiScalarMul v; + obj.convert(v); + value = v; + } else if (tag == "EmbeddedCurveAdd") { + EmbeddedCurveAdd v; + obj.convert(v); + value = v; + } else if (tag == "BigIntAdd") { + BigIntAdd v; + obj.convert(v); + value = v; + } else if (tag == "BigIntSub") { + BigIntSub v; + obj.convert(v); + value = v; + } else if (tag == "BigIntMul") { + BigIntMul v; + obj.convert(v); + value = v; + } else if (tag == "BigIntDiv") { + BigIntDiv v; + obj.convert(v); + value = v; + } else if (tag == "BigIntFromLeBytes") { + BigIntFromLeBytes v; + obj.convert(v); + value = v; + } else if (tag == "BigIntToLeBytes") { + BigIntToLeBytes v; + obj.convert(v); + value = v; + } else if (tag == "Poseidon2Permutation") { + Poseidon2Permutation v; + obj.convert(v); + value = v; + } else if (tag == "Sha256Compression") { + Sha256Compression v; + obj.convert(v); + value = v; + } else if (tag == "ToRadix") { + ToRadix v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'BlackBoxOp' enum variant: " + tag); + } + } }; struct HeapValueType; @@ -462,28 +1088,35 @@ struct HeapValueType; struct HeapValueType { struct Simple { - Program::BitSize value; + Acir::BitSize value; friend bool operator==(const Simple&, const Simple&); std::vector bincodeSerialize() const; static Simple bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct Array { - std::vector value_types; + std::vector value_types; uint64_t size; friend bool operator==(const Array&, const Array&); std::vector bincodeSerialize() const; static Array bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(value_types, size); }; struct Vector { - std::vector value_types; + std::vector value_types; friend bool operator==(const Vector&, const Vector&); std::vector bincodeSerialize() const; static Vector bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(value_types); }; std::variant value; @@ -491,32 +1124,90 @@ struct HeapValueType { friend bool operator==(const HeapValueType&, const HeapValueType&); std::vector bincodeSerialize() const; static HeapValueType bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "Simple"; + break; + case 1: + tag = "Array"; + break; + case 2: + tag = "Vector"; + break; + default: + throw_or_abort("unknown 'HeapValueType' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "Simple") { + Simple v; + obj.convert(v); + value = v; + } else if (tag == "Array") { + Array v; + obj.convert(v); + value = v; + } else if (tag == "Vector") { + Vector v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'HeapValueType' enum variant: " + tag); + } + } }; struct ValueOrArray { struct MemoryAddress { - Program::MemoryAddress value; + Acir::MemoryAddress value; friend bool operator==(const MemoryAddress&, const MemoryAddress&); std::vector bincodeSerialize() const; static MemoryAddress bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct HeapArray { - Program::HeapArray value; + Acir::HeapArray value; friend bool operator==(const HeapArray&, const HeapArray&); std::vector bincodeSerialize() const; static HeapArray bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct HeapVector { - Program::HeapVector value; + Acir::HeapVector value; friend bool operator==(const HeapVector&, const HeapVector&); std::vector bincodeSerialize() const; static HeapVector bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; std::variant value; @@ -524,69 +1215,130 @@ struct ValueOrArray { friend bool operator==(const ValueOrArray&, const ValueOrArray&); std::vector bincodeSerialize() const; static ValueOrArray bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "MemoryAddress"; + break; + case 1: + tag = "HeapArray"; + break; + case 2: + tag = "HeapVector"; + break; + default: + throw_or_abort("unknown 'ValueOrArray' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "MemoryAddress") { + MemoryAddress v; + obj.convert(v); + value = v; + } else if (tag == "HeapArray") { + HeapArray v; + obj.convert(v); + value = v; + } else if (tag == "HeapVector") { + HeapVector v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'ValueOrArray' enum variant: " + tag); + } + } }; struct BrilligOpcode { struct BinaryFieldOp { - Program::MemoryAddress destination; - Program::BinaryFieldOp op; - Program::MemoryAddress lhs; - Program::MemoryAddress rhs; + Acir::MemoryAddress destination; + Acir::BinaryFieldOp op; + Acir::MemoryAddress lhs; + Acir::MemoryAddress rhs; friend bool operator==(const BinaryFieldOp&, const BinaryFieldOp&); std::vector bincodeSerialize() const; static BinaryFieldOp bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(destination, op, lhs, rhs); }; struct BinaryIntOp { - Program::MemoryAddress destination; - Program::BinaryIntOp op; - Program::IntegerBitSize bit_size; - Program::MemoryAddress lhs; - Program::MemoryAddress rhs; + Acir::MemoryAddress destination; + Acir::BinaryIntOp op; + Acir::IntegerBitSize bit_size; + Acir::MemoryAddress lhs; + Acir::MemoryAddress rhs; friend bool operator==(const BinaryIntOp&, const BinaryIntOp&); std::vector bincodeSerialize() const; static BinaryIntOp bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(destination, op, bit_size, lhs, rhs); }; struct Not { - Program::MemoryAddress destination; - Program::MemoryAddress source; - Program::IntegerBitSize bit_size; + Acir::MemoryAddress destination; + Acir::MemoryAddress source; + Acir::IntegerBitSize bit_size; friend bool operator==(const Not&, const Not&); std::vector bincodeSerialize() const; static Not bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(destination, source, bit_size); }; struct Cast { - Program::MemoryAddress destination; - Program::MemoryAddress source; - Program::BitSize bit_size; + Acir::MemoryAddress destination; + Acir::MemoryAddress source; + Acir::BitSize bit_size; friend bool operator==(const Cast&, const Cast&); std::vector bincodeSerialize() const; static Cast bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(destination, source, bit_size); }; struct JumpIfNot { - Program::MemoryAddress condition; + Acir::MemoryAddress condition; uint64_t location; friend bool operator==(const JumpIfNot&, const JumpIfNot&); std::vector bincodeSerialize() const; static JumpIfNot bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(condition, location); }; struct JumpIf { - Program::MemoryAddress condition; + Acir::MemoryAddress condition; uint64_t location; friend bool operator==(const JumpIf&, const JumpIf&); std::vector bincodeSerialize() const; static JumpIf bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(condition, location); }; struct Jump { @@ -595,16 +1347,20 @@ struct BrilligOpcode { friend bool operator==(const Jump&, const Jump&); std::vector bincodeSerialize() const; static Jump bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(location); }; struct CalldataCopy { - Program::MemoryAddress destination_address; - Program::MemoryAddress size_address; - Program::MemoryAddress offset_address; + Acir::MemoryAddress destination_address; + Acir::MemoryAddress size_address; + Acir::MemoryAddress offset_address; friend bool operator==(const CalldataCopy&, const CalldataCopy&); std::vector bincodeSerialize() const; static CalldataCopy bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(destination_address, size_address, offset_address); }; struct Call { @@ -613,106 +1369,132 @@ struct BrilligOpcode { friend bool operator==(const Call&, const Call&); std::vector bincodeSerialize() const; static Call bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(location); }; struct Const { - Program::MemoryAddress destination; - Program::BitSize bit_size; + Acir::MemoryAddress destination; + Acir::BitSize bit_size; std::string value; friend bool operator==(const Const&, const Const&); std::vector bincodeSerialize() const; static Const bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(destination, bit_size, value); }; struct IndirectConst { - Program::MemoryAddress destination_pointer; - Program::BitSize bit_size; + Acir::MemoryAddress destination_pointer; + Acir::BitSize bit_size; std::string value; friend bool operator==(const IndirectConst&, const IndirectConst&); std::vector bincodeSerialize() const; static IndirectConst bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(destination_pointer, bit_size, value); }; struct Return { friend bool operator==(const Return&, const Return&); std::vector bincodeSerialize() const; static Return bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct ForeignCall { std::string function; - std::vector destinations; - std::vector destination_value_types; - std::vector inputs; - std::vector input_value_types; + std::vector destinations; + std::vector destination_value_types; + std::vector inputs; + std::vector input_value_types; friend bool operator==(const ForeignCall&, const ForeignCall&); std::vector bincodeSerialize() const; static ForeignCall bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(function, destinations, destination_value_types, inputs, input_value_types); }; struct Mov { - Program::MemoryAddress destination; - Program::MemoryAddress source; + Acir::MemoryAddress destination; + Acir::MemoryAddress source; friend bool operator==(const Mov&, const Mov&); std::vector bincodeSerialize() const; static Mov bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(destination, source); }; struct ConditionalMov { - Program::MemoryAddress destination; - Program::MemoryAddress source_a; - Program::MemoryAddress source_b; - Program::MemoryAddress condition; + Acir::MemoryAddress destination; + Acir::MemoryAddress source_a; + Acir::MemoryAddress source_b; + Acir::MemoryAddress condition; friend bool operator==(const ConditionalMov&, const ConditionalMov&); std::vector bincodeSerialize() const; static ConditionalMov bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(destination, source_a, source_b, condition); }; struct Load { - Program::MemoryAddress destination; - Program::MemoryAddress source_pointer; + Acir::MemoryAddress destination; + Acir::MemoryAddress source_pointer; friend bool operator==(const Load&, const Load&); std::vector bincodeSerialize() const; static Load bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(destination, source_pointer); }; struct Store { - Program::MemoryAddress destination_pointer; - Program::MemoryAddress source; + Acir::MemoryAddress destination_pointer; + Acir::MemoryAddress source; friend bool operator==(const Store&, const Store&); std::vector bincodeSerialize() const; static Store bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(destination_pointer, source); }; struct BlackBox { - Program::BlackBoxOp value; + Acir::BlackBoxOp value; friend bool operator==(const BlackBox&, const BlackBox&); std::vector bincodeSerialize() const; static BlackBox bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct Trap { - Program::HeapVector revert_data; + Acir::HeapVector revert_data; friend bool operator==(const Trap&, const Trap&); std::vector bincodeSerialize() const; static Trap bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(revert_data); }; struct Stop { - Program::HeapVector return_data; + Acir::HeapVector return_data; friend bool operator==(const Stop&, const Stop&); std::vector bincodeSerialize() const; static Stop bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(return_data); }; std::variant bincodeSerialize() const; static BrilligOpcode bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "BinaryFieldOp"; + break; + case 1: + tag = "BinaryIntOp"; + break; + case 2: + tag = "Not"; + break; + case 3: + tag = "Cast"; + break; + case 4: + tag = "JumpIfNot"; + break; + case 5: + tag = "JumpIf"; + break; + case 6: + tag = "Jump"; + break; + case 7: + tag = "CalldataCopy"; + break; + case 8: + tag = "Call"; + break; + case 9: + tag = "Const"; + break; + case 10: + tag = "IndirectConst"; + break; + case 11: + tag = "Return"; + break; + case 12: + tag = "ForeignCall"; + break; + case 13: + tag = "Mov"; + break; + case 14: + tag = "ConditionalMov"; + break; + case 15: + tag = "Load"; + break; + case 16: + tag = "Store"; + break; + case 17: + tag = "BlackBox"; + break; + case 18: + tag = "Trap"; + break; + case 19: + tag = "Stop"; + break; + default: + throw_or_abort("unknown 'BrilligOpcode' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "BinaryFieldOp") { + BinaryFieldOp v; + obj.convert(v); + value = v; + } else if (tag == "BinaryIntOp") { + BinaryIntOp v; + obj.convert(v); + value = v; + } else if (tag == "Not") { + Not v; + obj.convert(v); + value = v; + } else if (tag == "Cast") { + Cast v; + obj.convert(v); + value = v; + } else if (tag == "JumpIfNot") { + JumpIfNot v; + obj.convert(v); + value = v; + } else if (tag == "JumpIf") { + JumpIf v; + obj.convert(v); + value = v; + } else if (tag == "Jump") { + Jump v; + obj.convert(v); + value = v; + } else if (tag == "CalldataCopy") { + CalldataCopy v; + obj.convert(v); + value = v; + } else if (tag == "Call") { + Call v; + obj.convert(v); + value = v; + } else if (tag == "Const") { + Const v; + obj.convert(v); + value = v; + } else if (tag == "IndirectConst") { + IndirectConst v; + obj.convert(v); + value = v; + } else if (tag == "Return") { + Return v; + obj.convert(v); + value = v; + } else if (tag == "ForeignCall") { + ForeignCall v; + obj.convert(v); + value = v; + } else if (tag == "Mov") { + Mov v; + obj.convert(v); + value = v; + } else if (tag == "ConditionalMov") { + ConditionalMov v; + obj.convert(v); + value = v; + } else if (tag == "Load") { + Load v; + obj.convert(v); + value = v; + } else if (tag == "Store") { + Store v; + obj.convert(v); + value = v; + } else if (tag == "BlackBox") { + BlackBox v; + obj.convert(v); + value = v; + } else if (tag == "Trap") { + Trap v; + obj.convert(v); + value = v; + } else if (tag == "Stop") { + Stop v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'BrilligOpcode' enum variant: " + tag); + } + } }; struct Witness { @@ -748,6 +1698,9 @@ struct Witness { friend bool operator==(const Witness&, const Witness&); std::vector bincodeSerialize() const; static Witness bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct ConstantOrWitnessEnum { @@ -758,14 +1711,20 @@ struct ConstantOrWitnessEnum { friend bool operator==(const Constant&, const Constant&); std::vector bincodeSerialize() const; static Constant bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct Witness { - Program::Witness value; + Acir::Witness value; friend bool operator==(const Witness&, const Witness&); std::vector bincodeSerialize() const; static Witness bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; std::variant value; @@ -773,139 +1732,207 @@ struct ConstantOrWitnessEnum { friend bool operator==(const ConstantOrWitnessEnum&, const ConstantOrWitnessEnum&); std::vector bincodeSerialize() const; static ConstantOrWitnessEnum bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "Constant"; + break; + case 1: + tag = "Witness"; + break; + default: + throw_or_abort("unknown 'ConstantOrWitnessEnum' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "Constant") { + Constant v; + obj.convert(v); + value = v; + } else if (tag == "Witness") { + Witness v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'ConstantOrWitnessEnum' enum variant: " + tag); + } + } }; struct FunctionInput { - Program::ConstantOrWitnessEnum input; + Acir::ConstantOrWitnessEnum input; uint32_t num_bits; friend bool operator==(const FunctionInput&, const FunctionInput&); std::vector bincodeSerialize() const; static FunctionInput bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(input, num_bits); }; struct BlackBoxFuncCall { struct AES128Encrypt { - std::vector inputs; - std::array iv; - std::array key; - std::vector outputs; + std::vector inputs; + std::array iv; + std::array key; + std::vector outputs; friend bool operator==(const AES128Encrypt&, const AES128Encrypt&); std::vector bincodeSerialize() const; static AES128Encrypt bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(inputs, iv, key, outputs); }; struct AND { - Program::FunctionInput lhs; - Program::FunctionInput rhs; - Program::Witness output; + Acir::FunctionInput lhs; + Acir::FunctionInput rhs; + Acir::Witness output; friend bool operator==(const AND&, const AND&); std::vector bincodeSerialize() const; static AND bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(lhs, rhs, output); }; struct XOR { - Program::FunctionInput lhs; - Program::FunctionInput rhs; - Program::Witness output; + Acir::FunctionInput lhs; + Acir::FunctionInput rhs; + Acir::Witness output; friend bool operator==(const XOR&, const XOR&); std::vector bincodeSerialize() const; static XOR bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(lhs, rhs, output); }; struct RANGE { - Program::FunctionInput input; + Acir::FunctionInput input; friend bool operator==(const RANGE&, const RANGE&); std::vector bincodeSerialize() const; static RANGE bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(input); }; struct Blake2s { - std::vector inputs; - std::array outputs; + std::vector inputs; + std::array outputs; friend bool operator==(const Blake2s&, const Blake2s&); std::vector bincodeSerialize() const; static Blake2s bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(inputs, outputs); }; struct Blake3 { - std::vector inputs; - std::array outputs; + std::vector inputs; + std::array outputs; friend bool operator==(const Blake3&, const Blake3&); std::vector bincodeSerialize() const; static Blake3 bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(inputs, outputs); }; struct EcdsaSecp256k1 { - std::array public_key_x; - std::array public_key_y; - std::array signature; - std::array hashed_message; - Program::Witness output; + std::array public_key_x; + std::array public_key_y; + std::array signature; + std::array hashed_message; + Acir::Witness output; friend bool operator==(const EcdsaSecp256k1&, const EcdsaSecp256k1&); std::vector bincodeSerialize() const; static EcdsaSecp256k1 bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(public_key_x, public_key_y, signature, hashed_message, output); }; struct EcdsaSecp256r1 { - std::array public_key_x; - std::array public_key_y; - std::array signature; - std::array hashed_message; - Program::Witness output; + std::array public_key_x; + std::array public_key_y; + std::array signature; + std::array hashed_message; + Acir::Witness output; friend bool operator==(const EcdsaSecp256r1&, const EcdsaSecp256r1&); std::vector bincodeSerialize() const; static EcdsaSecp256r1 bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(public_key_x, public_key_y, signature, hashed_message, output); }; struct MultiScalarMul { - std::vector points; - std::vector scalars; - std::array outputs; + std::vector points; + std::vector scalars; + std::array outputs; friend bool operator==(const MultiScalarMul&, const MultiScalarMul&); std::vector bincodeSerialize() const; static MultiScalarMul bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(points, scalars, outputs); }; struct EmbeddedCurveAdd { - std::array input1; - std::array input2; - std::array outputs; + std::array input1; + std::array input2; + std::array outputs; friend bool operator==(const EmbeddedCurveAdd&, const EmbeddedCurveAdd&); std::vector bincodeSerialize() const; static EmbeddedCurveAdd bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(input1, input2, outputs); }; struct Keccakf1600 { - std::array inputs; - std::array outputs; + std::array inputs; + std::array outputs; friend bool operator==(const Keccakf1600&, const Keccakf1600&); std::vector bincodeSerialize() const; static Keccakf1600 bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(inputs, outputs); }; struct RecursiveAggregation { - std::vector verification_key; - std::vector proof; - std::vector public_inputs; - Program::FunctionInput key_hash; + std::vector verification_key; + std::vector proof; + std::vector public_inputs; + Acir::FunctionInput key_hash; uint32_t proof_type; friend bool operator==(const RecursiveAggregation&, const RecursiveAggregation&); std::vector bincodeSerialize() const; static RecursiveAggregation bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(verification_key, proof, public_inputs, key_hash, proof_type); }; struct BigIntAdd { @@ -916,6 +1943,8 @@ struct BlackBoxFuncCall { friend bool operator==(const BigIntAdd&, const BigIntAdd&); std::vector bincodeSerialize() const; static BigIntAdd bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntSub { @@ -926,6 +1955,8 @@ struct BlackBoxFuncCall { friend bool operator==(const BigIntSub&, const BigIntSub&); std::vector bincodeSerialize() const; static BigIntSub bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntMul { @@ -936,6 +1967,8 @@ struct BlackBoxFuncCall { friend bool operator==(const BigIntMul&, const BigIntMul&); std::vector bincodeSerialize() const; static BigIntMul bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntDiv { @@ -946,45 +1979,55 @@ struct BlackBoxFuncCall { friend bool operator==(const BigIntDiv&, const BigIntDiv&); std::vector bincodeSerialize() const; static BigIntDiv bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntFromLeBytes { - std::vector inputs; + std::vector inputs; std::vector modulus; uint32_t output; friend bool operator==(const BigIntFromLeBytes&, const BigIntFromLeBytes&); std::vector bincodeSerialize() const; static BigIntFromLeBytes bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(inputs, modulus, output); }; struct BigIntToLeBytes { uint32_t input; - std::vector outputs; + std::vector outputs; friend bool operator==(const BigIntToLeBytes&, const BigIntToLeBytes&); std::vector bincodeSerialize() const; static BigIntToLeBytes bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(input, outputs); }; struct Poseidon2Permutation { - std::vector inputs; - std::vector outputs; + std::vector inputs; + std::vector outputs; uint32_t len; friend bool operator==(const Poseidon2Permutation&, const Poseidon2Permutation&); std::vector bincodeSerialize() const; static Poseidon2Permutation bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(inputs, outputs, len); }; struct Sha256Compression { - std::array inputs; - std::array hash_values; - std::array outputs; + std::array inputs; + std::array hash_values; + std::array outputs; friend bool operator==(const Sha256Compression&, const Sha256Compression&); std::vector bincodeSerialize() const; static Sha256Compression bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(inputs, hash_values, outputs); }; std::variant bincodeSerialize() const; static BlackBoxFuncCall bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "AES128Encrypt"; + break; + case 1: + tag = "AND"; + break; + case 2: + tag = "XOR"; + break; + case 3: + tag = "RANGE"; + break; + case 4: + tag = "Blake2s"; + break; + case 5: + tag = "Blake3"; + break; + case 6: + tag = "EcdsaSecp256k1"; + break; + case 7: + tag = "EcdsaSecp256r1"; + break; + case 8: + tag = "MultiScalarMul"; + break; + case 9: + tag = "EmbeddedCurveAdd"; + break; + case 10: + tag = "Keccakf1600"; + break; + case 11: + tag = "RecursiveAggregation"; + break; + case 12: + tag = "BigIntAdd"; + break; + case 13: + tag = "BigIntSub"; + break; + case 14: + tag = "BigIntMul"; + break; + case 15: + tag = "BigIntDiv"; + break; + case 16: + tag = "BigIntFromLeBytes"; + break; + case 17: + tag = "BigIntToLeBytes"; + break; + case 18: + tag = "Poseidon2Permutation"; + break; + case 19: + tag = "Sha256Compression"; + break; + default: + throw_or_abort("unknown 'BlackBoxFuncCall' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "AES128Encrypt") { + AES128Encrypt v; + obj.convert(v); + value = v; + } else if (tag == "AND") { + AND v; + obj.convert(v); + value = v; + } else if (tag == "XOR") { + XOR v; + obj.convert(v); + value = v; + } else if (tag == "RANGE") { + RANGE v; + obj.convert(v); + value = v; + } else if (tag == "Blake2s") { + Blake2s v; + obj.convert(v); + value = v; + } else if (tag == "Blake3") { + Blake3 v; + obj.convert(v); + value = v; + } else if (tag == "EcdsaSecp256k1") { + EcdsaSecp256k1 v; + obj.convert(v); + value = v; + } else if (tag == "EcdsaSecp256r1") { + EcdsaSecp256r1 v; + obj.convert(v); + value = v; + } else if (tag == "MultiScalarMul") { + MultiScalarMul v; + obj.convert(v); + value = v; + } else if (tag == "EmbeddedCurveAdd") { + EmbeddedCurveAdd v; + obj.convert(v); + value = v; + } else if (tag == "Keccakf1600") { + Keccakf1600 v; + obj.convert(v); + value = v; + } else if (tag == "RecursiveAggregation") { + RecursiveAggregation v; + obj.convert(v); + value = v; + } else if (tag == "BigIntAdd") { + BigIntAdd v; + obj.convert(v); + value = v; + } else if (tag == "BigIntSub") { + BigIntSub v; + obj.convert(v); + value = v; + } else if (tag == "BigIntMul") { + BigIntMul v; + obj.convert(v); + value = v; + } else if (tag == "BigIntDiv") { + BigIntDiv v; + obj.convert(v); + value = v; + } else if (tag == "BigIntFromLeBytes") { + BigIntFromLeBytes v; + obj.convert(v); + value = v; + } else if (tag == "BigIntToLeBytes") { + BigIntToLeBytes v; + obj.convert(v); + value = v; + } else if (tag == "Poseidon2Permutation") { + Poseidon2Permutation v; + obj.convert(v); + value = v; + } else if (tag == "Sha256Compression") { + Sha256Compression v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'BlackBoxFuncCall' enum variant: " + tag); + } + } }; struct BlockId { @@ -1020,6 +2231,9 @@ struct BlockId { friend bool operator==(const BlockId&, const BlockId&); std::vector bincodeSerialize() const; static BlockId bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct BlockType { @@ -1028,6 +2242,9 @@ struct BlockType { friend bool operator==(const Memory&, const Memory&); std::vector bincodeSerialize() const; static Memory bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct CallData { @@ -1036,12 +2253,18 @@ struct BlockType { friend bool operator==(const CallData&, const CallData&); std::vector bincodeSerialize() const; static CallData bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct ReturnData { friend bool operator==(const ReturnData&, const ReturnData&); std::vector bincodeSerialize() const; static ReturnData bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; std::variant value; @@ -1049,42 +2272,102 @@ struct BlockType { friend bool operator==(const BlockType&, const BlockType&); std::vector bincodeSerialize() const; static BlockType bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "Memory"; + break; + case 1: + tag = "CallData"; + break; + case 2: + tag = "ReturnData"; + break; + default: + throw_or_abort("unknown 'BlockType' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "Memory") { + Memory v; + obj.convert(v); + value = v; + } else if (tag == "CallData") { + CallData v; + obj.convert(v); + value = v; + } else if (tag == "ReturnData") { + ReturnData v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'BlockType' enum variant: " + tag); + } + } }; struct Expression { - std::vector> mul_terms; - std::vector> linear_combinations; + std::vector> mul_terms; + std::vector> linear_combinations; std::string q_c; friend bool operator==(const Expression&, const Expression&); std::vector bincodeSerialize() const; static Expression bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(mul_terms, linear_combinations, q_c); }; struct BrilligInputs { struct Single { - Program::Expression value; + Acir::Expression value; friend bool operator==(const Single&, const Single&); std::vector bincodeSerialize() const; static Single bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct Array { - std::vector value; + std::vector value; friend bool operator==(const Array&, const Array&); std::vector bincodeSerialize() const; static Array bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct MemoryArray { - Program::BlockId value; + Acir::BlockId value; friend bool operator==(const MemoryArray&, const MemoryArray&); std::vector bincodeSerialize() const; static MemoryArray bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; std::variant value; @@ -1092,24 +2375,79 @@ struct BrilligInputs { friend bool operator==(const BrilligInputs&, const BrilligInputs&); std::vector bincodeSerialize() const; static BrilligInputs bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "Single"; + break; + case 1: + tag = "Array"; + break; + case 2: + tag = "MemoryArray"; + break; + default: + throw_or_abort("unknown 'BrilligInputs' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "Single") { + Single v; + obj.convert(v); + value = v; + } else if (tag == "Array") { + Array v; + obj.convert(v); + value = v; + } else if (tag == "MemoryArray") { + MemoryArray v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'BrilligInputs' enum variant: " + tag); + } + } }; struct BrilligOutputs { struct Simple { - Program::Witness value; + Acir::Witness value; friend bool operator==(const Simple&, const Simple&); std::vector bincodeSerialize() const; static Simple bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct Array { - std::vector value; + std::vector value; friend bool operator==(const Array&, const Array&); std::vector bincodeSerialize() const; static Array bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; std::variant value; @@ -1117,76 +2455,134 @@ struct BrilligOutputs { friend bool operator==(const BrilligOutputs&, const BrilligOutputs&); std::vector bincodeSerialize() const; static BrilligOutputs bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "Simple"; + break; + case 1: + tag = "Array"; + break; + default: + throw_or_abort("unknown 'BrilligOutputs' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "Simple") { + Simple v; + obj.convert(v); + value = v; + } else if (tag == "Array") { + Array v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'BrilligOutputs' enum variant: " + tag); + } + } }; struct MemOp { - Program::Expression operation; - Program::Expression index; - Program::Expression value; + Acir::Expression operation; + Acir::Expression index; + Acir::Expression value; friend bool operator==(const MemOp&, const MemOp&); std::vector bincodeSerialize() const; static MemOp bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(operation, index, value); }; struct Opcode { struct AssertZero { - Program::Expression value; + Acir::Expression value; friend bool operator==(const AssertZero&, const AssertZero&); std::vector bincodeSerialize() const; static AssertZero bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct BlackBoxFuncCall { - Program::BlackBoxFuncCall value; + Acir::BlackBoxFuncCall value; friend bool operator==(const BlackBoxFuncCall&, const BlackBoxFuncCall&); std::vector bincodeSerialize() const; static BlackBoxFuncCall bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct MemoryOp { - Program::BlockId block_id; - Program::MemOp op; - std::optional predicate; + Acir::BlockId block_id; + Acir::MemOp op; + std::optional predicate; friend bool operator==(const MemoryOp&, const MemoryOp&); std::vector bincodeSerialize() const; static MemoryOp bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(block_id, op, predicate); }; struct MemoryInit { - Program::BlockId block_id; - std::vector init; - Program::BlockType block_type; + Acir::BlockId block_id; + std::vector init; + Acir::BlockType block_type; friend bool operator==(const MemoryInit&, const MemoryInit&); std::vector bincodeSerialize() const; static MemoryInit bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(block_id, init, block_type); }; struct BrilligCall { uint32_t id; - std::vector inputs; - std::vector outputs; - std::optional predicate; + std::vector inputs; + std::vector outputs; + std::optional predicate; friend bool operator==(const BrilligCall&, const BrilligCall&); std::vector bincodeSerialize() const; static BrilligCall bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(id, inputs, outputs, predicate); }; struct Call { uint32_t id; - std::vector inputs; - std::vector outputs; - std::optional predicate; + std::vector inputs; + std::vector outputs; + std::optional predicate; friend bool operator==(const Call&, const Call&); std::vector bincodeSerialize() const; static Call bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(id, inputs, outputs, predicate); }; std::variant value; @@ -1194,24 +2590,100 @@ struct Opcode { friend bool operator==(const Opcode&, const Opcode&); std::vector bincodeSerialize() const; static Opcode bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "AssertZero"; + break; + case 1: + tag = "BlackBoxFuncCall"; + break; + case 2: + tag = "MemoryOp"; + break; + case 3: + tag = "MemoryInit"; + break; + case 4: + tag = "BrilligCall"; + break; + case 5: + tag = "Call"; + break; + default: + throw_or_abort("unknown 'Opcode' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "AssertZero") { + AssertZero v; + obj.convert(v); + value = v; + } else if (tag == "BlackBoxFuncCall") { + BlackBoxFuncCall v; + obj.convert(v); + value = v; + } else if (tag == "MemoryOp") { + MemoryOp v; + obj.convert(v); + value = v; + } else if (tag == "MemoryInit") { + MemoryInit v; + obj.convert(v); + value = v; + } else if (tag == "BrilligCall") { + BrilligCall v; + obj.convert(v); + value = v; + } else if (tag == "Call") { + Call v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'Opcode' enum variant: " + tag); + } + } }; struct ExpressionOrMemory { struct Expression { - Program::Expression value; + Acir::Expression value; friend bool operator==(const Expression&, const Expression&); std::vector bincodeSerialize() const; static Expression bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct Memory { - Program::BlockId value; + Acir::BlockId value; friend bool operator==(const Memory&, const Memory&); std::vector bincodeSerialize() const; static Memory bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; std::variant value; @@ -1219,15 +2691,59 @@ struct ExpressionOrMemory { friend bool operator==(const ExpressionOrMemory&, const ExpressionOrMemory&); std::vector bincodeSerialize() const; static ExpressionOrMemory bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "Expression"; + break; + case 1: + tag = "Memory"; + break; + default: + throw_or_abort("unknown 'ExpressionOrMemory' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "Expression") { + Expression v; + obj.convert(v); + value = v; + } else if (tag == "Memory") { + Memory v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'ExpressionOrMemory' enum variant: " + tag); + } + } }; struct AssertionPayload { uint64_t error_selector; - std::vector payload; + std::vector payload; friend bool operator==(const AssertionPayload&, const AssertionPayload&); std::vector bincodeSerialize() const; static AssertionPayload bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(error_selector, payload); }; struct ExpressionWidth { @@ -1236,6 +2752,9 @@ struct ExpressionWidth { friend bool operator==(const Unbounded&, const Unbounded&); std::vector bincodeSerialize() const; static Unbounded bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const {} + void msgpack_unpack(auto const& o) {} }; struct Bounded { @@ -1244,6 +2763,8 @@ struct ExpressionWidth { friend bool operator==(const Bounded&, const Bounded&); std::vector bincodeSerialize() const; static Bounded bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(width); }; std::variant value; @@ -1251,6 +2772,48 @@ struct ExpressionWidth { friend bool operator==(const ExpressionWidth&, const ExpressionWidth&); std::vector bincodeSerialize() const; static ExpressionWidth bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "Unbounded"; + break; + case 1: + tag = "Bounded"; + break; + default: + throw_or_abort("unknown 'ExpressionWidth' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "Unbounded") { + Unbounded v; + obj.convert(v); + value = v; + } else if (tag == "Bounded") { + Bounded v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'ExpressionWidth' enum variant: " + tag); + } + } }; struct OpcodeLocation { @@ -1261,6 +2824,9 @@ struct OpcodeLocation { friend bool operator==(const Acir&, const Acir&); std::vector bincodeSerialize() const; static Acir bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct Brillig { @@ -1270,6 +2836,8 @@ struct OpcodeLocation { friend bool operator==(const Brillig&, const Brillig&); std::vector bincodeSerialize() const; static Brillig bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(acir_index, brillig_index); }; std::variant value; @@ -1277,50 +2845,107 @@ struct OpcodeLocation { friend bool operator==(const OpcodeLocation&, const OpcodeLocation&); std::vector bincodeSerialize() const; static OpcodeLocation bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const + { + std::string tag; + switch (value.index()) { + + case 0: + tag = "Acir"; + break; + case 1: + tag = "Brillig"; + break; + default: + throw_or_abort("unknown 'OpcodeLocation' enum variant index: " + std::to_string(value.index())); + } + std::visit( + [&packer, tag](const auto& arg) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + }, + value); + } + + void msgpack_unpack(auto const& o) + { + std::map data = o.convert(); + auto entry = data.begin(); + auto tag = entry->first; + auto obj = entry->second; + if (tag == "Acir") { + Acir v; + obj.convert(v); + value = v; + } else if (tag == "Brillig") { + Brillig v; + obj.convert(v); + value = v; + } else { + throw_or_abort("unknown 'OpcodeLocation' enum variant: " + tag); + } + } }; struct PublicInputs { - std::vector value; + std::vector value; friend bool operator==(const PublicInputs&, const PublicInputs&); std::vector bincodeSerialize() const; static PublicInputs bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct Circuit { uint32_t current_witness_index; - std::vector opcodes; - Program::ExpressionWidth expression_width; - std::vector private_parameters; - Program::PublicInputs public_parameters; - Program::PublicInputs return_values; - std::vector> assert_messages; + std::vector opcodes; + Acir::ExpressionWidth expression_width; + std::vector private_parameters; + Acir::PublicInputs public_parameters; + Acir::PublicInputs return_values; + std::vector> assert_messages; friend bool operator==(const Circuit&, const Circuit&); std::vector bincodeSerialize() const; static Circuit bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(current_witness_index, + opcodes, + expression_width, + private_parameters, + public_parameters, + return_values, + assert_messages); }; struct BrilligBytecode { - std::vector bytecode; + std::vector bytecode; friend bool operator==(const BrilligBytecode&, const BrilligBytecode&); std::vector bincodeSerialize() const; static BrilligBytecode bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(bytecode); }; struct Program { - std::vector functions; - std::vector unconstrained_functions; + std::vector functions; + std::vector unconstrained_functions; friend bool operator==(const Program&, const Program&); std::vector bincodeSerialize() const; static Program bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(functions, unconstrained_functions); }; -} // end of namespace Program +} // end of namespace Acir -namespace Program { +namespace Acir { inline bool operator==(const AssertionPayload& lhs, const AssertionPayload& rhs) { @@ -1350,12 +2975,11 @@ inline AssertionPayload AssertionPayload::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::AssertionPayload& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::AssertionPayload& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.error_selector, serializer); @@ -1365,17 +2989,17 @@ void serde::Serializable::serialize(const Program::As template <> template -Program::AssertionPayload serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::AssertionPayload serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::AssertionPayload obj; + Acir::AssertionPayload obj; obj.error_selector = serde::Deserializable::deserialize(deserializer); obj.payload = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryFieldOp& lhs, const BinaryFieldOp& rhs) { @@ -1402,11 +3026,11 @@ inline BinaryFieldOp BinaryFieldOp::bincodeDeserialize(std::vector inpu return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BinaryFieldOp& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryFieldOp& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -1415,16 +3039,16 @@ void serde::Serializable::serialize(const Program::Binar template <> template -Program::BinaryFieldOp serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryFieldOp serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::BinaryFieldOp obj; + Acir::BinaryFieldOp obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryFieldOp::Add& lhs, const BinaryFieldOp::Add& rhs) { @@ -1448,23 +3072,23 @@ inline BinaryFieldOp::Add BinaryFieldOp::Add::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BinaryFieldOp::Add& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryFieldOp::Add& obj, + Serializer& serializer) {} template <> template -Program::BinaryFieldOp::Add serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryFieldOp::Add serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryFieldOp::Add obj; + Acir::BinaryFieldOp::Add obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryFieldOp::Sub& lhs, const BinaryFieldOp::Sub& rhs) { @@ -1488,23 +3112,23 @@ inline BinaryFieldOp::Sub BinaryFieldOp::Sub::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BinaryFieldOp::Sub& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryFieldOp::Sub& obj, + Serializer& serializer) {} template <> template -Program::BinaryFieldOp::Sub serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryFieldOp::Sub serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryFieldOp::Sub obj; + Acir::BinaryFieldOp::Sub obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryFieldOp::Mul& lhs, const BinaryFieldOp::Mul& rhs) { @@ -1528,23 +3152,23 @@ inline BinaryFieldOp::Mul BinaryFieldOp::Mul::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BinaryFieldOp::Mul& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryFieldOp::Mul& obj, + Serializer& serializer) {} template <> template -Program::BinaryFieldOp::Mul serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryFieldOp::Mul serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryFieldOp::Mul obj; + Acir::BinaryFieldOp::Mul obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryFieldOp::Div& lhs, const BinaryFieldOp::Div& rhs) { @@ -1568,23 +3192,23 @@ inline BinaryFieldOp::Div BinaryFieldOp::Div::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BinaryFieldOp::Div& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryFieldOp::Div& obj, + Serializer& serializer) {} template <> template -Program::BinaryFieldOp::Div serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryFieldOp::Div serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryFieldOp::Div obj; + Acir::BinaryFieldOp::Div obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryFieldOp::IntegerDiv& lhs, const BinaryFieldOp::IntegerDiv& rhs) { @@ -1608,24 +3232,24 @@ inline BinaryFieldOp::IntegerDiv BinaryFieldOp::IntegerDiv::bincodeDeserialize(s return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BinaryFieldOp::IntegerDiv& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryFieldOp::IntegerDiv& obj, + Serializer& serializer) {} template <> template -Program::BinaryFieldOp::IntegerDiv serde::Deserializable::deserialize( +Acir::BinaryFieldOp::IntegerDiv serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BinaryFieldOp::IntegerDiv obj; + Acir::BinaryFieldOp::IntegerDiv obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryFieldOp::Equals& lhs, const BinaryFieldOp::Equals& rhs) { @@ -1649,24 +3273,23 @@ inline BinaryFieldOp::Equals BinaryFieldOp::Equals::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BinaryFieldOp::Equals& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryFieldOp::Equals& obj, + Serializer& serializer) {} template <> template -Program::BinaryFieldOp::Equals serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BinaryFieldOp::Equals serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryFieldOp::Equals obj; + Acir::BinaryFieldOp::Equals obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryFieldOp::LessThan& lhs, const BinaryFieldOp::LessThan& rhs) { @@ -1690,24 +3313,24 @@ inline BinaryFieldOp::LessThan BinaryFieldOp::LessThan::bincodeDeserialize(std:: return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BinaryFieldOp::LessThan& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryFieldOp::LessThan& obj, + Serializer& serializer) {} template <> template -Program::BinaryFieldOp::LessThan serde::Deserializable::deserialize( +Acir::BinaryFieldOp::LessThan serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BinaryFieldOp::LessThan obj; + Acir::BinaryFieldOp::LessThan obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryFieldOp::LessThanEquals& lhs, const BinaryFieldOp::LessThanEquals& rhs) { @@ -1731,24 +3354,24 @@ inline BinaryFieldOp::LessThanEquals BinaryFieldOp::LessThanEquals::bincodeDeser return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BinaryFieldOp::LessThanEquals& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryFieldOp::LessThanEquals& obj, + Serializer& serializer) {} template <> template -Program::BinaryFieldOp::LessThanEquals serde::Deserializable::deserialize( +Acir::BinaryFieldOp::LessThanEquals serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BinaryFieldOp::LessThanEquals obj; + Acir::BinaryFieldOp::LessThanEquals obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryIntOp& lhs, const BinaryIntOp& rhs) { @@ -1775,11 +3398,11 @@ inline BinaryIntOp BinaryIntOp::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BinaryIntOp& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryIntOp& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -1788,16 +3411,16 @@ void serde::Serializable::serialize(const Program::BinaryI template <> template -Program::BinaryIntOp serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryIntOp serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::BinaryIntOp obj; + Acir::BinaryIntOp obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryIntOp::Add& lhs, const BinaryIntOp::Add& rhs) { @@ -1821,23 +3444,22 @@ inline BinaryIntOp::Add BinaryIntOp::Add::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BinaryIntOp::Add& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryIntOp::Add& obj, Serializer& serializer) {} template <> template -Program::BinaryIntOp::Add serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryIntOp::Add serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryIntOp::Add obj; + Acir::BinaryIntOp::Add obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryIntOp::Sub& lhs, const BinaryIntOp::Sub& rhs) { @@ -1861,23 +3483,22 @@ inline BinaryIntOp::Sub BinaryIntOp::Sub::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BinaryIntOp::Sub& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryIntOp::Sub& obj, Serializer& serializer) {} template <> template -Program::BinaryIntOp::Sub serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryIntOp::Sub serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryIntOp::Sub obj; + Acir::BinaryIntOp::Sub obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryIntOp::Mul& lhs, const BinaryIntOp::Mul& rhs) { @@ -1901,23 +3522,22 @@ inline BinaryIntOp::Mul BinaryIntOp::Mul::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BinaryIntOp::Mul& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryIntOp::Mul& obj, Serializer& serializer) {} template <> template -Program::BinaryIntOp::Mul serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryIntOp::Mul serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryIntOp::Mul obj; + Acir::BinaryIntOp::Mul obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryIntOp::Div& lhs, const BinaryIntOp::Div& rhs) { @@ -1941,23 +3561,22 @@ inline BinaryIntOp::Div BinaryIntOp::Div::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BinaryIntOp::Div& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryIntOp::Div& obj, Serializer& serializer) {} template <> template -Program::BinaryIntOp::Div serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryIntOp::Div serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryIntOp::Div obj; + Acir::BinaryIntOp::Div obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryIntOp::Equals& lhs, const BinaryIntOp::Equals& rhs) { @@ -1981,24 +3600,23 @@ inline BinaryIntOp::Equals BinaryIntOp::Equals::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BinaryIntOp::Equals& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryIntOp::Equals& obj, + Serializer& serializer) {} template <> template -Program::BinaryIntOp::Equals serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BinaryIntOp::Equals serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryIntOp::Equals obj; + Acir::BinaryIntOp::Equals obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryIntOp::LessThan& lhs, const BinaryIntOp::LessThan& rhs) { @@ -2022,24 +3640,23 @@ inline BinaryIntOp::LessThan BinaryIntOp::LessThan::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BinaryIntOp::LessThan& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryIntOp::LessThan& obj, + Serializer& serializer) {} template <> template -Program::BinaryIntOp::LessThan serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BinaryIntOp::LessThan serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryIntOp::LessThan obj; + Acir::BinaryIntOp::LessThan obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryIntOp::LessThanEquals& lhs, const BinaryIntOp::LessThanEquals& rhs) { @@ -2063,24 +3680,24 @@ inline BinaryIntOp::LessThanEquals BinaryIntOp::LessThanEquals::bincodeDeseriali return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BinaryIntOp::LessThanEquals& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryIntOp::LessThanEquals& obj, + Serializer& serializer) {} template <> template -Program::BinaryIntOp::LessThanEquals serde::Deserializable::deserialize( +Acir::BinaryIntOp::LessThanEquals serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BinaryIntOp::LessThanEquals obj; + Acir::BinaryIntOp::LessThanEquals obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryIntOp::And& lhs, const BinaryIntOp::And& rhs) { @@ -2104,23 +3721,22 @@ inline BinaryIntOp::And BinaryIntOp::And::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BinaryIntOp::And& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryIntOp::And& obj, Serializer& serializer) {} template <> template -Program::BinaryIntOp::And serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryIntOp::And serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryIntOp::And obj; + Acir::BinaryIntOp::And obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryIntOp::Or& lhs, const BinaryIntOp::Or& rhs) { @@ -2144,23 +3760,22 @@ inline BinaryIntOp::Or BinaryIntOp::Or::bincodeDeserialize(std::vector return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BinaryIntOp::Or& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryIntOp::Or& obj, Serializer& serializer) {} template <> template -Program::BinaryIntOp::Or serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryIntOp::Or serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryIntOp::Or obj; + Acir::BinaryIntOp::Or obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryIntOp::Xor& lhs, const BinaryIntOp::Xor& rhs) { @@ -2184,23 +3799,22 @@ inline BinaryIntOp::Xor BinaryIntOp::Xor::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BinaryIntOp::Xor& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryIntOp::Xor& obj, Serializer& serializer) {} template <> template -Program::BinaryIntOp::Xor serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryIntOp::Xor serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryIntOp::Xor obj; + Acir::BinaryIntOp::Xor obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryIntOp::Shl& lhs, const BinaryIntOp::Shl& rhs) { @@ -2224,23 +3838,22 @@ inline BinaryIntOp::Shl BinaryIntOp::Shl::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BinaryIntOp::Shl& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryIntOp::Shl& obj, Serializer& serializer) {} template <> template -Program::BinaryIntOp::Shl serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryIntOp::Shl serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryIntOp::Shl obj; + Acir::BinaryIntOp::Shl obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BinaryIntOp::Shr& lhs, const BinaryIntOp::Shr& rhs) { @@ -2264,23 +3877,22 @@ inline BinaryIntOp::Shr BinaryIntOp::Shr::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BinaryIntOp::Shr& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BinaryIntOp::Shr& obj, Serializer& serializer) {} template <> template -Program::BinaryIntOp::Shr serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BinaryIntOp::Shr serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BinaryIntOp::Shr obj; + Acir::BinaryIntOp::Shr obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BitSize& lhs, const BitSize& rhs) { @@ -2307,11 +3919,11 @@ inline BitSize BitSize::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BitSize& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BitSize& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -2320,16 +3932,16 @@ void serde::Serializable::serialize(const Program::BitSize& ob template <> template -Program::BitSize serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BitSize serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::BitSize obj; + Acir::BitSize obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BitSize::Field& lhs, const BitSize::Field& rhs) { @@ -2353,22 +3965,22 @@ inline BitSize::Field BitSize::Field::bincodeDeserialize(std::vector in return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BitSize::Field& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BitSize::Field& obj, Serializer& serializer) {} template <> template -Program::BitSize::Field serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BitSize::Field serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BitSize::Field obj; + Acir::BitSize::Field obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BitSize::Integer& lhs, const BitSize::Integer& rhs) { @@ -2395,26 +4007,25 @@ inline BitSize::Integer BitSize::Integer::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BitSize::Integer& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BitSize::Integer& obj, Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::BitSize::Integer serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BitSize::Integer serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BitSize::Integer obj; + Acir::BitSize::Integer obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall& lhs, const BlackBoxFuncCall& rhs) { @@ -2441,12 +4052,11 @@ inline BlackBoxFuncCall BlackBoxFuncCall::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BlackBoxFuncCall& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxFuncCall& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -2455,16 +4065,16 @@ void serde::Serializable::serialize(const Program::Bl template <> template -Program::BlackBoxFuncCall serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BlackBoxFuncCall serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::BlackBoxFuncCall obj; + Acir::BlackBoxFuncCall obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::AES128Encrypt& lhs, const BlackBoxFuncCall::AES128Encrypt& rhs) { @@ -2500,12 +4110,12 @@ inline BlackBoxFuncCall::AES128Encrypt BlackBoxFuncCall::AES128Encrypt::bincodeD return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::AES128Encrypt& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::BlackBoxFuncCall::AES128Encrypt& obj, Serializer& serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.iv, serializer); @@ -2515,10 +4125,10 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxFuncCall::AES128Encrypt serde::Deserializable::deserialize( +Acir::BlackBoxFuncCall::AES128Encrypt serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxFuncCall::AES128Encrypt obj; + Acir::BlackBoxFuncCall::AES128Encrypt obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.iv = serde::Deserializable::deserialize(deserializer); obj.key = serde::Deserializable::deserialize(deserializer); @@ -2526,7 +4136,7 @@ Program::BlackBoxFuncCall::AES128Encrypt serde::Deserializable template -void serde::Serializable::serialize(const Program::BlackBoxFuncCall::AND& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxFuncCall::AND& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); @@ -2573,17 +4183,16 @@ void serde::Serializable::serialize(const Progra template <> template -Program::BlackBoxFuncCall::AND serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BlackBoxFuncCall::AND serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BlackBoxFuncCall::AND obj; + Acir::BlackBoxFuncCall::AND obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::XOR& lhs, const BlackBoxFuncCall::XOR& rhs) { @@ -2616,12 +4225,12 @@ inline BlackBoxFuncCall::XOR BlackBoxFuncCall::XOR::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlackBoxFuncCall::XOR& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxFuncCall::XOR& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); @@ -2630,17 +4239,16 @@ void serde::Serializable::serialize(const Progra template <> template -Program::BlackBoxFuncCall::XOR serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BlackBoxFuncCall::XOR serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BlackBoxFuncCall::XOR obj; + Acir::BlackBoxFuncCall::XOR obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::RANGE& lhs, const BlackBoxFuncCall::RANGE& rhs) { @@ -2667,27 +4275,27 @@ inline BlackBoxFuncCall::RANGE BlackBoxFuncCall::RANGE::bincodeDeserialize(std:: return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlackBoxFuncCall::RANGE& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxFuncCall::RANGE& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.input, serializer); } template <> template -Program::BlackBoxFuncCall::RANGE serde::Deserializable::deserialize( +Acir::BlackBoxFuncCall::RANGE serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxFuncCall::RANGE obj; + Acir::BlackBoxFuncCall::RANGE obj; obj.input = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::Blake2s& lhs, const BlackBoxFuncCall::Blake2s& rhs) { @@ -2717,12 +4325,12 @@ inline BlackBoxFuncCall::Blake2s BlackBoxFuncCall::Blake2s::bincodeDeserialize(s return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlackBoxFuncCall::Blake2s& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxFuncCall::Blake2s& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.outputs, serializer); @@ -2730,16 +4338,16 @@ void serde::Serializable::serialize(const Pr template <> template -Program::BlackBoxFuncCall::Blake2s serde::Deserializable::deserialize( +Acir::BlackBoxFuncCall::Blake2s serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxFuncCall::Blake2s obj; + Acir::BlackBoxFuncCall::Blake2s obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::Blake3& lhs, const BlackBoxFuncCall::Blake3& rhs) { @@ -2769,12 +4377,12 @@ inline BlackBoxFuncCall::Blake3 BlackBoxFuncCall::Blake3::bincodeDeserialize(std return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlackBoxFuncCall::Blake3& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxFuncCall::Blake3& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.outputs, serializer); @@ -2782,16 +4390,16 @@ void serde::Serializable::serialize(const Pro template <> template -Program::BlackBoxFuncCall::Blake3 serde::Deserializable::deserialize( +Acir::BlackBoxFuncCall::Blake3 serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxFuncCall::Blake3 obj; + Acir::BlackBoxFuncCall::Blake3 obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::EcdsaSecp256k1& lhs, const BlackBoxFuncCall::EcdsaSecp256k1& rhs) { @@ -2830,12 +4438,12 @@ inline BlackBoxFuncCall::EcdsaSecp256k1 BlackBoxFuncCall::EcdsaSecp256k1::bincod return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::EcdsaSecp256k1& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::BlackBoxFuncCall::EcdsaSecp256k1& obj, Serializer& serializer) { serde::Serializable::serialize(obj.public_key_x, serializer); serde::Serializable::serialize(obj.public_key_y, serializer); @@ -2846,10 +4454,10 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxFuncCall::EcdsaSecp256k1 serde::Deserializable::deserialize( +Acir::BlackBoxFuncCall::EcdsaSecp256k1 serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxFuncCall::EcdsaSecp256k1 obj; + Acir::BlackBoxFuncCall::EcdsaSecp256k1 obj; obj.public_key_x = serde::Deserializable::deserialize(deserializer); obj.public_key_y = serde::Deserializable::deserialize(deserializer); obj.signature = serde::Deserializable::deserialize(deserializer); @@ -2858,7 +4466,7 @@ Program::BlackBoxFuncCall::EcdsaSecp256k1 serde::Deserializable template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::EcdsaSecp256r1& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::BlackBoxFuncCall::EcdsaSecp256r1& obj, Serializer& serializer) { serde::Serializable::serialize(obj.public_key_x, serializer); serde::Serializable::serialize(obj.public_key_y, serializer); @@ -2913,10 +4521,10 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxFuncCall::EcdsaSecp256r1 serde::Deserializable::deserialize( +Acir::BlackBoxFuncCall::EcdsaSecp256r1 serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxFuncCall::EcdsaSecp256r1 obj; + Acir::BlackBoxFuncCall::EcdsaSecp256r1 obj; obj.public_key_x = serde::Deserializable::deserialize(deserializer); obj.public_key_y = serde::Deserializable::deserialize(deserializer); obj.signature = serde::Deserializable::deserialize(deserializer); @@ -2925,7 +4533,7 @@ Program::BlackBoxFuncCall::EcdsaSecp256r1 serde::Deserializable template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::MultiScalarMul& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::BlackBoxFuncCall::MultiScalarMul& obj, Serializer& serializer) { serde::Serializable::serialize(obj.points, serializer); serde::Serializable::serialize(obj.scalars, serializer); @@ -2972,17 +4580,17 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxFuncCall::MultiScalarMul serde::Deserializable::deserialize( +Acir::BlackBoxFuncCall::MultiScalarMul serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxFuncCall::MultiScalarMul obj; + Acir::BlackBoxFuncCall::MultiScalarMul obj; obj.points = serde::Deserializable::deserialize(deserializer); obj.scalars = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::EmbeddedCurveAdd& lhs, const BlackBoxFuncCall::EmbeddedCurveAdd& rhs) { @@ -3016,12 +4624,12 @@ inline BlackBoxFuncCall::EmbeddedCurveAdd BlackBoxFuncCall::EmbeddedCurveAdd::bi return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::EmbeddedCurveAdd& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::BlackBoxFuncCall::EmbeddedCurveAdd& obj, Serializer& serializer) { serde::Serializable::serialize(obj.input1, serializer); serde::Serializable::serialize(obj.input2, serializer); @@ -3030,17 +4638,17 @@ void serde::Serializable::serialize template <> template -Program::BlackBoxFuncCall::EmbeddedCurveAdd serde::Deserializable< - Program::BlackBoxFuncCall::EmbeddedCurveAdd>::deserialize(Deserializer& deserializer) +Acir::BlackBoxFuncCall::EmbeddedCurveAdd serde::Deserializable::deserialize( + Deserializer& deserializer) { - Program::BlackBoxFuncCall::EmbeddedCurveAdd obj; + Acir::BlackBoxFuncCall::EmbeddedCurveAdd obj; obj.input1 = serde::Deserializable::deserialize(deserializer); obj.input2 = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::Keccakf1600& lhs, const BlackBoxFuncCall::Keccakf1600& rhs) { @@ -3070,12 +4678,12 @@ inline BlackBoxFuncCall::Keccakf1600 BlackBoxFuncCall::Keccakf1600::bincodeDeser return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::Keccakf1600& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxFuncCall::Keccakf1600& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.outputs, serializer); @@ -3083,16 +4691,16 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxFuncCall::Keccakf1600 serde::Deserializable::deserialize( +Acir::BlackBoxFuncCall::Keccakf1600 serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxFuncCall::Keccakf1600 obj; + Acir::BlackBoxFuncCall::Keccakf1600 obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::RecursiveAggregation& lhs, const BlackBoxFuncCall::RecursiveAggregation& rhs) @@ -3133,12 +4741,12 @@ inline BlackBoxFuncCall::RecursiveAggregation BlackBoxFuncCall::RecursiveAggrega return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::RecursiveAggregation& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::BlackBoxFuncCall::RecursiveAggregation& obj, Serializer& serializer) { serde::Serializable::serialize(obj.verification_key, serializer); serde::Serializable::serialize(obj.proof, serializer); @@ -3149,10 +4757,10 @@ void serde::Serializable::seria template <> template -Program::BlackBoxFuncCall::RecursiveAggregation serde::Deserializable< - Program::BlackBoxFuncCall::RecursiveAggregation>::deserialize(Deserializer& deserializer) +Acir::BlackBoxFuncCall::RecursiveAggregation serde::Deserializable< + Acir::BlackBoxFuncCall::RecursiveAggregation>::deserialize(Deserializer& deserializer) { - Program::BlackBoxFuncCall::RecursiveAggregation obj; + Acir::BlackBoxFuncCall::RecursiveAggregation obj; obj.verification_key = serde::Deserializable::deserialize(deserializer); obj.proof = serde::Deserializable::deserialize(deserializer); obj.public_inputs = serde::Deserializable::deserialize(deserializer); @@ -3161,7 +4769,7 @@ Program::BlackBoxFuncCall::RecursiveAggregation serde::Deserializable< return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::BigIntAdd& lhs, const BlackBoxFuncCall::BigIntAdd& rhs) { @@ -3194,12 +4802,12 @@ inline BlackBoxFuncCall::BigIntAdd BlackBoxFuncCall::BigIntAdd::bincodeDeseriali return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::BigIntAdd& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxFuncCall::BigIntAdd& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); @@ -3208,17 +4816,17 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxFuncCall::BigIntAdd serde::Deserializable::deserialize( +Acir::BlackBoxFuncCall::BigIntAdd serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxFuncCall::BigIntAdd obj; + Acir::BlackBoxFuncCall::BigIntAdd obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::BigIntSub& lhs, const BlackBoxFuncCall::BigIntSub& rhs) { @@ -3251,12 +4859,12 @@ inline BlackBoxFuncCall::BigIntSub BlackBoxFuncCall::BigIntSub::bincodeDeseriali return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::BigIntSub& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxFuncCall::BigIntSub& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); @@ -3265,17 +4873,17 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxFuncCall::BigIntSub serde::Deserializable::deserialize( +Acir::BlackBoxFuncCall::BigIntSub serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxFuncCall::BigIntSub obj; + Acir::BlackBoxFuncCall::BigIntSub obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::BigIntMul& lhs, const BlackBoxFuncCall::BigIntMul& rhs) { @@ -3308,12 +4916,12 @@ inline BlackBoxFuncCall::BigIntMul BlackBoxFuncCall::BigIntMul::bincodeDeseriali return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::BigIntMul& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxFuncCall::BigIntMul& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); @@ -3322,17 +4930,17 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxFuncCall::BigIntMul serde::Deserializable::deserialize( +Acir::BlackBoxFuncCall::BigIntMul serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxFuncCall::BigIntMul obj; + Acir::BlackBoxFuncCall::BigIntMul obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::BigIntDiv& lhs, const BlackBoxFuncCall::BigIntDiv& rhs) { @@ -3365,12 +4973,12 @@ inline BlackBoxFuncCall::BigIntDiv BlackBoxFuncCall::BigIntDiv::bincodeDeseriali return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::BigIntDiv& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxFuncCall::BigIntDiv& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); @@ -3379,17 +4987,17 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxFuncCall::BigIntDiv serde::Deserializable::deserialize( +Acir::BlackBoxFuncCall::BigIntDiv serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxFuncCall::BigIntDiv obj; + Acir::BlackBoxFuncCall::BigIntDiv obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::BigIntFromLeBytes& lhs, const BlackBoxFuncCall::BigIntFromLeBytes& rhs) { @@ -3423,12 +5031,12 @@ inline BlackBoxFuncCall::BigIntFromLeBytes BlackBoxFuncCall::BigIntFromLeBytes:: return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::BigIntFromLeBytes& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::BlackBoxFuncCall::BigIntFromLeBytes& obj, Serializer& serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.modulus, serializer); @@ -3437,17 +5045,17 @@ void serde::Serializable::serializ template <> template -Program::BlackBoxFuncCall::BigIntFromLeBytes serde::Deserializable< - Program::BlackBoxFuncCall::BigIntFromLeBytes>::deserialize(Deserializer& deserializer) +Acir::BlackBoxFuncCall::BigIntFromLeBytes serde::Deserializable::deserialize( + Deserializer& deserializer) { - Program::BlackBoxFuncCall::BigIntFromLeBytes obj; + Acir::BlackBoxFuncCall::BigIntFromLeBytes obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.modulus = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::BigIntToLeBytes& lhs, const BlackBoxFuncCall::BigIntToLeBytes& rhs) { @@ -3478,12 +5086,12 @@ inline BlackBoxFuncCall::BigIntToLeBytes BlackBoxFuncCall::BigIntToLeBytes::binc return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::BigIntToLeBytes& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::BlackBoxFuncCall::BigIntToLeBytes& obj, Serializer& serializer) { serde::Serializable::serialize(obj.input, serializer); serde::Serializable::serialize(obj.outputs, serializer); @@ -3491,16 +5099,16 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxFuncCall::BigIntToLeBytes serde::Deserializable< - Program::BlackBoxFuncCall::BigIntToLeBytes>::deserialize(Deserializer& deserializer) +Acir::BlackBoxFuncCall::BigIntToLeBytes serde::Deserializable::deserialize( + Deserializer& deserializer) { - Program::BlackBoxFuncCall::BigIntToLeBytes obj; + Acir::BlackBoxFuncCall::BigIntToLeBytes obj; obj.input = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::Poseidon2Permutation& lhs, const BlackBoxFuncCall::Poseidon2Permutation& rhs) @@ -3535,12 +5143,12 @@ inline BlackBoxFuncCall::Poseidon2Permutation BlackBoxFuncCall::Poseidon2Permuta return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::Poseidon2Permutation& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::BlackBoxFuncCall::Poseidon2Permutation& obj, Serializer& serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.outputs, serializer); @@ -3549,17 +5157,17 @@ void serde::Serializable::seria template <> template -Program::BlackBoxFuncCall::Poseidon2Permutation serde::Deserializable< - Program::BlackBoxFuncCall::Poseidon2Permutation>::deserialize(Deserializer& deserializer) +Acir::BlackBoxFuncCall::Poseidon2Permutation serde::Deserializable< + Acir::BlackBoxFuncCall::Poseidon2Permutation>::deserialize(Deserializer& deserializer) { - Program::BlackBoxFuncCall::Poseidon2Permutation obj; + Acir::BlackBoxFuncCall::Poseidon2Permutation obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); obj.len = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxFuncCall::Sha256Compression& lhs, const BlackBoxFuncCall::Sha256Compression& rhs) { @@ -3593,12 +5201,12 @@ inline BlackBoxFuncCall::Sha256Compression BlackBoxFuncCall::Sha256Compression:: return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxFuncCall::Sha256Compression& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::BlackBoxFuncCall::Sha256Compression& obj, Serializer& serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.hash_values, serializer); @@ -3607,17 +5215,17 @@ void serde::Serializable::serializ template <> template -Program::BlackBoxFuncCall::Sha256Compression serde::Deserializable< - Program::BlackBoxFuncCall::Sha256Compression>::deserialize(Deserializer& deserializer) +Acir::BlackBoxFuncCall::Sha256Compression serde::Deserializable::deserialize( + Deserializer& deserializer) { - Program::BlackBoxFuncCall::Sha256Compression obj; + Acir::BlackBoxFuncCall::Sha256Compression obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.hash_values = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp& lhs, const BlackBoxOp& rhs) { @@ -3644,11 +5252,11 @@ inline BlackBoxOp BlackBoxOp::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlackBoxOp& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -3657,16 +5265,16 @@ void serde::Serializable::serialize(const Program::BlackBox template <> template -Program::BlackBoxOp serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BlackBoxOp serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::BlackBoxOp obj; + Acir::BlackBoxOp obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp::AES128Encrypt& lhs, const BlackBoxOp::AES128Encrypt& rhs) { @@ -3702,12 +5310,12 @@ inline BlackBoxOp::AES128Encrypt BlackBoxOp::AES128Encrypt::bincodeDeserialize(s return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlackBoxOp::AES128Encrypt& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::AES128Encrypt& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.iv, serializer); @@ -3717,10 +5325,10 @@ void serde::Serializable::serialize(const Pr template <> template -Program::BlackBoxOp::AES128Encrypt serde::Deserializable::deserialize( +Acir::BlackBoxOp::AES128Encrypt serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxOp::AES128Encrypt obj; + Acir::BlackBoxOp::AES128Encrypt obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.iv = serde::Deserializable::deserialize(deserializer); obj.key = serde::Deserializable::deserialize(deserializer); @@ -3728,7 +5336,7 @@ Program::BlackBoxOp::AES128Encrypt serde::Deserializable template -void serde::Serializable::serialize(const Program::BlackBoxOp::Blake2s& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::Blake2s& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.message, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -3771,16 +5379,15 @@ void serde::Serializable::serialize(const Program: template <> template -Program::BlackBoxOp::Blake2s serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BlackBoxOp::Blake2s serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BlackBoxOp::Blake2s obj; + Acir::BlackBoxOp::Blake2s obj; obj.message = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp::Blake3& lhs, const BlackBoxOp::Blake3& rhs) { @@ -3810,12 +5417,12 @@ inline BlackBoxOp::Blake3 BlackBoxOp::Blake3::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BlackBoxOp::Blake3& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::Blake3& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.message, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -3823,15 +5430,15 @@ void serde::Serializable::serialize(const Program:: template <> template -Program::BlackBoxOp::Blake3 serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BlackBoxOp::Blake3 serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BlackBoxOp::Blake3 obj; + Acir::BlackBoxOp::Blake3 obj; obj.message = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp::Keccakf1600& lhs, const BlackBoxOp::Keccakf1600& rhs) { @@ -3861,12 +5468,12 @@ inline BlackBoxOp::Keccakf1600 BlackBoxOp::Keccakf1600::bincodeDeserialize(std:: return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlackBoxOp::Keccakf1600& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::Keccakf1600& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.input, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -3874,16 +5481,16 @@ void serde::Serializable::serialize(const Prog template <> template -Program::BlackBoxOp::Keccakf1600 serde::Deserializable::deserialize( +Acir::BlackBoxOp::Keccakf1600 serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxOp::Keccakf1600 obj; + Acir::BlackBoxOp::Keccakf1600 obj; obj.input = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp::EcdsaSecp256k1& lhs, const BlackBoxOp::EcdsaSecp256k1& rhs) { @@ -3922,12 +5529,12 @@ inline BlackBoxOp::EcdsaSecp256k1 BlackBoxOp::EcdsaSecp256k1::bincodeDeserialize return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlackBoxOp::EcdsaSecp256k1& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::EcdsaSecp256k1& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.hashed_msg, serializer); serde::Serializable::serialize(obj.public_key_x, serializer); @@ -3938,10 +5545,10 @@ void serde::Serializable::serialize(const P template <> template -Program::BlackBoxOp::EcdsaSecp256k1 serde::Deserializable::deserialize( +Acir::BlackBoxOp::EcdsaSecp256k1 serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxOp::EcdsaSecp256k1 obj; + Acir::BlackBoxOp::EcdsaSecp256k1 obj; obj.hashed_msg = serde::Deserializable::deserialize(deserializer); obj.public_key_x = serde::Deserializable::deserialize(deserializer); obj.public_key_y = serde::Deserializable::deserialize(deserializer); @@ -3950,7 +5557,7 @@ Program::BlackBoxOp::EcdsaSecp256k1 serde::Deserializable template -void serde::Serializable::serialize(const Program::BlackBoxOp::EcdsaSecp256r1& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::EcdsaSecp256r1& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.hashed_msg, serializer); serde::Serializable::serialize(obj.public_key_x, serializer); @@ -4005,10 +5612,10 @@ void serde::Serializable::serialize(const P template <> template -Program::BlackBoxOp::EcdsaSecp256r1 serde::Deserializable::deserialize( +Acir::BlackBoxOp::EcdsaSecp256r1 serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxOp::EcdsaSecp256r1 obj; + Acir::BlackBoxOp::EcdsaSecp256r1 obj; obj.hashed_msg = serde::Deserializable::deserialize(deserializer); obj.public_key_x = serde::Deserializable::deserialize(deserializer); obj.public_key_y = serde::Deserializable::deserialize(deserializer); @@ -4017,7 +5624,7 @@ Program::BlackBoxOp::EcdsaSecp256r1 serde::Deserializable template -void serde::Serializable::serialize(const Program::BlackBoxOp::MultiScalarMul& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::MultiScalarMul& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.points, serializer); serde::Serializable::serialize(obj.scalars, serializer); @@ -4064,17 +5671,17 @@ void serde::Serializable::serialize(const P template <> template -Program::BlackBoxOp::MultiScalarMul serde::Deserializable::deserialize( +Acir::BlackBoxOp::MultiScalarMul serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxOp::MultiScalarMul obj; + Acir::BlackBoxOp::MultiScalarMul obj; obj.points = serde::Deserializable::deserialize(deserializer); obj.scalars = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp::EmbeddedCurveAdd& lhs, const BlackBoxOp::EmbeddedCurveAdd& rhs) { @@ -4119,12 +5726,12 @@ inline BlackBoxOp::EmbeddedCurveAdd BlackBoxOp::EmbeddedCurveAdd::bincodeDeseria return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxOp::EmbeddedCurveAdd& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::EmbeddedCurveAdd& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.input1_x, serializer); serde::Serializable::serialize(obj.input1_y, serializer); @@ -4137,10 +5744,10 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxOp::EmbeddedCurveAdd serde::Deserializable::deserialize( +Acir::BlackBoxOp::EmbeddedCurveAdd serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxOp::EmbeddedCurveAdd obj; + Acir::BlackBoxOp::EmbeddedCurveAdd obj; obj.input1_x = serde::Deserializable::deserialize(deserializer); obj.input1_y = serde::Deserializable::deserialize(deserializer); obj.input1_infinite = serde::Deserializable::deserialize(deserializer); @@ -4151,7 +5758,7 @@ Program::BlackBoxOp::EmbeddedCurveAdd serde::Deserializable template -void serde::Serializable::serialize(const Program::BlackBoxOp::BigIntAdd& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::BigIntAdd& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); @@ -4198,17 +5805,16 @@ void serde::Serializable::serialize(const Progra template <> template -Program::BlackBoxOp::BigIntAdd serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BlackBoxOp::BigIntAdd serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BlackBoxOp::BigIntAdd obj; + Acir::BlackBoxOp::BigIntAdd obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp::BigIntSub& lhs, const BlackBoxOp::BigIntSub& rhs) { @@ -4241,12 +5847,12 @@ inline BlackBoxOp::BigIntSub BlackBoxOp::BigIntSub::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlackBoxOp::BigIntSub& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::BigIntSub& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); @@ -4255,17 +5861,16 @@ void serde::Serializable::serialize(const Progra template <> template -Program::BlackBoxOp::BigIntSub serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BlackBoxOp::BigIntSub serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BlackBoxOp::BigIntSub obj; + Acir::BlackBoxOp::BigIntSub obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp::BigIntMul& lhs, const BlackBoxOp::BigIntMul& rhs) { @@ -4298,12 +5903,12 @@ inline BlackBoxOp::BigIntMul BlackBoxOp::BigIntMul::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlackBoxOp::BigIntMul& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::BigIntMul& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); @@ -4312,17 +5917,16 @@ void serde::Serializable::serialize(const Progra template <> template -Program::BlackBoxOp::BigIntMul serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BlackBoxOp::BigIntMul serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BlackBoxOp::BigIntMul obj; + Acir::BlackBoxOp::BigIntMul obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp::BigIntDiv& lhs, const BlackBoxOp::BigIntDiv& rhs) { @@ -4355,12 +5959,12 @@ inline BlackBoxOp::BigIntDiv BlackBoxOp::BigIntDiv::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlackBoxOp::BigIntDiv& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::BigIntDiv& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); @@ -4369,17 +5973,16 @@ void serde::Serializable::serialize(const Progra template <> template -Program::BlackBoxOp::BigIntDiv serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BlackBoxOp::BigIntDiv serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BlackBoxOp::BigIntDiv obj; + Acir::BlackBoxOp::BigIntDiv obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp::BigIntFromLeBytes& lhs, const BlackBoxOp::BigIntFromLeBytes& rhs) { @@ -4412,12 +6015,12 @@ inline BlackBoxOp::BigIntFromLeBytes BlackBoxOp::BigIntFromLeBytes::bincodeDeser return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxOp::BigIntFromLeBytes& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::BigIntFromLeBytes& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.modulus, serializer); @@ -4426,17 +6029,17 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxOp::BigIntFromLeBytes serde::Deserializable::deserialize( +Acir::BlackBoxOp::BigIntFromLeBytes serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxOp::BigIntFromLeBytes obj; + Acir::BlackBoxOp::BigIntFromLeBytes obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.modulus = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp::BigIntToLeBytes& lhs, const BlackBoxOp::BigIntToLeBytes& rhs) { @@ -4466,12 +6069,12 @@ inline BlackBoxOp::BigIntToLeBytes BlackBoxOp::BigIntToLeBytes::bincodeDeseriali return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxOp::BigIntToLeBytes& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::BigIntToLeBytes& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.input, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -4479,16 +6082,16 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxOp::BigIntToLeBytes serde::Deserializable::deserialize( +Acir::BlackBoxOp::BigIntToLeBytes serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxOp::BigIntToLeBytes obj; + Acir::BlackBoxOp::BigIntToLeBytes obj; obj.input = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp::Poseidon2Permutation& lhs, const BlackBoxOp::Poseidon2Permutation& rhs) { @@ -4521,12 +6124,12 @@ inline BlackBoxOp::Poseidon2Permutation BlackBoxOp::Poseidon2Permutation::bincod return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxOp::Poseidon2Permutation& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::BlackBoxOp::Poseidon2Permutation& obj, Serializer& serializer) { serde::Serializable::serialize(obj.message, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -4535,17 +6138,17 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxOp::Poseidon2Permutation serde::Deserializable::deserialize( +Acir::BlackBoxOp::Poseidon2Permutation serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxOp::Poseidon2Permutation obj; + Acir::BlackBoxOp::Poseidon2Permutation obj; obj.message = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); obj.len = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp::Sha256Compression& lhs, const BlackBoxOp::Sha256Compression& rhs) { @@ -4578,12 +6181,12 @@ inline BlackBoxOp::Sha256Compression BlackBoxOp::Sha256Compression::bincodeDeser return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BlackBoxOp::Sha256Compression& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::Sha256Compression& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.input, serializer); serde::Serializable::serialize(obj.hash_values, serializer); @@ -4592,17 +6195,17 @@ void serde::Serializable::serialize( template <> template -Program::BlackBoxOp::Sha256Compression serde::Deserializable::deserialize( +Acir::BlackBoxOp::Sha256Compression serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BlackBoxOp::Sha256Compression obj; + Acir::BlackBoxOp::Sha256Compression obj; obj.input = serde::Deserializable::deserialize(deserializer); obj.hash_values = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlackBoxOp::ToRadix& lhs, const BlackBoxOp::ToRadix& rhs) { @@ -4641,12 +6244,12 @@ inline BlackBoxOp::ToRadix BlackBoxOp::ToRadix::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BlackBoxOp::ToRadix& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlackBoxOp::ToRadix& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.input, serializer); serde::Serializable::serialize(obj.radix, serializer); @@ -4657,10 +6260,9 @@ void serde::Serializable::serialize(const Program: template <> template -Program::BlackBoxOp::ToRadix serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BlackBoxOp::ToRadix serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BlackBoxOp::ToRadix obj; + Acir::BlackBoxOp::ToRadix obj; obj.input = serde::Deserializable::deserialize(deserializer); obj.radix = serde::Deserializable::deserialize(deserializer); obj.output_pointer = serde::Deserializable::deserialize(deserializer); @@ -4669,7 +6271,7 @@ Program::BlackBoxOp::ToRadix serde::Deserializable return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlockId& lhs, const BlockId& rhs) { @@ -4696,11 +6298,11 @@ inline BlockId BlockId::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlockId& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlockId& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -4709,16 +6311,16 @@ void serde::Serializable::serialize(const Program::BlockId& ob template <> template -Program::BlockId serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BlockId serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::BlockId obj; + Acir::BlockId obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlockType& lhs, const BlockType& rhs) { @@ -4745,11 +6347,11 @@ inline BlockType BlockType::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlockType& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlockType& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -4758,16 +6360,16 @@ void serde::Serializable::serialize(const Program::BlockType template <> template -Program::BlockType serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BlockType serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::BlockType obj; + Acir::BlockType obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlockType::Memory& lhs, const BlockType::Memory& rhs) { @@ -4791,23 +6393,22 @@ inline BlockType::Memory BlockType::Memory::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BlockType::Memory& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlockType::Memory& obj, Serializer& serializer) {} template <> template -Program::BlockType::Memory serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BlockType::Memory serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BlockType::Memory obj; + Acir::BlockType::Memory obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlockType::CallData& lhs, const BlockType::CallData& rhs) { @@ -4834,27 +6435,26 @@ inline BlockType::CallData BlockType::CallData::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BlockType::CallData& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlockType::CallData& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::BlockType::CallData serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BlockType::CallData serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BlockType::CallData obj; + Acir::BlockType::CallData obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BlockType::ReturnData& lhs, const BlockType::ReturnData& rhs) { @@ -4878,24 +6478,23 @@ inline BlockType::ReturnData BlockType::ReturnData::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BlockType::ReturnData& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BlockType::ReturnData& obj, + Serializer& serializer) {} template <> template -Program::BlockType::ReturnData serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BlockType::ReturnData serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BlockType::ReturnData obj; + Acir::BlockType::ReturnData obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligBytecode& lhs, const BrilligBytecode& rhs) { @@ -4922,12 +6521,11 @@ inline BrilligBytecode BrilligBytecode::bincodeDeserialize(std::vector return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligBytecode& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligBytecode& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.bytecode, serializer); @@ -4936,16 +6534,16 @@ void serde::Serializable::serialize(const Program::Bri template <> template -Program::BrilligBytecode serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BrilligBytecode serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::BrilligBytecode obj; + Acir::BrilligBytecode obj; obj.bytecode = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligInputs& lhs, const BrilligInputs& rhs) { @@ -4972,11 +6570,11 @@ inline BrilligInputs BrilligInputs::bincodeDeserialize(std::vector inpu return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligInputs& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligInputs& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -4985,16 +6583,16 @@ void serde::Serializable::serialize(const Program::Brill template <> template -Program::BrilligInputs serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BrilligInputs serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::BrilligInputs obj; + Acir::BrilligInputs obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligInputs::Single& lhs, const BrilligInputs::Single& rhs) { @@ -5021,27 +6619,26 @@ inline BrilligInputs::Single BrilligInputs::Single::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligInputs::Single& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligInputs::Single& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::BrilligInputs::Single serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BrilligInputs::Single serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligInputs::Single obj; + Acir::BrilligInputs::Single obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligInputs::Array& lhs, const BrilligInputs::Array& rhs) { @@ -5068,27 +6665,26 @@ inline BrilligInputs::Array BrilligInputs::Array::bincodeDeserialize(std::vector return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligInputs::Array& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligInputs::Array& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::BrilligInputs::Array serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BrilligInputs::Array serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligInputs::Array obj; + Acir::BrilligInputs::Array obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligInputs::MemoryArray& lhs, const BrilligInputs::MemoryArray& rhs) { @@ -5115,27 +6711,27 @@ inline BrilligInputs::MemoryArray BrilligInputs::MemoryArray::bincodeDeserialize return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligInputs::MemoryArray& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligInputs::MemoryArray& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::BrilligInputs::MemoryArray serde::Deserializable::deserialize( +Acir::BrilligInputs::MemoryArray serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BrilligInputs::MemoryArray obj; + Acir::BrilligInputs::MemoryArray obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode& lhs, const BrilligOpcode& rhs) { @@ -5162,11 +6758,11 @@ inline BrilligOpcode BrilligOpcode::bincodeDeserialize(std::vector inpu return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligOpcode& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -5175,16 +6771,16 @@ void serde::Serializable::serialize(const Program::Brill template <> template -Program::BrilligOpcode serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BrilligOpcode serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::BrilligOpcode obj; + Acir::BrilligOpcode obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::BinaryFieldOp& lhs, const BrilligOpcode::BinaryFieldOp& rhs) { @@ -5220,12 +6816,12 @@ inline BrilligOpcode::BinaryFieldOp BrilligOpcode::BinaryFieldOp::bincodeDeseria return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BrilligOpcode::BinaryFieldOp& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::BinaryFieldOp& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.op, serializer); @@ -5235,10 +6831,10 @@ void serde::Serializable::serialize( template <> template -Program::BrilligOpcode::BinaryFieldOp serde::Deserializable::deserialize( +Acir::BrilligOpcode::BinaryFieldOp serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BrilligOpcode::BinaryFieldOp obj; + Acir::BrilligOpcode::BinaryFieldOp obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.op = serde::Deserializable::deserialize(deserializer); obj.lhs = serde::Deserializable::deserialize(deserializer); @@ -5246,7 +6842,7 @@ Program::BrilligOpcode::BinaryFieldOp serde::Deserializable template -void serde::Serializable::serialize(const Program::BrilligOpcode::BinaryIntOp& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::BinaryIntOp& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.op, serializer); @@ -5301,10 +6897,10 @@ void serde::Serializable::serialize(const P template <> template -Program::BrilligOpcode::BinaryIntOp serde::Deserializable::deserialize( +Acir::BrilligOpcode::BinaryIntOp serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BrilligOpcode::BinaryIntOp obj; + Acir::BrilligOpcode::BinaryIntOp obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.op = serde::Deserializable::deserialize(deserializer); obj.bit_size = serde::Deserializable::deserialize(deserializer); @@ -5313,7 +6909,7 @@ Program::BrilligOpcode::BinaryIntOp serde::Deserializable template -void serde::Serializable::serialize(const Program::BrilligOpcode::Not& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::Not& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.source, serializer); @@ -5360,16 +6956,16 @@ void serde::Serializable::serialize(const Program:: template <> template -Program::BrilligOpcode::Not serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BrilligOpcode::Not serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligOpcode::Not obj; + Acir::BrilligOpcode::Not obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.source = serde::Deserializable::deserialize(deserializer); obj.bit_size = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::Cast& lhs, const BrilligOpcode::Cast& rhs) { @@ -5402,12 +6998,12 @@ inline BrilligOpcode::Cast BrilligOpcode::Cast::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BrilligOpcode::Cast& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::Cast& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.source, serializer); @@ -5416,17 +7012,16 @@ void serde::Serializable::serialize(const Program: template <> template -Program::BrilligOpcode::Cast serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BrilligOpcode::Cast serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligOpcode::Cast obj; + Acir::BrilligOpcode::Cast obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.source = serde::Deserializable::deserialize(deserializer); obj.bit_size = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::JumpIfNot& lhs, const BrilligOpcode::JumpIfNot& rhs) { @@ -5456,12 +7051,12 @@ inline BrilligOpcode::JumpIfNot BrilligOpcode::JumpIfNot::bincodeDeserialize(std return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligOpcode::JumpIfNot& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::JumpIfNot& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.condition, serializer); serde::Serializable::serialize(obj.location, serializer); @@ -5469,16 +7064,16 @@ void serde::Serializable::serialize(const Pro template <> template -Program::BrilligOpcode::JumpIfNot serde::Deserializable::deserialize( +Acir::BrilligOpcode::JumpIfNot serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BrilligOpcode::JumpIfNot obj; + Acir::BrilligOpcode::JumpIfNot obj; obj.condition = serde::Deserializable::deserialize(deserializer); obj.location = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::JumpIf& lhs, const BrilligOpcode::JumpIf& rhs) { @@ -5508,12 +7103,12 @@ inline BrilligOpcode::JumpIf BrilligOpcode::JumpIf::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligOpcode::JumpIf& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::JumpIf& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.condition, serializer); serde::Serializable::serialize(obj.location, serializer); @@ -5521,16 +7116,15 @@ void serde::Serializable::serialize(const Progra template <> template -Program::BrilligOpcode::JumpIf serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BrilligOpcode::JumpIf serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligOpcode::JumpIf obj; + Acir::BrilligOpcode::JumpIf obj; obj.condition = serde::Deserializable::deserialize(deserializer); obj.location = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::Jump& lhs, const BrilligOpcode::Jump& rhs) { @@ -5557,27 +7151,26 @@ inline BrilligOpcode::Jump BrilligOpcode::Jump::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BrilligOpcode::Jump& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::Jump& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.location, serializer); } template <> template -Program::BrilligOpcode::Jump serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BrilligOpcode::Jump serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligOpcode::Jump obj; + Acir::BrilligOpcode::Jump obj; obj.location = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::CalldataCopy& lhs, const BrilligOpcode::CalldataCopy& rhs) { @@ -5610,12 +7203,12 @@ inline BrilligOpcode::CalldataCopy BrilligOpcode::CalldataCopy::bincodeDeseriali return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BrilligOpcode::CalldataCopy& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::CalldataCopy& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.destination_address, serializer); serde::Serializable::serialize(obj.size_address, serializer); @@ -5624,17 +7217,17 @@ void serde::Serializable::serialize( template <> template -Program::BrilligOpcode::CalldataCopy serde::Deserializable::deserialize( +Acir::BrilligOpcode::CalldataCopy serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BrilligOpcode::CalldataCopy obj; + Acir::BrilligOpcode::CalldataCopy obj; obj.destination_address = serde::Deserializable::deserialize(deserializer); obj.size_address = serde::Deserializable::deserialize(deserializer); obj.offset_address = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::Call& lhs, const BrilligOpcode::Call& rhs) { @@ -5661,27 +7254,26 @@ inline BrilligOpcode::Call BrilligOpcode::Call::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BrilligOpcode::Call& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::Call& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.location, serializer); } template <> template -Program::BrilligOpcode::Call serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BrilligOpcode::Call serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligOpcode::Call obj; + Acir::BrilligOpcode::Call obj; obj.location = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::Const& lhs, const BrilligOpcode::Const& rhs) { @@ -5714,12 +7306,12 @@ inline BrilligOpcode::Const BrilligOpcode::Const::bincodeDeserialize(std::vector return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligOpcode::Const& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::Const& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.bit_size, serializer); @@ -5728,17 +7320,16 @@ void serde::Serializable::serialize(const Program template <> template -Program::BrilligOpcode::Const serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BrilligOpcode::Const serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligOpcode::Const obj; + Acir::BrilligOpcode::Const obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.bit_size = serde::Deserializable::deserialize(deserializer); obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::IndirectConst& lhs, const BrilligOpcode::IndirectConst& rhs) { @@ -5771,12 +7362,12 @@ inline BrilligOpcode::IndirectConst BrilligOpcode::IndirectConst::bincodeDeseria return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BrilligOpcode::IndirectConst& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::IndirectConst& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.destination_pointer, serializer); serde::Serializable::serialize(obj.bit_size, serializer); @@ -5785,17 +7376,17 @@ void serde::Serializable::serialize( template <> template -Program::BrilligOpcode::IndirectConst serde::Deserializable::deserialize( +Acir::BrilligOpcode::IndirectConst serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BrilligOpcode::IndirectConst obj; + Acir::BrilligOpcode::IndirectConst obj; obj.destination_pointer = serde::Deserializable::deserialize(deserializer); obj.bit_size = serde::Deserializable::deserialize(deserializer); obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::Return& lhs, const BrilligOpcode::Return& rhs) { @@ -5819,24 +7410,23 @@ inline BrilligOpcode::Return BrilligOpcode::Return::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligOpcode::Return& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::Return& obj, + Serializer& serializer) {} template <> template -Program::BrilligOpcode::Return serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BrilligOpcode::Return serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligOpcode::Return obj; + Acir::BrilligOpcode::Return obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::ForeignCall& lhs, const BrilligOpcode::ForeignCall& rhs) { @@ -5875,12 +7465,12 @@ inline BrilligOpcode::ForeignCall BrilligOpcode::ForeignCall::bincodeDeserialize return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligOpcode::ForeignCall& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::ForeignCall& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.function, serializer); serde::Serializable::serialize(obj.destinations, serializer); @@ -5891,10 +7481,10 @@ void serde::Serializable::serialize(const P template <> template -Program::BrilligOpcode::ForeignCall serde::Deserializable::deserialize( +Acir::BrilligOpcode::ForeignCall serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BrilligOpcode::ForeignCall obj; + Acir::BrilligOpcode::ForeignCall obj; obj.function = serde::Deserializable::deserialize(deserializer); obj.destinations = serde::Deserializable::deserialize(deserializer); obj.destination_value_types = @@ -5904,7 +7494,7 @@ Program::BrilligOpcode::ForeignCall serde::Deserializable template -void serde::Serializable::serialize(const Program::BrilligOpcode::Mov& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::Mov& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.source, serializer); @@ -5947,15 +7537,15 @@ void serde::Serializable::serialize(const Program:: template <> template -Program::BrilligOpcode::Mov serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BrilligOpcode::Mov serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligOpcode::Mov obj; + Acir::BrilligOpcode::Mov obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.source = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::ConditionalMov& lhs, const BrilligOpcode::ConditionalMov& rhs) { @@ -5991,12 +7581,12 @@ inline BrilligOpcode::ConditionalMov BrilligOpcode::ConditionalMov::bincodeDeser return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::BrilligOpcode::ConditionalMov& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::ConditionalMov& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.source_a, serializer); @@ -6006,10 +7596,10 @@ void serde::Serializable::serialize( template <> template -Program::BrilligOpcode::ConditionalMov serde::Deserializable::deserialize( +Acir::BrilligOpcode::ConditionalMov serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BrilligOpcode::ConditionalMov obj; + Acir::BrilligOpcode::ConditionalMov obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.source_a = serde::Deserializable::deserialize(deserializer); obj.source_b = serde::Deserializable::deserialize(deserializer); @@ -6017,7 +7607,7 @@ Program::BrilligOpcode::ConditionalMov serde::Deserializable template -void serde::Serializable::serialize(const Program::BrilligOpcode::Load& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::Load& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.source_pointer, serializer); @@ -6060,16 +7650,15 @@ void serde::Serializable::serialize(const Program: template <> template -Program::BrilligOpcode::Load serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BrilligOpcode::Load serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligOpcode::Load obj; + Acir::BrilligOpcode::Load obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.source_pointer = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::Store& lhs, const BrilligOpcode::Store& rhs) { @@ -6099,12 +7688,12 @@ inline BrilligOpcode::Store BrilligOpcode::Store::bincodeDeserialize(std::vector return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligOpcode::Store& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::Store& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.destination_pointer, serializer); serde::Serializable::serialize(obj.source, serializer); @@ -6112,16 +7701,15 @@ void serde::Serializable::serialize(const Program template <> template -Program::BrilligOpcode::Store serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BrilligOpcode::Store serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligOpcode::Store obj; + Acir::BrilligOpcode::Store obj; obj.destination_pointer = serde::Deserializable::deserialize(deserializer); obj.source = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::BlackBox& lhs, const BrilligOpcode::BlackBox& rhs) { @@ -6148,27 +7736,27 @@ inline BrilligOpcode::BlackBox BrilligOpcode::BlackBox::bincodeDeserialize(std:: return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligOpcode::BlackBox& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::BlackBox& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::BrilligOpcode::BlackBox serde::Deserializable::deserialize( +Acir::BrilligOpcode::BlackBox serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BrilligOpcode::BlackBox obj; + Acir::BrilligOpcode::BlackBox obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::Trap& lhs, const BrilligOpcode::Trap& rhs) { @@ -6195,27 +7783,26 @@ inline BrilligOpcode::Trap BrilligOpcode::Trap::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BrilligOpcode::Trap& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::Trap& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.revert_data, serializer); } template <> template -Program::BrilligOpcode::Trap serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BrilligOpcode::Trap serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligOpcode::Trap obj; + Acir::BrilligOpcode::Trap obj; obj.revert_data = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOpcode::Stop& lhs, const BrilligOpcode::Stop& rhs) { @@ -6242,27 +7829,26 @@ inline BrilligOpcode::Stop BrilligOpcode::Stop::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::BrilligOpcode::Stop& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOpcode::Stop& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.return_data, serializer); } template <> template -Program::BrilligOpcode::Stop serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BrilligOpcode::Stop serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligOpcode::Stop obj; + Acir::BrilligOpcode::Stop obj; obj.return_data = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOutputs& lhs, const BrilligOutputs& rhs) { @@ -6289,11 +7875,11 @@ inline BrilligOutputs BrilligOutputs::bincodeDeserialize(std::vector in return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligOutputs& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOutputs& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -6302,16 +7888,16 @@ void serde::Serializable::serialize(const Program::Bril template <> template -Program::BrilligOutputs serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::BrilligOutputs serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::BrilligOutputs obj; + Acir::BrilligOutputs obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOutputs::Simple& lhs, const BrilligOutputs::Simple& rhs) { @@ -6338,27 +7924,27 @@ inline BrilligOutputs::Simple BrilligOutputs::Simple::bincodeDeserialize(std::ve return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligOutputs::Simple& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOutputs::Simple& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::BrilligOutputs::Simple serde::Deserializable::deserialize( +Acir::BrilligOutputs::Simple serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::BrilligOutputs::Simple obj; + Acir::BrilligOutputs::Simple obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const BrilligOutputs::Array& lhs, const BrilligOutputs::Array& rhs) { @@ -6385,27 +7971,26 @@ inline BrilligOutputs::Array BrilligOutputs::Array::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::BrilligOutputs::Array& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::BrilligOutputs::Array& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::BrilligOutputs::Array serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::BrilligOutputs::Array serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::BrilligOutputs::Array obj; + Acir::BrilligOutputs::Array obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const Circuit& lhs, const Circuit& rhs) { @@ -6450,11 +8035,11 @@ inline Circuit Circuit::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::Circuit& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::Circuit& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.current_witness_index, serializer); @@ -6469,10 +8054,10 @@ void serde::Serializable::serialize(const Program::Circuit& ob template <> template -Program::Circuit serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::Circuit serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::Circuit obj; + Acir::Circuit obj; obj.current_witness_index = serde::Deserializable::deserialize(deserializer); obj.opcodes = serde::Deserializable::deserialize(deserializer); obj.expression_width = serde::Deserializable::deserialize(deserializer); @@ -6484,7 +8069,7 @@ Program::Circuit serde::Deserializable::deserialize(Deserializ return obj; } -namespace Program { +namespace Acir { inline bool operator==(const ConstantOrWitnessEnum& lhs, const ConstantOrWitnessEnum& rhs) { @@ -6511,12 +8096,12 @@ inline ConstantOrWitnessEnum ConstantOrWitnessEnum::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::ConstantOrWitnessEnum& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::ConstantOrWitnessEnum& obj, + Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -6525,17 +8110,16 @@ void serde::Serializable::serialize(const Progra template <> template -Program::ConstantOrWitnessEnum serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::ConstantOrWitnessEnum serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::ConstantOrWitnessEnum obj; + Acir::ConstantOrWitnessEnum obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const ConstantOrWitnessEnum::Constant& lhs, const ConstantOrWitnessEnum::Constant& rhs) { @@ -6562,27 +8146,27 @@ inline ConstantOrWitnessEnum::Constant ConstantOrWitnessEnum::Constant::bincodeD return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::ConstantOrWitnessEnum::Constant& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::ConstantOrWitnessEnum::Constant& obj, Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::ConstantOrWitnessEnum::Constant serde::Deserializable::deserialize( +Acir::ConstantOrWitnessEnum::Constant serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::ConstantOrWitnessEnum::Constant obj; + Acir::ConstantOrWitnessEnum::Constant obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const ConstantOrWitnessEnum::Witness& lhs, const ConstantOrWitnessEnum::Witness& rhs) { @@ -6609,27 +8193,27 @@ inline ConstantOrWitnessEnum::Witness ConstantOrWitnessEnum::Witness::bincodeDes return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::ConstantOrWitnessEnum::Witness& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::ConstantOrWitnessEnum::Witness& obj, Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::ConstantOrWitnessEnum::Witness serde::Deserializable::deserialize( +Acir::ConstantOrWitnessEnum::Witness serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::ConstantOrWitnessEnum::Witness obj; + Acir::ConstantOrWitnessEnum::Witness obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const Expression& lhs, const Expression& rhs) { @@ -6662,11 +8246,11 @@ inline Expression Expression::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::Expression& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::Expression& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.mul_terms, serializer); @@ -6677,10 +8261,10 @@ void serde::Serializable::serialize(const Program::Expressi template <> template -Program::Expression serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::Expression serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::Expression obj; + Acir::Expression obj; obj.mul_terms = serde::Deserializable::deserialize(deserializer); obj.linear_combinations = serde::Deserializable::deserialize(deserializer); obj.q_c = serde::Deserializable::deserialize(deserializer); @@ -6688,7 +8272,7 @@ Program::Expression serde::Deserializable::deserialize(Dese return obj; } -namespace Program { +namespace Acir { inline bool operator==(const ExpressionOrMemory& lhs, const ExpressionOrMemory& rhs) { @@ -6715,12 +8299,12 @@ inline ExpressionOrMemory ExpressionOrMemory::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::ExpressionOrMemory& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::ExpressionOrMemory& obj, + Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -6729,16 +8313,16 @@ void serde::Serializable::serialize(const Program:: template <> template -Program::ExpressionOrMemory serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::ExpressionOrMemory serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::ExpressionOrMemory obj; + Acir::ExpressionOrMemory obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const ExpressionOrMemory::Expression& lhs, const ExpressionOrMemory::Expression& rhs) { @@ -6765,27 +8349,27 @@ inline ExpressionOrMemory::Expression ExpressionOrMemory::Expression::bincodeDes return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::ExpressionOrMemory::Expression& obj, Serializer& serializer) +void serde::Serializable::serialize( + const Acir::ExpressionOrMemory::Expression& obj, Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::ExpressionOrMemory::Expression serde::Deserializable::deserialize( +Acir::ExpressionOrMemory::Expression serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::ExpressionOrMemory::Expression obj; + Acir::ExpressionOrMemory::Expression obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const ExpressionOrMemory::Memory& lhs, const ExpressionOrMemory::Memory& rhs) { @@ -6812,27 +8396,27 @@ inline ExpressionOrMemory::Memory ExpressionOrMemory::Memory::bincodeDeserialize return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::ExpressionOrMemory::Memory& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::ExpressionOrMemory::Memory& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::ExpressionOrMemory::Memory serde::Deserializable::deserialize( +Acir::ExpressionOrMemory::Memory serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::ExpressionOrMemory::Memory obj; + Acir::ExpressionOrMemory::Memory obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const ExpressionWidth& lhs, const ExpressionWidth& rhs) { @@ -6859,12 +8443,11 @@ inline ExpressionWidth ExpressionWidth::bincodeDeserialize(std::vector return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::ExpressionWidth& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::ExpressionWidth& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -6873,16 +8456,16 @@ void serde::Serializable::serialize(const Program::Exp template <> template -Program::ExpressionWidth serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::ExpressionWidth serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::ExpressionWidth obj; + Acir::ExpressionWidth obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const ExpressionWidth::Unbounded& lhs, const ExpressionWidth::Unbounded& rhs) { @@ -6906,24 +8489,24 @@ inline ExpressionWidth::Unbounded ExpressionWidth::Unbounded::bincodeDeserialize return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::ExpressionWidth::Unbounded& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::ExpressionWidth::Unbounded& obj, + Serializer& serializer) {} template <> template -Program::ExpressionWidth::Unbounded serde::Deserializable::deserialize( +Acir::ExpressionWidth::Unbounded serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::ExpressionWidth::Unbounded obj; + Acir::ExpressionWidth::Unbounded obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const ExpressionWidth::Bounded& lhs, const ExpressionWidth::Bounded& rhs) { @@ -6950,27 +8533,27 @@ inline ExpressionWidth::Bounded ExpressionWidth::Bounded::bincodeDeserialize(std return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::ExpressionWidth::Bounded& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::ExpressionWidth::Bounded& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.width, serializer); } template <> template -Program::ExpressionWidth::Bounded serde::Deserializable::deserialize( +Acir::ExpressionWidth::Bounded serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::ExpressionWidth::Bounded obj; + Acir::ExpressionWidth::Bounded obj; obj.width = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const FunctionInput& lhs, const FunctionInput& rhs) { @@ -7000,11 +8583,11 @@ inline FunctionInput FunctionInput::bincodeDeserialize(std::vector inpu return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::FunctionInput& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::FunctionInput& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.input, serializer); @@ -7014,17 +8597,17 @@ void serde::Serializable::serialize(const Program::Funct template <> template -Program::FunctionInput serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::FunctionInput serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::FunctionInput obj; + Acir::FunctionInput obj; obj.input = serde::Deserializable::deserialize(deserializer); obj.num_bits = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const HeapArray& lhs, const HeapArray& rhs) { @@ -7054,11 +8637,11 @@ inline HeapArray HeapArray::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::HeapArray& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::HeapArray& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.pointer, serializer); @@ -7068,17 +8651,17 @@ void serde::Serializable::serialize(const Program::HeapArray template <> template -Program::HeapArray serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::HeapArray serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::HeapArray obj; + Acir::HeapArray obj; obj.pointer = serde::Deserializable::deserialize(deserializer); obj.size = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const HeapValueType& lhs, const HeapValueType& rhs) { @@ -7105,11 +8688,11 @@ inline HeapValueType HeapValueType::bincodeDeserialize(std::vector inpu return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::HeapValueType& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::HeapValueType& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -7118,16 +8701,16 @@ void serde::Serializable::serialize(const Program::HeapV template <> template -Program::HeapValueType serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::HeapValueType serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::HeapValueType obj; + Acir::HeapValueType obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const HeapValueType::Simple& lhs, const HeapValueType::Simple& rhs) { @@ -7154,27 +8737,26 @@ inline HeapValueType::Simple HeapValueType::Simple::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::HeapValueType::Simple& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::HeapValueType::Simple& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::HeapValueType::Simple serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::HeapValueType::Simple serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::HeapValueType::Simple obj; + Acir::HeapValueType::Simple obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const HeapValueType::Array& lhs, const HeapValueType::Array& rhs) { @@ -7204,12 +8786,12 @@ inline HeapValueType::Array HeapValueType::Array::bincodeDeserialize(std::vector return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::HeapValueType::Array& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::HeapValueType::Array& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value_types, serializer); serde::Serializable::serialize(obj.size, serializer); @@ -7217,16 +8799,15 @@ void serde::Serializable::serialize(const Program template <> template -Program::HeapValueType::Array serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::HeapValueType::Array serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::HeapValueType::Array obj; + Acir::HeapValueType::Array obj; obj.value_types = serde::Deserializable::deserialize(deserializer); obj.size = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const HeapValueType::Vector& lhs, const HeapValueType::Vector& rhs) { @@ -7253,27 +8834,26 @@ inline HeapValueType::Vector HeapValueType::Vector::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::HeapValueType::Vector& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::HeapValueType::Vector& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value_types, serializer); } template <> template -Program::HeapValueType::Vector serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::HeapValueType::Vector serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::HeapValueType::Vector obj; + Acir::HeapValueType::Vector obj; obj.value_types = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const HeapVector& lhs, const HeapVector& rhs) { @@ -7303,11 +8883,11 @@ inline HeapVector HeapVector::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::HeapVector& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::HeapVector& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.pointer, serializer); @@ -7317,17 +8897,17 @@ void serde::Serializable::serialize(const Program::HeapVect template <> template -Program::HeapVector serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::HeapVector serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::HeapVector obj; + Acir::HeapVector obj; obj.pointer = serde::Deserializable::deserialize(deserializer); obj.size = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const IntegerBitSize& lhs, const IntegerBitSize& rhs) { @@ -7354,11 +8934,11 @@ inline IntegerBitSize IntegerBitSize::bincodeDeserialize(std::vector in return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::IntegerBitSize& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::IntegerBitSize& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -7367,16 +8947,16 @@ void serde::Serializable::serialize(const Program::Inte template <> template -Program::IntegerBitSize serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::IntegerBitSize serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::IntegerBitSize obj; + Acir::IntegerBitSize obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const IntegerBitSize::U1& lhs, const IntegerBitSize::U1& rhs) { @@ -7400,23 +8980,23 @@ inline IntegerBitSize::U1 IntegerBitSize::U1::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::IntegerBitSize::U1& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::IntegerBitSize::U1& obj, + Serializer& serializer) {} template <> template -Program::IntegerBitSize::U1 serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::IntegerBitSize::U1 serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::IntegerBitSize::U1 obj; + Acir::IntegerBitSize::U1 obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const IntegerBitSize::U8& lhs, const IntegerBitSize::U8& rhs) { @@ -7440,23 +9020,23 @@ inline IntegerBitSize::U8 IntegerBitSize::U8::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::IntegerBitSize::U8& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::IntegerBitSize::U8& obj, + Serializer& serializer) {} template <> template -Program::IntegerBitSize::U8 serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::IntegerBitSize::U8 serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::IntegerBitSize::U8 obj; + Acir::IntegerBitSize::U8 obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const IntegerBitSize::U16& lhs, const IntegerBitSize::U16& rhs) { @@ -7480,24 +9060,23 @@ inline IntegerBitSize::U16 IntegerBitSize::U16::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::IntegerBitSize::U16& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::IntegerBitSize::U16& obj, + Serializer& serializer) {} template <> template -Program::IntegerBitSize::U16 serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::IntegerBitSize::U16 serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::IntegerBitSize::U16 obj; + Acir::IntegerBitSize::U16 obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const IntegerBitSize::U32& lhs, const IntegerBitSize::U32& rhs) { @@ -7521,24 +9100,23 @@ inline IntegerBitSize::U32 IntegerBitSize::U32::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::IntegerBitSize::U32& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::IntegerBitSize::U32& obj, + Serializer& serializer) {} template <> template -Program::IntegerBitSize::U32 serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::IntegerBitSize::U32 serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::IntegerBitSize::U32 obj; + Acir::IntegerBitSize::U32 obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const IntegerBitSize::U64& lhs, const IntegerBitSize::U64& rhs) { @@ -7562,24 +9140,23 @@ inline IntegerBitSize::U64 IntegerBitSize::U64::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::IntegerBitSize::U64& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::IntegerBitSize::U64& obj, + Serializer& serializer) {} template <> template -Program::IntegerBitSize::U64 serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::IntegerBitSize::U64 serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::IntegerBitSize::U64 obj; + Acir::IntegerBitSize::U64 obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const IntegerBitSize::U128& lhs, const IntegerBitSize::U128& rhs) { @@ -7603,24 +9180,23 @@ inline IntegerBitSize::U128 IntegerBitSize::U128::bincodeDeserialize(std::vector return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::IntegerBitSize::U128& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::IntegerBitSize::U128& obj, + Serializer& serializer) {} template <> template -Program::IntegerBitSize::U128 serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::IntegerBitSize::U128 serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::IntegerBitSize::U128 obj; + Acir::IntegerBitSize::U128 obj; return obj; } -namespace Program { +namespace Acir { inline bool operator==(const MemOp& lhs, const MemOp& rhs) { @@ -7653,11 +9229,11 @@ inline MemOp MemOp::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::MemOp& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::MemOp& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.operation, serializer); @@ -7668,10 +9244,10 @@ void serde::Serializable::serialize(const Program::MemOp& obj, S template <> template -Program::MemOp serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::MemOp serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::MemOp obj; + Acir::MemOp obj; obj.operation = serde::Deserializable::deserialize(deserializer); obj.index = serde::Deserializable::deserialize(deserializer); obj.value = serde::Deserializable::deserialize(deserializer); @@ -7679,7 +9255,7 @@ Program::MemOp serde::Deserializable::deserialize(Deserializer& return obj; } -namespace Program { +namespace Acir { inline bool operator==(const MemoryAddress& lhs, const MemoryAddress& rhs) { @@ -7706,11 +9282,11 @@ inline MemoryAddress MemoryAddress::bincodeDeserialize(std::vector inpu return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::MemoryAddress& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::MemoryAddress& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -7719,16 +9295,16 @@ void serde::Serializable::serialize(const Program::Memor template <> template -Program::MemoryAddress serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::MemoryAddress serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::MemoryAddress obj; + Acir::MemoryAddress obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const MemoryAddress::Direct& lhs, const MemoryAddress::Direct& rhs) { @@ -7755,27 +9331,26 @@ inline MemoryAddress::Direct MemoryAddress::Direct::bincodeDeserialize(std::vect return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::MemoryAddress::Direct& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::MemoryAddress::Direct& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::MemoryAddress::Direct serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::MemoryAddress::Direct serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::MemoryAddress::Direct obj; + Acir::MemoryAddress::Direct obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const MemoryAddress::Relative& lhs, const MemoryAddress::Relative& rhs) { @@ -7802,27 +9377,27 @@ inline MemoryAddress::Relative MemoryAddress::Relative::bincodeDeserialize(std:: return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::MemoryAddress::Relative& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::MemoryAddress::Relative& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::MemoryAddress::Relative serde::Deserializable::deserialize( +Acir::MemoryAddress::Relative serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::MemoryAddress::Relative obj; + Acir::MemoryAddress::Relative obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const Opcode& lhs, const Opcode& rhs) { @@ -7849,11 +9424,11 @@ inline Opcode Opcode::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::Opcode& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::Opcode& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -7862,16 +9437,16 @@ void serde::Serializable::serialize(const Program::Opcode& obj, template <> template -Program::Opcode serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::Opcode serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::Opcode obj; + Acir::Opcode obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const Opcode::AssertZero& lhs, const Opcode::AssertZero& rhs) { @@ -7898,26 +9473,26 @@ inline Opcode::AssertZero Opcode::AssertZero::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::Opcode::AssertZero& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::Opcode::AssertZero& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::Opcode::AssertZero serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::Opcode::AssertZero serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::Opcode::AssertZero obj; + Acir::Opcode::AssertZero obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const Opcode::BlackBoxFuncCall& lhs, const Opcode::BlackBoxFuncCall& rhs) { @@ -7944,27 +9519,27 @@ inline Opcode::BlackBoxFuncCall Opcode::BlackBoxFuncCall::bincodeDeserialize(std return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::Opcode::BlackBoxFuncCall& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::Opcode::BlackBoxFuncCall& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::Opcode::BlackBoxFuncCall serde::Deserializable::deserialize( +Acir::Opcode::BlackBoxFuncCall serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::Opcode::BlackBoxFuncCall obj; + Acir::Opcode::BlackBoxFuncCall obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const Opcode::MemoryOp& lhs, const Opcode::MemoryOp& rhs) { @@ -7997,12 +9572,11 @@ inline Opcode::MemoryOp Opcode::MemoryOp::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::Opcode::MemoryOp& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::Opcode::MemoryOp& obj, Serializer& serializer) { serde::Serializable::serialize(obj.block_id, serializer); serde::Serializable::serialize(obj.op, serializer); @@ -8011,16 +9585,16 @@ void serde::Serializable::serialize(const Program::Op template <> template -Program::Opcode::MemoryOp serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::Opcode::MemoryOp serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::Opcode::MemoryOp obj; + Acir::Opcode::MemoryOp obj; obj.block_id = serde::Deserializable::deserialize(deserializer); obj.op = serde::Deserializable::deserialize(deserializer); obj.predicate = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const Opcode::MemoryInit& lhs, const Opcode::MemoryInit& rhs) { @@ -8053,12 +9627,12 @@ inline Opcode::MemoryInit Opcode::MemoryInit::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::Opcode::MemoryInit& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::Opcode::MemoryInit& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.block_id, serializer); serde::Serializable::serialize(obj.init, serializer); @@ -8067,16 +9641,16 @@ void serde::Serializable::serialize(const Program:: template <> template -Program::Opcode::MemoryInit serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::Opcode::MemoryInit serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::Opcode::MemoryInit obj; + Acir::Opcode::MemoryInit obj; obj.block_id = serde::Deserializable::deserialize(deserializer); obj.init = serde::Deserializable::deserialize(deserializer); obj.block_type = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const Opcode::BrilligCall& lhs, const Opcode::BrilligCall& rhs) { @@ -8112,12 +9686,12 @@ inline Opcode::BrilligCall Opcode::BrilligCall::bincodeDeserialize(std::vector template -void serde::Serializable::serialize(const Program::Opcode::BrilligCall& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::Opcode::BrilligCall& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.id, serializer); serde::Serializable::serialize(obj.inputs, serializer); @@ -8127,10 +9701,9 @@ void serde::Serializable::serialize(const Program: template <> template -Program::Opcode::BrilligCall serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::Opcode::BrilligCall serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::Opcode::BrilligCall obj; + Acir::Opcode::BrilligCall obj; obj.id = serde::Deserializable::deserialize(deserializer); obj.inputs = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); @@ -8138,7 +9711,7 @@ Program::Opcode::BrilligCall serde::Deserializable return obj; } -namespace Program { +namespace Acir { inline bool operator==(const Opcode::Call& lhs, const Opcode::Call& rhs) { @@ -8174,11 +9747,11 @@ inline Opcode::Call Opcode::Call::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::Opcode::Call& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::Opcode::Call& obj, Serializer& serializer) { serde::Serializable::serialize(obj.id, serializer); serde::Serializable::serialize(obj.inputs, serializer); @@ -8188,9 +9761,9 @@ void serde::Serializable::serialize(const Program::Opcode template <> template -Program::Opcode::Call serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::Opcode::Call serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::Opcode::Call obj; + Acir::Opcode::Call obj; obj.id = serde::Deserializable::deserialize(deserializer); obj.inputs = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); @@ -8198,7 +9771,7 @@ Program::Opcode::Call serde::Deserializable::deserialize( return obj; } -namespace Program { +namespace Acir { inline bool operator==(const OpcodeLocation& lhs, const OpcodeLocation& rhs) { @@ -8225,11 +9798,11 @@ inline OpcodeLocation OpcodeLocation::bincodeDeserialize(std::vector in return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::OpcodeLocation& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::OpcodeLocation& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -8238,16 +9811,16 @@ void serde::Serializable::serialize(const Program::Opco template <> template -Program::OpcodeLocation serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::OpcodeLocation serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::OpcodeLocation obj; + Acir::OpcodeLocation obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const OpcodeLocation::Acir& lhs, const OpcodeLocation::Acir& rhs) { @@ -8274,27 +9847,26 @@ inline OpcodeLocation::Acir OpcodeLocation::Acir::bincodeDeserialize(std::vector return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::OpcodeLocation::Acir& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::OpcodeLocation::Acir& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::OpcodeLocation::Acir serde::Deserializable::deserialize( - Deserializer& deserializer) +Acir::OpcodeLocation::Acir serde::Deserializable::deserialize(Deserializer& deserializer) { - Program::OpcodeLocation::Acir obj; + Acir::OpcodeLocation::Acir obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const OpcodeLocation::Brillig& lhs, const OpcodeLocation::Brillig& rhs) { @@ -8324,12 +9896,12 @@ inline OpcodeLocation::Brillig OpcodeLocation::Brillig::bincodeDeserialize(std:: return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::OpcodeLocation::Brillig& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::OpcodeLocation::Brillig& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.acir_index, serializer); serde::Serializable::serialize(obj.brillig_index, serializer); @@ -8337,16 +9909,16 @@ void serde::Serializable::serialize(const Prog template <> template -Program::OpcodeLocation::Brillig serde::Deserializable::deserialize( +Acir::OpcodeLocation::Brillig serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::OpcodeLocation::Brillig obj; + Acir::OpcodeLocation::Brillig obj; obj.acir_index = serde::Deserializable::deserialize(deserializer); obj.brillig_index = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const Program& lhs, const Program& rhs) { @@ -8376,11 +9948,11 @@ inline Program Program::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::Program& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::Program& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.functions, serializer); @@ -8390,10 +9962,10 @@ void serde::Serializable::serialize(const Program::Program& ob template <> template -Program::Program serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::Program serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::Program obj; + Acir::Program obj; obj.functions = serde::Deserializable::deserialize(deserializer); obj.unconstrained_functions = serde::Deserializable::deserialize(deserializer); @@ -8401,7 +9973,7 @@ Program::Program serde::Deserializable::deserialize(Deserializ return obj; } -namespace Program { +namespace Acir { inline bool operator==(const PublicInputs& lhs, const PublicInputs& rhs) { @@ -8428,11 +10000,11 @@ inline PublicInputs PublicInputs::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::PublicInputs& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::PublicInputs& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -8441,16 +10013,16 @@ void serde::Serializable::serialize(const Program::Public template <> template -Program::PublicInputs serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::PublicInputs serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::PublicInputs obj; + Acir::PublicInputs obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const ValueOrArray& lhs, const ValueOrArray& rhs) { @@ -8477,11 +10049,11 @@ inline ValueOrArray ValueOrArray::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::ValueOrArray& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::ValueOrArray& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -8490,16 +10062,16 @@ void serde::Serializable::serialize(const Program::ValueO template <> template -Program::ValueOrArray serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::ValueOrArray serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::ValueOrArray obj; + Acir::ValueOrArray obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const ValueOrArray::MemoryAddress& lhs, const ValueOrArray::MemoryAddress& rhs) { @@ -8526,27 +10098,27 @@ inline ValueOrArray::MemoryAddress ValueOrArray::MemoryAddress::bincodeDeseriali return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize( - const Program::ValueOrArray::MemoryAddress& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::ValueOrArray::MemoryAddress& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::ValueOrArray::MemoryAddress serde::Deserializable::deserialize( +Acir::ValueOrArray::MemoryAddress serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::ValueOrArray::MemoryAddress obj; + Acir::ValueOrArray::MemoryAddress obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const ValueOrArray::HeapArray& lhs, const ValueOrArray::HeapArray& rhs) { @@ -8573,27 +10145,27 @@ inline ValueOrArray::HeapArray ValueOrArray::HeapArray::bincodeDeserialize(std:: return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::ValueOrArray::HeapArray& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::ValueOrArray::HeapArray& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::ValueOrArray::HeapArray serde::Deserializable::deserialize( +Acir::ValueOrArray::HeapArray serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::ValueOrArray::HeapArray obj; + Acir::ValueOrArray::HeapArray obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const ValueOrArray::HeapVector& lhs, const ValueOrArray::HeapVector& rhs) { @@ -8620,27 +10192,27 @@ inline ValueOrArray::HeapVector ValueOrArray::HeapVector::bincodeDeserialize(std return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::ValueOrArray::HeapVector& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Acir::ValueOrArray::HeapVector& obj, + Serializer& serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Program::ValueOrArray::HeapVector serde::Deserializable::deserialize( +Acir::ValueOrArray::HeapVector serde::Deserializable::deserialize( Deserializer& deserializer) { - Program::ValueOrArray::HeapVector obj; + Acir::ValueOrArray::HeapVector obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Program { +namespace Acir { inline bool operator==(const Witness& lhs, const Witness& rhs) { @@ -8667,11 +10239,11 @@ inline Witness Witness::bincodeDeserialize(std::vector input) return value; } -} // end of namespace Program +} // end of namespace Acir template <> template -void serde::Serializable::serialize(const Program::Witness& obj, Serializer& serializer) +void serde::Serializable::serialize(const Acir::Witness& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -8680,10 +10252,10 @@ void serde::Serializable::serialize(const Program::Witness& ob template <> template -Program::Witness serde::Deserializable::deserialize(Deserializer& deserializer) +Acir::Witness serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - Program::Witness obj; + Acir::Witness obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp index 67ef655babfd..5aeae0355d21 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp @@ -1,49 +1,57 @@ #pragma once #include "bincode.hpp" +#include "msgpack.hpp" #include "serde.hpp" -namespace WitnessStack { +namespace Witnesses { struct Witness { uint32_t value; friend bool operator==(const Witness&, const Witness&); - - bool operator<(Witness const& rhs) const { return value < rhs.value; } - std::vector bincodeSerialize() const; static Witness bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct WitnessMap { - std::map value; + std::map value; friend bool operator==(const WitnessMap&, const WitnessMap&); std::vector bincodeSerialize() const; static WitnessMap bincodeDeserialize(std::vector); + + void msgpack_pack(auto& packer) const { packer.pack(value); } + void msgpack_unpack(auto const& o) { o.convert(value); } }; struct StackItem { uint32_t index; - WitnessStack::WitnessMap witness; + Witnesses::WitnessMap witness; friend bool operator==(const StackItem&, const StackItem&); std::vector bincodeSerialize() const; static StackItem bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(index, witness); }; struct WitnessStack { - std::vector stack; + std::vector stack; friend bool operator==(const WitnessStack&, const WitnessStack&); std::vector bincodeSerialize() const; static WitnessStack bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(stack); }; -} // end of namespace WitnessStack +} // end of namespace Witnesses -namespace WitnessStack { +namespace Witnesses { inline bool operator==(const StackItem& lhs, const StackItem& rhs) { @@ -73,11 +81,11 @@ inline StackItem StackItem::bincodeDeserialize(std::vector input) return value; } -} // end of namespace WitnessStack +} // end of namespace Witnesses template <> template -void serde::Serializable::serialize(const WitnessStack::StackItem& obj, Serializer& serializer) +void serde::Serializable::serialize(const Witnesses::StackItem& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.index, serializer); @@ -87,17 +95,17 @@ void serde::Serializable::serialize(const WitnessStack: template <> template -WitnessStack::StackItem serde::Deserializable::deserialize(Deserializer& deserializer) +Witnesses::StackItem serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - WitnessStack::StackItem obj; + Witnesses::StackItem obj; obj.index = serde::Deserializable::deserialize(deserializer); obj.witness = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace WitnessStack { +namespace Witnesses { inline bool operator==(const Witness& lhs, const Witness& rhs) { @@ -124,11 +132,11 @@ inline Witness Witness::bincodeDeserialize(std::vector input) return value; } -} // end of namespace WitnessStack +} // end of namespace Witnesses template <> template -void serde::Serializable::serialize(const WitnessStack::Witness& obj, Serializer& serializer) +void serde::Serializable::serialize(const Witnesses::Witness& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -137,16 +145,16 @@ void serde::Serializable::serialize(const WitnessStack::W template <> template -WitnessStack::Witness serde::Deserializable::deserialize(Deserializer& deserializer) +Witnesses::Witness serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - WitnessStack::Witness obj; + Witnesses::Witness obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace WitnessStack { +namespace Witnesses { inline bool operator==(const WitnessMap& lhs, const WitnessMap& rhs) { @@ -173,12 +181,11 @@ inline WitnessMap WitnessMap::bincodeDeserialize(std::vector input) return value; } -} // end of namespace WitnessStack +} // end of namespace Witnesses template <> template -void serde::Serializable::serialize(const WitnessStack::WitnessMap& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Witnesses::WitnessMap& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); @@ -187,16 +194,16 @@ void serde::Serializable::serialize(const WitnessStack template <> template -WitnessStack::WitnessMap serde::Deserializable::deserialize(Deserializer& deserializer) +Witnesses::WitnessMap serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - WitnessStack::WitnessMap obj; + Witnesses::WitnessMap obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace WitnessStack { +namespace Witnesses { inline bool operator==(const WitnessStack& lhs, const WitnessStack& rhs) { @@ -223,12 +230,11 @@ inline WitnessStack WitnessStack::bincodeDeserialize(std::vector input) return value; } -} // end of namespace WitnessStack +} // end of namespace Witnesses template <> template -void serde::Serializable::serialize(const WitnessStack::WitnessStack& obj, - Serializer& serializer) +void serde::Serializable::serialize(const Witnesses::WitnessStack& obj, Serializer& serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.stack, serializer); @@ -237,10 +243,10 @@ void serde::Serializable::serialize(const WitnessSta template <> template -WitnessStack::WitnessStack serde::Deserializable::deserialize(Deserializer& deserializer) +Witnesses::WitnessStack serde::Deserializable::deserialize(Deserializer& deserializer) { deserializer.increase_container_depth(); - WitnessStack::WitnessStack obj; + Witnesses::WitnessStack obj; obj.stack = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; From aeefaf33884ce74266f193e9685917f1e85f41f9 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 18 Mar 2025 15:43:46 +0000 Subject: [PATCH 04/36] Add Witness lt --- .../cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp index 5aeae0355d21..2882219bab1d 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp @@ -13,6 +13,7 @@ struct Witness { std::vector bincodeSerialize() const; static Witness bincodeDeserialize(std::vector); + bool operator<(Witness const& rhs) const { return value < rhs.value; } void msgpack_pack(auto& packer) const { packer.pack(value); } void msgpack_unpack(auto const& o) { o.convert(value); } }; From 07566e7357149b11bca6e5ddcd2e19a1d65a3ba0 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 18 Mar 2025 16:14:29 +0000 Subject: [PATCH 05/36] AVM transpiler Cargo.lock --- avm-transpiler/Cargo.lock | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/avm-transpiler/Cargo.lock b/avm-transpiler/Cargo.lock index 61ebfba95473..2526a67a85e4 100644 --- a/avm-transpiler/Cargo.lock +++ b/avm-transpiler/Cargo.lock @@ -16,6 +16,7 @@ dependencies = [ "prost", "prost-build", "protoc-prebuilt", + "rmp-serde", "serde", "serde-big-array", "strum", @@ -787,7 +788,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1575,6 +1576,28 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rmp" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "228ed7c16fa39782c3b3468e974aec2795e9089153cd08ee2e9aefb3613334c4" +dependencies = [ + "byteorder", + "num-traits", + "paste", +] + +[[package]] +name = "rmp-serde" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e599a477cf9840e92f2cde9a7189e67b42c57532749bf90aea6ec10facd4db" +dependencies = [ + "byteorder", + "rmp", + "serde", +] + [[package]] name = "rustc-demangle" version = "0.1.24" From d356f69303068315358d5db185bc2acb34bdaf47 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Wed, 19 Mar 2025 10:16:49 +0000 Subject: [PATCH 06/36] Remove comments about massaging the C++ code --- barretenberg/cpp/src/barretenberg/dsl/README.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/README.md b/barretenberg/cpp/src/barretenberg/dsl/README.md index 440eec6c4a8b..f9f434deefaa 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/README.md +++ b/barretenberg/cpp/src/barretenberg/dsl/README.md @@ -8,16 +8,11 @@ There are two types of breaking serialization changes. One that alters the inter 1. Internal Structure Change -Go to the ACVM `acir` crate and re-run the [serde reflection test](https://github.com/noir-lang/noir/blob/master/acvm-repo/acir/src/lib.rs#L51). Remember to comment out the hash check to write the updated C++ serde file. Copy that file into the `dsl` package's [serde folder](./acir_format/serde/) where you will see an `acir.hpp` file. +The C++ bindings are generated by the ACVM `acir` crate and while running the [serde reflection test](https://github.com/noir-lang/noir/blob/master/acvm-repo/acir/src/lib.rs#L51). +By default it just ascretains that the format has not changed, but it can be told to write the updated mappings to `acir.cpp` and `witness_stack.cpp`, which become `acir.hpp` and +`witness_stack.hpp` in `aztec-packages`. -You will have to update a couple things in the new `acir.hpp`: - -- Replace all `throw serde::deserialization_error` with `throw_or_abort` -- The top-level struct (such as `Program`) will still use its own namespace for its internal fields. This extra `Program::` can be removed from the top-level `struct Program { .. }` object. - -The same can then be done for any breaking changes introduced to `witness_stack.hpp`. - -The steps described above can be executed like so: +The code can be regenerated and copied over with the following commands: ```shell cd noir/noir-repo && NOIR_CODEGEN_OVERWRITE=1 cargo test -p acir cpp_codegen && cd - From 0d9dc2201bf98e08e024d31b8cbce6d3e642dd49 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Wed, 19 Mar 2025 16:36:09 +0000 Subject: [PATCH 07/36] Try to deserialize as msgpack instead of binpack --- .../acir_format/acir_to_constraint_buf.cpp | 27 +++++++++++++++++-- .../acir_format/acir_to_constraint_buf.hpp | 3 ++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index c582220ef956..d48546500538 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -3,6 +3,7 @@ #include "barretenberg/dsl/acir_format/recursion_constraint.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" #include "barretenberg/plonk_honk_shared/execution_trace/gate_data.hpp" +#include "barretenberg/serialize/msgpack.hpp" #include #include #include @@ -828,7 +829,14 @@ AcirFormat circuit_buf_to_acir_format(std::vector const& buf, uint32_t // TODO(https://github.com/AztecProtocol/barretenberg/issues/927): Move to using just // `program_buf_to_acir_format` once Honk fully supports all ACIR test flows For now the backend still expects // to work with a single ACIR function - auto circuit = Acir::Program::bincodeDeserialize(buf).functions[0]; + + // TODO: We can't rely on exceptions to deserialize one format or the other because they are + // not supported in Wasm (turned off in arch.cmake, aborting in throw_or_abort). + // For now just try the new format and see what happens. + // auto circuit = Acir::Program::bincodeDeserialize(buf).functions[0]; + + auto program = program_buf_to_program(buf); + auto circuit = program.functions[0]; return circuit_serde_to_acir_format(circuit, honk_recursion); } @@ -878,9 +886,24 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) return witness_map_to_witness_vector(w); } +Acir::Program program_buf_to_program(std::vector const& buf) +{ + // TODO: We can't rely on exceptions to deserialize one format or the other because they are + // not supported in Wasm (turned off in arch.cmake, aborting in throw_or_abort). + // For now just try the new format and see what happens. + // auto program = Acir::Program::bincodeDeserialize(buf); + + Acir::Program program; + + // Skip the first byte; we know it's going to be msgpack for this experiment. + msgpack::unpack(&reinterpret_cast(buf.data())[1], buf.size() - 1).get().convert(program); + + return program; +} + std::vector program_buf_to_acir_format(std::vector const& buf, uint32_t honk_recursion) { - auto program = Acir::Program::bincodeDeserialize(buf); + auto program = program_buf_to_program(buf); std::vector constraint_systems; constraint_systems.reserve(program.functions.size()); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 4560c8245445..3d755db14b3b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -4,6 +4,7 @@ namespace acir_format { +Acir::Program program_buf_to_program(std::vector const& buf); AcirFormat circuit_buf_to_acir_format(std::vector const& buf, uint32_t honk_recursion); /** @@ -25,4 +26,4 @@ AcirProgramStack get_acir_program_stack(std::string const& bytecode_path, std::string const& witness_path, uint32_t honk_recursion); #endif -} // namespace acir_format \ No newline at end of file +} // namespace acir_format From 16124ce7512506cae7cac3805922f11e91b52d4a Mon Sep 17 00:00:00 2001 From: aakoshh Date: Wed, 19 Mar 2025 16:36:26 +0000 Subject: [PATCH 08/36] Patch no longer needed with this branch --- noir/noir-repo.patch | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/noir/noir-repo.patch b/noir/noir-repo.patch index 416a6f859586..399654ea75a2 100644 --- a/noir/noir-repo.patch +++ b/noir/noir-repo.patch @@ -217,26 +217,3 @@ index 5f819990..00000000 -[dependencies] -- 2.43.0 - -From fd8f444eba5db51bee2173d7c2f66bebaa693d30 Mon Sep 17 00:00:00 2001 -From: aakoshh -Date: Mon, 17 Mar 2025 12:10:58 +0000 -Subject: [PATCH 4/4] Ignore package.tgz - ---- - .gitignore | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/.gitignore b/.gitignore -index 3349018..c93fe8e 100644 ---- a/.gitignore -+++ b/.gitignore -@@ -59,3 +59,6 @@ codegen - - mutants.out - mutants.out.old -+ -+# Artifacts created by `noir/bootstrap.sh build_packages` -+**/package.tgz --- -2.43.0 From 0ecd8d449eecc17009b9b06b6e386b72721edb65 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Wed, 19 Mar 2025 21:50:44 +0000 Subject: [PATCH 09/36] Use obj.via.map --- .../dsl/acir_format/serde/acir.hpp | 707 ++++++++---------- .../dsl/acir_format/serde/witness_stack.hpp | 4 +- 2 files changed, 334 insertions(+), 377 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index dcdc6dbd79f4..59cbf7ff0b94 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -14,7 +14,7 @@ struct BinaryFieldOp { static Add bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Sub { @@ -23,7 +23,7 @@ struct BinaryFieldOp { static Sub bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Mul { @@ -32,7 +32,7 @@ struct BinaryFieldOp { static Mul bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Div { @@ -41,7 +41,7 @@ struct BinaryFieldOp { static Div bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct IntegerDiv { @@ -50,7 +50,7 @@ struct BinaryFieldOp { static IntegerDiv bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Equals { @@ -59,7 +59,7 @@ struct BinaryFieldOp { static Equals bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct LessThan { @@ -68,7 +68,7 @@ struct BinaryFieldOp { static LessThan bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct LessThanEquals { @@ -77,7 +77,7 @@ struct BinaryFieldOp { static LessThanEquals bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; std::variant value; @@ -127,43 +127,39 @@ struct BinaryFieldOp { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'BinaryFieldOp' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'BinaryFieldOp' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Add") { - Add v; - obj.convert(v); + Add v = obj.convert(); value = v; } else if (tag == "Sub") { - Sub v; - obj.convert(v); + Sub v = obj.convert(); value = v; } else if (tag == "Mul") { - Mul v; - obj.convert(v); + Mul v = obj.convert(); value = v; } else if (tag == "Div") { - Div v; - obj.convert(v); + Div v = obj.convert(); value = v; } else if (tag == "IntegerDiv") { - IntegerDiv v; - obj.convert(v); + IntegerDiv v = obj.convert(); value = v; } else if (tag == "Equals") { - Equals v; - obj.convert(v); + Equals v = obj.convert(); value = v; } else if (tag == "LessThan") { - LessThan v; - obj.convert(v); + LessThan v = obj.convert(); value = v; } else if (tag == "LessThanEquals") { - LessThanEquals v; - obj.convert(v); + LessThanEquals v = obj.convert(); value = v; } else { throw_or_abort("unknown 'BinaryFieldOp' enum variant: " + tag); @@ -179,7 +175,7 @@ struct BinaryIntOp { static Add bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Sub { @@ -188,7 +184,7 @@ struct BinaryIntOp { static Sub bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Mul { @@ -197,7 +193,7 @@ struct BinaryIntOp { static Mul bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Div { @@ -206,7 +202,7 @@ struct BinaryIntOp { static Div bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Equals { @@ -215,7 +211,7 @@ struct BinaryIntOp { static Equals bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct LessThan { @@ -224,7 +220,7 @@ struct BinaryIntOp { static LessThan bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct LessThanEquals { @@ -233,7 +229,7 @@ struct BinaryIntOp { static LessThanEquals bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct And { @@ -242,7 +238,7 @@ struct BinaryIntOp { static And bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Or { @@ -251,7 +247,7 @@ struct BinaryIntOp { static Or bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Xor { @@ -260,7 +256,7 @@ struct BinaryIntOp { static Xor bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Shl { @@ -269,7 +265,7 @@ struct BinaryIntOp { static Shl bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Shr { @@ -278,7 +274,7 @@ struct BinaryIntOp { static Shr bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; std::variant value; @@ -340,59 +336,51 @@ struct BinaryIntOp { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'BinaryIntOp' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'BinaryIntOp' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Add") { - Add v; - obj.convert(v); + Add v = obj.convert(); value = v; } else if (tag == "Sub") { - Sub v; - obj.convert(v); + Sub v = obj.convert(); value = v; } else if (tag == "Mul") { - Mul v; - obj.convert(v); + Mul v = obj.convert(); value = v; } else if (tag == "Div") { - Div v; - obj.convert(v); + Div v = obj.convert(); value = v; } else if (tag == "Equals") { - Equals v; - obj.convert(v); + Equals v = obj.convert(); value = v; } else if (tag == "LessThan") { - LessThan v; - obj.convert(v); + LessThan v = obj.convert(); value = v; } else if (tag == "LessThanEquals") { - LessThanEquals v; - obj.convert(v); + LessThanEquals v = obj.convert(); value = v; } else if (tag == "And") { - And v; - obj.convert(v); + And v = obj.convert(); value = v; } else if (tag == "Or") { - Or v; - obj.convert(v); + Or v = obj.convert(); value = v; } else if (tag == "Xor") { - Xor v; - obj.convert(v); + Xor v = obj.convert(); value = v; } else if (tag == "Shl") { - Shl v; - obj.convert(v); + Shl v = obj.convert(); value = v; } else if (tag == "Shr") { - Shr v; - obj.convert(v); + Shr v = obj.convert(); value = v; } else { throw_or_abort("unknown 'BinaryIntOp' enum variant: " + tag); @@ -408,7 +396,7 @@ struct IntegerBitSize { static U1 bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct U8 { @@ -417,7 +405,7 @@ struct IntegerBitSize { static U8 bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct U16 { @@ -426,7 +414,7 @@ struct IntegerBitSize { static U16 bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct U32 { @@ -435,7 +423,7 @@ struct IntegerBitSize { static U32 bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct U64 { @@ -444,7 +432,7 @@ struct IntegerBitSize { static U64 bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct U128 { @@ -453,7 +441,7 @@ struct IntegerBitSize { static U128 bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; std::variant value; @@ -497,35 +485,33 @@ struct IntegerBitSize { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'IntegerBitSize' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'IntegerBitSize' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "U1") { - U1 v; - obj.convert(v); + U1 v = obj.convert(); value = v; } else if (tag == "U8") { - U8 v; - obj.convert(v); + U8 v = obj.convert(); value = v; } else if (tag == "U16") { - U16 v; - obj.convert(v); + U16 v = obj.convert(); value = v; } else if (tag == "U32") { - U32 v; - obj.convert(v); + U32 v = obj.convert(); value = v; } else if (tag == "U64") { - U64 v; - obj.convert(v); + U64 v = obj.convert(); value = v; } else if (tag == "U128") { - U128 v; - obj.convert(v); + U128 v = obj.convert(); value = v; } else { throw_or_abort("unknown 'IntegerBitSize' enum variant: " + tag); @@ -541,7 +527,7 @@ struct BitSize { static Field bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Integer { @@ -552,7 +538,7 @@ struct BitSize { static Integer bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; std::variant value; @@ -584,19 +570,21 @@ struct BitSize { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'BitSize' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'BitSize' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Field") { - Field v; - obj.convert(v); + Field v = obj.convert(); value = v; } else if (tag == "Integer") { - Integer v; - obj.convert(v); + Integer v = obj.convert(); value = v; } else { throw_or_abort("unknown 'BitSize' enum variant: " + tag); @@ -614,7 +602,7 @@ struct MemoryAddress { static Direct bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct Relative { @@ -625,7 +613,7 @@ struct MemoryAddress { static Relative bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; std::variant value; @@ -657,19 +645,21 @@ struct MemoryAddress { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'MemoryAddress' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'MemoryAddress' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Direct") { - Direct v; - obj.convert(v); + Direct v = obj.convert(); value = v; } else if (tag == "Relative") { - Relative v; - obj.convert(v); + Relative v = obj.convert(); value = v; } else { throw_or_abort("unknown 'MemoryAddress' enum variant: " + tag); @@ -1003,79 +993,66 @@ struct BlackBoxOp { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'BlackBoxOp' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'BlackBoxOp' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "AES128Encrypt") { - AES128Encrypt v; - obj.convert(v); + AES128Encrypt v = obj.convert(); value = v; } else if (tag == "Blake2s") { - Blake2s v; - obj.convert(v); + Blake2s v = obj.convert(); value = v; } else if (tag == "Blake3") { - Blake3 v; - obj.convert(v); + Blake3 v = obj.convert(); value = v; } else if (tag == "Keccakf1600") { - Keccakf1600 v; - obj.convert(v); + Keccakf1600 v = obj.convert(); value = v; } else if (tag == "EcdsaSecp256k1") { - EcdsaSecp256k1 v; - obj.convert(v); + EcdsaSecp256k1 v = obj.convert(); value = v; } else if (tag == "EcdsaSecp256r1") { - EcdsaSecp256r1 v; - obj.convert(v); + EcdsaSecp256r1 v = obj.convert(); value = v; } else if (tag == "MultiScalarMul") { - MultiScalarMul v; - obj.convert(v); + MultiScalarMul v = obj.convert(); value = v; } else if (tag == "EmbeddedCurveAdd") { - EmbeddedCurveAdd v; - obj.convert(v); + EmbeddedCurveAdd v = obj.convert(); value = v; } else if (tag == "BigIntAdd") { - BigIntAdd v; - obj.convert(v); + BigIntAdd v = obj.convert(); value = v; } else if (tag == "BigIntSub") { - BigIntSub v; - obj.convert(v); + BigIntSub v = obj.convert(); value = v; } else if (tag == "BigIntMul") { - BigIntMul v; - obj.convert(v); + BigIntMul v = obj.convert(); value = v; } else if (tag == "BigIntDiv") { - BigIntDiv v; - obj.convert(v); + BigIntDiv v = obj.convert(); value = v; } else if (tag == "BigIntFromLeBytes") { - BigIntFromLeBytes v; - obj.convert(v); + BigIntFromLeBytes v = obj.convert(); value = v; } else if (tag == "BigIntToLeBytes") { - BigIntToLeBytes v; - obj.convert(v); + BigIntToLeBytes v = obj.convert(); value = v; } else if (tag == "Poseidon2Permutation") { - Poseidon2Permutation v; - obj.convert(v); + Poseidon2Permutation v = obj.convert(); value = v; } else if (tag == "Sha256Compression") { - Sha256Compression v; - obj.convert(v); + Sha256Compression v = obj.convert(); value = v; } else if (tag == "ToRadix") { - ToRadix v; - obj.convert(v); + ToRadix v = obj.convert(); value = v; } else { throw_or_abort("unknown 'BlackBoxOp' enum variant: " + tag); @@ -1095,7 +1072,7 @@ struct HeapValueType { static Simple bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct Array { @@ -1151,23 +1128,24 @@ struct HeapValueType { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'HeapValueType' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'HeapValueType' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Simple") { - Simple v; - obj.convert(v); + Simple v = obj.convert(); value = v; } else if (tag == "Array") { - Array v; - obj.convert(v); + Array v = obj.convert(); value = v; } else if (tag == "Vector") { - Vector v; - obj.convert(v); + Vector v = obj.convert(); value = v; } else { throw_or_abort("unknown 'HeapValueType' enum variant: " + tag); @@ -1185,7 +1163,7 @@ struct ValueOrArray { static MemoryAddress bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct HeapArray { @@ -1196,7 +1174,7 @@ struct ValueOrArray { static HeapArray bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct HeapVector { @@ -1207,7 +1185,7 @@ struct ValueOrArray { static HeapVector bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; std::variant value; @@ -1242,23 +1220,24 @@ struct ValueOrArray { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'ValueOrArray' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'ValueOrArray' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "MemoryAddress") { - MemoryAddress v; - obj.convert(v); + MemoryAddress v = obj.convert(); value = v; } else if (tag == "HeapArray") { - HeapArray v; - obj.convert(v); + HeapArray v = obj.convert(); value = v; } else if (tag == "HeapVector") { - HeapVector v; - obj.convert(v); + HeapVector v = obj.convert(); value = v; } else { throw_or_abort("unknown 'ValueOrArray' enum variant: " + tag); @@ -1403,7 +1382,7 @@ struct BrilligOpcode { static Return bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct ForeignCall { @@ -1474,7 +1453,7 @@ struct BrilligOpcode { static BlackBox bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct Trap { @@ -1600,91 +1579,75 @@ struct BrilligOpcode { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'BrilligOpcode' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'BrilligOpcode' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "BinaryFieldOp") { - BinaryFieldOp v; - obj.convert(v); + BinaryFieldOp v = obj.convert(); value = v; } else if (tag == "BinaryIntOp") { - BinaryIntOp v; - obj.convert(v); + BinaryIntOp v = obj.convert(); value = v; } else if (tag == "Not") { - Not v; - obj.convert(v); + Not v = obj.convert(); value = v; } else if (tag == "Cast") { - Cast v; - obj.convert(v); + Cast v = obj.convert(); value = v; } else if (tag == "JumpIfNot") { - JumpIfNot v; - obj.convert(v); + JumpIfNot v = obj.convert(); value = v; } else if (tag == "JumpIf") { - JumpIf v; - obj.convert(v); + JumpIf v = obj.convert(); value = v; } else if (tag == "Jump") { - Jump v; - obj.convert(v); + Jump v = obj.convert(); value = v; } else if (tag == "CalldataCopy") { - CalldataCopy v; - obj.convert(v); + CalldataCopy v = obj.convert(); value = v; } else if (tag == "Call") { - Call v; - obj.convert(v); + Call v = obj.convert(); value = v; } else if (tag == "Const") { - Const v; - obj.convert(v); + Const v = obj.convert(); value = v; } else if (tag == "IndirectConst") { - IndirectConst v; - obj.convert(v); + IndirectConst v = obj.convert(); value = v; } else if (tag == "Return") { - Return v; - obj.convert(v); + Return v = obj.convert(); value = v; } else if (tag == "ForeignCall") { - ForeignCall v; - obj.convert(v); + ForeignCall v = obj.convert(); value = v; } else if (tag == "Mov") { - Mov v; - obj.convert(v); + Mov v = obj.convert(); value = v; } else if (tag == "ConditionalMov") { - ConditionalMov v; - obj.convert(v); + ConditionalMov v = obj.convert(); value = v; } else if (tag == "Load") { - Load v; - obj.convert(v); + Load v = obj.convert(); value = v; } else if (tag == "Store") { - Store v; - obj.convert(v); + Store v = obj.convert(); value = v; } else if (tag == "BlackBox") { - BlackBox v; - obj.convert(v); + BlackBox v = obj.convert(); value = v; } else if (tag == "Trap") { - Trap v; - obj.convert(v); + Trap v = obj.convert(); value = v; } else if (tag == "Stop") { - Stop v; - obj.convert(v); + Stop v = obj.convert(); value = v; } else { throw_or_abort("unknown 'BrilligOpcode' enum variant: " + tag); @@ -1700,7 +1663,7 @@ struct Witness { static Witness bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct ConstantOrWitnessEnum { @@ -1713,7 +1676,7 @@ struct ConstantOrWitnessEnum { static Constant bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct Witness { @@ -1724,7 +1687,7 @@ struct ConstantOrWitnessEnum { static Witness bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; std::variant value; @@ -1756,19 +1719,21 @@ struct ConstantOrWitnessEnum { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'ConstantOrWitnessEnum' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'ConstantOrWitnessEnum' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Constant") { - Constant v; - obj.convert(v); + Constant v = obj.convert(); value = v; } else if (tag == "Witness") { - Witness v; - obj.convert(v); + Witness v = obj.convert(); value = v; } else { throw_or_abort("unknown 'ConstantOrWitnessEnum' enum variant: " + tag); @@ -2133,91 +2098,75 @@ struct BlackBoxFuncCall { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'BlackBoxFuncCall' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'BlackBoxFuncCall' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "AES128Encrypt") { - AES128Encrypt v; - obj.convert(v); + AES128Encrypt v = obj.convert(); value = v; } else if (tag == "AND") { - AND v; - obj.convert(v); + AND v = obj.convert(); value = v; } else if (tag == "XOR") { - XOR v; - obj.convert(v); + XOR v = obj.convert(); value = v; } else if (tag == "RANGE") { - RANGE v; - obj.convert(v); + RANGE v = obj.convert(); value = v; } else if (tag == "Blake2s") { - Blake2s v; - obj.convert(v); + Blake2s v = obj.convert(); value = v; } else if (tag == "Blake3") { - Blake3 v; - obj.convert(v); + Blake3 v = obj.convert(); value = v; } else if (tag == "EcdsaSecp256k1") { - EcdsaSecp256k1 v; - obj.convert(v); + EcdsaSecp256k1 v = obj.convert(); value = v; } else if (tag == "EcdsaSecp256r1") { - EcdsaSecp256r1 v; - obj.convert(v); + EcdsaSecp256r1 v = obj.convert(); value = v; } else if (tag == "MultiScalarMul") { - MultiScalarMul v; - obj.convert(v); + MultiScalarMul v = obj.convert(); value = v; } else if (tag == "EmbeddedCurveAdd") { - EmbeddedCurveAdd v; - obj.convert(v); + EmbeddedCurveAdd v = obj.convert(); value = v; } else if (tag == "Keccakf1600") { - Keccakf1600 v; - obj.convert(v); + Keccakf1600 v = obj.convert(); value = v; } else if (tag == "RecursiveAggregation") { - RecursiveAggregation v; - obj.convert(v); + RecursiveAggregation v = obj.convert(); value = v; } else if (tag == "BigIntAdd") { - BigIntAdd v; - obj.convert(v); + BigIntAdd v = obj.convert(); value = v; } else if (tag == "BigIntSub") { - BigIntSub v; - obj.convert(v); + BigIntSub v = obj.convert(); value = v; } else if (tag == "BigIntMul") { - BigIntMul v; - obj.convert(v); + BigIntMul v = obj.convert(); value = v; } else if (tag == "BigIntDiv") { - BigIntDiv v; - obj.convert(v); + BigIntDiv v = obj.convert(); value = v; } else if (tag == "BigIntFromLeBytes") { - BigIntFromLeBytes v; - obj.convert(v); + BigIntFromLeBytes v = obj.convert(); value = v; } else if (tag == "BigIntToLeBytes") { - BigIntToLeBytes v; - obj.convert(v); + BigIntToLeBytes v = obj.convert(); value = v; } else if (tag == "Poseidon2Permutation") { - Poseidon2Permutation v; - obj.convert(v); + Poseidon2Permutation v = obj.convert(); value = v; } else if (tag == "Sha256Compression") { - Sha256Compression v; - obj.convert(v); + Sha256Compression v = obj.convert(); value = v; } else { throw_or_abort("unknown 'BlackBoxFuncCall' enum variant: " + tag); @@ -2233,7 +2182,7 @@ struct BlockId { static BlockId bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct BlockType { @@ -2244,7 +2193,7 @@ struct BlockType { static Memory bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct CallData { @@ -2255,7 +2204,7 @@ struct BlockType { static CallData bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct ReturnData { @@ -2264,7 +2213,7 @@ struct BlockType { static ReturnData bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; std::variant value; @@ -2299,23 +2248,24 @@ struct BlockType { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'BlockType' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'BlockType' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Memory") { - Memory v; - obj.convert(v); + Memory v = obj.convert(); value = v; } else if (tag == "CallData") { - CallData v; - obj.convert(v); + CallData v = obj.convert(); value = v; } else if (tag == "ReturnData") { - ReturnData v; - obj.convert(v); + ReturnData v = obj.convert(); value = v; } else { throw_or_abort("unknown 'BlockType' enum variant: " + tag); @@ -2345,7 +2295,7 @@ struct BrilligInputs { static Single bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct Array { @@ -2356,7 +2306,7 @@ struct BrilligInputs { static Array bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct MemoryArray { @@ -2367,7 +2317,7 @@ struct BrilligInputs { static MemoryArray bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; std::variant value; @@ -2402,23 +2352,24 @@ struct BrilligInputs { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'BrilligInputs' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'BrilligInputs' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Single") { - Single v; - obj.convert(v); + Single v = obj.convert(); value = v; } else if (tag == "Array") { - Array v; - obj.convert(v); + Array v = obj.convert(); value = v; } else if (tag == "MemoryArray") { - MemoryArray v; - obj.convert(v); + MemoryArray v = obj.convert(); value = v; } else { throw_or_abort("unknown 'BrilligInputs' enum variant: " + tag); @@ -2436,7 +2387,7 @@ struct BrilligOutputs { static Simple bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct Array { @@ -2447,7 +2398,7 @@ struct BrilligOutputs { static Array bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; std::variant value; @@ -2479,19 +2430,21 @@ struct BrilligOutputs { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'BrilligOutputs' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'BrilligOutputs' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Simple") { - Simple v; - obj.convert(v); + Simple v = obj.convert(); value = v; } else if (tag == "Array") { - Array v; - obj.convert(v); + Array v = obj.convert(); value = v; } else { throw_or_abort("unknown 'BrilligOutputs' enum variant: " + tag); @@ -2521,7 +2474,7 @@ struct Opcode { static AssertZero bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct BlackBoxFuncCall { @@ -2532,7 +2485,7 @@ struct Opcode { static BlackBoxFuncCall bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct MemoryOp { @@ -2626,35 +2579,33 @@ struct Opcode { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'Opcode' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'Opcode' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "AssertZero") { - AssertZero v; - obj.convert(v); + AssertZero v = obj.convert(); value = v; } else if (tag == "BlackBoxFuncCall") { - BlackBoxFuncCall v; - obj.convert(v); + BlackBoxFuncCall v = obj.convert(); value = v; } else if (tag == "MemoryOp") { - MemoryOp v; - obj.convert(v); + MemoryOp v = obj.convert(); value = v; } else if (tag == "MemoryInit") { - MemoryInit v; - obj.convert(v); + MemoryInit v = obj.convert(); value = v; } else if (tag == "BrilligCall") { - BrilligCall v; - obj.convert(v); + BrilligCall v = obj.convert(); value = v; } else if (tag == "Call") { - Call v; - obj.convert(v); + Call v = obj.convert(); value = v; } else { throw_or_abort("unknown 'Opcode' enum variant: " + tag); @@ -2672,7 +2623,7 @@ struct ExpressionOrMemory { static Expression bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct Memory { @@ -2683,7 +2634,7 @@ struct ExpressionOrMemory { static Memory bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; std::variant value; @@ -2715,19 +2666,21 @@ struct ExpressionOrMemory { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'ExpressionOrMemory' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'ExpressionOrMemory' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Expression") { - Expression v; - obj.convert(v); + Expression v = obj.convert(); value = v; } else if (tag == "Memory") { - Memory v; - obj.convert(v); + Memory v = obj.convert(); value = v; } else { throw_or_abort("unknown 'ExpressionOrMemory' enum variant: " + tag); @@ -2754,7 +2707,7 @@ struct ExpressionWidth { static Unbounded bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const {} - void msgpack_unpack(auto const& o) {} + void msgpack_unpack(msgpack::object const& o) {} }; struct Bounded { @@ -2796,19 +2749,21 @@ struct ExpressionWidth { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'ExpressionWidth' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'ExpressionWidth' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Unbounded") { - Unbounded v; - obj.convert(v); + Unbounded v = obj.convert(); value = v; } else if (tag == "Bounded") { - Bounded v; - obj.convert(v); + Bounded v = obj.convert(); value = v; } else { throw_or_abort("unknown 'ExpressionWidth' enum variant: " + tag); @@ -2826,7 +2781,7 @@ struct OpcodeLocation { static Acir bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct Brillig { @@ -2869,19 +2824,21 @@ struct OpcodeLocation { value); } - void msgpack_unpack(auto const& o) + void msgpack_unpack(msgpack::object const& o) { - std::map data = o.convert(); - auto entry = data.begin(); - auto tag = entry->first; - auto obj = entry->second; + if (o.type != msgpack::type::object_type::MAP) { + throw_or_abort("expected map for 'OpcodeLocation' enum; got " + std::to_string(o.type)); + } + if (o.via.map.size != 1) { + throw_or_abort("expected 1 entry for 'OpcodeLocation' enum; got " + std::to_string(o.via.map.size)); + } + std::string tag = o.via.map.ptr[0].key.convert(); + msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Acir") { - Acir v; - obj.convert(v); + Acir v = obj.convert(); value = v; } else if (tag == "Brillig") { - Brillig v; - obj.convert(v); + Brillig v = obj.convert(); value = v; } else { throw_or_abort("unknown 'OpcodeLocation' enum variant: " + tag); @@ -2897,7 +2854,7 @@ struct PublicInputs { static PublicInputs bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct Circuit { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp index 2882219bab1d..caf4df43e69d 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp @@ -15,7 +15,7 @@ struct Witness { bool operator<(Witness const& rhs) const { return value < rhs.value; } void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct WitnessMap { @@ -26,7 +26,7 @@ struct WitnessMap { static WitnessMap bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(auto const& o) { o.convert(value); } + void msgpack_unpack(msgpack::object const& o) { o.convert(value); } }; struct StackItem { From ebf72f5e8d01fe4e194f67f74ee976137f73ae28 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Wed, 19 Mar 2025 22:17:47 +0000 Subject: [PATCH 10/36] Check if the data can be parsed as msgpack --- .../acir_format/acir_to_constraint_buf.cpp | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index d48546500538..220c1df1ba00 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -886,19 +886,32 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) return witness_map_to_witness_vector(w); } +/** + * @brief Deserializes a `Program` from bytes, trying `msgpack` or `bincode` formats. + */ Acir::Program program_buf_to_program(std::vector const& buf) { - // TODO: We can't rely on exceptions to deserialize one format or the other because they are - // not supported in Wasm (turned off in arch.cmake, aborting in throw_or_abort). - // For now just try the new format and see what happens. - // auto program = Acir::Program::bincodeDeserialize(buf); - - Acir::Program program; - - // Skip the first byte; we know it's going to be msgpack for this experiment. - msgpack::unpack(&reinterpret_cast(buf.data())[1], buf.size() - 1).get().convert(program); - - return program; + // We can't rely on exceptions to try to deserialize binpack, falling back to + // msgpack if it fails, because exceptions are (or were) not supported in Wasm + // and they are turned off in arch.cmake. + // For now our other option is to check if the data is valid msgpack, + // which slows things down, but we can't tell if the first byte of + // the data accidentally matches one of our format values. + if (buf.size() > 0) { + // Skip the first byte, which would be our format marker; + // we know it's going to be msgpack in this experiment. + // Once we remove support for legacy format (ie. without the + // format marker), we can get rid of this. + auto buffer = reinterpret_cast(buf.data())[1]; + size_t size = buf.size() - 1; + msgpack::null_visitor probe; + if (msgpack::parse(&buffer, size, probe)) { + Acir::Program program; + msgpack::unpack(&buffer, size).get().convert(program); + return program; + } + } + return Acir::Program::bincodeDeserialize(buf); } std::vector program_buf_to_acir_format(std::vector const& buf, uint32_t honk_recursion) From f764a86013391f46c5b5287d01817d6db95c54ed Mon Sep 17 00:00:00 2001 From: aakoshh Date: Thu, 20 Mar 2025 09:18:55 +0000 Subject: [PATCH 11/36] Disable msgpack in bb --- .../acir_format/acir_to_constraint_buf.cpp | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 220c1df1ba00..cd88046998dc 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -897,20 +897,20 @@ Acir::Program program_buf_to_program(std::vector const& buf) // For now our other option is to check if the data is valid msgpack, // which slows things down, but we can't tell if the first byte of // the data accidentally matches one of our format values. - if (buf.size() > 0) { - // Skip the first byte, which would be our format marker; - // we know it's going to be msgpack in this experiment. - // Once we remove support for legacy format (ie. without the - // format marker), we can get rid of this. - auto buffer = reinterpret_cast(buf.data())[1]; - size_t size = buf.size() - 1; - msgpack::null_visitor probe; - if (msgpack::parse(&buffer, size, probe)) { - Acir::Program program; - msgpack::unpack(&buffer, size).get().convert(program); - return program; - } - } + // if (buf.size() > 0) { + // // Skip the first byte, which would be our format marker; + // // we know it's going to be msgpack in this experiment. + // // Once we remove support for legacy format (ie. without the + // // format marker), we can get rid of this. + // auto buffer = reinterpret_cast(buf.data())[1]; + // size_t size = buf.size() - 1; + // msgpack::null_visitor probe; + // if (msgpack::parse(&buffer, size, probe)) { + // Acir::Program program; + // msgpack::unpack(&buffer, size).get().convert(program); + // return program; + // } + // } return Acir::Program::bincodeDeserialize(buf); } From c8f6157e4c3063bd1bff482ce0916679bb8d8b81 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Fri, 21 Mar 2025 11:32:30 +0000 Subject: [PATCH 12/36] Fixed codegen --- .../dsl/acir_format/serde/acir.hpp | 1809 ++++++++++++++--- .../dsl/acir_format/serde/witness_stack.hpp | 22 +- 2 files changed, 1492 insertions(+), 339 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index 59cbf7ff0b94..dee1a5e9fc83 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -89,79 +89,99 @@ struct BinaryFieldOp { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "Add"; + is_unit = true; break; case 1: tag = "Sub"; + is_unit = true; break; case 2: tag = "Mul"; + is_unit = true; break; case 3: tag = "Div"; + is_unit = true; break; case 4: tag = "IntegerDiv"; + is_unit = true; break; case 5: tag = "Equals"; + is_unit = true; break; case 6: tag = "LessThan"; + is_unit = true; break; case 7: tag = "LessThanEquals"; + is_unit = true; break; default: - throw_or_abort("unknown 'BinaryFieldOp' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'BinaryFieldOp' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'BinaryFieldOp' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'BinaryFieldOp': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'BinaryFieldOp'; got type " + std::to_string(o.type)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'BinaryFieldOp' enum; got " + std::to_string(o.via.map.size)); + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'BinaryFieldOp'; got " + std::to_string(o.via.map.size)); + } + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Add") { - Add v = obj.convert(); + Add v; value = v; } else if (tag == "Sub") { - Sub v = obj.convert(); + Sub v; value = v; } else if (tag == "Mul") { - Mul v = obj.convert(); + Mul v; value = v; } else if (tag == "Div") { - Div v = obj.convert(); + Div v; value = v; } else if (tag == "IntegerDiv") { - IntegerDiv v = obj.convert(); + IntegerDiv v; value = v; } else if (tag == "Equals") { - Equals v = obj.convert(); + Equals v; value = v; } else if (tag == "LessThan") { - LessThan v = obj.convert(); + LessThan v; value = v; } else if (tag == "LessThanEquals") { - LessThanEquals v = obj.convert(); + LessThanEquals v; value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'BinaryFieldOp' enum variant: " + tag); } } @@ -286,103 +306,127 @@ struct BinaryIntOp { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "Add"; + is_unit = true; break; case 1: tag = "Sub"; + is_unit = true; break; case 2: tag = "Mul"; + is_unit = true; break; case 3: tag = "Div"; + is_unit = true; break; case 4: tag = "Equals"; + is_unit = true; break; case 5: tag = "LessThan"; + is_unit = true; break; case 6: tag = "LessThanEquals"; + is_unit = true; break; case 7: tag = "And"; + is_unit = true; break; case 8: tag = "Or"; + is_unit = true; break; case 9: tag = "Xor"; + is_unit = true; break; case 10: tag = "Shl"; + is_unit = true; break; case 11: tag = "Shr"; + is_unit = true; break; default: - throw_or_abort("unknown 'BinaryIntOp' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'BinaryIntOp' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'BinaryIntOp' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'BinaryIntOp': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'BinaryIntOp'; got type " + std::to_string(o.type)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'BinaryIntOp' enum; got " + std::to_string(o.via.map.size)); + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'BinaryIntOp'; got " + std::to_string(o.via.map.size)); + } + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Add") { - Add v = obj.convert(); + Add v; value = v; } else if (tag == "Sub") { - Sub v = obj.convert(); + Sub v; value = v; } else if (tag == "Mul") { - Mul v = obj.convert(); + Mul v; value = v; } else if (tag == "Div") { - Div v = obj.convert(); + Div v; value = v; } else if (tag == "Equals") { - Equals v = obj.convert(); + Equals v; value = v; } else if (tag == "LessThan") { - LessThan v = obj.convert(); + LessThan v; value = v; } else if (tag == "LessThanEquals") { - LessThanEquals v = obj.convert(); + LessThanEquals v; value = v; } else if (tag == "And") { - And v = obj.convert(); + And v; value = v; } else if (tag == "Or") { - Or v = obj.convert(); + Or v; value = v; } else if (tag == "Xor") { - Xor v = obj.convert(); + Xor v; value = v; } else if (tag == "Shl") { - Shl v = obj.convert(); + Shl v; value = v; } else if (tag == "Shr") { - Shr v = obj.convert(); + Shr v; value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'BinaryIntOp' enum variant: " + tag); } } @@ -453,67 +497,85 @@ struct IntegerBitSize { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "U1"; + is_unit = true; break; case 1: tag = "U8"; + is_unit = true; break; case 2: tag = "U16"; + is_unit = true; break; case 3: tag = "U32"; + is_unit = true; break; case 4: tag = "U64"; + is_unit = true; break; case 5: tag = "U128"; + is_unit = true; break; default: - throw_or_abort("unknown 'IntegerBitSize' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'IntegerBitSize' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'IntegerBitSize' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'IntegerBitSize': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'IntegerBitSize'; got type " + std::to_string(o.type)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'IntegerBitSize' enum; got " + std::to_string(o.via.map.size)); + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'IntegerBitSize'; got " + std::to_string(o.via.map.size)); + } + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "U1") { - U1 v = obj.convert(); + U1 v; value = v; } else if (tag == "U8") { - U8 v = obj.convert(); + U8 v; value = v; } else if (tag == "U16") { - U16 v = obj.convert(); + U16 v; value = v; } else if (tag == "U32") { - U32 v = obj.convert(); + U32 v; value = v; } else if (tag == "U64") { - U64 v = obj.convert(); + U64 v; value = v; } else if (tag == "U128") { - U128 v = obj.convert(); + U128 v; value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'IntegerBitSize' enum variant: " + tag); } } @@ -538,7 +600,16 @@ struct BitSize { static Integer bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Integer'"); + } + } }; std::variant value; @@ -550,43 +621,64 @@ struct BitSize { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "Field"; + is_unit = true; break; case 1: tag = "Integer"; + is_unit = false; break; default: - throw_or_abort("unknown 'BitSize' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'BitSize' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'BitSize' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'BitSize': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'BitSize'; got type " + std::to_string(o.type)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'BitSize' enum; got " + std::to_string(o.via.map.size)); + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'BitSize'; got " + std::to_string(o.via.map.size)); + } + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Field") { - Field v = obj.convert(); + Field v; value = v; } else if (tag == "Integer") { - Integer v = obj.convert(); + Integer v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BitSize::Integer'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'BitSize' enum variant: " + tag); } } @@ -602,7 +694,16 @@ struct MemoryAddress { static Direct bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Direct'"); + } + } }; struct Relative { @@ -613,7 +714,16 @@ struct MemoryAddress { static Relative bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Relative'"); + } + } }; std::variant value; @@ -625,43 +735,71 @@ struct MemoryAddress { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "Direct"; + is_unit = false; break; case 1: tag = "Relative"; + is_unit = false; break; default: - throw_or_abort("unknown 'MemoryAddress' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'MemoryAddress' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'MemoryAddress' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'MemoryAddress': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'MemoryAddress'; got type " + std::to_string(o.type)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'MemoryAddress' enum; got " + std::to_string(o.via.map.size)); + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'MemoryAddress'; got " + std::to_string(o.via.map.size)); + } + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Direct") { - Direct v = obj.convert(); + Direct v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'MemoryAddress::Direct'"); + } + value = v; } else if (tag == "Relative") { - Relative v = obj.convert(); + Relative v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'MemoryAddress::Relative'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'MemoryAddress' enum variant: " + tag); } } @@ -928,133 +1066,281 @@ struct BlackBoxOp { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "AES128Encrypt"; + is_unit = false; break; case 1: tag = "Blake2s"; + is_unit = false; break; case 2: tag = "Blake3"; + is_unit = false; break; case 3: tag = "Keccakf1600"; + is_unit = false; break; case 4: tag = "EcdsaSecp256k1"; + is_unit = false; break; case 5: tag = "EcdsaSecp256r1"; + is_unit = false; break; case 6: tag = "MultiScalarMul"; + is_unit = false; break; case 7: tag = "EmbeddedCurveAdd"; + is_unit = false; break; case 8: tag = "BigIntAdd"; + is_unit = false; break; case 9: tag = "BigIntSub"; + is_unit = false; break; case 10: tag = "BigIntMul"; + is_unit = false; break; case 11: tag = "BigIntDiv"; + is_unit = false; break; case 12: tag = "BigIntFromLeBytes"; + is_unit = false; break; case 13: tag = "BigIntToLeBytes"; + is_unit = false; break; case 14: tag = "Poseidon2Permutation"; + is_unit = false; break; case 15: tag = "Sha256Compression"; + is_unit = false; break; case 16: tag = "ToRadix"; + is_unit = false; break; default: - throw_or_abort("unknown 'BlackBoxOp' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'BlackBoxOp' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'BlackBoxOp' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'BlackBoxOp': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'BlackBoxOp'; got type " + std::to_string(o.type)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'BlackBoxOp' enum; got " + std::to_string(o.via.map.size)); + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'BlackBoxOp'; got " + std::to_string(o.via.map.size)); + } + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "AES128Encrypt") { - AES128Encrypt v = obj.convert(); + AES128Encrypt v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::AES128Encrypt'"); + } + value = v; } else if (tag == "Blake2s") { - Blake2s v = obj.convert(); + Blake2s v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::Blake2s'"); + } + value = v; } else if (tag == "Blake3") { - Blake3 v = obj.convert(); + Blake3 v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::Blake3'"); + } + value = v; } else if (tag == "Keccakf1600") { - Keccakf1600 v = obj.convert(); + Keccakf1600 v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::Keccakf1600'"); + } + value = v; } else if (tag == "EcdsaSecp256k1") { - EcdsaSecp256k1 v = obj.convert(); + EcdsaSecp256k1 v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::EcdsaSecp256k1'"); + } + value = v; } else if (tag == "EcdsaSecp256r1") { - EcdsaSecp256r1 v = obj.convert(); + EcdsaSecp256r1 v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::EcdsaSecp256r1'"); + } + value = v; } else if (tag == "MultiScalarMul") { - MultiScalarMul v = obj.convert(); + MultiScalarMul v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::MultiScalarMul'"); + } + value = v; } else if (tag == "EmbeddedCurveAdd") { - EmbeddedCurveAdd v = obj.convert(); + EmbeddedCurveAdd v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::EmbeddedCurveAdd'"); + } + value = v; } else if (tag == "BigIntAdd") { - BigIntAdd v = obj.convert(); + BigIntAdd v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::BigIntAdd'"); + } + value = v; } else if (tag == "BigIntSub") { - BigIntSub v = obj.convert(); + BigIntSub v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::BigIntSub'"); + } + value = v; } else if (tag == "BigIntMul") { - BigIntMul v = obj.convert(); + BigIntMul v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::BigIntMul'"); + } + value = v; } else if (tag == "BigIntDiv") { - BigIntDiv v = obj.convert(); + BigIntDiv v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::BigIntDiv'"); + } + value = v; } else if (tag == "BigIntFromLeBytes") { - BigIntFromLeBytes v = obj.convert(); + BigIntFromLeBytes v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::BigIntFromLeBytes'"); + } + value = v; } else if (tag == "BigIntToLeBytes") { - BigIntToLeBytes v = obj.convert(); + BigIntToLeBytes v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::BigIntToLeBytes'"); + } + value = v; } else if (tag == "Poseidon2Permutation") { - Poseidon2Permutation v = obj.convert(); + Poseidon2Permutation v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::Poseidon2Permutation'"); + } + value = v; } else if (tag == "Sha256Compression") { - Sha256Compression v = obj.convert(); + Sha256Compression v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::Sha256Compression'"); + } + value = v; } else if (tag == "ToRadix") { - ToRadix v = obj.convert(); + ToRadix v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxOp::ToRadix'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'BlackBoxOp' enum variant: " + tag); } } @@ -1072,7 +1358,16 @@ struct HeapValueType { static Simple bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Simple'"); + } + } }; struct Array { @@ -1105,49 +1400,85 @@ struct HeapValueType { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "Simple"; + is_unit = false; break; case 1: tag = "Array"; + is_unit = false; break; case 2: tag = "Vector"; + is_unit = false; break; default: - throw_or_abort("unknown 'HeapValueType' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'HeapValueType' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'HeapValueType' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'HeapValueType': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'HeapValueType'; got type " + std::to_string(o.type)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'HeapValueType' enum; got " + std::to_string(o.via.map.size)); + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'HeapValueType'; got " + std::to_string(o.via.map.size)); + } + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Simple") { - Simple v = obj.convert(); + Simple v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'HeapValueType::Simple'"); + } + value = v; } else if (tag == "Array") { - Array v = obj.convert(); + Array v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'HeapValueType::Array'"); + } + value = v; } else if (tag == "Vector") { - Vector v = obj.convert(); + Vector v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'HeapValueType::Vector'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'HeapValueType' enum variant: " + tag); } } @@ -1163,7 +1494,16 @@ struct ValueOrArray { static MemoryAddress bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'MemoryAddress'"); + } + } }; struct HeapArray { @@ -1174,7 +1514,16 @@ struct ValueOrArray { static HeapArray bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'HeapArray'"); + } + } }; struct HeapVector { @@ -1185,7 +1534,16 @@ struct ValueOrArray { static HeapVector bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'HeapVector'"); + } + } }; std::variant value; @@ -1197,49 +1555,85 @@ struct ValueOrArray { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "MemoryAddress"; + is_unit = false; break; case 1: tag = "HeapArray"; + is_unit = false; break; case 2: tag = "HeapVector"; + is_unit = false; break; default: - throw_or_abort("unknown 'ValueOrArray' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'ValueOrArray' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'ValueOrArray' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'ValueOrArray': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'ValueOrArray'; got type " + std::to_string(o.type)); + } + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'ValueOrArray'; got " + std::to_string(o.via.map.size)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'ValueOrArray' enum; got " + std::to_string(o.via.map.size)); + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "MemoryAddress") { - MemoryAddress v = obj.convert(); + MemoryAddress v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'ValueOrArray::MemoryAddress'"); + } + value = v; } else if (tag == "HeapArray") { - HeapArray v = obj.convert(); + HeapArray v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'ValueOrArray::HeapArray'"); + } + value = v; } else if (tag == "HeapVector") { - HeapVector v = obj.convert(); + HeapVector v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'ValueOrArray::HeapVector'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'ValueOrArray' enum variant: " + tag); } } @@ -1453,7 +1847,16 @@ struct BrilligOpcode { static BlackBox bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'BlackBox'"); + } + } }; struct Trap { @@ -1505,151 +1908,316 @@ struct BrilligOpcode { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "BinaryFieldOp"; + is_unit = false; break; case 1: tag = "BinaryIntOp"; + is_unit = false; break; case 2: tag = "Not"; + is_unit = false; break; case 3: tag = "Cast"; + is_unit = false; break; case 4: tag = "JumpIfNot"; + is_unit = false; break; case 5: tag = "JumpIf"; + is_unit = false; break; case 6: tag = "Jump"; + is_unit = false; break; case 7: tag = "CalldataCopy"; + is_unit = false; break; case 8: tag = "Call"; + is_unit = false; break; case 9: tag = "Const"; + is_unit = false; break; case 10: tag = "IndirectConst"; + is_unit = false; break; case 11: tag = "Return"; + is_unit = true; break; case 12: tag = "ForeignCall"; + is_unit = false; break; case 13: tag = "Mov"; + is_unit = false; break; case 14: tag = "ConditionalMov"; + is_unit = false; break; case 15: tag = "Load"; + is_unit = false; break; case 16: tag = "Store"; + is_unit = false; break; case 17: tag = "BlackBox"; + is_unit = false; break; case 18: tag = "Trap"; + is_unit = false; break; case 19: tag = "Stop"; + is_unit = false; break; default: - throw_or_abort("unknown 'BrilligOpcode' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'BrilligOpcode' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'BrilligOpcode' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'BrilligOpcode': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'BrilligOpcode'; got type " + std::to_string(o.type)); + } + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'BrilligOpcode'; got " + std::to_string(o.via.map.size)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'BrilligOpcode' enum; got " + std::to_string(o.via.map.size)); + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "BinaryFieldOp") { - BinaryFieldOp v = obj.convert(); + BinaryFieldOp v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::BinaryFieldOp'"); + } + value = v; } else if (tag == "BinaryIntOp") { - BinaryIntOp v = obj.convert(); + BinaryIntOp v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::BinaryIntOp'"); + } + value = v; } else if (tag == "Not") { - Not v = obj.convert(); + Not v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::Not'"); + } + value = v; } else if (tag == "Cast") { - Cast v = obj.convert(); + Cast v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::Cast'"); + } + value = v; } else if (tag == "JumpIfNot") { - JumpIfNot v = obj.convert(); + JumpIfNot v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::JumpIfNot'"); + } + value = v; } else if (tag == "JumpIf") { - JumpIf v = obj.convert(); + JumpIf v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::JumpIf'"); + } + value = v; } else if (tag == "Jump") { - Jump v = obj.convert(); + Jump v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::Jump'"); + } + value = v; } else if (tag == "CalldataCopy") { - CalldataCopy v = obj.convert(); + CalldataCopy v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::CalldataCopy'"); + } + value = v; } else if (tag == "Call") { - Call v = obj.convert(); + Call v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::Call'"); + } + value = v; } else if (tag == "Const") { - Const v = obj.convert(); + Const v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::Const'"); + } + value = v; } else if (tag == "IndirectConst") { - IndirectConst v = obj.convert(); + IndirectConst v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::IndirectConst'"); + } + value = v; } else if (tag == "Return") { - Return v = obj.convert(); + Return v; value = v; } else if (tag == "ForeignCall") { - ForeignCall v = obj.convert(); + ForeignCall v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::ForeignCall'"); + } + value = v; } else if (tag == "Mov") { - Mov v = obj.convert(); + Mov v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::Mov'"); + } + value = v; } else if (tag == "ConditionalMov") { - ConditionalMov v = obj.convert(); + ConditionalMov v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::ConditionalMov'"); + } + value = v; } else if (tag == "Load") { - Load v = obj.convert(); + Load v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::Load'"); + } + value = v; } else if (tag == "Store") { - Store v = obj.convert(); + Store v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::Store'"); + } + value = v; } else if (tag == "BlackBox") { - BlackBox v = obj.convert(); + BlackBox v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::BlackBox'"); + } + value = v; } else if (tag == "Trap") { - Trap v = obj.convert(); + Trap v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::Trap'"); + } + value = v; } else if (tag == "Stop") { - Stop v = obj.convert(); + Stop v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOpcode::Stop'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'BrilligOpcode' enum variant: " + tag); } } @@ -1663,7 +2231,16 @@ struct Witness { static Witness bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Witness'"); + } + } }; struct ConstantOrWitnessEnum { @@ -1676,7 +2253,16 @@ struct ConstantOrWitnessEnum { static Constant bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Constant'"); + } + } }; struct Witness { @@ -1687,7 +2273,16 @@ struct ConstantOrWitnessEnum { static Witness bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Witness'"); + } + } }; std::variant value; @@ -1699,43 +2294,71 @@ struct ConstantOrWitnessEnum { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "Constant"; + is_unit = false; break; case 1: tag = "Witness"; + is_unit = false; break; default: - throw_or_abort("unknown 'ConstantOrWitnessEnum' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'ConstantOrWitnessEnum' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'ConstantOrWitnessEnum' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'ConstantOrWitnessEnum': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'ConstantOrWitnessEnum'; got type " + std::to_string(o.type)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'ConstantOrWitnessEnum' enum; got " + std::to_string(o.via.map.size)); + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'ConstantOrWitnessEnum'; got " + std::to_string(o.via.map.size)); + } + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Constant") { - Constant v = obj.convert(); + Constant v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'ConstantOrWitnessEnum::Constant'"); + } + value = v; } else if (tag == "Witness") { - Witness v = obj.convert(); + Witness v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'ConstantOrWitnessEnum::Witness'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'ConstantOrWitnessEnum' enum variant: " + tag); } } @@ -2024,151 +2647,323 @@ struct BlackBoxFuncCall { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "AES128Encrypt"; + is_unit = false; break; case 1: tag = "AND"; + is_unit = false; break; case 2: tag = "XOR"; + is_unit = false; break; case 3: tag = "RANGE"; + is_unit = false; break; case 4: tag = "Blake2s"; + is_unit = false; break; case 5: tag = "Blake3"; + is_unit = false; break; case 6: tag = "EcdsaSecp256k1"; + is_unit = false; break; case 7: tag = "EcdsaSecp256r1"; + is_unit = false; break; case 8: tag = "MultiScalarMul"; + is_unit = false; break; case 9: tag = "EmbeddedCurveAdd"; + is_unit = false; break; case 10: tag = "Keccakf1600"; + is_unit = false; break; case 11: tag = "RecursiveAggregation"; + is_unit = false; break; case 12: tag = "BigIntAdd"; + is_unit = false; break; case 13: tag = "BigIntSub"; + is_unit = false; break; case 14: tag = "BigIntMul"; + is_unit = false; break; case 15: tag = "BigIntDiv"; + is_unit = false; break; case 16: tag = "BigIntFromLeBytes"; + is_unit = false; break; case 17: tag = "BigIntToLeBytes"; + is_unit = false; break; case 18: tag = "Poseidon2Permutation"; + is_unit = false; break; case 19: tag = "Sha256Compression"; + is_unit = false; break; default: - throw_or_abort("unknown 'BlackBoxFuncCall' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'BlackBoxFuncCall' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'BlackBoxFuncCall' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'BlackBoxFuncCall': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'BlackBoxFuncCall'; got type " + std::to_string(o.type)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'BlackBoxFuncCall' enum; got " + std::to_string(o.via.map.size)); + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'BlackBoxFuncCall'; got " + std::to_string(o.via.map.size)); + } + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "AES128Encrypt") { - AES128Encrypt v = obj.convert(); + AES128Encrypt v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::AES128Encrypt'"); + } + value = v; } else if (tag == "AND") { - AND v = obj.convert(); + AND v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::AND'"); + } + value = v; } else if (tag == "XOR") { - XOR v = obj.convert(); + XOR v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::XOR'"); + } + value = v; } else if (tag == "RANGE") { - RANGE v = obj.convert(); + RANGE v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::RANGE'"); + } + value = v; } else if (tag == "Blake2s") { - Blake2s v = obj.convert(); + Blake2s v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::Blake2s'"); + } + value = v; } else if (tag == "Blake3") { - Blake3 v = obj.convert(); + Blake3 v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::Blake3'"); + } + value = v; } else if (tag == "EcdsaSecp256k1") { - EcdsaSecp256k1 v = obj.convert(); + EcdsaSecp256k1 v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::EcdsaSecp256k1'"); + } + value = v; } else if (tag == "EcdsaSecp256r1") { - EcdsaSecp256r1 v = obj.convert(); + EcdsaSecp256r1 v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::EcdsaSecp256r1'"); + } + value = v; } else if (tag == "MultiScalarMul") { - MultiScalarMul v = obj.convert(); + MultiScalarMul v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::MultiScalarMul'"); + } + value = v; } else if (tag == "EmbeddedCurveAdd") { - EmbeddedCurveAdd v = obj.convert(); + EmbeddedCurveAdd v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::EmbeddedCurveAdd'"); + } + value = v; } else if (tag == "Keccakf1600") { - Keccakf1600 v = obj.convert(); + Keccakf1600 v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::Keccakf1600'"); + } + value = v; } else if (tag == "RecursiveAggregation") { - RecursiveAggregation v = obj.convert(); + RecursiveAggregation v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::RecursiveAggregation'"); + } + value = v; } else if (tag == "BigIntAdd") { - BigIntAdd v = obj.convert(); + BigIntAdd v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::BigIntAdd'"); + } + value = v; } else if (tag == "BigIntSub") { - BigIntSub v = obj.convert(); + BigIntSub v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::BigIntSub'"); + } + value = v; } else if (tag == "BigIntMul") { - BigIntMul v = obj.convert(); + BigIntMul v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::BigIntMul'"); + } + value = v; } else if (tag == "BigIntDiv") { - BigIntDiv v = obj.convert(); + BigIntDiv v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::BigIntDiv'"); + } + value = v; } else if (tag == "BigIntFromLeBytes") { - BigIntFromLeBytes v = obj.convert(); + BigIntFromLeBytes v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::BigIntFromLeBytes'"); + } + value = v; } else if (tag == "BigIntToLeBytes") { - BigIntToLeBytes v = obj.convert(); + BigIntToLeBytes v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::BigIntToLeBytes'"); + } + value = v; } else if (tag == "Poseidon2Permutation") { - Poseidon2Permutation v = obj.convert(); + Poseidon2Permutation v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::Poseidon2Permutation'"); + } + value = v; } else if (tag == "Sha256Compression") { - Sha256Compression v = obj.convert(); + Sha256Compression v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlackBoxFuncCall::Sha256Compression'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'BlackBoxFuncCall' enum variant: " + tag); } } @@ -2182,7 +2977,16 @@ struct BlockId { static BlockId bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'BlockId'"); + } + } }; struct BlockType { @@ -2204,7 +3008,16 @@ struct BlockType { static CallData bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'CallData'"); + } + } }; struct ReturnData { @@ -2225,49 +3038,71 @@ struct BlockType { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "Memory"; + is_unit = true; break; case 1: tag = "CallData"; + is_unit = false; break; case 2: tag = "ReturnData"; + is_unit = true; break; default: - throw_or_abort("unknown 'BlockType' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'BlockType' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'BlockType' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'BlockType': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'BlockType'; got type " + std::to_string(o.type)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'BlockType' enum; got " + std::to_string(o.via.map.size)); + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'BlockType'; got " + std::to_string(o.via.map.size)); + } + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Memory") { - Memory v = obj.convert(); + Memory v; value = v; } else if (tag == "CallData") { - CallData v = obj.convert(); + CallData v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BlockType::CallData'"); + } + value = v; } else if (tag == "ReturnData") { - ReturnData v = obj.convert(); + ReturnData v; value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'BlockType' enum variant: " + tag); } } @@ -2295,7 +3130,16 @@ struct BrilligInputs { static Single bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Single'"); + } + } }; struct Array { @@ -2306,7 +3150,16 @@ struct BrilligInputs { static Array bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Array'"); + } + } }; struct MemoryArray { @@ -2317,7 +3170,16 @@ struct BrilligInputs { static MemoryArray bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'MemoryArray'"); + } + } }; std::variant value; @@ -2329,49 +3191,85 @@ struct BrilligInputs { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "Single"; + is_unit = false; break; case 1: tag = "Array"; + is_unit = false; break; case 2: tag = "MemoryArray"; + is_unit = false; break; default: - throw_or_abort("unknown 'BrilligInputs' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'BrilligInputs' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'BrilligInputs' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'BrilligInputs': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'BrilligInputs'; got type " + std::to_string(o.type)); + } + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'BrilligInputs'; got " + std::to_string(o.via.map.size)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'BrilligInputs' enum; got " + std::to_string(o.via.map.size)); + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Single") { - Single v = obj.convert(); + Single v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligInputs::Single'"); + } + value = v; } else if (tag == "Array") { - Array v = obj.convert(); + Array v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligInputs::Array'"); + } + value = v; } else if (tag == "MemoryArray") { - MemoryArray v = obj.convert(); + MemoryArray v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligInputs::MemoryArray'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'BrilligInputs' enum variant: " + tag); } } @@ -2387,7 +3285,16 @@ struct BrilligOutputs { static Simple bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Simple'"); + } + } }; struct Array { @@ -2398,7 +3305,16 @@ struct BrilligOutputs { static Array bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Array'"); + } + } }; std::variant value; @@ -2410,43 +3326,71 @@ struct BrilligOutputs { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "Simple"; + is_unit = false; break; case 1: tag = "Array"; + is_unit = false; break; default: - throw_or_abort("unknown 'BrilligOutputs' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'BrilligOutputs' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'BrilligOutputs' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'BrilligOutputs': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'BrilligOutputs'; got type " + std::to_string(o.type)); + } + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'BrilligOutputs'; got " + std::to_string(o.via.map.size)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'BrilligOutputs' enum; got " + std::to_string(o.via.map.size)); + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Simple") { - Simple v = obj.convert(); + Simple v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOutputs::Simple'"); + } + value = v; } else if (tag == "Array") { - Array v = obj.convert(); + Array v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'BrilligOutputs::Array'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'BrilligOutputs' enum variant: " + tag); } } @@ -2474,7 +3418,16 @@ struct Opcode { static AssertZero bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'AssertZero'"); + } + } }; struct BlackBoxFuncCall { @@ -2485,7 +3438,16 @@ struct Opcode { static BlackBoxFuncCall bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'BlackBoxFuncCall'"); + } + } }; struct MemoryOp { @@ -2547,67 +3509,127 @@ struct Opcode { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "AssertZero"; + is_unit = false; break; case 1: tag = "BlackBoxFuncCall"; + is_unit = false; break; case 2: tag = "MemoryOp"; + is_unit = false; break; case 3: tag = "MemoryInit"; + is_unit = false; break; case 4: tag = "BrilligCall"; + is_unit = false; break; case 5: tag = "Call"; + is_unit = false; break; default: - throw_or_abort("unknown 'Opcode' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'Opcode' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'Opcode' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'Opcode': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'Opcode'; got type " + std::to_string(o.type)); + } + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'Opcode'; got " + std::to_string(o.via.map.size)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'Opcode' enum; got " + std::to_string(o.via.map.size)); + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "AssertZero") { - AssertZero v = obj.convert(); + AssertZero v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'Opcode::AssertZero'"); + } + value = v; } else if (tag == "BlackBoxFuncCall") { - BlackBoxFuncCall v = obj.convert(); + BlackBoxFuncCall v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'Opcode::BlackBoxFuncCall'"); + } + value = v; } else if (tag == "MemoryOp") { - MemoryOp v = obj.convert(); + MemoryOp v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'Opcode::MemoryOp'"); + } + value = v; } else if (tag == "MemoryInit") { - MemoryInit v = obj.convert(); + MemoryInit v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'Opcode::MemoryInit'"); + } + value = v; } else if (tag == "BrilligCall") { - BrilligCall v = obj.convert(); + BrilligCall v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'Opcode::BrilligCall'"); + } + value = v; } else if (tag == "Call") { - Call v = obj.convert(); + Call v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'Opcode::Call'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'Opcode' enum variant: " + tag); } } @@ -2623,7 +3645,16 @@ struct ExpressionOrMemory { static Expression bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Expression'"); + } + } }; struct Memory { @@ -2634,7 +3665,16 @@ struct ExpressionOrMemory { static Memory bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Memory'"); + } + } }; std::variant value; @@ -2646,43 +3686,71 @@ struct ExpressionOrMemory { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "Expression"; + is_unit = false; break; case 1: tag = "Memory"; + is_unit = false; break; default: - throw_or_abort("unknown 'ExpressionOrMemory' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'ExpressionOrMemory' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'ExpressionOrMemory' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'ExpressionOrMemory': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'ExpressionOrMemory'; got type " + std::to_string(o.type)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'ExpressionOrMemory' enum; got " + std::to_string(o.via.map.size)); + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'ExpressionOrMemory'; got " + std::to_string(o.via.map.size)); + } + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Expression") { - Expression v = obj.convert(); + Expression v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'ExpressionOrMemory::Expression'"); + } + value = v; } else if (tag == "Memory") { - Memory v = obj.convert(); + Memory v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'ExpressionOrMemory::Memory'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'ExpressionOrMemory' enum variant: " + tag); } } @@ -2729,43 +3797,64 @@ struct ExpressionWidth { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "Unbounded"; + is_unit = true; break; case 1: tag = "Bounded"; + is_unit = false; break; default: - throw_or_abort("unknown 'ExpressionWidth' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'ExpressionWidth' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'ExpressionWidth' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'ExpressionWidth': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'ExpressionWidth'; got type " + std::to_string(o.type)); + } + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'ExpressionWidth'; got " + std::to_string(o.via.map.size)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'ExpressionWidth' enum; got " + std::to_string(o.via.map.size)); + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Unbounded") { - Unbounded v = obj.convert(); + Unbounded v; value = v; } else if (tag == "Bounded") { - Bounded v = obj.convert(); + Bounded v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'ExpressionWidth::Bounded'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'ExpressionWidth' enum variant: " + tag); } } @@ -2781,7 +3870,16 @@ struct OpcodeLocation { static Acir bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Acir'"); + } + } }; struct Brillig { @@ -2804,43 +3902,71 @@ struct OpcodeLocation { void msgpack_pack(auto& packer) const { std::string tag; + bool is_unit; switch (value.index()) { case 0: tag = "Acir"; + is_unit = false; break; case 1: tag = "Brillig"; + is_unit = false; break; default: - throw_or_abort("unknown 'OpcodeLocation' enum variant index: " + std::to_string(value.index())); + throw_or_abort("unknown enum 'OpcodeLocation' variant index: " + std::to_string(value.index())); } std::visit( - [&packer, tag](const auto& arg) { - std::map data; - data[tag] = msgpack::object(arg); - packer.pack(data); + [&packer, tag, is_unit](const auto& arg) { + if (is_unit) { + std::map data; + data[tag] = msgpack::object(arg); + packer.pack(data); + } else { + packer.pack(tag); + } }, value); } void msgpack_unpack(msgpack::object const& o) { - if (o.type != msgpack::type::object_type::MAP) { - throw_or_abort("expected map for 'OpcodeLocation' enum; got " + std::to_string(o.type)); + std::cerr << "reading into 'OpcodeLocation': " << o << std::endl; + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP or STR for enum 'OpcodeLocation'; got type " + std::to_string(o.type)); + } + if (o.type == msgpack::type::object_type::MAP && o.via.map.size != 1) { + throw_or_abort("expected 1 entry for enum 'OpcodeLocation'; got " + std::to_string(o.via.map.size)); } - if (o.via.map.size != 1) { - throw_or_abort("expected 1 entry for 'OpcodeLocation' enum; got " + std::to_string(o.via.map.size)); + std::string tag; + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); } - std::string tag = o.via.map.ptr[0].key.convert(); - msgpack::object obj = o.via.map.ptr[0].val; if (tag == "Acir") { - Acir v = obj.convert(); + Acir v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'OpcodeLocation::Acir'"); + } + value = v; } else if (tag == "Brillig") { - Brillig v = obj.convert(); + Brillig v; + try { + o.via.map.ptr[0].val.convert(v); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into enum variant 'OpcodeLocation::Brillig'"); + } + value = v; } else { + std::cerr << o << std::endl; throw_or_abort("unknown 'OpcodeLocation' enum variant: " + tag); } } @@ -2854,7 +3980,16 @@ struct PublicInputs { static PublicInputs bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'PublicInputs'"); + } + } }; struct Circuit { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp index caf4df43e69d..9cf5d5b48269 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp @@ -15,7 +15,16 @@ struct Witness { bool operator<(Witness const& rhs) const { return value < rhs.value; } void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'Witness'"); + } + } }; struct WitnessMap { @@ -26,7 +35,16 @@ struct WitnessMap { static WitnessMap bincodeDeserialize(std::vector); void msgpack_pack(auto& packer) const { packer.pack(value); } - void msgpack_unpack(msgpack::object const& o) { o.convert(value); } + + void msgpack_unpack(msgpack::object const& o) + { + try { + o.convert(value); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting into newtype 'WitnessMap'"); + } + } }; struct StackItem { From ffdeb65b242792d671e3bc2e56659431c94ddd8a Mon Sep 17 00:00:00 2001 From: aakoshh Date: Fri, 21 Mar 2025 11:33:00 +0000 Subject: [PATCH 13/36] Parse program with fallback --- .../acir_format/acir_to_constraint_buf.cpp | 62 ++++++++++++++----- .../acir_format/acir_to_constraint_buf.hpp | 1 + 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index cd88046998dc..07fcac2008fe 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -887,30 +887,60 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) } /** - * @brief Deserializes a `Program` from bytes, trying `msgpack` or `bincode` formats. + * @brief Check if `buf` could be deserialized as a `msgpack` encoding from Noir. + * @note This is needed due to the lack of exception handling available to us in Wasm, + * ie. we can't try `bincode` format and if it fails try `msgpack`, instad we + * have to make a decision and commit to it. */ -Acir::Program program_buf_to_program(std::vector const& buf) +bool is_buf_msgpack(std::vector const& buf) { // We can't rely on exceptions to try to deserialize binpack, falling back to // msgpack if it fails, because exceptions are (or were) not supported in Wasm // and they are turned off in arch.cmake. + // // For now our other option is to check if the data is valid msgpack, // which slows things down, but we can't tell if the first byte of // the data accidentally matches one of our format values. - // if (buf.size() > 0) { - // // Skip the first byte, which would be our format marker; - // // we know it's going to be msgpack in this experiment. - // // Once we remove support for legacy format (ie. without the - // // format marker), we can get rid of this. - // auto buffer = reinterpret_cast(buf.data())[1]; - // size_t size = buf.size() - 1; - // msgpack::null_visitor probe; - // if (msgpack::parse(&buffer, size, probe)) { - // Acir::Program program; - // msgpack::unpack(&buffer, size).get().convert(program); - // return program; - // } - // } + // + // Unfortunately this doesn't seem to work either: `msgpack::parse` + // returns true for a `bincode` encoded program, and we have to check + // whether the value parsed is plausible. + if (buf.size() > 0) { + // Skip the first byte, which would be our format marker; + // we know it's going to be msgpack in this experiment. + // Once we remove support for legacy bincode format, + // we should be able to just look at the value + const char* buffer = &reinterpret_cast(buf.data())[1]; + size_t size = buf.size() - 1; + msgpack::null_visitor probe; + if (msgpack::parse(buffer, size, probe)) { + auto o = msgpack::unpack(buffer, size).get(); + // In my experiment bincode data was parsed as 0. + return o.type == msgpack::type::MAP; + } + } + return false; +} + +/** + * @brief Deserializes a `Program` from bytes, trying `msgpack` or `bincode` formats. + */ +Acir::Program program_buf_to_program(std::vector const& buf) +{ + if (is_buf_msgpack(buf)) { + const char* buffer = &reinterpret_cast(buf.data())[1]; + size_t size = buf.size() - 1; + auto o = msgpack::unpack(buffer, size).get(); + try { + Acir::Program program; + // To see the raw msgpack data structure as JSON: + o.convert(program); + return program; + } catch (msgpack::type_error) { + std::cerr << o << std::endl; + throw_or_abort("failed to convert msgpack data to Program"); + } + } return Acir::Program::bincodeDeserialize(buf); } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 3d755db14b3b..0d4baf021fc0 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -4,6 +4,7 @@ namespace acir_format { +bool is_buf_msgpack(std::vector const& buf); Acir::Program program_buf_to_program(std::vector const& buf); AcirFormat circuit_buf_to_acir_format(std::vector const& buf, uint32_t honk_recursion); From d05544d4c6120b4b9c9b00f2273c4e37d41c1682 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Fri, 21 Mar 2025 11:49:45 +0000 Subject: [PATCH 14/36] Parse Program ignoring Brillig --- .../acir_format/acir_to_constraint_buf.cpp | 9 ++- .../dsl/acir_format/serde/acir.hpp | 78 ++++++++++++++----- 2 files changed, 67 insertions(+), 20 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 07fcac2008fe..95209f9a2c97 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -924,6 +924,7 @@ bool is_buf_msgpack(std::vector const& buf) /** * @brief Deserializes a `Program` from bytes, trying `msgpack` or `bincode` formats. + * @note Ignores the Brillig parts of the bytecode when using `msgpack`. */ Acir::Program program_buf_to_program(std::vector const& buf) { @@ -932,11 +933,15 @@ Acir::Program program_buf_to_program(std::vector const& buf) size_t size = buf.size() - 1; auto o = msgpack::unpack(buffer, size).get(); try { + // Deserialize into a partial structure that ignores the Brillig parts, + // so that new opcodes can be added without breaking Barretenberg. + Acir::ProgramWithoutBrillig program_wob; + o.convert(program_wob); Acir::Program program; - // To see the raw msgpack data structure as JSON: - o.convert(program); + program.functions = program_wob.functions; return program; } catch (msgpack::type_error) { + // To see the raw msgpack data structure as JSON: std::cerr << o << std::endl; throw_or_abort("failed to convert msgpack data to Program"); } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index dee1a5e9fc83..de83ade343d3 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -142,7 +142,6 @@ struct BinaryFieldOp { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'BinaryFieldOp': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BinaryFieldOp'; got type " + std::to_string(o.type)); @@ -375,7 +374,6 @@ struct BinaryIntOp { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'BinaryIntOp': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BinaryIntOp'; got type " + std::to_string(o.type)); @@ -542,7 +540,6 @@ struct IntegerBitSize { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'IntegerBitSize': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'IntegerBitSize'; got type " + std::to_string(o.type)); @@ -650,7 +647,6 @@ struct BitSize { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'BitSize': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BitSize'; got type " + std::to_string(o.type)); @@ -764,7 +760,6 @@ struct MemoryAddress { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'MemoryAddress': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'MemoryAddress'; got type " + std::to_string(o.type)); @@ -1155,7 +1150,6 @@ struct BlackBoxOp { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'BlackBoxOp': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BlackBoxOp'; got type " + std::to_string(o.type)); @@ -1433,7 +1427,6 @@ struct HeapValueType { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'HeapValueType': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'HeapValueType'; got type " + std::to_string(o.type)); @@ -1588,7 +1581,6 @@ struct ValueOrArray { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'ValueOrArray': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'ValueOrArray'; got type " + std::to_string(o.type)); @@ -2009,7 +2001,6 @@ struct BrilligOpcode { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'BrilligOpcode': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BrilligOpcode'; got type " + std::to_string(o.type)); @@ -2323,7 +2314,6 @@ struct ConstantOrWitnessEnum { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'ConstantOrWitnessEnum': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'ConstantOrWitnessEnum'; got type " + std::to_string(o.type)); @@ -2748,7 +2738,6 @@ struct BlackBoxFuncCall { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'BlackBoxFuncCall': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BlackBoxFuncCall'; got type " + std::to_string(o.type)); @@ -3071,7 +3060,6 @@ struct BlockType { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'BlockType': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BlockType'; got type " + std::to_string(o.type)); @@ -3224,7 +3212,6 @@ struct BrilligInputs { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'BrilligInputs': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BrilligInputs'; got type " + std::to_string(o.type)); @@ -3355,7 +3342,6 @@ struct BrilligOutputs { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'BrilligOutputs': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BrilligOutputs'; got type " + std::to_string(o.type)); @@ -3554,7 +3540,6 @@ struct Opcode { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'Opcode': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'Opcode'; got type " + std::to_string(o.type)); @@ -3715,7 +3700,6 @@ struct ExpressionOrMemory { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'ExpressionOrMemory': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'ExpressionOrMemory'; got type " + std::to_string(o.type)); @@ -3826,7 +3810,6 @@ struct ExpressionWidth { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'ExpressionWidth': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'ExpressionWidth'; got type " + std::to_string(o.type)); @@ -3931,7 +3914,6 @@ struct OpcodeLocation { void msgpack_unpack(msgpack::object const& o) { - std::cerr << "reading into 'OpcodeLocation': " << o << std::endl; if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'OpcodeLocation'; got type " + std::to_string(o.type)); @@ -4035,6 +4017,16 @@ struct Program { MSGPACK_FIELDS(functions, unconstrained_functions); }; +struct ProgramWithoutBrillig { + std::vector functions; + + friend bool operator==(const ProgramWithoutBrillig&, const ProgramWithoutBrillig&); + std::vector bincodeSerialize() const; + static ProgramWithoutBrillig bincodeDeserialize(std::vector); + + MSGPACK_FIELDS(functions); +}; + } // end of namespace Acir namespace Acir { @@ -11067,6 +11059,56 @@ Acir::Program serde::Deserializable::deserialize(Deserializer& de namespace Acir { +inline bool operator==(const ProgramWithoutBrillig& lhs, const ProgramWithoutBrillig& rhs) +{ + if (!(lhs.functions == rhs.functions)) { + return false; + } + return true; +} + +inline std::vector ProgramWithoutBrillig::bincodeSerialize() const +{ + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); +} + +inline ProgramWithoutBrillig ProgramWithoutBrillig::bincodeDeserialize(std::vector input) +{ + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw_or_abort("Some input bytes were not read"); + } + return value; +} + +} // end of namespace Acir + +template <> +template +void serde::Serializable::serialize(const Acir::ProgramWithoutBrillig& obj, + Serializer& serializer) +{ + serializer.increase_container_depth(); + serde::Serializable::serialize(obj.functions, serializer); + serializer.decrease_container_depth(); +} + +template <> +template +Acir::ProgramWithoutBrillig serde::Deserializable::deserialize(Deserializer& deserializer) +{ + deserializer.increase_container_depth(); + Acir::ProgramWithoutBrillig obj; + obj.functions = serde::Deserializable::deserialize(deserializer); + deserializer.decrease_container_depth(); + return obj; +} + +namespace Acir { + inline bool operator==(const PublicInputs& lhs, const PublicInputs& rhs) { if (!(lhs.value == rhs.value)) { From 74880c21990577ebc902911495e0de10a202b4fc Mon Sep 17 00:00:00 2001 From: aakoshh Date: Fri, 21 Mar 2025 11:56:44 +0000 Subject: [PATCH 15/36] Update msgpack git commit to include fix --- barretenberg/cpp/cmake/msgpack.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/cmake/msgpack.cmake b/barretenberg/cpp/cmake/msgpack.cmake index b89b9c547d55..22b696c02858 100644 --- a/barretenberg/cpp/cmake/msgpack.cmake +++ b/barretenberg/cpp/cmake/msgpack.cmake @@ -8,9 +8,9 @@ ExternalProject_Add( msgpack-c PREFIX ${MSGPACK_PREFIX} GIT_REPOSITORY "https://github.com/AztecProtocol/msgpack-c.git" - GIT_TAG 492d78fc4ea1f0a277433a64129cffd979f60070 + GIT_TAG 54e9865b84bbdc73cfbf8d1d437dbf769b64e386 CONFIGURE_COMMAND "" # No configure step BUILD_COMMAND "" # No build step INSTALL_COMMAND "" # No install step UPDATE_COMMAND "" # No update step -) \ No newline at end of file +) From 15c1c717ec90b5f60d7a0befd02dcd9b0a82dad9 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Fri, 21 Mar 2025 12:51:02 +0000 Subject: [PATCH 16/36] Deserialize WitnessStack with msgpack --- .../acir_format/acir_to_constraint_buf.cpp | 32 ++++++++++++++----- .../acir_format/acir_to_constraint_buf.hpp | 2 ++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 95209f9a2c97..04d4c512b706 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -829,12 +829,6 @@ AcirFormat circuit_buf_to_acir_format(std::vector const& buf, uint32_t // TODO(https://github.com/AztecProtocol/barretenberg/issues/927): Move to using just // `program_buf_to_acir_format` once Honk fully supports all ACIR test flows For now the backend still expects // to work with a single ACIR function - - // TODO: We can't rely on exceptions to deserialize one format or the other because they are - // not supported in Wasm (turned off in arch.cmake, aborting in throw_or_abort). - // For now just try the new format and see what happens. - // auto circuit = Acir::Program::bincodeDeserialize(buf).functions[0]; - auto program = program_buf_to_program(buf); auto circuit = program.functions[0]; @@ -880,7 +874,7 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) // TODO(https://github.com/AztecProtocol/barretenberg/issues/927): Move to using just // `witness_buf_to_witness_stack` once Honk fully supports all ACIR test flows. For now the backend still // expects to work with the stop of the `WitnessStack`. - auto witness_stack = Witnesses::WitnessStack::bincodeDeserialize(buf); + auto witness_stack = witness_buf_to_witness(buf); auto w = witness_stack.stack[witness_stack.stack.size() - 1].witness; return witness_map_to_witness_vector(w); @@ -949,6 +943,28 @@ Acir::Program program_buf_to_program(std::vector const& buf) return Acir::Program::bincodeDeserialize(buf); } +/** + * @brief Deserializes a `WitnessStack` from bytes, trying `msgpack` or `bincode` formats. + */ +Witnesses::WitnessStack witness_buf_to_witness(std::vector const& buf) +{ + if (is_buf_msgpack(buf)) { + const char* buffer = &reinterpret_cast(buf.data())[1]; + size_t size = buf.size() - 1; + auto o = msgpack::unpack(buffer, size).get(); + try { + Witnesses::WitnessStack witness_stack; + o.convert(witness_stack); + return witness_stack; + } catch (msgpack::type_error) { + // To see the raw msgpack data structure as JSON: + std::cerr << o << std::endl; + throw_or_abort("failed to convert msgpack data to witness_stack"); + } + } + return Witnesses::WitnessStack::bincodeDeserialize(buf); +} + std::vector program_buf_to_acir_format(std::vector const& buf, uint32_t honk_recursion) { auto program = program_buf_to_program(buf); @@ -964,7 +980,7 @@ std::vector program_buf_to_acir_format(std::vector const& b WitnessVectorStack witness_buf_to_witness_stack(std::vector const& buf) { - auto witness_stack = Witnesses::WitnessStack::bincodeDeserialize(buf); + auto witness_stack = witness_buf_to_witness(buf); WitnessVectorStack witness_vector_stack; witness_vector_stack.reserve(witness_stack.stack.size()); for (auto const& stack_item : witness_stack.stack) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 0d4baf021fc0..cd42df080e5d 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -6,6 +6,8 @@ namespace acir_format { bool is_buf_msgpack(std::vector const& buf); Acir::Program program_buf_to_program(std::vector const& buf); +Witnesses::WitnessStack witness_buf_to_witness(std::vector const& buf); + AcirFormat circuit_buf_to_acir_format(std::vector const& buf, uint32_t honk_recursion); /** From 24756ff8e6daf730d08aa2db0b7c2b55438824a1 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Fri, 21 Mar 2025 13:32:00 +0000 Subject: [PATCH 17/36] Fix catch --- .../barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 04d4c512b706..8e697a726aff 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -934,7 +934,7 @@ Acir::Program program_buf_to_program(std::vector const& buf) Acir::Program program; program.functions = program_wob.functions; return program; - } catch (msgpack::type_error) { + } catch (const msgpack::type_error&) { // To see the raw msgpack data structure as JSON: std::cerr << o << std::endl; throw_or_abort("failed to convert msgpack data to Program"); @@ -956,10 +956,10 @@ Witnesses::WitnessStack witness_buf_to_witness(std::vector const& buf) Witnesses::WitnessStack witness_stack; o.convert(witness_stack); return witness_stack; - } catch (msgpack::type_error) { + } catch (const msgpack::type_error&) { // To see the raw msgpack data structure as JSON: std::cerr << o << std::endl; - throw_or_abort("failed to convert msgpack data to witness_stack"); + throw_or_abort("failed to convert msgpack data to WitnessStack"); } } return Witnesses::WitnessStack::bincodeDeserialize(buf); From dfd4ee892194ea53eede1631896332a2d6f80800 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Fri, 21 Mar 2025 13:54:41 +0000 Subject: [PATCH 18/36] Remove rmp-serde from avm-transpiler dependencies --- avm-transpiler/Cargo.lock | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/avm-transpiler/Cargo.lock b/avm-transpiler/Cargo.lock index 16d8fce1d8e5..f5d473b4a95d 100644 --- a/avm-transpiler/Cargo.lock +++ b/avm-transpiler/Cargo.lock @@ -16,7 +16,6 @@ dependencies = [ "prost", "prost-build", "protoc-prebuilt", - "rmp-serde", "serde", "serde-big-array", "strum", @@ -1790,28 +1789,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rmp" -version = "0.8.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "228ed7c16fa39782c3b3468e974aec2795e9089153cd08ee2e9aefb3613334c4" -dependencies = [ - "byteorder", - "num-traits", - "paste", -] - -[[package]] -name = "rmp-serde" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52e599a477cf9840e92f2cde9a7189e67b42c57532749bf90aea6ec10facd4db" -dependencies = [ - "byteorder", - "rmp", - "serde", -] - [[package]] name = "rustc-demangle" version = "0.1.24" From c82f1b106720add01c41292f83a0d5f9e15b7490 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Fri, 21 Mar 2025 16:23:59 +0000 Subject: [PATCH 19/36] Fix packing newtype is_unit --- .../dsl/acir_format/serde/acir.hpp | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index de83ade343d3..d968a4ea9d1f 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -130,11 +130,11 @@ struct BinaryFieldOp { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -362,11 +362,11 @@ struct BinaryIntOp { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -528,11 +528,11 @@ struct IntegerBitSize { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -635,11 +635,11 @@ struct BitSize { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -748,11 +748,11 @@ struct MemoryAddress { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -1138,11 +1138,11 @@ struct BlackBoxOp { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -1415,11 +1415,11 @@ struct HeapValueType { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -1569,11 +1569,11 @@ struct ValueOrArray { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -1989,11 +1989,11 @@ struct BrilligOpcode { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -2302,11 +2302,11 @@ struct ConstantOrWitnessEnum { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -2726,11 +2726,11 @@ struct BlackBoxFuncCall { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -3048,11 +3048,11 @@ struct BlockType { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -3200,11 +3200,11 @@ struct BrilligInputs { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -3330,11 +3330,11 @@ struct BrilligOutputs { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -3528,11 +3528,11 @@ struct Opcode { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -3688,11 +3688,11 @@ struct ExpressionOrMemory { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -3798,11 +3798,11 @@ struct ExpressionWidth { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); @@ -3902,11 +3902,11 @@ struct OpcodeLocation { std::visit( [&packer, tag, is_unit](const auto& arg) { if (is_unit) { + packer.pack(tag); + } else { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } else { - packer.pack(tag); } }, value); From 919ab7aaf81879579fc84aabcce266048ca4ca1a Mon Sep 17 00:00:00 2001 From: aakoshh Date: Fri, 21 Mar 2025 16:33:09 +0000 Subject: [PATCH 20/36] Don't use visit for unit variants --- .../dsl/acir_format/serde/acir.hpp | 288 +++++++++--------- 1 file changed, 144 insertions(+), 144 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index d968a4ea9d1f..a214ce73a527 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -127,17 +127,17 @@ struct BinaryFieldOp { default: throw_or_abort("unknown enum 'BinaryFieldOp' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -359,17 +359,17 @@ struct BinaryIntOp { default: throw_or_abort("unknown enum 'BinaryIntOp' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -525,17 +525,17 @@ struct IntegerBitSize { default: throw_or_abort("unknown enum 'IntegerBitSize' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -632,17 +632,17 @@ struct BitSize { default: throw_or_abort("unknown enum 'BitSize' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -745,17 +745,17 @@ struct MemoryAddress { default: throw_or_abort("unknown enum 'MemoryAddress' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -1135,17 +1135,17 @@ struct BlackBoxOp { default: throw_or_abort("unknown enum 'BlackBoxOp' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -1412,17 +1412,17 @@ struct HeapValueType { default: throw_or_abort("unknown enum 'HeapValueType' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -1566,17 +1566,17 @@ struct ValueOrArray { default: throw_or_abort("unknown enum 'ValueOrArray' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -1986,17 +1986,17 @@ struct BrilligOpcode { default: throw_or_abort("unknown enum 'BrilligOpcode' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -2299,17 +2299,17 @@ struct ConstantOrWitnessEnum { default: throw_or_abort("unknown enum 'ConstantOrWitnessEnum' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -2723,17 +2723,17 @@ struct BlackBoxFuncCall { default: throw_or_abort("unknown enum 'BlackBoxFuncCall' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -3045,17 +3045,17 @@ struct BlockType { default: throw_or_abort("unknown enum 'BlockType' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -3197,17 +3197,17 @@ struct BrilligInputs { default: throw_or_abort("unknown enum 'BrilligInputs' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -3327,17 +3327,17 @@ struct BrilligOutputs { default: throw_or_abort("unknown enum 'BrilligOutputs' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -3525,17 +3525,17 @@ struct Opcode { default: throw_or_abort("unknown enum 'Opcode' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -3685,17 +3685,17 @@ struct ExpressionOrMemory { default: throw_or_abort("unknown enum 'ExpressionOrMemory' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -3795,17 +3795,17 @@ struct ExpressionWidth { default: throw_or_abort("unknown enum 'ExpressionWidth' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) @@ -3899,17 +3899,17 @@ struct OpcodeLocation { default: throw_or_abort("unknown enum 'OpcodeLocation' variant index: " + std::to_string(value.index())); } - std::visit( - [&packer, tag, is_unit](const auto& arg) { - if (is_unit) { - packer.pack(tag); - } else { + if (is_unit) { + packer.pack(tag); + } else { + std::visit( + [&packer, tag](const auto& arg) { std::map data; data[tag] = msgpack::object(arg); packer.pack(data); - } - }, - value); + }, + value); + } } void msgpack_unpack(msgpack::object const& o) From a6ec247ca59ea48a822cad8c01d93a247cb88204 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Fri, 21 Mar 2025 19:54:08 +0000 Subject: [PATCH 21/36] Return optional msgpack::object to avoid double parsing --- .../acir_format/acir_to_constraint_buf.cpp | 29 +++++++++---------- .../acir_format/acir_to_constraint_buf.hpp | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 8e697a726aff..02b77bf727ab 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -886,7 +886,7 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) * ie. we can't try `bincode` format and if it fails try `msgpack`, instad we * have to make a decision and commit to it. */ -bool is_buf_msgpack(std::vector const& buf) +std::optional maybe_buf_to_msgpack(std::vector const& buf) { // We can't rely on exceptions to try to deserialize binpack, falling back to // msgpack if it fails, because exceptions are (or were) not supported in Wasm @@ -909,11 +909,14 @@ bool is_buf_msgpack(std::vector const& buf) msgpack::null_visitor probe; if (msgpack::parse(buffer, size, probe)) { auto o = msgpack::unpack(buffer, size).get(); - // In my experiment bincode data was parsed as 0. - return o.type == msgpack::type::MAP; + // In experiments bincode data was parsed as 0. + // The types usd by Noir are MAPs. + if (o.type == msgpack::type::MAP) { + return std::make_optional(std::move(o)); + } } } - return false; + return std::nullopt; } /** @@ -922,21 +925,18 @@ bool is_buf_msgpack(std::vector const& buf) */ Acir::Program program_buf_to_program(std::vector const& buf) { - if (is_buf_msgpack(buf)) { - const char* buffer = &reinterpret_cast(buf.data())[1]; - size_t size = buf.size() - 1; - auto o = msgpack::unpack(buffer, size).get(); + if (auto o = maybe_buf_to_msgpack(buf)) { try { // Deserialize into a partial structure that ignores the Brillig parts, // so that new opcodes can be added without breaking Barretenberg. Acir::ProgramWithoutBrillig program_wob; - o.convert(program_wob); + o->convert(program_wob); Acir::Program program; program.functions = program_wob.functions; return program; } catch (const msgpack::type_error&) { // To see the raw msgpack data structure as JSON: - std::cerr << o << std::endl; + std::cerr << *o << std::endl; throw_or_abort("failed to convert msgpack data to Program"); } } @@ -948,17 +948,14 @@ Acir::Program program_buf_to_program(std::vector const& buf) */ Witnesses::WitnessStack witness_buf_to_witness(std::vector const& buf) { - if (is_buf_msgpack(buf)) { - const char* buffer = &reinterpret_cast(buf.data())[1]; - size_t size = buf.size() - 1; - auto o = msgpack::unpack(buffer, size).get(); + if (auto o = maybe_buf_to_msgpack(buf)) { try { Witnesses::WitnessStack witness_stack; - o.convert(witness_stack); + o->convert(witness_stack); return witness_stack; } catch (const msgpack::type_error&) { // To see the raw msgpack data structure as JSON: - std::cerr << o << std::endl; + std::cerr << *o << std::endl; throw_or_abort("failed to convert msgpack data to WitnessStack"); } } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index cd42df080e5d..8360558ff202 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -4,7 +4,7 @@ namespace acir_format { -bool is_buf_msgpack(std::vector const& buf); +std::optional maybe_buf_to_msgpack(std::vector const& buf); Acir::Program program_buf_to_program(std::vector const& buf); Witnesses::WitnessStack witness_buf_to_witness(std::vector const& buf); From 8387aff5510ada63d60c2bcd4225b6b50c161b18 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Fri, 21 Mar 2025 21:31:34 +0000 Subject: [PATCH 22/36] Revert "Return optional msgpack::object to avoid double parsing" This reverts commit a6ec247ca59ea48a822cad8c01d93a247cb88204. --- .../acir_format/acir_to_constraint_buf.cpp | 29 ++++++++++--------- .../acir_format/acir_to_constraint_buf.hpp | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 02b77bf727ab..8e697a726aff 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -886,7 +886,7 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) * ie. we can't try `bincode` format and if it fails try `msgpack`, instad we * have to make a decision and commit to it. */ -std::optional maybe_buf_to_msgpack(std::vector const& buf) +bool is_buf_msgpack(std::vector const& buf) { // We can't rely on exceptions to try to deserialize binpack, falling back to // msgpack if it fails, because exceptions are (or were) not supported in Wasm @@ -909,14 +909,11 @@ std::optional maybe_buf_to_msgpack(std::vector const& msgpack::null_visitor probe; if (msgpack::parse(buffer, size, probe)) { auto o = msgpack::unpack(buffer, size).get(); - // In experiments bincode data was parsed as 0. - // The types usd by Noir are MAPs. - if (o.type == msgpack::type::MAP) { - return std::make_optional(std::move(o)); - } + // In my experiment bincode data was parsed as 0. + return o.type == msgpack::type::MAP; } } - return std::nullopt; + return false; } /** @@ -925,18 +922,21 @@ std::optional maybe_buf_to_msgpack(std::vector const& */ Acir::Program program_buf_to_program(std::vector const& buf) { - if (auto o = maybe_buf_to_msgpack(buf)) { + if (is_buf_msgpack(buf)) { + const char* buffer = &reinterpret_cast(buf.data())[1]; + size_t size = buf.size() - 1; + auto o = msgpack::unpack(buffer, size).get(); try { // Deserialize into a partial structure that ignores the Brillig parts, // so that new opcodes can be added without breaking Barretenberg. Acir::ProgramWithoutBrillig program_wob; - o->convert(program_wob); + o.convert(program_wob); Acir::Program program; program.functions = program_wob.functions; return program; } catch (const msgpack::type_error&) { // To see the raw msgpack data structure as JSON: - std::cerr << *o << std::endl; + std::cerr << o << std::endl; throw_or_abort("failed to convert msgpack data to Program"); } } @@ -948,14 +948,17 @@ Acir::Program program_buf_to_program(std::vector const& buf) */ Witnesses::WitnessStack witness_buf_to_witness(std::vector const& buf) { - if (auto o = maybe_buf_to_msgpack(buf)) { + if (is_buf_msgpack(buf)) { + const char* buffer = &reinterpret_cast(buf.data())[1]; + size_t size = buf.size() - 1; + auto o = msgpack::unpack(buffer, size).get(); try { Witnesses::WitnessStack witness_stack; - o->convert(witness_stack); + o.convert(witness_stack); return witness_stack; } catch (const msgpack::type_error&) { // To see the raw msgpack data structure as JSON: - std::cerr << *o << std::endl; + std::cerr << o << std::endl; throw_or_abort("failed to convert msgpack data to WitnessStack"); } } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 8360558ff202..cd42df080e5d 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -4,7 +4,7 @@ namespace acir_format { -std::optional maybe_buf_to_msgpack(std::vector const& buf); +bool is_buf_msgpack(std::vector const& buf); Acir::Program program_buf_to_program(std::vector const& buf); Witnesses::WitnessStack witness_buf_to_witness(std::vector const& buf); From 02e3d64e87f9799f19288b75b2e8cd1e02fc804b Mon Sep 17 00:00:00 2001 From: aakoshh Date: Sat, 22 Mar 2025 07:45:58 +0000 Subject: [PATCH 23/36] Check the value of the format byte --- .../dsl/acir_format/acir_to_constraint_buf.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 8e697a726aff..1500440f138c 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -888,6 +888,10 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) */ bool is_buf_msgpack(std::vector const& buf) { + // TODO: It would be nice to return `std::optional` + // to avoid having to parse again, but some integration test failed + // when I tried. Need to investigate. + // We can't rely on exceptions to try to deserialize binpack, falling back to // msgpack if it fails, because exceptions are (or were) not supported in Wasm // and they are turned off in arch.cmake. @@ -899,17 +903,18 @@ bool is_buf_msgpack(std::vector const& buf) // Unfortunately this doesn't seem to work either: `msgpack::parse` // returns true for a `bincode` encoded program, and we have to check // whether the value parsed is plausible. - if (buf.size() > 0) { - // Skip the first byte, which would be our format marker; - // we know it's going to be msgpack in this experiment. - // Once we remove support for legacy bincode format, - // we should be able to just look at the value + + // Once we remove support for legacy bincode format, we should expect to always + // have a format marker corresponding to acir::serialization::Format::Msgpack + if (buf.size() > 0 && buf[0] == 2) { + // Skip the format marker to get the data. const char* buffer = &reinterpret_cast(buf.data())[1]; size_t size = buf.size() - 1; msgpack::null_visitor probe; if (msgpack::parse(buffer, size, probe)) { auto o = msgpack::unpack(buffer, size).get(); // In my experiment bincode data was parsed as 0. + // All the top level formats we look for are MAP types. return o.type == msgpack::type::MAP; } } From 63254d3ec907a0b038d5f76531626340313f9475 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Sat, 22 Mar 2025 21:26:02 +0000 Subject: [PATCH 24/36] Use lambdas to avoid double parsing --- .../acir_format/acir_to_constraint_buf.cpp | 111 ++++++++++-------- .../acir_format/acir_to_constraint_buf.hpp | 6 +- 2 files changed, 64 insertions(+), 53 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 1500440f138c..8a340b9dfcec 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -881,17 +881,19 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) } /** - * @brief Check if `buf` could be deserialized as a `msgpack` encoding from Noir. - * @note This is needed due to the lack of exception handling available to us in Wasm, - * ie. we can't try `bincode` format and if it fails try `msgpack`, instad we - * have to make a decision and commit to it. + * @brief Deserialize `buf` either based on the first byte interpreted as a + Noir serialization format byte, or falling back to `bincode` if + the format cannot be recognized. Currently only `msgpack` format + is expected, or the legacy `bincode` format. + * @note Due to the lack of exception handling available to us in Wasm we can't + * try `bincode` format and if it fails try `msgpack`; instead we have to + * make a decision and commit to it. */ -bool is_buf_msgpack(std::vector const& buf) +template +T deserialize_any_format(std::vector const& buf, + std::function decode_msgpack, + std::function)> decode_binpack) { - // TODO: It would be nice to return `std::optional` - // to avoid having to parse again, but some integration test failed - // when I tried. Need to investigate. - // We can't rely on exceptions to try to deserialize binpack, falling back to // msgpack if it fails, because exceptions are (or were) not supported in Wasm // and they are turned off in arch.cmake. @@ -904,21 +906,30 @@ bool is_buf_msgpack(std::vector const& buf) // returns true for a `bincode` encoded program, and we have to check // whether the value parsed is plausible. - // Once we remove support for legacy bincode format, we should expect to always - // have a format marker corresponding to acir::serialization::Format::Msgpack - if (buf.size() > 0 && buf[0] == 2) { - // Skip the format marker to get the data. - const char* buffer = &reinterpret_cast(buf.data())[1]; - size_t size = buf.size() - 1; - msgpack::null_visitor probe; - if (msgpack::parse(buffer, size, probe)) { - auto o = msgpack::unpack(buffer, size).get(); - // In my experiment bincode data was parsed as 0. - // All the top level formats we look for are MAP types. - return o.type == msgpack::type::MAP; + if (buf.size() > 0) { + // Once we remove support for legacy bincode format, we should expect to always + // have a format marker corresponding to acir::serialization::Format::Msgpack, + // but until then a match could be pure coincidence. + if (buf[0] == 2) { + // Skip the format marker to get the data. + const char* buffer = &reinterpret_cast(buf.data())[1]; + size_t size = buf.size() - 1; + msgpack::null_visitor probe; + if (msgpack::parse(buffer, size, probe)) { + auto o = msgpack::unpack(buffer, size).get(); + // In experiments bincode data was parsed as 0. + // All the top level formats we look for are MAP types. + if (o.type == msgpack::type::MAP) { + return decode_msgpack(o); + } + } } + // `buf[0] == 0` would indicate bincode starting with a format byte, + // but if it's a coincidence and it fails to parse then we can't recover + // from it, so let's just acknowledge that for now we don't want to + // exercise this code path and treat the whole data as bincode. } - return false; + return decode_binpack(buf); } /** @@ -927,25 +938,23 @@ bool is_buf_msgpack(std::vector const& buf) */ Acir::Program program_buf_to_program(std::vector const& buf) { - if (is_buf_msgpack(buf)) { - const char* buffer = &reinterpret_cast(buf.data())[1]; - size_t size = buf.size() - 1; - auto o = msgpack::unpack(buffer, size).get(); - try { - // Deserialize into a partial structure that ignores the Brillig parts, - // so that new opcodes can be added without breaking Barretenberg. - Acir::ProgramWithoutBrillig program_wob; - o.convert(program_wob); + return deserialize_any_format( + buf, + [](auto o) -> Acir::Program { Acir::Program program; - program.functions = program_wob.functions; + try { + // Deserialize into a partial structure that ignores the Brillig parts, + // so that new opcodes can be added without breaking Barretenberg. + Acir::ProgramWithoutBrillig program_wob; + o.convert(program_wob); + program.functions = program_wob.functions; + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("failed to convert msgpack data to Program"); + } return program; - } catch (const msgpack::type_error&) { - // To see the raw msgpack data structure as JSON: - std::cerr << o << std::endl; - throw_or_abort("failed to convert msgpack data to Program"); - } - } - return Acir::Program::bincodeDeserialize(buf); + }, + &Acir::Program::bincodeDeserialize); } /** @@ -953,21 +962,19 @@ Acir::Program program_buf_to_program(std::vector const& buf) */ Witnesses::WitnessStack witness_buf_to_witness(std::vector const& buf) { - if (is_buf_msgpack(buf)) { - const char* buffer = &reinterpret_cast(buf.data())[1]; - size_t size = buf.size() - 1; - auto o = msgpack::unpack(buffer, size).get(); - try { + return deserialize_any_format( + buf, + [](auto o) { Witnesses::WitnessStack witness_stack; - o.convert(witness_stack); + try { + o.convert(witness_stack); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("failed to convert msgpack data to WitnessStack"); + } return witness_stack; - } catch (const msgpack::type_error&) { - // To see the raw msgpack data structure as JSON: - std::cerr << o << std::endl; - throw_or_abort("failed to convert msgpack data to WitnessStack"); - } - } - return Witnesses::WitnessStack::bincodeDeserialize(buf); + }, + &Witnesses::WitnessStack::bincodeDeserialize); } std::vector program_buf_to_acir_format(std::vector const& buf, uint32_t honk_recursion) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index cd42df080e5d..71890916998b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -4,7 +4,11 @@ namespace acir_format { -bool is_buf_msgpack(std::vector const& buf); +template +T deserialize_any_format(std::vector const& buf, + std::function decode_msgpack, + std::function)> decode_binpack); + Acir::Program program_buf_to_program(std::vector const& buf); Witnesses::WitnessStack witness_buf_to_witness(std::vector const& buf); From 4123f84dbd8e655563b3b0a0bb6295eac68c9174 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Sat, 22 Mar 2025 21:45:15 +0000 Subject: [PATCH 25/36] Rename to deserialize_program and deserialize_witness_stack --- .../dsl/acir_format/acir_to_constraint_buf.cpp | 16 ++++++++-------- .../dsl/acir_format/acir_to_constraint_buf.hpp | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 8a340b9dfcec..431f07310605 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -829,7 +829,7 @@ AcirFormat circuit_buf_to_acir_format(std::vector const& buf, uint32_t // TODO(https://github.com/AztecProtocol/barretenberg/issues/927): Move to using just // `program_buf_to_acir_format` once Honk fully supports all ACIR test flows For now the backend still expects // to work with a single ACIR function - auto program = program_buf_to_program(buf); + auto program = deserialize_program(buf); auto circuit = program.functions[0]; return circuit_serde_to_acir_format(circuit, honk_recursion); @@ -862,10 +862,10 @@ WitnessVector witness_map_to_witness_vector(Witnesses::WitnessMap const& witness } /** - * @brief Converts from the ACIR-native `WitnessMap` format to Barretenberg's internal `WitnessVector` format. + * @brief Converts from the ACIR-native `WitnessStack` format to Barretenberg's internal `WitnessVector` format. * * @param buf Serialized representation of a `WitnessMap`. - * @return A `WitnessVector` equivalent to the passed `WitnessMap`. + * @return A `WitnessVector` equivalent to the last `WitnessMap` in the stack. * @note This transformation results in all unassigned witnesses within the `WitnessMap` being assigned the value 0. * Converting the `WitnessVector` back to a `WitnessMap` is unlikely to return the exact same `WitnessMap`. */ @@ -874,7 +874,7 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) // TODO(https://github.com/AztecProtocol/barretenberg/issues/927): Move to using just // `witness_buf_to_witness_stack` once Honk fully supports all ACIR test flows. For now the backend still // expects to work with the stop of the `WitnessStack`. - auto witness_stack = witness_buf_to_witness(buf); + auto witness_stack = deserialize_witness_stack(buf); auto w = witness_stack.stack[witness_stack.stack.size() - 1].witness; return witness_map_to_witness_vector(w); @@ -936,7 +936,7 @@ T deserialize_any_format(std::vector const& buf, * @brief Deserializes a `Program` from bytes, trying `msgpack` or `bincode` formats. * @note Ignores the Brillig parts of the bytecode when using `msgpack`. */ -Acir::Program program_buf_to_program(std::vector const& buf) +Acir::Program deserialize_program(std::vector const& buf) { return deserialize_any_format( buf, @@ -960,7 +960,7 @@ Acir::Program program_buf_to_program(std::vector const& buf) /** * @brief Deserializes a `WitnessStack` from bytes, trying `msgpack` or `bincode` formats. */ -Witnesses::WitnessStack witness_buf_to_witness(std::vector const& buf) +Witnesses::WitnessStack deserialize_witness_stack(std::vector const& buf) { return deserialize_any_format( buf, @@ -979,7 +979,7 @@ Witnesses::WitnessStack witness_buf_to_witness(std::vector const& buf) std::vector program_buf_to_acir_format(std::vector const& buf, uint32_t honk_recursion) { - auto program = program_buf_to_program(buf); + auto program = deserialize_program(buf); std::vector constraint_systems; constraint_systems.reserve(program.functions.size()); @@ -992,7 +992,7 @@ std::vector program_buf_to_acir_format(std::vector const& b WitnessVectorStack witness_buf_to_witness_stack(std::vector const& buf) { - auto witness_stack = witness_buf_to_witness(buf); + auto witness_stack = deserialize_witness_stack(buf); WitnessVectorStack witness_vector_stack; witness_vector_stack.reserve(witness_stack.stack.size()); for (auto const& stack_item : witness_stack.stack) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 71890916998b..6fa680a53e32 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -9,13 +9,11 @@ T deserialize_any_format(std::vector const& buf, std::function decode_msgpack, std::function)> decode_binpack); -Acir::Program program_buf_to_program(std::vector const& buf); -Witnesses::WitnessStack witness_buf_to_witness(std::vector const& buf); - -AcirFormat circuit_buf_to_acir_format(std::vector const& buf, uint32_t honk_recursion); +Acir::Program deserialize_program(std::vector const& buf); +Witnesses::WitnessStack deserialize_witness_stack(std::vector const& buf); /** - * @brief Converts from the ACIR-native `WitnessMap` format to Barretenberg's internal `WitnessVector` format. + * @brief Converts from the ACIR-native `WitnessStack` format to Barretenberg's internal `WitnessVector` format. * * @param buf Serialized representation of a `WitnessMap`. * @return A `WitnessVector` equivalent to the passed `WitnessMap`. @@ -24,6 +22,8 @@ AcirFormat circuit_buf_to_acir_format(std::vector const& buf, uint32_t */ WitnessVector witness_buf_to_witness_data(std::vector const& buf); +AcirFormat circuit_buf_to_acir_format(std::vector const& buf, uint32_t honk_recursion); + std::vector program_buf_to_acir_format(std::vector const& buf, uint32_t honk_recursion); WitnessVectorStack witness_buf_to_witness_stack(std::vector const& buf); From 859b4c36b25899f330144ffaa4ce6b4b134d6dc2 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Sat, 22 Mar 2025 21:47:12 +0000 Subject: [PATCH 26/36] Move docs into the header --- .../acir_format/acir_to_constraint_buf.cpp | 24 ------------------- .../acir_format/acir_to_constraint_buf.hpp | 21 ++++++++++++++-- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 431f07310605..4cf36bcf8e45 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -861,14 +861,6 @@ WitnessVector witness_map_to_witness_vector(Witnesses::WitnessMap const& witness return wv; } -/** - * @brief Converts from the ACIR-native `WitnessStack` format to Barretenberg's internal `WitnessVector` format. - * - * @param buf Serialized representation of a `WitnessMap`. - * @return A `WitnessVector` equivalent to the last `WitnessMap` in the stack. - * @note This transformation results in all unassigned witnesses within the `WitnessMap` being assigned the value 0. - * Converting the `WitnessVector` back to a `WitnessMap` is unlikely to return the exact same `WitnessMap`. - */ WitnessVector witness_buf_to_witness_data(std::vector const& buf) { // TODO(https://github.com/AztecProtocol/barretenberg/issues/927): Move to using just @@ -880,15 +872,6 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) return witness_map_to_witness_vector(w); } -/** - * @brief Deserialize `buf` either based on the first byte interpreted as a - Noir serialization format byte, or falling back to `bincode` if - the format cannot be recognized. Currently only `msgpack` format - is expected, or the legacy `bincode` format. - * @note Due to the lack of exception handling available to us in Wasm we can't - * try `bincode` format and if it fails try `msgpack`; instead we have to - * make a decision and commit to it. - */ template T deserialize_any_format(std::vector const& buf, std::function decode_msgpack, @@ -932,10 +915,6 @@ T deserialize_any_format(std::vector const& buf, return decode_binpack(buf); } -/** - * @brief Deserializes a `Program` from bytes, trying `msgpack` or `bincode` formats. - * @note Ignores the Brillig parts of the bytecode when using `msgpack`. - */ Acir::Program deserialize_program(std::vector const& buf) { return deserialize_any_format( @@ -957,9 +936,6 @@ Acir::Program deserialize_program(std::vector const& buf) &Acir::Program::bincodeDeserialize); } -/** - * @brief Deserializes a `WitnessStack` from bytes, trying `msgpack` or `bincode` formats. - */ Witnesses::WitnessStack deserialize_witness_stack(std::vector const& buf) { return deserialize_any_format( diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index 6fa680a53e32..a98fc1d626a2 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -4,19 +4,36 @@ namespace acir_format { +/** + * @brief Deserialize `buf` either based on the first byte interpreted as a + Noir serialization format byte, or falling back to `bincode` if + the format cannot be recognized. Currently only `msgpack` format + is expected, or the legacy `bincode` format. + * @note Due to the lack of exception handling available to us in Wasm we can't + * try `bincode` format and if it fails try `msgpack`; instead we have to + * make a decision and commit to it. + */ template T deserialize_any_format(std::vector const& buf, std::function decode_msgpack, std::function)> decode_binpack); +/** + * @brief Deserializes a `Program` from bytes, trying `msgpack` or `bincode` formats. + * @note Ignores the Brillig parts of the bytecode when using `msgpack`. + */ Acir::Program deserialize_program(std::vector const& buf); + +/** + * @brief Deserializes a `WitnessStack` from bytes, trying `msgpack` or `bincode` formats. + */ Witnesses::WitnessStack deserialize_witness_stack(std::vector const& buf); /** * @brief Converts from the ACIR-native `WitnessStack` format to Barretenberg's internal `WitnessVector` format. * - * @param buf Serialized representation of a `WitnessMap`. - * @return A `WitnessVector` equivalent to the passed `WitnessMap`. + * @param buf Serialized representation of a `WitnessStack`. + * @return A `WitnessVector` equivalent to the last `WitnessMap` in the stack. * @note This transformation results in all unassigned witnesses within the `WitnessMap` being assigned the value 0. * Converting the `WitnessVector` back to a `WitnessMap` is unlikely to return the exact same `WitnessMap`. */ From 4c576941d0e386545701a236d182e38d5a444476 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Sat, 22 Mar 2025 22:00:18 +0000 Subject: [PATCH 27/36] Typo --- barretenberg/cpp/src/barretenberg/dsl/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/README.md b/barretenberg/cpp/src/barretenberg/dsl/README.md index f9f434deefaa..5069ad1ef6c1 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/README.md +++ b/barretenberg/cpp/src/barretenberg/dsl/README.md @@ -9,8 +9,9 @@ There are two types of breaking serialization changes. One that alters the inter 1. Internal Structure Change The C++ bindings are generated by the ACVM `acir` crate and while running the [serde reflection test](https://github.com/noir-lang/noir/blob/master/acvm-repo/acir/src/lib.rs#L51). -By default it just ascretains that the format has not changed, but it can be told to write the updated mappings to `acir.cpp` and `witness_stack.cpp`, which become `acir.hpp` and -`witness_stack.hpp` in `aztec-packages`. +By default it just ascertains that the format has not changed, but it can be told to +write the updated mappings to `acir.cpp` and `witness_stack.cpp`, +which become `acir.hpp` and `witness_stack.hpp` in `aztec-packages`. The code can be regenerated and copied over with the following commands: From a095acc6ce7766ad9bc4065ce4fcc782b9b4f37e Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 25 Mar 2025 14:42:02 +0000 Subject: [PATCH 28/36] Try without using MSGPACK_FIELDS --- .../dsl/acir_format/serde/acir.hpp | 1527 +++++++++++++++-- .../dsl/acir_format/serde/witness_stack.hpp | 68 +- 2 files changed, 1440 insertions(+), 155 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index a214ce73a527..e6c76f5c0ac0 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -4,6 +4,46 @@ #include "msgpack.hpp" #include "serde.hpp" +namespace Acir { +struct Helpers { + static std::map make_kvmap(msgpack::object const& o, std::string name) + { + if (o.type != msgpack::type::MAP) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP for " + name); + } + std::map kvmap; + for (uint32_t i = 0; i < o.via.map.size; ++i) { + if (o.via.map.ptr[i].key.type != msgpack::type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected STR for keys of " + name); + } + kvmap.emplace(std::string(o.via.map.ptr[i].key.via.str.ptr, o.via.map.ptr[i].key.via.str.size), + &o.via.map.ptr[i].val); + } + return kvmap; + } + + template + static void conv_fld_from_kvmap(std::map const& kvmap, + std::string struct_name, + std::string field_name, + T& field) + { + auto it = kvmap.find(field_name); + if (it != kvmap.end()) { + try { + it->second->convert(field); + } catch (const msgpack::type_error&) { + throw_or_abort("error converting into field " + struct_name + "::" + field_name); + } + } else { + throw_or_abort("missing field: " + struct_name + "::" + field_name); + } + } +}; +} // namespace Acir + namespace Acir { struct BinaryFieldOp { @@ -142,6 +182,7 @@ struct BinaryFieldOp { void msgpack_unpack(msgpack::object const& o) { + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BinaryFieldOp'; got type " + std::to_string(o.type)); @@ -150,10 +191,15 @@ struct BinaryFieldOp { throw_or_abort("expected 1 entry for enum 'BinaryFieldOp'; got " + std::to_string(o.via.map.size)); } std::string tag; - if (o.type == msgpack::type::object_type::MAP) { - o.via.map.ptr[0].key.convert(tag); - } else { - o.convert(tag); + try { + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); + } + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting tag to string for enum 'BinaryFieldOp'"); } if (tag == "Add") { Add v; @@ -374,6 +420,7 @@ struct BinaryIntOp { void msgpack_unpack(msgpack::object const& o) { + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BinaryIntOp'; got type " + std::to_string(o.type)); @@ -382,10 +429,15 @@ struct BinaryIntOp { throw_or_abort("expected 1 entry for enum 'BinaryIntOp'; got " + std::to_string(o.via.map.size)); } std::string tag; - if (o.type == msgpack::type::object_type::MAP) { - o.via.map.ptr[0].key.convert(tag); - } else { - o.convert(tag); + try { + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); + } + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting tag to string for enum 'BinaryIntOp'"); } if (tag == "Add") { Add v; @@ -540,6 +592,7 @@ struct IntegerBitSize { void msgpack_unpack(msgpack::object const& o) { + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'IntegerBitSize'; got type " + std::to_string(o.type)); @@ -548,10 +601,15 @@ struct IntegerBitSize { throw_or_abort("expected 1 entry for enum 'IntegerBitSize'; got " + std::to_string(o.via.map.size)); } std::string tag; - if (o.type == msgpack::type::object_type::MAP) { - o.via.map.ptr[0].key.convert(tag); - } else { - o.convert(tag); + try { + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); + } + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting tag to string for enum 'IntegerBitSize'"); } if (tag == "U1") { U1 v; @@ -647,6 +705,7 @@ struct BitSize { void msgpack_unpack(msgpack::object const& o) { + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BitSize'; got type " + std::to_string(o.type)); @@ -655,10 +714,15 @@ struct BitSize { throw_or_abort("expected 1 entry for enum 'BitSize'; got " + std::to_string(o.via.map.size)); } std::string tag; - if (o.type == msgpack::type::object_type::MAP) { - o.via.map.ptr[0].key.convert(tag); - } else { - o.convert(tag); + try { + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); + } + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting tag to string for enum 'BitSize'"); } if (tag == "Field") { Field v; @@ -760,6 +824,7 @@ struct MemoryAddress { void msgpack_unpack(msgpack::object const& o) { + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'MemoryAddress'; got type " + std::to_string(o.type)); @@ -768,10 +833,15 @@ struct MemoryAddress { throw_or_abort("expected 1 entry for enum 'MemoryAddress'; got " + std::to_string(o.via.map.size)); } std::string tag; - if (o.type == msgpack::type::object_type::MAP) { - o.via.map.ptr[0].key.convert(tag); - } else { - o.convert(tag); + try { + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); + } + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting tag to string for enum 'MemoryAddress'"); } if (tag == "Direct") { Direct v; @@ -808,7 +878,20 @@ struct HeapArray { std::vector bincodeSerialize() const; static HeapArray bincodeDeserialize(std::vector); - MSGPACK_FIELDS(pointer, size); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("pointer", pointer)); + packer.pack(std::make_pair("size", size)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "HeapArray"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "pointer", pointer); + Helpers::conv_fld_from_kvmap(kvmap, name, "size", size); + } }; struct HeapVector { @@ -819,7 +902,20 @@ struct HeapVector { std::vector bincodeSerialize() const; static HeapVector bincodeDeserialize(std::vector); - MSGPACK_FIELDS(pointer, size); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("pointer", pointer)); + packer.pack(std::make_pair("size", size)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "HeapVector"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "pointer", pointer); + Helpers::conv_fld_from_kvmap(kvmap, name, "size", size); + } }; struct BlackBoxOp { @@ -834,7 +930,24 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static AES128Encrypt bincodeDeserialize(std::vector); - MSGPACK_FIELDS(inputs, iv, key, outputs); + void msgpack_pack(auto& packer) const + { + packer.pack_map(4); + packer.pack(std::make_pair("inputs", inputs)); + packer.pack(std::make_pair("iv", iv)); + packer.pack(std::make_pair("key", key)); + packer.pack(std::make_pair("outputs", outputs)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "AES128Encrypt"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "iv", iv); + Helpers::conv_fld_from_kvmap(kvmap, name, "key", key); + Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); + } }; struct Blake2s { @@ -845,7 +958,20 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static Blake2s bincodeDeserialize(std::vector); - MSGPACK_FIELDS(message, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("message", message)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Blake2s"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "message", message); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct Blake3 { @@ -856,7 +982,20 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static Blake3 bincodeDeserialize(std::vector); - MSGPACK_FIELDS(message, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("message", message)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Blake3"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "message", message); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct Keccakf1600 { @@ -867,7 +1006,20 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static Keccakf1600 bincodeDeserialize(std::vector); - MSGPACK_FIELDS(input, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("input", input)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Keccakf1600"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct EcdsaSecp256k1 { @@ -881,7 +1033,26 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static EcdsaSecp256k1 bincodeDeserialize(std::vector); - MSGPACK_FIELDS(hashed_msg, public_key_x, public_key_y, signature, result); + void msgpack_pack(auto& packer) const + { + packer.pack_map(5); + packer.pack(std::make_pair("hashed_msg", hashed_msg)); + packer.pack(std::make_pair("public_key_x", public_key_x)); + packer.pack(std::make_pair("public_key_y", public_key_y)); + packer.pack(std::make_pair("signature", signature)); + packer.pack(std::make_pair("result", result)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "EcdsaSecp256k1"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "hashed_msg", hashed_msg); + Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_x", public_key_x); + Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_y", public_key_y); + Helpers::conv_fld_from_kvmap(kvmap, name, "signature", signature); + Helpers::conv_fld_from_kvmap(kvmap, name, "result", result); + } }; struct EcdsaSecp256r1 { @@ -895,7 +1066,26 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static EcdsaSecp256r1 bincodeDeserialize(std::vector); - MSGPACK_FIELDS(hashed_msg, public_key_x, public_key_y, signature, result); + void msgpack_pack(auto& packer) const + { + packer.pack_map(5); + packer.pack(std::make_pair("hashed_msg", hashed_msg)); + packer.pack(std::make_pair("public_key_x", public_key_x)); + packer.pack(std::make_pair("public_key_y", public_key_y)); + packer.pack(std::make_pair("signature", signature)); + packer.pack(std::make_pair("result", result)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "EcdsaSecp256r1"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "hashed_msg", hashed_msg); + Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_x", public_key_x); + Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_y", public_key_y); + Helpers::conv_fld_from_kvmap(kvmap, name, "signature", signature); + Helpers::conv_fld_from_kvmap(kvmap, name, "result", result); + } }; struct MultiScalarMul { @@ -907,7 +1097,22 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static MultiScalarMul bincodeDeserialize(std::vector); - MSGPACK_FIELDS(points, scalars, outputs); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("points", points)); + packer.pack(std::make_pair("scalars", scalars)); + packer.pack(std::make_pair("outputs", outputs)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "MultiScalarMul"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "points", points); + Helpers::conv_fld_from_kvmap(kvmap, name, "scalars", scalars); + Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); + } }; struct EmbeddedCurveAdd { @@ -923,7 +1128,30 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static EmbeddedCurveAdd bincodeDeserialize(std::vector); - MSGPACK_FIELDS(input1_x, input1_y, input1_infinite, input2_x, input2_y, input2_infinite, result); + void msgpack_pack(auto& packer) const + { + packer.pack_map(7); + packer.pack(std::make_pair("input1_x", input1_x)); + packer.pack(std::make_pair("input1_y", input1_y)); + packer.pack(std::make_pair("input1_infinite", input1_infinite)); + packer.pack(std::make_pair("input2_x", input2_x)); + packer.pack(std::make_pair("input2_y", input2_y)); + packer.pack(std::make_pair("input2_infinite", input2_infinite)); + packer.pack(std::make_pair("result", result)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "EmbeddedCurveAdd"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "input1_x", input1_x); + Helpers::conv_fld_from_kvmap(kvmap, name, "input1_y", input1_y); + Helpers::conv_fld_from_kvmap(kvmap, name, "input1_infinite", input1_infinite); + Helpers::conv_fld_from_kvmap(kvmap, name, "input2_x", input2_x); + Helpers::conv_fld_from_kvmap(kvmap, name, "input2_y", input2_y); + Helpers::conv_fld_from_kvmap(kvmap, name, "input2_infinite", input2_infinite); + Helpers::conv_fld_from_kvmap(kvmap, name, "result", result); + } }; struct BigIntAdd { @@ -935,7 +1163,22 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static BigIntAdd bincodeDeserialize(std::vector); - MSGPACK_FIELDS(lhs, rhs, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("lhs", lhs)); + packer.pack(std::make_pair("rhs", rhs)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BigIntAdd"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct BigIntSub { @@ -947,7 +1190,22 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static BigIntSub bincodeDeserialize(std::vector); - MSGPACK_FIELDS(lhs, rhs, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("lhs", lhs)); + packer.pack(std::make_pair("rhs", rhs)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BigIntSub"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct BigIntMul { @@ -959,7 +1217,22 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static BigIntMul bincodeDeserialize(std::vector); - MSGPACK_FIELDS(lhs, rhs, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("lhs", lhs)); + packer.pack(std::make_pair("rhs", rhs)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BigIntMul"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct BigIntDiv { @@ -971,7 +1244,22 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static BigIntDiv bincodeDeserialize(std::vector); - MSGPACK_FIELDS(lhs, rhs, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("lhs", lhs)); + packer.pack(std::make_pair("rhs", rhs)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BigIntDiv"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct BigIntFromLeBytes { @@ -983,7 +1271,22 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static BigIntFromLeBytes bincodeDeserialize(std::vector); - MSGPACK_FIELDS(inputs, modulus, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("inputs", inputs)); + packer.pack(std::make_pair("modulus", modulus)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BigIntFromLeBytes"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "modulus", modulus); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct BigIntToLeBytes { @@ -994,7 +1297,20 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static BigIntToLeBytes bincodeDeserialize(std::vector); - MSGPACK_FIELDS(input, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("input", input)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BigIntToLeBytes"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct Poseidon2Permutation { @@ -1006,7 +1322,22 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static Poseidon2Permutation bincodeDeserialize(std::vector); - MSGPACK_FIELDS(message, output, len); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("message", message)); + packer.pack(std::make_pair("output", output)); + packer.pack(std::make_pair("len", len)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Poseidon2Permutation"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "message", message); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + Helpers::conv_fld_from_kvmap(kvmap, name, "len", len); + } }; struct Sha256Compression { @@ -1018,7 +1349,22 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static Sha256Compression bincodeDeserialize(std::vector); - MSGPACK_FIELDS(input, hash_values, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("input", input)); + packer.pack(std::make_pair("hash_values", hash_values)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Sha256Compression"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); + Helpers::conv_fld_from_kvmap(kvmap, name, "hash_values", hash_values); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct ToRadix { @@ -1032,7 +1378,26 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static ToRadix bincodeDeserialize(std::vector); - MSGPACK_FIELDS(input, radix, output_pointer, num_limbs, output_bits); + void msgpack_pack(auto& packer) const + { + packer.pack_map(5); + packer.pack(std::make_pair("input", input)); + packer.pack(std::make_pair("radix", radix)); + packer.pack(std::make_pair("output_pointer", output_pointer)); + packer.pack(std::make_pair("num_limbs", num_limbs)); + packer.pack(std::make_pair("output_bits", output_bits)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "ToRadix"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); + Helpers::conv_fld_from_kvmap(kvmap, name, "radix", radix); + Helpers::conv_fld_from_kvmap(kvmap, name, "output_pointer", output_pointer); + Helpers::conv_fld_from_kvmap(kvmap, name, "num_limbs", num_limbs); + Helpers::conv_fld_from_kvmap(kvmap, name, "output_bits", output_bits); + } }; std::variant bincodeSerialize() const; static Array bincodeDeserialize(std::vector); - MSGPACK_FIELDS(value_types, size); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("value_types", value_types)); + packer.pack(std::make_pair("size", size)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Array"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "value_types", value_types); + Helpers::conv_fld_from_kvmap(kvmap, name, "size", size); + } }; struct Vector { @@ -1382,7 +1766,18 @@ struct HeapValueType { std::vector bincodeSerialize() const; static Vector bincodeDeserialize(std::vector); - MSGPACK_FIELDS(value_types); + void msgpack_pack(auto& packer) const + { + packer.pack_map(1); + packer.pack(std::make_pair("value_types", value_types)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Vector"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "value_types", value_types); + } }; std::variant value; @@ -1427,6 +1822,7 @@ struct HeapValueType { void msgpack_unpack(msgpack::object const& o) { + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'HeapValueType'; got type " + std::to_string(o.type)); @@ -1435,10 +1831,15 @@ struct HeapValueType { throw_or_abort("expected 1 entry for enum 'HeapValueType'; got " + std::to_string(o.via.map.size)); } std::string tag; - if (o.type == msgpack::type::object_type::MAP) { - o.via.map.ptr[0].key.convert(tag); - } else { - o.convert(tag); + try { + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); + } + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting tag to string for enum 'HeapValueType'"); } if (tag == "Simple") { Simple v; @@ -1581,6 +1982,7 @@ struct ValueOrArray { void msgpack_unpack(msgpack::object const& o) { + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'ValueOrArray'; got type " + std::to_string(o.type)); @@ -1589,10 +1991,15 @@ struct ValueOrArray { throw_or_abort("expected 1 entry for enum 'ValueOrArray'; got " + std::to_string(o.via.map.size)); } std::string tag; - if (o.type == msgpack::type::object_type::MAP) { - o.via.map.ptr[0].key.convert(tag); - } else { - o.convert(tag); + try { + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); + } + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting tag to string for enum 'ValueOrArray'"); } if (tag == "MemoryAddress") { MemoryAddress v; @@ -1643,7 +2050,24 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static BinaryFieldOp bincodeDeserialize(std::vector); - MSGPACK_FIELDS(destination, op, lhs, rhs); + void msgpack_pack(auto& packer) const + { + packer.pack_map(4); + packer.pack(std::make_pair("destination", destination)); + packer.pack(std::make_pair("op", op)); + packer.pack(std::make_pair("lhs", lhs)); + packer.pack(std::make_pair("rhs", rhs)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BinaryFieldOp"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); + Helpers::conv_fld_from_kvmap(kvmap, name, "op", op); + Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); + } }; struct BinaryIntOp { @@ -1657,7 +2081,26 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static BinaryIntOp bincodeDeserialize(std::vector); - MSGPACK_FIELDS(destination, op, bit_size, lhs, rhs); + void msgpack_pack(auto& packer) const + { + packer.pack_map(5); + packer.pack(std::make_pair("destination", destination)); + packer.pack(std::make_pair("op", op)); + packer.pack(std::make_pair("bit_size", bit_size)); + packer.pack(std::make_pair("lhs", lhs)); + packer.pack(std::make_pair("rhs", rhs)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BinaryIntOp"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); + Helpers::conv_fld_from_kvmap(kvmap, name, "op", op); + Helpers::conv_fld_from_kvmap(kvmap, name, "bit_size", bit_size); + Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); + } }; struct Not { @@ -1669,7 +2112,22 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Not bincodeDeserialize(std::vector); - MSGPACK_FIELDS(destination, source, bit_size); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("destination", destination)); + packer.pack(std::make_pair("source", source)); + packer.pack(std::make_pair("bit_size", bit_size)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Not"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); + Helpers::conv_fld_from_kvmap(kvmap, name, "source", source); + Helpers::conv_fld_from_kvmap(kvmap, name, "bit_size", bit_size); + } }; struct Cast { @@ -1681,7 +2139,22 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Cast bincodeDeserialize(std::vector); - MSGPACK_FIELDS(destination, source, bit_size); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("destination", destination)); + packer.pack(std::make_pair("source", source)); + packer.pack(std::make_pair("bit_size", bit_size)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Cast"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); + Helpers::conv_fld_from_kvmap(kvmap, name, "source", source); + Helpers::conv_fld_from_kvmap(kvmap, name, "bit_size", bit_size); + } }; struct JumpIfNot { @@ -1692,7 +2165,20 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static JumpIfNot bincodeDeserialize(std::vector); - MSGPACK_FIELDS(condition, location); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("condition", condition)); + packer.pack(std::make_pair("location", location)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "JumpIfNot"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "condition", condition); + Helpers::conv_fld_from_kvmap(kvmap, name, "location", location); + } }; struct JumpIf { @@ -1703,7 +2189,20 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static JumpIf bincodeDeserialize(std::vector); - MSGPACK_FIELDS(condition, location); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("condition", condition)); + packer.pack(std::make_pair("location", location)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "JumpIf"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "condition", condition); + Helpers::conv_fld_from_kvmap(kvmap, name, "location", location); + } }; struct Jump { @@ -1713,7 +2212,18 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Jump bincodeDeserialize(std::vector); - MSGPACK_FIELDS(location); + void msgpack_pack(auto& packer) const + { + packer.pack_map(1); + packer.pack(std::make_pair("location", location)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Jump"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "location", location); + } }; struct CalldataCopy { @@ -1725,7 +2235,22 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static CalldataCopy bincodeDeserialize(std::vector); - MSGPACK_FIELDS(destination_address, size_address, offset_address); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("destination_address", destination_address)); + packer.pack(std::make_pair("size_address", size_address)); + packer.pack(std::make_pair("offset_address", offset_address)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "CalldataCopy"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "destination_address", destination_address); + Helpers::conv_fld_from_kvmap(kvmap, name, "size_address", size_address); + Helpers::conv_fld_from_kvmap(kvmap, name, "offset_address", offset_address); + } }; struct Call { @@ -1735,7 +2260,18 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Call bincodeDeserialize(std::vector); - MSGPACK_FIELDS(location); + void msgpack_pack(auto& packer) const + { + packer.pack_map(1); + packer.pack(std::make_pair("location", location)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Call"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "location", location); + } }; struct Const { @@ -1747,7 +2283,22 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Const bincodeDeserialize(std::vector); - MSGPACK_FIELDS(destination, bit_size, value); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("destination", destination)); + packer.pack(std::make_pair("bit_size", bit_size)); + packer.pack(std::make_pair("value", value)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Const"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); + Helpers::conv_fld_from_kvmap(kvmap, name, "bit_size", bit_size); + Helpers::conv_fld_from_kvmap(kvmap, name, "value", value); + } }; struct IndirectConst { @@ -1759,9 +2310,24 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static IndirectConst bincodeDeserialize(std::vector); - MSGPACK_FIELDS(destination_pointer, bit_size, value); - }; - + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("destination_pointer", destination_pointer)); + packer.pack(std::make_pair("bit_size", bit_size)); + packer.pack(std::make_pair("value", value)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "IndirectConst"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "destination_pointer", destination_pointer); + Helpers::conv_fld_from_kvmap(kvmap, name, "bit_size", bit_size); + Helpers::conv_fld_from_kvmap(kvmap, name, "value", value); + } + }; + struct Return { friend bool operator==(const Return&, const Return&); std::vector bincodeSerialize() const; @@ -1782,7 +2348,26 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static ForeignCall bincodeDeserialize(std::vector); - MSGPACK_FIELDS(function, destinations, destination_value_types, inputs, input_value_types); + void msgpack_pack(auto& packer) const + { + packer.pack_map(5); + packer.pack(std::make_pair("function", function)); + packer.pack(std::make_pair("destinations", destinations)); + packer.pack(std::make_pair("destination_value_types", destination_value_types)); + packer.pack(std::make_pair("inputs", inputs)); + packer.pack(std::make_pair("input_value_types", input_value_types)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "ForeignCall"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "function", function); + Helpers::conv_fld_from_kvmap(kvmap, name, "destinations", destinations); + Helpers::conv_fld_from_kvmap(kvmap, name, "destination_value_types", destination_value_types); + Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "input_value_types", input_value_types); + } }; struct Mov { @@ -1793,7 +2378,20 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Mov bincodeDeserialize(std::vector); - MSGPACK_FIELDS(destination, source); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("destination", destination)); + packer.pack(std::make_pair("source", source)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Mov"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); + Helpers::conv_fld_from_kvmap(kvmap, name, "source", source); + } }; struct ConditionalMov { @@ -1806,7 +2404,24 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static ConditionalMov bincodeDeserialize(std::vector); - MSGPACK_FIELDS(destination, source_a, source_b, condition); + void msgpack_pack(auto& packer) const + { + packer.pack_map(4); + packer.pack(std::make_pair("destination", destination)); + packer.pack(std::make_pair("source_a", source_a)); + packer.pack(std::make_pair("source_b", source_b)); + packer.pack(std::make_pair("condition", condition)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "ConditionalMov"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); + Helpers::conv_fld_from_kvmap(kvmap, name, "source_a", source_a); + Helpers::conv_fld_from_kvmap(kvmap, name, "source_b", source_b); + Helpers::conv_fld_from_kvmap(kvmap, name, "condition", condition); + } }; struct Load { @@ -1817,7 +2432,20 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Load bincodeDeserialize(std::vector); - MSGPACK_FIELDS(destination, source_pointer); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("destination", destination)); + packer.pack(std::make_pair("source_pointer", source_pointer)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Load"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); + Helpers::conv_fld_from_kvmap(kvmap, name, "source_pointer", source_pointer); + } }; struct Store { @@ -1828,7 +2456,20 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Store bincodeDeserialize(std::vector); - MSGPACK_FIELDS(destination_pointer, source); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("destination_pointer", destination_pointer)); + packer.pack(std::make_pair("source", source)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Store"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "destination_pointer", destination_pointer); + Helpers::conv_fld_from_kvmap(kvmap, name, "source", source); + } }; struct BlackBox { @@ -1858,7 +2499,18 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Trap bincodeDeserialize(std::vector); - MSGPACK_FIELDS(revert_data); + void msgpack_pack(auto& packer) const + { + packer.pack_map(1); + packer.pack(std::make_pair("revert_data", revert_data)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Trap"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "revert_data", revert_data); + } }; struct Stop { @@ -1868,7 +2520,18 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Stop bincodeDeserialize(std::vector); - MSGPACK_FIELDS(return_data); + void msgpack_pack(auto& packer) const + { + packer.pack_map(1); + packer.pack(std::make_pair("return_data", return_data)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Stop"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "return_data", return_data); + } }; std::variant bincodeSerialize() const; static FunctionInput bincodeDeserialize(std::vector); - MSGPACK_FIELDS(input, num_bits); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("input", input)); + packer.pack(std::make_pair("num_bits", num_bits)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "FunctionInput"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); + Helpers::conv_fld_from_kvmap(kvmap, name, "num_bits", num_bits); + } }; struct BlackBoxFuncCall { @@ -2377,7 +3065,24 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static AES128Encrypt bincodeDeserialize(std::vector); - MSGPACK_FIELDS(inputs, iv, key, outputs); + void msgpack_pack(auto& packer) const + { + packer.pack_map(4); + packer.pack(std::make_pair("inputs", inputs)); + packer.pack(std::make_pair("iv", iv)); + packer.pack(std::make_pair("key", key)); + packer.pack(std::make_pair("outputs", outputs)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "AES128Encrypt"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "iv", iv); + Helpers::conv_fld_from_kvmap(kvmap, name, "key", key); + Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); + } }; struct AND { @@ -2389,7 +3094,22 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static AND bincodeDeserialize(std::vector); - MSGPACK_FIELDS(lhs, rhs, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("lhs", lhs)); + packer.pack(std::make_pair("rhs", rhs)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "AND"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct XOR { @@ -2401,7 +3121,22 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static XOR bincodeDeserialize(std::vector); - MSGPACK_FIELDS(lhs, rhs, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("lhs", lhs)); + packer.pack(std::make_pair("rhs", rhs)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "XOR"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct RANGE { @@ -2411,7 +3146,18 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static RANGE bincodeDeserialize(std::vector); - MSGPACK_FIELDS(input); + void msgpack_pack(auto& packer) const + { + packer.pack_map(1); + packer.pack(std::make_pair("input", input)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "RANGE"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); + } }; struct Blake2s { @@ -2422,7 +3168,20 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static Blake2s bincodeDeserialize(std::vector); - MSGPACK_FIELDS(inputs, outputs); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("inputs", inputs)); + packer.pack(std::make_pair("outputs", outputs)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Blake2s"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); + } }; struct Blake3 { @@ -2433,7 +3192,20 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static Blake3 bincodeDeserialize(std::vector); - MSGPACK_FIELDS(inputs, outputs); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("inputs", inputs)); + packer.pack(std::make_pair("outputs", outputs)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Blake3"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); + } }; struct EcdsaSecp256k1 { @@ -2447,7 +3219,26 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static EcdsaSecp256k1 bincodeDeserialize(std::vector); - MSGPACK_FIELDS(public_key_x, public_key_y, signature, hashed_message, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(5); + packer.pack(std::make_pair("public_key_x", public_key_x)); + packer.pack(std::make_pair("public_key_y", public_key_y)); + packer.pack(std::make_pair("signature", signature)); + packer.pack(std::make_pair("hashed_message", hashed_message)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "EcdsaSecp256k1"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_x", public_key_x); + Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_y", public_key_y); + Helpers::conv_fld_from_kvmap(kvmap, name, "signature", signature); + Helpers::conv_fld_from_kvmap(kvmap, name, "hashed_message", hashed_message); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct EcdsaSecp256r1 { @@ -2461,7 +3252,26 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static EcdsaSecp256r1 bincodeDeserialize(std::vector); - MSGPACK_FIELDS(public_key_x, public_key_y, signature, hashed_message, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(5); + packer.pack(std::make_pair("public_key_x", public_key_x)); + packer.pack(std::make_pair("public_key_y", public_key_y)); + packer.pack(std::make_pair("signature", signature)); + packer.pack(std::make_pair("hashed_message", hashed_message)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "EcdsaSecp256r1"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_x", public_key_x); + Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_y", public_key_y); + Helpers::conv_fld_from_kvmap(kvmap, name, "signature", signature); + Helpers::conv_fld_from_kvmap(kvmap, name, "hashed_message", hashed_message); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct MultiScalarMul { @@ -2473,7 +3283,22 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static MultiScalarMul bincodeDeserialize(std::vector); - MSGPACK_FIELDS(points, scalars, outputs); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("points", points)); + packer.pack(std::make_pair("scalars", scalars)); + packer.pack(std::make_pair("outputs", outputs)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "MultiScalarMul"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "points", points); + Helpers::conv_fld_from_kvmap(kvmap, name, "scalars", scalars); + Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); + } }; struct EmbeddedCurveAdd { @@ -2485,7 +3310,22 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static EmbeddedCurveAdd bincodeDeserialize(std::vector); - MSGPACK_FIELDS(input1, input2, outputs); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("input1", input1)); + packer.pack(std::make_pair("input2", input2)); + packer.pack(std::make_pair("outputs", outputs)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "EmbeddedCurveAdd"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "input1", input1); + Helpers::conv_fld_from_kvmap(kvmap, name, "input2", input2); + Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); + } }; struct Keccakf1600 { @@ -2496,7 +3336,20 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static Keccakf1600 bincodeDeserialize(std::vector); - MSGPACK_FIELDS(inputs, outputs); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("inputs", inputs)); + packer.pack(std::make_pair("outputs", outputs)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Keccakf1600"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); + } }; struct RecursiveAggregation { @@ -2510,7 +3363,26 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static RecursiveAggregation bincodeDeserialize(std::vector); - MSGPACK_FIELDS(verification_key, proof, public_inputs, key_hash, proof_type); + void msgpack_pack(auto& packer) const + { + packer.pack_map(5); + packer.pack(std::make_pair("verification_key", verification_key)); + packer.pack(std::make_pair("proof", proof)); + packer.pack(std::make_pair("public_inputs", public_inputs)); + packer.pack(std::make_pair("key_hash", key_hash)); + packer.pack(std::make_pair("proof_type", proof_type)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "RecursiveAggregation"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "verification_key", verification_key); + Helpers::conv_fld_from_kvmap(kvmap, name, "proof", proof); + Helpers::conv_fld_from_kvmap(kvmap, name, "public_inputs", public_inputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "key_hash", key_hash); + Helpers::conv_fld_from_kvmap(kvmap, name, "proof_type", proof_type); + } }; struct BigIntAdd { @@ -2522,7 +3394,22 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static BigIntAdd bincodeDeserialize(std::vector); - MSGPACK_FIELDS(lhs, rhs, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("lhs", lhs)); + packer.pack(std::make_pair("rhs", rhs)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BigIntAdd"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct BigIntSub { @@ -2534,7 +3421,22 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static BigIntSub bincodeDeserialize(std::vector); - MSGPACK_FIELDS(lhs, rhs, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("lhs", lhs)); + packer.pack(std::make_pair("rhs", rhs)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BigIntSub"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct BigIntMul { @@ -2546,7 +3448,22 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static BigIntMul bincodeDeserialize(std::vector); - MSGPACK_FIELDS(lhs, rhs, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("lhs", lhs)); + packer.pack(std::make_pair("rhs", rhs)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BigIntMul"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct BigIntDiv { @@ -2558,7 +3475,22 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static BigIntDiv bincodeDeserialize(std::vector); - MSGPACK_FIELDS(lhs, rhs, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("lhs", lhs)); + packer.pack(std::make_pair("rhs", rhs)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BigIntDiv"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct BigIntFromLeBytes { @@ -2570,7 +3502,22 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static BigIntFromLeBytes bincodeDeserialize(std::vector); - MSGPACK_FIELDS(inputs, modulus, output); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("inputs", inputs)); + packer.pack(std::make_pair("modulus", modulus)); + packer.pack(std::make_pair("output", output)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BigIntFromLeBytes"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "modulus", modulus); + Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); + } }; struct BigIntToLeBytes { @@ -2581,7 +3528,20 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static BigIntToLeBytes bincodeDeserialize(std::vector); - MSGPACK_FIELDS(input, outputs); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("input", input)); + packer.pack(std::make_pair("outputs", outputs)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BigIntToLeBytes"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); + Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); + } }; struct Poseidon2Permutation { @@ -2593,7 +3553,22 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static Poseidon2Permutation bincodeDeserialize(std::vector); - MSGPACK_FIELDS(inputs, outputs, len); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("inputs", inputs)); + packer.pack(std::make_pair("outputs", outputs)); + packer.pack(std::make_pair("len", len)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Poseidon2Permutation"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "len", len); + } }; struct Sha256Compression { @@ -2605,7 +3580,22 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static Sha256Compression bincodeDeserialize(std::vector); - MSGPACK_FIELDS(inputs, hash_values, outputs); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("inputs", inputs)); + packer.pack(std::make_pair("hash_values", hash_values)); + packer.pack(std::make_pair("outputs", outputs)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Sha256Compression"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "hash_values", hash_values); + Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); + } }; std::variant bincodeSerialize() const; static Expression bincodeDeserialize(std::vector); - MSGPACK_FIELDS(mul_terms, linear_combinations, q_c); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("mul_terms", mul_terms)); + packer.pack(std::make_pair("linear_combinations", linear_combinations)); + packer.pack(std::make_pair("q_c", q_c)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Expression"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "mul_terms", mul_terms); + Helpers::conv_fld_from_kvmap(kvmap, name, "linear_combinations", linear_combinations); + Helpers::conv_fld_from_kvmap(kvmap, name, "q_c", q_c); + } }; struct BrilligInputs { @@ -3212,6 +4229,7 @@ struct BrilligInputs { void msgpack_unpack(msgpack::object const& o) { + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BrilligInputs'; got type " + std::to_string(o.type)); @@ -3220,10 +4238,15 @@ struct BrilligInputs { throw_or_abort("expected 1 entry for enum 'BrilligInputs'; got " + std::to_string(o.via.map.size)); } std::string tag; - if (o.type == msgpack::type::object_type::MAP) { - o.via.map.ptr[0].key.convert(tag); - } else { - o.convert(tag); + try { + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); + } + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting tag to string for enum 'BrilligInputs'"); } if (tag == "Single") { Single v; @@ -3342,6 +4365,7 @@ struct BrilligOutputs { void msgpack_unpack(msgpack::object const& o) { + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'BrilligOutputs'; got type " + std::to_string(o.type)); @@ -3350,10 +4374,15 @@ struct BrilligOutputs { throw_or_abort("expected 1 entry for enum 'BrilligOutputs'; got " + std::to_string(o.via.map.size)); } std::string tag; - if (o.type == msgpack::type::object_type::MAP) { - o.via.map.ptr[0].key.convert(tag); - } else { - o.convert(tag); + try { + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); + } + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting tag to string for enum 'BrilligOutputs'"); } if (tag == "Simple") { Simple v; @@ -3391,7 +4420,22 @@ struct MemOp { std::vector bincodeSerialize() const; static MemOp bincodeDeserialize(std::vector); - MSGPACK_FIELDS(operation, index, value); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("operation", operation)); + packer.pack(std::make_pair("index", index)); + packer.pack(std::make_pair("value", value)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "MemOp"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "operation", operation); + Helpers::conv_fld_from_kvmap(kvmap, name, "index", index); + Helpers::conv_fld_from_kvmap(kvmap, name, "value", value); + } }; struct Opcode { @@ -3445,7 +4489,22 @@ struct Opcode { std::vector bincodeSerialize() const; static MemoryOp bincodeDeserialize(std::vector); - MSGPACK_FIELDS(block_id, op, predicate); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("block_id", block_id)); + packer.pack(std::make_pair("op", op)); + packer.pack(std::make_pair("predicate", predicate)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "MemoryOp"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "block_id", block_id); + Helpers::conv_fld_from_kvmap(kvmap, name, "op", op); + Helpers::conv_fld_from_kvmap(kvmap, name, "predicate", predicate); + } }; struct MemoryInit { @@ -3457,7 +4516,22 @@ struct Opcode { std::vector bincodeSerialize() const; static MemoryInit bincodeDeserialize(std::vector); - MSGPACK_FIELDS(block_id, init, block_type); + void msgpack_pack(auto& packer) const + { + packer.pack_map(3); + packer.pack(std::make_pair("block_id", block_id)); + packer.pack(std::make_pair("init", init)); + packer.pack(std::make_pair("block_type", block_type)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "MemoryInit"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "block_id", block_id); + Helpers::conv_fld_from_kvmap(kvmap, name, "init", init); + Helpers::conv_fld_from_kvmap(kvmap, name, "block_type", block_type); + } }; struct BrilligCall { @@ -3470,7 +4544,24 @@ struct Opcode { std::vector bincodeSerialize() const; static BrilligCall bincodeDeserialize(std::vector); - MSGPACK_FIELDS(id, inputs, outputs, predicate); + void msgpack_pack(auto& packer) const + { + packer.pack_map(4); + packer.pack(std::make_pair("id", id)); + packer.pack(std::make_pair("inputs", inputs)); + packer.pack(std::make_pair("outputs", outputs)); + packer.pack(std::make_pair("predicate", predicate)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BrilligCall"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "id", id); + Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "predicate", predicate); + } }; struct Call { @@ -3483,7 +4574,24 @@ struct Opcode { std::vector bincodeSerialize() const; static Call bincodeDeserialize(std::vector); - MSGPACK_FIELDS(id, inputs, outputs, predicate); + void msgpack_pack(auto& packer) const + { + packer.pack_map(4); + packer.pack(std::make_pair("id", id)); + packer.pack(std::make_pair("inputs", inputs)); + packer.pack(std::make_pair("outputs", outputs)); + packer.pack(std::make_pair("predicate", predicate)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Call"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "id", id); + Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); + Helpers::conv_fld_from_kvmap(kvmap, name, "predicate", predicate); + } }; std::variant value; @@ -3540,6 +4648,7 @@ struct Opcode { void msgpack_unpack(msgpack::object const& o) { + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'Opcode'; got type " + std::to_string(o.type)); @@ -3548,10 +4657,15 @@ struct Opcode { throw_or_abort("expected 1 entry for enum 'Opcode'; got " + std::to_string(o.via.map.size)); } std::string tag; - if (o.type == msgpack::type::object_type::MAP) { - o.via.map.ptr[0].key.convert(tag); - } else { - o.convert(tag); + try { + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); + } + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting tag to string for enum 'Opcode'"); } if (tag == "AssertZero") { AssertZero v; @@ -3700,6 +4814,7 @@ struct ExpressionOrMemory { void msgpack_unpack(msgpack::object const& o) { + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'ExpressionOrMemory'; got type " + std::to_string(o.type)); @@ -3708,10 +4823,15 @@ struct ExpressionOrMemory { throw_or_abort("expected 1 entry for enum 'ExpressionOrMemory'; got " + std::to_string(o.via.map.size)); } std::string tag; - if (o.type == msgpack::type::object_type::MAP) { - o.via.map.ptr[0].key.convert(tag); - } else { - o.convert(tag); + try { + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); + } + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting tag to string for enum 'ExpressionOrMemory'"); } if (tag == "Expression") { Expression v; @@ -3748,7 +4868,20 @@ struct AssertionPayload { std::vector bincodeSerialize() const; static AssertionPayload bincodeDeserialize(std::vector); - MSGPACK_FIELDS(error_selector, payload); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("error_selector", error_selector)); + packer.pack(std::make_pair("payload", payload)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "AssertionPayload"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "error_selector", error_selector); + Helpers::conv_fld_from_kvmap(kvmap, name, "payload", payload); + } }; struct ExpressionWidth { @@ -3769,7 +4902,18 @@ struct ExpressionWidth { std::vector bincodeSerialize() const; static Bounded bincodeDeserialize(std::vector); - MSGPACK_FIELDS(width); + void msgpack_pack(auto& packer) const + { + packer.pack_map(1); + packer.pack(std::make_pair("width", width)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Bounded"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "width", width); + } }; std::variant value; @@ -3810,6 +4954,7 @@ struct ExpressionWidth { void msgpack_unpack(msgpack::object const& o) { + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'ExpressionWidth'; got type " + std::to_string(o.type)); @@ -3818,10 +4963,15 @@ struct ExpressionWidth { throw_or_abort("expected 1 entry for enum 'ExpressionWidth'; got " + std::to_string(o.via.map.size)); } std::string tag; - if (o.type == msgpack::type::object_type::MAP) { - o.via.map.ptr[0].key.convert(tag); - } else { - o.convert(tag); + try { + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); + } + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting tag to string for enum 'ExpressionWidth'"); } if (tag == "Unbounded") { Unbounded v; @@ -3873,7 +5023,20 @@ struct OpcodeLocation { std::vector bincodeSerialize() const; static Brillig bincodeDeserialize(std::vector); - MSGPACK_FIELDS(acir_index, brillig_index); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("acir_index", acir_index)); + packer.pack(std::make_pair("brillig_index", brillig_index)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Brillig"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "acir_index", acir_index); + Helpers::conv_fld_from_kvmap(kvmap, name, "brillig_index", brillig_index); + } }; std::variant value; @@ -3914,6 +5077,7 @@ struct OpcodeLocation { void msgpack_unpack(msgpack::object const& o) { + if (o.type != msgpack::type::object_type::MAP && o.type != msgpack::type::object_type::STR) { std::cerr << o << std::endl; throw_or_abort("expected MAP or STR for enum 'OpcodeLocation'; got type " + std::to_string(o.type)); @@ -3922,10 +5086,15 @@ struct OpcodeLocation { throw_or_abort("expected 1 entry for enum 'OpcodeLocation'; got " + std::to_string(o.via.map.size)); } std::string tag; - if (o.type == msgpack::type::object_type::MAP) { - o.via.map.ptr[0].key.convert(tag); - } else { - o.convert(tag); + try { + if (o.type == msgpack::type::object_type::MAP) { + o.via.map.ptr[0].key.convert(tag); + } else { + o.convert(tag); + } + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("error converting tag to string for enum 'OpcodeLocation'"); } if (tag == "Acir") { Acir v; @@ -3987,13 +5156,30 @@ struct Circuit { std::vector bincodeSerialize() const; static Circuit bincodeDeserialize(std::vector); - MSGPACK_FIELDS(current_witness_index, - opcodes, - expression_width, - private_parameters, - public_parameters, - return_values, - assert_messages); + void msgpack_pack(auto& packer) const + { + packer.pack_map(7); + packer.pack(std::make_pair("current_witness_index", current_witness_index)); + packer.pack(std::make_pair("opcodes", opcodes)); + packer.pack(std::make_pair("expression_width", expression_width)); + packer.pack(std::make_pair("private_parameters", private_parameters)); + packer.pack(std::make_pair("public_parameters", public_parameters)); + packer.pack(std::make_pair("return_values", return_values)); + packer.pack(std::make_pair("assert_messages", assert_messages)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Circuit"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "current_witness_index", current_witness_index); + Helpers::conv_fld_from_kvmap(kvmap, name, "opcodes", opcodes); + Helpers::conv_fld_from_kvmap(kvmap, name, "expression_width", expression_width); + Helpers::conv_fld_from_kvmap(kvmap, name, "private_parameters", private_parameters); + Helpers::conv_fld_from_kvmap(kvmap, name, "public_parameters", public_parameters); + Helpers::conv_fld_from_kvmap(kvmap, name, "return_values", return_values); + Helpers::conv_fld_from_kvmap(kvmap, name, "assert_messages", assert_messages); + } }; struct BrilligBytecode { @@ -4003,7 +5189,18 @@ struct BrilligBytecode { std::vector bincodeSerialize() const; static BrilligBytecode bincodeDeserialize(std::vector); - MSGPACK_FIELDS(bytecode); + void msgpack_pack(auto& packer) const + { + packer.pack_map(1); + packer.pack(std::make_pair("bytecode", bytecode)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "BrilligBytecode"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "bytecode", bytecode); + } }; struct Program { @@ -4014,7 +5211,20 @@ struct Program { std::vector bincodeSerialize() const; static Program bincodeDeserialize(std::vector); - MSGPACK_FIELDS(functions, unconstrained_functions); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("functions", functions)); + packer.pack(std::make_pair("unconstrained_functions", unconstrained_functions)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "Program"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "functions", functions); + Helpers::conv_fld_from_kvmap(kvmap, name, "unconstrained_functions", unconstrained_functions); + } }; struct ProgramWithoutBrillig { @@ -4024,7 +5234,18 @@ struct ProgramWithoutBrillig { std::vector bincodeSerialize() const; static ProgramWithoutBrillig bincodeDeserialize(std::vector); - MSGPACK_FIELDS(functions); + void msgpack_pack(auto& packer) const + { + packer.pack_map(1); + packer.pack(std::make_pair("functions", functions)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "ProgramWithoutBrillig"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "functions", functions); + } }; } // end of namespace Acir diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp index 9cf5d5b48269..8230ddf21f41 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp @@ -4,6 +4,46 @@ #include "msgpack.hpp" #include "serde.hpp" +namespace Witnesses { +struct Helpers { + static std::map make_kvmap(msgpack::object const& o, std::string name) + { + if (o.type != msgpack::type::MAP) { + std::cerr << o << std::endl; + throw_or_abort("expected MAP for " + name); + } + std::map kvmap; + for (uint32_t i = 0; i < o.via.map.size; ++i) { + if (o.via.map.ptr[i].key.type != msgpack::type::STR) { + std::cerr << o << std::endl; + throw_or_abort("expected STR for keys of " + name); + } + kvmap.emplace(std::string(o.via.map.ptr[i].key.via.str.ptr, o.via.map.ptr[i].key.via.str.size), + &o.via.map.ptr[i].val); + } + return kvmap; + } + + template + static void conv_fld_from_kvmap(std::map const& kvmap, + std::string struct_name, + std::string field_name, + T& field) + { + auto it = kvmap.find(field_name); + if (it != kvmap.end()) { + try { + it->second->convert(field); + } catch (const msgpack::type_error&) { + throw_or_abort("error converting into field " + struct_name + "::" + field_name); + } + } else { + throw_or_abort("missing field: " + struct_name + "::" + field_name); + } + } +}; +} // namespace Witnesses + namespace Witnesses { struct Witness { @@ -55,7 +95,20 @@ struct StackItem { std::vector bincodeSerialize() const; static StackItem bincodeDeserialize(std::vector); - MSGPACK_FIELDS(index, witness); + void msgpack_pack(auto& packer) const + { + packer.pack_map(2); + packer.pack(std::make_pair("index", index)); + packer.pack(std::make_pair("witness", witness)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "StackItem"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "index", index); + Helpers::conv_fld_from_kvmap(kvmap, name, "witness", witness); + } }; struct WitnessStack { @@ -65,7 +118,18 @@ struct WitnessStack { std::vector bincodeSerialize() const; static WitnessStack bincodeDeserialize(std::vector); - MSGPACK_FIELDS(stack); + void msgpack_pack(auto& packer) const + { + packer.pack_map(1); + packer.pack(std::make_pair("stack", stack)); + } + + void msgpack_unpack(msgpack::object const& o) + { + auto name = "WitnessStack"; + auto kvmap = Helpers::make_kvmap(o, name); + Helpers::conv_fld_from_kvmap(kvmap, name, "stack", stack); + } }; } // end of namespace Witnesses From 0759002b408e7d4962746ab192f09081f9349ece Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 25 Mar 2025 14:42:21 +0000 Subject: [PATCH 29/36] Try copying into a buffer --- .../dsl/acir_format/acir_to_constraint_buf.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 4cf36bcf8e45..4054b10d0cd7 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -895,17 +895,27 @@ T deserialize_any_format(std::vector const& buf, // but until then a match could be pure coincidence. if (buf[0] == 2) { // Skip the format marker to get the data. - const char* buffer = &reinterpret_cast(buf.data())[1]; size_t size = buf.size() - 1; + + // This works by treating the byte vector as a char* + // const char* buffer = &reinterpret_cast(buf.data())[1]; + + // Or we can make a copy of it, which we delete when we're done. + char* buffer = new char[size]; + std::copy(buf.begin() + 1, buf.end(), buffer); + msgpack::null_visitor probe; if (msgpack::parse(buffer, size, probe)) { auto o = msgpack::unpack(buffer, size).get(); // In experiments bincode data was parsed as 0. // All the top level formats we look for are MAP types. if (o.type == msgpack::type::MAP) { - return decode_msgpack(o); + auto v = decode_msgpack(o); + delete[] buffer; + return v; } } + delete[] buffer; } // `buf[0] == 0` would indicate bincode starting with a format byte, // but if it's a coincidence and it fails to parse then we can't recover From f8f04739a5d0f6188c4806ebc92f1c5e339d9185 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 25 Mar 2025 14:42:28 +0000 Subject: [PATCH 30/36] Revert "Try copying into a buffer" This reverts commit 0759002b408e7d4962746ab192f09081f9349ece. --- .../dsl/acir_format/acir_to_constraint_buf.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 4054b10d0cd7..4cf36bcf8e45 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -895,27 +895,17 @@ T deserialize_any_format(std::vector const& buf, // but until then a match could be pure coincidence. if (buf[0] == 2) { // Skip the format marker to get the data. + const char* buffer = &reinterpret_cast(buf.data())[1]; size_t size = buf.size() - 1; - - // This works by treating the byte vector as a char* - // const char* buffer = &reinterpret_cast(buf.data())[1]; - - // Or we can make a copy of it, which we delete when we're done. - char* buffer = new char[size]; - std::copy(buf.begin() + 1, buf.end(), buffer); - msgpack::null_visitor probe; if (msgpack::parse(buffer, size, probe)) { auto o = msgpack::unpack(buffer, size).get(); // In experiments bincode data was parsed as 0. // All the top level formats we look for are MAP types. if (o.type == msgpack::type::MAP) { - auto v = decode_msgpack(o); - delete[] buffer; - return v; + return decode_msgpack(o); } } - delete[] buffer; } // `buf[0] == 0` would indicate bincode starting with a format byte, // but if it's a coincidence and it fails to parse then we can't recover From aba2338b5fbd39ff39c662f0b0c445572847f605 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 25 Mar 2025 15:14:40 +0000 Subject: [PATCH 31/36] Print field that can't be decoded --- barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp | 1 + .../cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index e6c76f5c0ac0..e9a41cdffee0 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -35,6 +35,7 @@ struct Helpers { try { it->second->convert(field); } catch (const msgpack::type_error&) { + std::cerr << *it->second << std::endl; throw_or_abort("error converting into field " + struct_name + "::" + field_name); } } else { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp index 8230ddf21f41..2e7d5d8923bc 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp @@ -35,6 +35,7 @@ struct Helpers { try { it->second->convert(field); } catch (const msgpack::type_error&) { + std::cerr << *it->second << std::endl; throw_or_abort("error converting into field " + struct_name + "::" + field_name); } } else { From 5810e3b5120c09fbe9887461f4b4fa56332c1b7d Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 25 Mar 2025 20:35:21 +0000 Subject: [PATCH 32/36] Fix dangling obj pointer --- .../barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 4cf36bcf8e45..822035d45de4 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -899,7 +899,10 @@ T deserialize_any_format(std::vector const& buf, size_t size = buf.size() - 1; msgpack::null_visitor probe; if (msgpack::parse(buffer, size, probe)) { - auto o = msgpack::unpack(buffer, size).get(); + auto oh = msgpack::unpack(buffer, size); + // This has to be on a separate line, see + // https://github.com/msgpack/msgpack-c/issues/695#issuecomment-393035172 + auto o = oh.get(); // In experiments bincode data was parsed as 0. // All the top level formats we look for are MAP types. if (o.type == msgpack::type::MAP) { From 073a9d5fe13c7ff3854a4a1685e6a1a2027e9156 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Tue, 25 Mar 2025 20:37:00 +0000 Subject: [PATCH 33/36] Revert to original msgpack-c commit version --- barretenberg/cpp/cmake/msgpack.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/cmake/msgpack.cmake b/barretenberg/cpp/cmake/msgpack.cmake index 22b696c02858..22f2fd1a2eed 100644 --- a/barretenberg/cpp/cmake/msgpack.cmake +++ b/barretenberg/cpp/cmake/msgpack.cmake @@ -8,7 +8,7 @@ ExternalProject_Add( msgpack-c PREFIX ${MSGPACK_PREFIX} GIT_REPOSITORY "https://github.com/AztecProtocol/msgpack-c.git" - GIT_TAG 54e9865b84bbdc73cfbf8d1d437dbf769b64e386 + GIT_TAG 492d78fc4ea1f0a277433a64129cffd979f60070 CONFIGURE_COMMAND "" # No configure step BUILD_COMMAND "" # No build step INSTALL_COMMAND "" # No install step From d39ebcfcf60df00ed2a0f4f91fe464a0f4d8d8fc Mon Sep 17 00:00:00 2001 From: aakoshh Date: Wed, 26 Mar 2025 13:11:01 +0000 Subject: [PATCH 34/36] Add docs to warn about keeping a reference to the object_handle --- .../cpp/src/barretenberg/serialize/msgpack.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/serialize/msgpack.hpp b/barretenberg/cpp/src/barretenberg/serialize/msgpack.hpp index 2b31ac49994d..642affd82f17 100644 --- a/barretenberg/cpp/src/barretenberg/serialize/msgpack.hpp +++ b/barretenberg/cpp/src/barretenberg/serialize/msgpack.hpp @@ -90,6 +90,21 @@ e.g. unpacking ``` msgpack::unpack((const char*)encoded_data, encoded_data_size).get().convert(*value); ``` + +Note that `msgpack::unpack` returns a `msgpack::object_handle` which controls the lifetime +of the `msgpack::object` returned by `msgpack::object_handle::get`, so if you need access +to the object itself, do break up the above to keep a reference to the handle, for example: + +``` + msgpack::object_handle oh = msgpack::unpack((const char*)encoded_data, encoded_data_size); + msgpack::object o = oh.get(); + try { + o.convert(*value); + } catch (const msgpack::type_error&) { + std::cerr << "failed to unpack: " << o << std::endl; + throw; + } +``` */ #include "msgpack_impl/concepts.hpp" #include "msgpack_impl/name_value_pair_macro.hpp" From 3561f813d552187dc6de058c559b39a0d6f57688 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Thu, 27 Mar 2025 15:59:04 +0000 Subject: [PATCH 35/36] Move deserializers into the cpp --- .../acir_format/acir_to_constraint_buf.cpp | 184 ++++++++++-------- .../acir_format/acir_to_constraint_buf.hpp | 25 --- 2 files changed, 100 insertions(+), 109 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index 822035d45de4..9085db37ac6d 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -16,6 +16,106 @@ namespace acir_format { using namespace bb; +/** + * @brief Deserialize `buf` either based on the first byte interpreted as a + Noir serialization format byte, or falling back to `bincode` if + the format cannot be recognized. Currently only `msgpack` format + is expected, or the legacy `bincode` format. + * @note Due to the lack of exception handling available to us in Wasm we can't + * try `bincode` format and if it fails try `msgpack`; instead we have to + * make a decision and commit to it. + */ +template +T deserialize_any_format(std::vector const& buf, + std::function decode_msgpack, + std::function)> decode_binpack) +{ + // We can't rely on exceptions to try to deserialize binpack, falling back to + // msgpack if it fails, because exceptions are (or were) not supported in Wasm + // and they are turned off in arch.cmake. + // + // For now our other option is to check if the data is valid msgpack, + // which slows things down, but we can't tell if the first byte of + // the data accidentally matches one of our format values. + // + // Unfortunately this doesn't seem to work either: `msgpack::parse` + // returns true for a `bincode` encoded program, and we have to check + // whether the value parsed is plausible. + + if (buf.size() > 0) { + // Once we remove support for legacy bincode format, we should expect to always + // have a format marker corresponding to acir::serialization::Format::Msgpack, + // but until then a match could be pure coincidence. + if (buf[0] == 2) { + // Skip the format marker to get the data. + const char* buffer = &reinterpret_cast(buf.data())[1]; + size_t size = buf.size() - 1; + msgpack::null_visitor probe; + if (msgpack::parse(buffer, size, probe)) { + auto oh = msgpack::unpack(buffer, size); + // This has to be on a separate line, see + // https://github.com/msgpack/msgpack-c/issues/695#issuecomment-393035172 + auto o = oh.get(); + // In experiments bincode data was parsed as 0. + // All the top level formats we look for are MAP types. + if (o.type == msgpack::type::MAP) { + return decode_msgpack(o); + } + } + } + // `buf[0] == 0` would indicate bincode starting with a format byte, + // but if it's a coincidence and it fails to parse then we can't recover + // from it, so let's just acknowledge that for now we don't want to + // exercise this code path and treat the whole data as bincode. + } + return decode_binpack(buf); +} + +/** + * @brief Deserializes a `Program` from bytes, trying `msgpack` or `bincode` formats. + * @note Ignores the Brillig parts of the bytecode when using `msgpack`. + */ +Acir::Program deserialize_program(std::vector const& buf) +{ + return deserialize_any_format( + buf, + [](auto o) -> Acir::Program { + Acir::Program program; + try { + // Deserialize into a partial structure that ignores the Brillig parts, + // so that new opcodes can be added without breaking Barretenberg. + Acir::ProgramWithoutBrillig program_wob; + o.convert(program_wob); + program.functions = program_wob.functions; + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("failed to convert msgpack data to Program"); + } + return program; + }, + &Acir::Program::bincodeDeserialize); +} + +/** + * @brief Deserializes a `WitnessStack` from bytes, trying `msgpack` or `bincode` formats. + */ +Witnesses::WitnessStack deserialize_witness_stack(std::vector const& buf) +{ + return deserialize_any_format( + buf, + [](auto o) { + Witnesses::WitnessStack witness_stack; + try { + o.convert(witness_stack); + } catch (const msgpack::type_error&) { + std::cerr << o << std::endl; + throw_or_abort("failed to convert msgpack data to WitnessStack"); + } + return witness_stack; + }, + &Witnesses::WitnessStack::bincodeDeserialize); +} + /** * @brief Construct a poly_tuple for a standard width-3 arithmetic gate from its acir representation * @@ -872,90 +972,6 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) return witness_map_to_witness_vector(w); } -template -T deserialize_any_format(std::vector const& buf, - std::function decode_msgpack, - std::function)> decode_binpack) -{ - // We can't rely on exceptions to try to deserialize binpack, falling back to - // msgpack if it fails, because exceptions are (or were) not supported in Wasm - // and they are turned off in arch.cmake. - // - // For now our other option is to check if the data is valid msgpack, - // which slows things down, but we can't tell if the first byte of - // the data accidentally matches one of our format values. - // - // Unfortunately this doesn't seem to work either: `msgpack::parse` - // returns true for a `bincode` encoded program, and we have to check - // whether the value parsed is plausible. - - if (buf.size() > 0) { - // Once we remove support for legacy bincode format, we should expect to always - // have a format marker corresponding to acir::serialization::Format::Msgpack, - // but until then a match could be pure coincidence. - if (buf[0] == 2) { - // Skip the format marker to get the data. - const char* buffer = &reinterpret_cast(buf.data())[1]; - size_t size = buf.size() - 1; - msgpack::null_visitor probe; - if (msgpack::parse(buffer, size, probe)) { - auto oh = msgpack::unpack(buffer, size); - // This has to be on a separate line, see - // https://github.com/msgpack/msgpack-c/issues/695#issuecomment-393035172 - auto o = oh.get(); - // In experiments bincode data was parsed as 0. - // All the top level formats we look for are MAP types. - if (o.type == msgpack::type::MAP) { - return decode_msgpack(o); - } - } - } - // `buf[0] == 0` would indicate bincode starting with a format byte, - // but if it's a coincidence and it fails to parse then we can't recover - // from it, so let's just acknowledge that for now we don't want to - // exercise this code path and treat the whole data as bincode. - } - return decode_binpack(buf); -} - -Acir::Program deserialize_program(std::vector const& buf) -{ - return deserialize_any_format( - buf, - [](auto o) -> Acir::Program { - Acir::Program program; - try { - // Deserialize into a partial structure that ignores the Brillig parts, - // so that new opcodes can be added without breaking Barretenberg. - Acir::ProgramWithoutBrillig program_wob; - o.convert(program_wob); - program.functions = program_wob.functions; - } catch (const msgpack::type_error&) { - std::cerr << o << std::endl; - throw_or_abort("failed to convert msgpack data to Program"); - } - return program; - }, - &Acir::Program::bincodeDeserialize); -} - -Witnesses::WitnessStack deserialize_witness_stack(std::vector const& buf) -{ - return deserialize_any_format( - buf, - [](auto o) { - Witnesses::WitnessStack witness_stack; - try { - o.convert(witness_stack); - } catch (const msgpack::type_error&) { - std::cerr << o << std::endl; - throw_or_abort("failed to convert msgpack data to WitnessStack"); - } - return witness_stack; - }, - &Witnesses::WitnessStack::bincodeDeserialize); -} - std::vector program_buf_to_acir_format(std::vector const& buf, uint32_t honk_recursion) { auto program = deserialize_program(buf); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp index a98fc1d626a2..383547ce6a20 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.hpp @@ -4,31 +4,6 @@ namespace acir_format { -/** - * @brief Deserialize `buf` either based on the first byte interpreted as a - Noir serialization format byte, or falling back to `bincode` if - the format cannot be recognized. Currently only `msgpack` format - is expected, or the legacy `bincode` format. - * @note Due to the lack of exception handling available to us in Wasm we can't - * try `bincode` format and if it fails try `msgpack`; instead we have to - * make a decision and commit to it. - */ -template -T deserialize_any_format(std::vector const& buf, - std::function decode_msgpack, - std::function)> decode_binpack); - -/** - * @brief Deserializes a `Program` from bytes, trying `msgpack` or `bincode` formats. - * @note Ignores the Brillig parts of the bytecode when using `msgpack`. - */ -Acir::Program deserialize_program(std::vector const& buf); - -/** - * @brief Deserializes a `WitnessStack` from bytes, trying `msgpack` or `bincode` formats. - */ -Witnesses::WitnessStack deserialize_witness_stack(std::vector const& buf); - /** * @brief Converts from the ACIR-native `WitnessStack` format to Barretenberg's internal `WitnessVector` format. * From 44d05fd87138cf234935cf84be77707810a96d41 Mon Sep 17 00:00:00 2001 From: aakoshh Date: Thu, 27 Mar 2025 16:09:05 +0000 Subject: [PATCH 36/36] Use MSGPACK_FIELDS. Remove Helpers. --- .../dsl/acir_format/serde/acir.hpp | 1272 +---------------- .../dsl/acir_format/serde/witness_stack.hpp | 69 +- 2 files changed, 81 insertions(+), 1260 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index e9a41cdffee0..64e761c25684 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -4,47 +4,6 @@ #include "msgpack.hpp" #include "serde.hpp" -namespace Acir { -struct Helpers { - static std::map make_kvmap(msgpack::object const& o, std::string name) - { - if (o.type != msgpack::type::MAP) { - std::cerr << o << std::endl; - throw_or_abort("expected MAP for " + name); - } - std::map kvmap; - for (uint32_t i = 0; i < o.via.map.size; ++i) { - if (o.via.map.ptr[i].key.type != msgpack::type::STR) { - std::cerr << o << std::endl; - throw_or_abort("expected STR for keys of " + name); - } - kvmap.emplace(std::string(o.via.map.ptr[i].key.via.str.ptr, o.via.map.ptr[i].key.via.str.size), - &o.via.map.ptr[i].val); - } - return kvmap; - } - - template - static void conv_fld_from_kvmap(std::map const& kvmap, - std::string struct_name, - std::string field_name, - T& field) - { - auto it = kvmap.find(field_name); - if (it != kvmap.end()) { - try { - it->second->convert(field); - } catch (const msgpack::type_error&) { - std::cerr << *it->second << std::endl; - throw_or_abort("error converting into field " + struct_name + "::" + field_name); - } - } else { - throw_or_abort("missing field: " + struct_name + "::" + field_name); - } - } -}; -} // namespace Acir - namespace Acir { struct BinaryFieldOp { @@ -879,20 +838,7 @@ struct HeapArray { std::vector bincodeSerialize() const; static HeapArray bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("pointer", pointer)); - packer.pack(std::make_pair("size", size)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "HeapArray"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "pointer", pointer); - Helpers::conv_fld_from_kvmap(kvmap, name, "size", size); - } + MSGPACK_FIELDS(pointer, size); }; struct HeapVector { @@ -903,20 +849,7 @@ struct HeapVector { std::vector bincodeSerialize() const; static HeapVector bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("pointer", pointer)); - packer.pack(std::make_pair("size", size)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "HeapVector"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "pointer", pointer); - Helpers::conv_fld_from_kvmap(kvmap, name, "size", size); - } + MSGPACK_FIELDS(pointer, size); }; struct BlackBoxOp { @@ -931,24 +864,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static AES128Encrypt bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(4); - packer.pack(std::make_pair("inputs", inputs)); - packer.pack(std::make_pair("iv", iv)); - packer.pack(std::make_pair("key", key)); - packer.pack(std::make_pair("outputs", outputs)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "AES128Encrypt"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "iv", iv); - Helpers::conv_fld_from_kvmap(kvmap, name, "key", key); - Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); - } + MSGPACK_FIELDS(inputs, iv, key, outputs); }; struct Blake2s { @@ -959,20 +875,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static Blake2s bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("message", message)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Blake2s"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "message", message); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(message, output); }; struct Blake3 { @@ -983,20 +886,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static Blake3 bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("message", message)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Blake3"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "message", message); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(message, output); }; struct Keccakf1600 { @@ -1007,20 +897,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static Keccakf1600 bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("input", input)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Keccakf1600"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(input, output); }; struct EcdsaSecp256k1 { @@ -1034,26 +911,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static EcdsaSecp256k1 bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(5); - packer.pack(std::make_pair("hashed_msg", hashed_msg)); - packer.pack(std::make_pair("public_key_x", public_key_x)); - packer.pack(std::make_pair("public_key_y", public_key_y)); - packer.pack(std::make_pair("signature", signature)); - packer.pack(std::make_pair("result", result)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "EcdsaSecp256k1"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "hashed_msg", hashed_msg); - Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_x", public_key_x); - Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_y", public_key_y); - Helpers::conv_fld_from_kvmap(kvmap, name, "signature", signature); - Helpers::conv_fld_from_kvmap(kvmap, name, "result", result); - } + MSGPACK_FIELDS(hashed_msg, public_key_x, public_key_y, signature, result); }; struct EcdsaSecp256r1 { @@ -1067,26 +925,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static EcdsaSecp256r1 bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(5); - packer.pack(std::make_pair("hashed_msg", hashed_msg)); - packer.pack(std::make_pair("public_key_x", public_key_x)); - packer.pack(std::make_pair("public_key_y", public_key_y)); - packer.pack(std::make_pair("signature", signature)); - packer.pack(std::make_pair("result", result)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "EcdsaSecp256r1"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "hashed_msg", hashed_msg); - Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_x", public_key_x); - Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_y", public_key_y); - Helpers::conv_fld_from_kvmap(kvmap, name, "signature", signature); - Helpers::conv_fld_from_kvmap(kvmap, name, "result", result); - } + MSGPACK_FIELDS(hashed_msg, public_key_x, public_key_y, signature, result); }; struct MultiScalarMul { @@ -1098,22 +937,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static MultiScalarMul bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("points", points)); - packer.pack(std::make_pair("scalars", scalars)); - packer.pack(std::make_pair("outputs", outputs)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "MultiScalarMul"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "points", points); - Helpers::conv_fld_from_kvmap(kvmap, name, "scalars", scalars); - Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); - } + MSGPACK_FIELDS(points, scalars, outputs); }; struct EmbeddedCurveAdd { @@ -1129,30 +953,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static EmbeddedCurveAdd bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(7); - packer.pack(std::make_pair("input1_x", input1_x)); - packer.pack(std::make_pair("input1_y", input1_y)); - packer.pack(std::make_pair("input1_infinite", input1_infinite)); - packer.pack(std::make_pair("input2_x", input2_x)); - packer.pack(std::make_pair("input2_y", input2_y)); - packer.pack(std::make_pair("input2_infinite", input2_infinite)); - packer.pack(std::make_pair("result", result)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "EmbeddedCurveAdd"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "input1_x", input1_x); - Helpers::conv_fld_from_kvmap(kvmap, name, "input1_y", input1_y); - Helpers::conv_fld_from_kvmap(kvmap, name, "input1_infinite", input1_infinite); - Helpers::conv_fld_from_kvmap(kvmap, name, "input2_x", input2_x); - Helpers::conv_fld_from_kvmap(kvmap, name, "input2_y", input2_y); - Helpers::conv_fld_from_kvmap(kvmap, name, "input2_infinite", input2_infinite); - Helpers::conv_fld_from_kvmap(kvmap, name, "result", result); - } + MSGPACK_FIELDS(input1_x, input1_y, input1_infinite, input2_x, input2_y, input2_infinite, result); }; struct BigIntAdd { @@ -1164,22 +965,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static BigIntAdd bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("lhs", lhs)); - packer.pack(std::make_pair("rhs", rhs)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BigIntAdd"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntSub { @@ -1191,22 +977,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static BigIntSub bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("lhs", lhs)); - packer.pack(std::make_pair("rhs", rhs)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BigIntSub"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntMul { @@ -1218,22 +989,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static BigIntMul bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("lhs", lhs)); - packer.pack(std::make_pair("rhs", rhs)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BigIntMul"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntDiv { @@ -1245,22 +1001,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static BigIntDiv bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("lhs", lhs)); - packer.pack(std::make_pair("rhs", rhs)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BigIntDiv"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntFromLeBytes { @@ -1272,22 +1013,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static BigIntFromLeBytes bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("inputs", inputs)); - packer.pack(std::make_pair("modulus", modulus)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BigIntFromLeBytes"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "modulus", modulus); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(inputs, modulus, output); }; struct BigIntToLeBytes { @@ -1298,20 +1024,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static BigIntToLeBytes bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("input", input)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BigIntToLeBytes"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(input, output); }; struct Poseidon2Permutation { @@ -1323,22 +1036,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static Poseidon2Permutation bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("message", message)); - packer.pack(std::make_pair("output", output)); - packer.pack(std::make_pair("len", len)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Poseidon2Permutation"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "message", message); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - Helpers::conv_fld_from_kvmap(kvmap, name, "len", len); - } + MSGPACK_FIELDS(message, output, len); }; struct Sha256Compression { @@ -1350,22 +1048,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static Sha256Compression bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("input", input)); - packer.pack(std::make_pair("hash_values", hash_values)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Sha256Compression"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); - Helpers::conv_fld_from_kvmap(kvmap, name, "hash_values", hash_values); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(input, hash_values, output); }; struct ToRadix { @@ -1379,26 +1062,7 @@ struct BlackBoxOp { std::vector bincodeSerialize() const; static ToRadix bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(5); - packer.pack(std::make_pair("input", input)); - packer.pack(std::make_pair("radix", radix)); - packer.pack(std::make_pair("output_pointer", output_pointer)); - packer.pack(std::make_pair("num_limbs", num_limbs)); - packer.pack(std::make_pair("output_bits", output_bits)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "ToRadix"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); - Helpers::conv_fld_from_kvmap(kvmap, name, "radix", radix); - Helpers::conv_fld_from_kvmap(kvmap, name, "output_pointer", output_pointer); - Helpers::conv_fld_from_kvmap(kvmap, name, "num_limbs", num_limbs); - Helpers::conv_fld_from_kvmap(kvmap, name, "output_bits", output_bits); - } + MSGPACK_FIELDS(input, radix, output_pointer, num_limbs, output_bits); }; std::variant bincodeSerialize() const; static Array bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("value_types", value_types)); - packer.pack(std::make_pair("size", size)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Array"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "value_types", value_types); - Helpers::conv_fld_from_kvmap(kvmap, name, "size", size); - } + MSGPACK_FIELDS(value_types, size); }; struct Vector { @@ -1767,18 +1418,7 @@ struct HeapValueType { std::vector bincodeSerialize() const; static Vector bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(1); - packer.pack(std::make_pair("value_types", value_types)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Vector"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "value_types", value_types); - } + MSGPACK_FIELDS(value_types); }; std::variant value; @@ -2051,24 +1691,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static BinaryFieldOp bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(4); - packer.pack(std::make_pair("destination", destination)); - packer.pack(std::make_pair("op", op)); - packer.pack(std::make_pair("lhs", lhs)); - packer.pack(std::make_pair("rhs", rhs)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BinaryFieldOp"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); - Helpers::conv_fld_from_kvmap(kvmap, name, "op", op); - Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); - } + MSGPACK_FIELDS(destination, op, lhs, rhs); }; struct BinaryIntOp { @@ -2082,26 +1705,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static BinaryIntOp bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(5); - packer.pack(std::make_pair("destination", destination)); - packer.pack(std::make_pair("op", op)); - packer.pack(std::make_pair("bit_size", bit_size)); - packer.pack(std::make_pair("lhs", lhs)); - packer.pack(std::make_pair("rhs", rhs)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BinaryIntOp"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); - Helpers::conv_fld_from_kvmap(kvmap, name, "op", op); - Helpers::conv_fld_from_kvmap(kvmap, name, "bit_size", bit_size); - Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); - } + MSGPACK_FIELDS(destination, op, bit_size, lhs, rhs); }; struct Not { @@ -2113,22 +1717,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Not bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("destination", destination)); - packer.pack(std::make_pair("source", source)); - packer.pack(std::make_pair("bit_size", bit_size)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Not"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); - Helpers::conv_fld_from_kvmap(kvmap, name, "source", source); - Helpers::conv_fld_from_kvmap(kvmap, name, "bit_size", bit_size); - } + MSGPACK_FIELDS(destination, source, bit_size); }; struct Cast { @@ -2140,22 +1729,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Cast bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("destination", destination)); - packer.pack(std::make_pair("source", source)); - packer.pack(std::make_pair("bit_size", bit_size)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Cast"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); - Helpers::conv_fld_from_kvmap(kvmap, name, "source", source); - Helpers::conv_fld_from_kvmap(kvmap, name, "bit_size", bit_size); - } + MSGPACK_FIELDS(destination, source, bit_size); }; struct JumpIfNot { @@ -2166,20 +1740,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static JumpIfNot bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("condition", condition)); - packer.pack(std::make_pair("location", location)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "JumpIfNot"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "condition", condition); - Helpers::conv_fld_from_kvmap(kvmap, name, "location", location); - } + MSGPACK_FIELDS(condition, location); }; struct JumpIf { @@ -2190,20 +1751,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static JumpIf bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("condition", condition)); - packer.pack(std::make_pair("location", location)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "JumpIf"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "condition", condition); - Helpers::conv_fld_from_kvmap(kvmap, name, "location", location); - } + MSGPACK_FIELDS(condition, location); }; struct Jump { @@ -2213,18 +1761,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Jump bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(1); - packer.pack(std::make_pair("location", location)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Jump"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "location", location); - } + MSGPACK_FIELDS(location); }; struct CalldataCopy { @@ -2236,22 +1773,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static CalldataCopy bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("destination_address", destination_address)); - packer.pack(std::make_pair("size_address", size_address)); - packer.pack(std::make_pair("offset_address", offset_address)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "CalldataCopy"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "destination_address", destination_address); - Helpers::conv_fld_from_kvmap(kvmap, name, "size_address", size_address); - Helpers::conv_fld_from_kvmap(kvmap, name, "offset_address", offset_address); - } + MSGPACK_FIELDS(destination_address, size_address, offset_address); }; struct Call { @@ -2261,18 +1783,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Call bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(1); - packer.pack(std::make_pair("location", location)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Call"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "location", location); - } + MSGPACK_FIELDS(location); }; struct Const { @@ -2284,22 +1795,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Const bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("destination", destination)); - packer.pack(std::make_pair("bit_size", bit_size)); - packer.pack(std::make_pair("value", value)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Const"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); - Helpers::conv_fld_from_kvmap(kvmap, name, "bit_size", bit_size); - Helpers::conv_fld_from_kvmap(kvmap, name, "value", value); - } + MSGPACK_FIELDS(destination, bit_size, value); }; struct IndirectConst { @@ -2311,22 +1807,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static IndirectConst bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("destination_pointer", destination_pointer)); - packer.pack(std::make_pair("bit_size", bit_size)); - packer.pack(std::make_pair("value", value)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "IndirectConst"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "destination_pointer", destination_pointer); - Helpers::conv_fld_from_kvmap(kvmap, name, "bit_size", bit_size); - Helpers::conv_fld_from_kvmap(kvmap, name, "value", value); - } + MSGPACK_FIELDS(destination_pointer, bit_size, value); }; struct Return { @@ -2349,26 +1830,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static ForeignCall bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(5); - packer.pack(std::make_pair("function", function)); - packer.pack(std::make_pair("destinations", destinations)); - packer.pack(std::make_pair("destination_value_types", destination_value_types)); - packer.pack(std::make_pair("inputs", inputs)); - packer.pack(std::make_pair("input_value_types", input_value_types)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "ForeignCall"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "function", function); - Helpers::conv_fld_from_kvmap(kvmap, name, "destinations", destinations); - Helpers::conv_fld_from_kvmap(kvmap, name, "destination_value_types", destination_value_types); - Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "input_value_types", input_value_types); - } + MSGPACK_FIELDS(function, destinations, destination_value_types, inputs, input_value_types); }; struct Mov { @@ -2379,20 +1841,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Mov bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("destination", destination)); - packer.pack(std::make_pair("source", source)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Mov"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); - Helpers::conv_fld_from_kvmap(kvmap, name, "source", source); - } + MSGPACK_FIELDS(destination, source); }; struct ConditionalMov { @@ -2405,24 +1854,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static ConditionalMov bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(4); - packer.pack(std::make_pair("destination", destination)); - packer.pack(std::make_pair("source_a", source_a)); - packer.pack(std::make_pair("source_b", source_b)); - packer.pack(std::make_pair("condition", condition)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "ConditionalMov"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); - Helpers::conv_fld_from_kvmap(kvmap, name, "source_a", source_a); - Helpers::conv_fld_from_kvmap(kvmap, name, "source_b", source_b); - Helpers::conv_fld_from_kvmap(kvmap, name, "condition", condition); - } + MSGPACK_FIELDS(destination, source_a, source_b, condition); }; struct Load { @@ -2433,20 +1865,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Load bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("destination", destination)); - packer.pack(std::make_pair("source_pointer", source_pointer)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Load"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "destination", destination); - Helpers::conv_fld_from_kvmap(kvmap, name, "source_pointer", source_pointer); - } + MSGPACK_FIELDS(destination, source_pointer); }; struct Store { @@ -2457,20 +1876,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Store bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("destination_pointer", destination_pointer)); - packer.pack(std::make_pair("source", source)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Store"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "destination_pointer", destination_pointer); - Helpers::conv_fld_from_kvmap(kvmap, name, "source", source); - } + MSGPACK_FIELDS(destination_pointer, source); }; struct BlackBox { @@ -2500,18 +1906,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Trap bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(1); - packer.pack(std::make_pair("revert_data", revert_data)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Trap"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "revert_data", revert_data); - } + MSGPACK_FIELDS(revert_data); }; struct Stop { @@ -2521,18 +1916,7 @@ struct BrilligOpcode { std::vector bincodeSerialize() const; static Stop bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(1); - packer.pack(std::make_pair("return_data", return_data)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Stop"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "return_data", return_data); - } + MSGPACK_FIELDS(return_data); }; std::variant bincodeSerialize() const; static FunctionInput bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("input", input)); - packer.pack(std::make_pair("num_bits", num_bits)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "FunctionInput"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); - Helpers::conv_fld_from_kvmap(kvmap, name, "num_bits", num_bits); - } + MSGPACK_FIELDS(input, num_bits); }; struct BlackBoxFuncCall { @@ -3066,24 +2437,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static AES128Encrypt bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(4); - packer.pack(std::make_pair("inputs", inputs)); - packer.pack(std::make_pair("iv", iv)); - packer.pack(std::make_pair("key", key)); - packer.pack(std::make_pair("outputs", outputs)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "AES128Encrypt"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "iv", iv); - Helpers::conv_fld_from_kvmap(kvmap, name, "key", key); - Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); - } + MSGPACK_FIELDS(inputs, iv, key, outputs); }; struct AND { @@ -3095,22 +2449,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static AND bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("lhs", lhs)); - packer.pack(std::make_pair("rhs", rhs)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "AND"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(lhs, rhs, output); }; struct XOR { @@ -3122,22 +2461,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static XOR bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("lhs", lhs)); - packer.pack(std::make_pair("rhs", rhs)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "XOR"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(lhs, rhs, output); }; struct RANGE { @@ -3147,18 +2471,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static RANGE bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(1); - packer.pack(std::make_pair("input", input)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "RANGE"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); - } + MSGPACK_FIELDS(input); }; struct Blake2s { @@ -3169,20 +2482,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static Blake2s bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("inputs", inputs)); - packer.pack(std::make_pair("outputs", outputs)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Blake2s"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); - } + MSGPACK_FIELDS(inputs, outputs); }; struct Blake3 { @@ -3193,20 +2493,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static Blake3 bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("inputs", inputs)); - packer.pack(std::make_pair("outputs", outputs)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Blake3"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); - } + MSGPACK_FIELDS(inputs, outputs); }; struct EcdsaSecp256k1 { @@ -3220,26 +2507,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static EcdsaSecp256k1 bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(5); - packer.pack(std::make_pair("public_key_x", public_key_x)); - packer.pack(std::make_pair("public_key_y", public_key_y)); - packer.pack(std::make_pair("signature", signature)); - packer.pack(std::make_pair("hashed_message", hashed_message)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "EcdsaSecp256k1"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_x", public_key_x); - Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_y", public_key_y); - Helpers::conv_fld_from_kvmap(kvmap, name, "signature", signature); - Helpers::conv_fld_from_kvmap(kvmap, name, "hashed_message", hashed_message); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(public_key_x, public_key_y, signature, hashed_message, output); }; struct EcdsaSecp256r1 { @@ -3253,26 +2521,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static EcdsaSecp256r1 bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(5); - packer.pack(std::make_pair("public_key_x", public_key_x)); - packer.pack(std::make_pair("public_key_y", public_key_y)); - packer.pack(std::make_pair("signature", signature)); - packer.pack(std::make_pair("hashed_message", hashed_message)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "EcdsaSecp256r1"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_x", public_key_x); - Helpers::conv_fld_from_kvmap(kvmap, name, "public_key_y", public_key_y); - Helpers::conv_fld_from_kvmap(kvmap, name, "signature", signature); - Helpers::conv_fld_from_kvmap(kvmap, name, "hashed_message", hashed_message); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(public_key_x, public_key_y, signature, hashed_message, output); }; struct MultiScalarMul { @@ -3284,22 +2533,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static MultiScalarMul bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("points", points)); - packer.pack(std::make_pair("scalars", scalars)); - packer.pack(std::make_pair("outputs", outputs)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "MultiScalarMul"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "points", points); - Helpers::conv_fld_from_kvmap(kvmap, name, "scalars", scalars); - Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); - } + MSGPACK_FIELDS(points, scalars, outputs); }; struct EmbeddedCurveAdd { @@ -3311,22 +2545,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static EmbeddedCurveAdd bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("input1", input1)); - packer.pack(std::make_pair("input2", input2)); - packer.pack(std::make_pair("outputs", outputs)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "EmbeddedCurveAdd"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "input1", input1); - Helpers::conv_fld_from_kvmap(kvmap, name, "input2", input2); - Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); - } + MSGPACK_FIELDS(input1, input2, outputs); }; struct Keccakf1600 { @@ -3337,20 +2556,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static Keccakf1600 bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("inputs", inputs)); - packer.pack(std::make_pair("outputs", outputs)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Keccakf1600"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); - } + MSGPACK_FIELDS(inputs, outputs); }; struct RecursiveAggregation { @@ -3364,26 +2570,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static RecursiveAggregation bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(5); - packer.pack(std::make_pair("verification_key", verification_key)); - packer.pack(std::make_pair("proof", proof)); - packer.pack(std::make_pair("public_inputs", public_inputs)); - packer.pack(std::make_pair("key_hash", key_hash)); - packer.pack(std::make_pair("proof_type", proof_type)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "RecursiveAggregation"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "verification_key", verification_key); - Helpers::conv_fld_from_kvmap(kvmap, name, "proof", proof); - Helpers::conv_fld_from_kvmap(kvmap, name, "public_inputs", public_inputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "key_hash", key_hash); - Helpers::conv_fld_from_kvmap(kvmap, name, "proof_type", proof_type); - } + MSGPACK_FIELDS(verification_key, proof, public_inputs, key_hash, proof_type); }; struct BigIntAdd { @@ -3395,22 +2582,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static BigIntAdd bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("lhs", lhs)); - packer.pack(std::make_pair("rhs", rhs)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BigIntAdd"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntSub { @@ -3422,22 +2594,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static BigIntSub bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("lhs", lhs)); - packer.pack(std::make_pair("rhs", rhs)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BigIntSub"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntMul { @@ -3449,22 +2606,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static BigIntMul bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("lhs", lhs)); - packer.pack(std::make_pair("rhs", rhs)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BigIntMul"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntDiv { @@ -3476,22 +2618,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static BigIntDiv bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("lhs", lhs)); - packer.pack(std::make_pair("rhs", rhs)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BigIntDiv"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "lhs", lhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "rhs", rhs); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(lhs, rhs, output); }; struct BigIntFromLeBytes { @@ -3503,22 +2630,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static BigIntFromLeBytes bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("inputs", inputs)); - packer.pack(std::make_pair("modulus", modulus)); - packer.pack(std::make_pair("output", output)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BigIntFromLeBytes"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "modulus", modulus); - Helpers::conv_fld_from_kvmap(kvmap, name, "output", output); - } + MSGPACK_FIELDS(inputs, modulus, output); }; struct BigIntToLeBytes { @@ -3529,20 +2641,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static BigIntToLeBytes bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("input", input)); - packer.pack(std::make_pair("outputs", outputs)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BigIntToLeBytes"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "input", input); - Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); - } + MSGPACK_FIELDS(input, outputs); }; struct Poseidon2Permutation { @@ -3554,22 +2653,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static Poseidon2Permutation bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("inputs", inputs)); - packer.pack(std::make_pair("outputs", outputs)); - packer.pack(std::make_pair("len", len)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Poseidon2Permutation"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "len", len); - } + MSGPACK_FIELDS(inputs, outputs, len); }; struct Sha256Compression { @@ -3581,22 +2665,7 @@ struct BlackBoxFuncCall { std::vector bincodeSerialize() const; static Sha256Compression bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("inputs", inputs)); - packer.pack(std::make_pair("hash_values", hash_values)); - packer.pack(std::make_pair("outputs", outputs)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Sha256Compression"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "hash_values", hash_values); - Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); - } + MSGPACK_FIELDS(inputs, hash_values, outputs); }; std::variant bincodeSerialize() const; static Expression bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("mul_terms", mul_terms)); - packer.pack(std::make_pair("linear_combinations", linear_combinations)); - packer.pack(std::make_pair("q_c", q_c)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Expression"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "mul_terms", mul_terms); - Helpers::conv_fld_from_kvmap(kvmap, name, "linear_combinations", linear_combinations); - Helpers::conv_fld_from_kvmap(kvmap, name, "q_c", q_c); - } + MSGPACK_FIELDS(mul_terms, linear_combinations, q_c); }; struct BrilligInputs { @@ -4421,22 +3475,7 @@ struct MemOp { std::vector bincodeSerialize() const; static MemOp bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("operation", operation)); - packer.pack(std::make_pair("index", index)); - packer.pack(std::make_pair("value", value)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "MemOp"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "operation", operation); - Helpers::conv_fld_from_kvmap(kvmap, name, "index", index); - Helpers::conv_fld_from_kvmap(kvmap, name, "value", value); - } + MSGPACK_FIELDS(operation, index, value); }; struct Opcode { @@ -4490,22 +3529,7 @@ struct Opcode { std::vector bincodeSerialize() const; static MemoryOp bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("block_id", block_id)); - packer.pack(std::make_pair("op", op)); - packer.pack(std::make_pair("predicate", predicate)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "MemoryOp"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "block_id", block_id); - Helpers::conv_fld_from_kvmap(kvmap, name, "op", op); - Helpers::conv_fld_from_kvmap(kvmap, name, "predicate", predicate); - } + MSGPACK_FIELDS(block_id, op, predicate); }; struct MemoryInit { @@ -4517,22 +3541,7 @@ struct Opcode { std::vector bincodeSerialize() const; static MemoryInit bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(3); - packer.pack(std::make_pair("block_id", block_id)); - packer.pack(std::make_pair("init", init)); - packer.pack(std::make_pair("block_type", block_type)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "MemoryInit"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "block_id", block_id); - Helpers::conv_fld_from_kvmap(kvmap, name, "init", init); - Helpers::conv_fld_from_kvmap(kvmap, name, "block_type", block_type); - } + MSGPACK_FIELDS(block_id, init, block_type); }; struct BrilligCall { @@ -4545,24 +3554,7 @@ struct Opcode { std::vector bincodeSerialize() const; static BrilligCall bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(4); - packer.pack(std::make_pair("id", id)); - packer.pack(std::make_pair("inputs", inputs)); - packer.pack(std::make_pair("outputs", outputs)); - packer.pack(std::make_pair("predicate", predicate)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BrilligCall"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "id", id); - Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "predicate", predicate); - } + MSGPACK_FIELDS(id, inputs, outputs, predicate); }; struct Call { @@ -4575,24 +3567,7 @@ struct Opcode { std::vector bincodeSerialize() const; static Call bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(4); - packer.pack(std::make_pair("id", id)); - packer.pack(std::make_pair("inputs", inputs)); - packer.pack(std::make_pair("outputs", outputs)); - packer.pack(std::make_pair("predicate", predicate)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Call"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "id", id); - Helpers::conv_fld_from_kvmap(kvmap, name, "inputs", inputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "outputs", outputs); - Helpers::conv_fld_from_kvmap(kvmap, name, "predicate", predicate); - } + MSGPACK_FIELDS(id, inputs, outputs, predicate); }; std::variant value; @@ -4869,20 +3844,7 @@ struct AssertionPayload { std::vector bincodeSerialize() const; static AssertionPayload bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("error_selector", error_selector)); - packer.pack(std::make_pair("payload", payload)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "AssertionPayload"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "error_selector", error_selector); - Helpers::conv_fld_from_kvmap(kvmap, name, "payload", payload); - } + MSGPACK_FIELDS(error_selector, payload); }; struct ExpressionWidth { @@ -4903,18 +3865,7 @@ struct ExpressionWidth { std::vector bincodeSerialize() const; static Bounded bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(1); - packer.pack(std::make_pair("width", width)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Bounded"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "width", width); - } + MSGPACK_FIELDS(width); }; std::variant value; @@ -5024,20 +3975,7 @@ struct OpcodeLocation { std::vector bincodeSerialize() const; static Brillig bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("acir_index", acir_index)); - packer.pack(std::make_pair("brillig_index", brillig_index)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Brillig"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "acir_index", acir_index); - Helpers::conv_fld_from_kvmap(kvmap, name, "brillig_index", brillig_index); - } + MSGPACK_FIELDS(acir_index, brillig_index); }; std::variant value; @@ -5157,30 +4095,13 @@ struct Circuit { std::vector bincodeSerialize() const; static Circuit bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(7); - packer.pack(std::make_pair("current_witness_index", current_witness_index)); - packer.pack(std::make_pair("opcodes", opcodes)); - packer.pack(std::make_pair("expression_width", expression_width)); - packer.pack(std::make_pair("private_parameters", private_parameters)); - packer.pack(std::make_pair("public_parameters", public_parameters)); - packer.pack(std::make_pair("return_values", return_values)); - packer.pack(std::make_pair("assert_messages", assert_messages)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Circuit"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "current_witness_index", current_witness_index); - Helpers::conv_fld_from_kvmap(kvmap, name, "opcodes", opcodes); - Helpers::conv_fld_from_kvmap(kvmap, name, "expression_width", expression_width); - Helpers::conv_fld_from_kvmap(kvmap, name, "private_parameters", private_parameters); - Helpers::conv_fld_from_kvmap(kvmap, name, "public_parameters", public_parameters); - Helpers::conv_fld_from_kvmap(kvmap, name, "return_values", return_values); - Helpers::conv_fld_from_kvmap(kvmap, name, "assert_messages", assert_messages); - } + MSGPACK_FIELDS(current_witness_index, + opcodes, + expression_width, + private_parameters, + public_parameters, + return_values, + assert_messages); }; struct BrilligBytecode { @@ -5190,18 +4111,7 @@ struct BrilligBytecode { std::vector bincodeSerialize() const; static BrilligBytecode bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(1); - packer.pack(std::make_pair("bytecode", bytecode)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "BrilligBytecode"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "bytecode", bytecode); - } + MSGPACK_FIELDS(bytecode); }; struct Program { @@ -5212,20 +4122,7 @@ struct Program { std::vector bincodeSerialize() const; static Program bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("functions", functions)); - packer.pack(std::make_pair("unconstrained_functions", unconstrained_functions)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "Program"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "functions", functions); - Helpers::conv_fld_from_kvmap(kvmap, name, "unconstrained_functions", unconstrained_functions); - } + MSGPACK_FIELDS(functions, unconstrained_functions); }; struct ProgramWithoutBrillig { @@ -5235,18 +4132,7 @@ struct ProgramWithoutBrillig { std::vector bincodeSerialize() const; static ProgramWithoutBrillig bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(1); - packer.pack(std::make_pair("functions", functions)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "ProgramWithoutBrillig"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "functions", functions); - } + MSGPACK_FIELDS(functions); }; } // end of namespace Acir diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp index 2e7d5d8923bc..9cf5d5b48269 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/witness_stack.hpp @@ -4,47 +4,6 @@ #include "msgpack.hpp" #include "serde.hpp" -namespace Witnesses { -struct Helpers { - static std::map make_kvmap(msgpack::object const& o, std::string name) - { - if (o.type != msgpack::type::MAP) { - std::cerr << o << std::endl; - throw_or_abort("expected MAP for " + name); - } - std::map kvmap; - for (uint32_t i = 0; i < o.via.map.size; ++i) { - if (o.via.map.ptr[i].key.type != msgpack::type::STR) { - std::cerr << o << std::endl; - throw_or_abort("expected STR for keys of " + name); - } - kvmap.emplace(std::string(o.via.map.ptr[i].key.via.str.ptr, o.via.map.ptr[i].key.via.str.size), - &o.via.map.ptr[i].val); - } - return kvmap; - } - - template - static void conv_fld_from_kvmap(std::map const& kvmap, - std::string struct_name, - std::string field_name, - T& field) - { - auto it = kvmap.find(field_name); - if (it != kvmap.end()) { - try { - it->second->convert(field); - } catch (const msgpack::type_error&) { - std::cerr << *it->second << std::endl; - throw_or_abort("error converting into field " + struct_name + "::" + field_name); - } - } else { - throw_or_abort("missing field: " + struct_name + "::" + field_name); - } - } -}; -} // namespace Witnesses - namespace Witnesses { struct Witness { @@ -96,20 +55,7 @@ struct StackItem { std::vector bincodeSerialize() const; static StackItem bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(2); - packer.pack(std::make_pair("index", index)); - packer.pack(std::make_pair("witness", witness)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "StackItem"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "index", index); - Helpers::conv_fld_from_kvmap(kvmap, name, "witness", witness); - } + MSGPACK_FIELDS(index, witness); }; struct WitnessStack { @@ -119,18 +65,7 @@ struct WitnessStack { std::vector bincodeSerialize() const; static WitnessStack bincodeDeserialize(std::vector); - void msgpack_pack(auto& packer) const - { - packer.pack_map(1); - packer.pack(std::make_pair("stack", stack)); - } - - void msgpack_unpack(msgpack::object const& o) - { - auto name = "WitnessStack"; - auto kvmap = Helpers::make_kvmap(o, name); - Helpers::conv_fld_from_kvmap(kvmap, name, "stack", stack); - } + MSGPACK_FIELDS(stack); }; } // end of namespace Witnesses