diff --git a/barretenberg/cpp/CMakeLists.txt b/barretenberg/cpp/CMakeLists.txt index 6554d94836c..61790ddc4da 100644 --- a/barretenberg/cpp/CMakeLists.txt +++ b/barretenberg/cpp/CMakeLists.txt @@ -19,7 +19,6 @@ option(BENCHMARKS "Build benchmarks" ON) option(FUZZING "Build fuzzing harnesses" OFF) option(DISABLE_TBB "Intel Thread Building Blocks" ON) option(COVERAGE "Enable collecting coverage from tests" OFF) -option(SERIALIZE_CANARY "Build with serialize canary" OFF) option(ENABLE_ASAN "Address sanitizer for debugging tricky memory corruption" OFF) option(ENABLE_HEAVY_TESTS "Enable heavy tests when collecting coverage" OFF) option(INSTALL_BARRETENBERG "Enable installation of barretenberg. (Projects embedding barretenberg may want to turn this OFF.)" ON) @@ -40,10 +39,6 @@ if(ENABLE_ASAN) set(DISABLE_ASM ON) endif() -if(SERIALIZE_CANARY) - add_definitions(-DENABLE_SERIALIZE_CANARY) -endif() - if(FUZZING) add_definitions(-DFUZZING=1) diff --git a/barretenberg/cpp/src/barretenberg/common/serialize.hpp b/barretenberg/cpp/src/barretenberg/common/serialize.hpp index 3d50f6b3f48..08e1db78bf0 100644 --- a/barretenberg/cpp/src/barretenberg/common/serialize.hpp +++ b/barretenberg/cpp/src/barretenberg/common/serialize.hpp @@ -30,10 +30,12 @@ #pragma once #include "barretenberg/common/log.hpp" #include "barretenberg/common/net.hpp" +#include "barretenberg/serialize/msgpack_apply.hpp" #include #include #include #include +#include #include #include #include @@ -42,7 +44,14 @@ __extension__ using uint128_t = unsigned __int128; #endif +template +concept IntegralOrEnum = std::integral || std::is_enum_v; + namespace serialize { +// Forward declare derived msgpack methods +void read(auto& it, msgpack_concepts::HasMsgPack auto& obj); +void write(auto& buf, const msgpack_concepts::HasMsgPack auto& obj); + // Basic integer read / write, to / from raw buffers. // Pointers to buffers are advanced by length of type. inline void read(uint8_t const*& it, uint8_t& value) @@ -123,74 +132,51 @@ inline void write(uint8_t*& it, uint128_t value) #endif // Reading / writing integer types to / from vectors. -template inline std::enable_if_t> read(std::vector const& buf, T& value) +void read(std::vector const& buf, std::integral auto& value) { auto ptr = &buf[0]; read(ptr, value); } -template inline std::enable_if_t> write(std::vector& buf, T value) +void write(std::vector& buf, const std::integral auto& value) { - buf.resize(buf.size() + sizeof(T)); - uint8_t* ptr = &*buf.end() - sizeof(T); + buf.resize(buf.size() + sizeof(value)); + uint8_t* ptr = &*buf.end() - sizeof(value); write(ptr, value); } // Reading writing integer types to / from streams. -template inline std::enable_if_t> read(std::istream& is, T& value) +void read(std::istream& is, std::integral auto& value) { - std::array buf; - is.read((char*)buf.data(), sizeof(T)); + std::array buf; + is.read((char*)buf.data(), sizeof(value)); uint8_t const* ptr = &buf[0]; read(ptr, value); } -template inline std::enable_if_t> write(std::ostream& os, T value) +void write(std::ostream& os, const std::integral auto& value) { - std::array buf; + std::array buf; uint8_t* ptr = &buf[0]; write(ptr, value); - os.write((char*)buf.data(), sizeof(T)); -} - -// DEBUG_CANARY_READ and DEBUG_CANARY_WRITE write strings during debug testing -// so that we can detect serialization misalignment for more complicated types. -// This is in an awkward location as it must see the above functions, and be seen by the below functions. -#ifndef ENABLE_SERIALIZE_CANARY -#define DEBUG_CANARY_WRITE(buf, x) -#define DEBUG_CANARY_READ(it, x) -#else -#define DEBUG_CANARY_WRITE(buf, x) serialize::write(buf, (uint64_t) typeid(x).hash_code()) -#define DEBUG_CANARY_READ(it, x) \ - { \ - uint64_t hash_code; \ - serialize::read(it, hash_code); \ - if (hash_code != (uint64_t) typeid(x).hash_code()) { \ - throw std::runtime_error(std::string("Could not read magic string for ") + typeid(x).name()); \ - } \ - } -#endif + os.write((char*)buf.data(), sizeof(value)); +} } // namespace serialize namespace std { - -// Forwarding functions from std to serialize namespace for integers. -template inline std::enable_if_t> read(B& buf, T& value) +inline void read(auto& buf, std::integral auto& value) { - DEBUG_CANARY_READ(buf, value); serialize::read(buf, value); } -template inline std::enable_if_t> write(B& buf, T value) +inline void write(auto& buf, std::integral auto value) { - DEBUG_CANARY_WRITE(buf, value); serialize::write(buf, value); } // Optimised specialisation for reading arrays of bytes from a raw buffer. template inline void read(uint8_t const*& it, std::array& value) { - DEBUG_CANARY_READ(it, value); std::copy(it, it + N, value.data()); it += N; } @@ -198,7 +184,6 @@ template inline void read(uint8_t const*& it, std::array& // Optimised specialisation for writing arrays of bytes to a raw buffer. template inline void write(uint8_t*& buf, std::array const& value) { - DEBUG_CANARY_WRITE(buf, value); std::copy(value.begin(), value.end(), buf); buf += N; } @@ -206,7 +191,6 @@ template inline void write(uint8_t*& buf, std::array cons // Optimised specialisation for reading vectors of bytes from a raw buffer. inline void read(uint8_t const*& it, std::vector& value) { - DEBUG_CANARY_READ(it, value); uint32_t size; read(it, size); value.resize(size); @@ -217,7 +201,6 @@ inline void read(uint8_t const*& it, std::vector& value) // Optimised specialisation for writing vectors of bytes to a raw buffer. inline void write(uint8_t*& buf, std::vector const& value) { - DEBUG_CANARY_WRITE(buf, value); write(buf, static_cast(value.size())); std::copy(value.begin(), value.end(), buf); buf += value.size(); @@ -226,7 +209,6 @@ inline void write(uint8_t*& buf, std::vector const& value) // Optimised specialisation for reading vectors of bytes from an input stream. inline void read(std::istream& is, std::vector& value) { - DEBUG_CANARY_READ(is, value); uint32_t size; read(is, size); value.resize(size); @@ -236,7 +218,6 @@ inline void read(std::istream& is, std::vector& value) // Optimised specialisation for writing vectors of bytes to an output stream. inline void write(std::ostream& os, std::vector const& value) { - DEBUG_CANARY_WRITE(os, value); write(os, static_cast(value.size())); os.write((char*)value.data(), (std::streamsize)value.size()); } @@ -244,7 +225,6 @@ inline void write(std::ostream& os, std::vector const& value) // Optimised specialisation for writing arrays of bytes to a vector. template inline void write(std::vector& buf, std::array const& value) { - DEBUG_CANARY_WRITE(buf, value); buf.resize(buf.size() + N); auto ptr = &*buf.end() - N; write(ptr, value); @@ -253,14 +233,13 @@ template inline void write(std::vector& buf, std::array inline void write(std::ostream& os, std::array const& value) { - DEBUG_CANARY_WRITE(os, value); os.write((char*)value.data(), value.size()); } // Generic read of array of types from supported buffer types. template inline void read(B& it, std::array& value) { - DEBUG_CANARY_READ(it, value); + using serialize::read; for (size_t i = 0; i < N; ++i) { read(it, value[i]); } @@ -269,7 +248,7 @@ template inline void read(B& it, std::array inline void write(B& buf, std::array const& value) { - DEBUG_CANARY_WRITE(buf, value); + using serialize::write; for (size_t i = 0; i < N; ++i) { write(buf, value[i]); } @@ -278,7 +257,7 @@ template inline void write(B& buf, std::array // Generic read of vector of types from supported buffer types. template inline void read(B& it, std::vector& value) { - DEBUG_CANARY_READ(it, value); + using serialize::read; uint32_t size; read(it, size); value.resize(size); @@ -290,6 +269,7 @@ template inline void read(B& it, std::vecto // Generic write of vector of types to supported buffer types. template inline void write(B& buf, std::vector const& value) { + using serialize::write; write(buf, static_cast(value.size())); for (size_t i = 0; i < value.size(); ++i) { write(buf, value[i]); @@ -299,7 +279,7 @@ template inline void write(B& buf, std::vec // Read string from supported buffer types. template inline void read(B& it, std::string& value) { - DEBUG_CANARY_READ(it, value); + using serialize::read; std::vector buf; read(it, buf); value = std::string(buf.begin(), buf.end()); @@ -308,13 +288,14 @@ template inline void read(B& it, std::string& value) // Write of strings to supported buffer types. template inline void write(B& buf, std::string const& value) { + using serialize::write; write(buf, std::vector(value.begin(), value.end())); } // Read std::pair. template inline void read(B& it, std::pair& value) { - DEBUG_CANARY_READ(it, value); + using serialize::read; read(it, value.first); read(it, value.second); } @@ -322,15 +303,31 @@ template inline void read(B& it, std::pair< // Write std::pair. template inline void write(B& buf, std::pair const& value) { - DEBUG_CANARY_WRITE(buf, value); + using serialize::write; write(buf, value.first); write(buf, value.second); } +// Read std::shared_ptr. +template inline void read(B& it, std::shared_ptr& value_ptr) +{ + using serialize::read; + T value; + read(it, value); + *value_ptr = std::make_shared(value); +} + +// Write std::shared_ptr. +template inline void write(B& buf, std::shared_ptr const& value_ptr) +{ + using serialize::write; + write(buf, *value_ptr); +} + // Read std::map template inline void read(B& it, std::map& value) { - DEBUG_CANARY_READ(it, value); + using serialize::read; value.clear(); uint32_t size; read(it, size); @@ -344,7 +341,7 @@ template inline void read(B& it, std::map inline void write(B& buf, std::map const& value) { - DEBUG_CANARY_WRITE(buf, value); + using serialize::write; write(buf, static_cast(value.size())); for (auto const& kv : value) { write(buf, kv); @@ -354,7 +351,7 @@ template inline void write(B& buf, std::map // Read std::optional. template inline void read(B& it, std::optional& opt_value) { - DEBUG_CANARY_READ(it, opt_value); + using serialize::read; bool is_nullopt; read(it, is_nullopt); if (is_nullopt) { @@ -371,7 +368,7 @@ template inline void read(B& it, std::optional& opt_ // value. template inline void write(B& buf, std::optional const& opt_value) { - DEBUG_CANARY_WRITE(buf, opt_value); + using serialize::write; if (opt_value) { write(buf, false); // is not nullopt write(buf, *opt_value); @@ -449,4 +446,53 @@ using out_str_buf = uint8_t**; // Use these to pass a raw memory pointer. using in_ptr = void* const*; -using out_ptr = void**; \ No newline at end of file +using out_ptr = void**; + +namespace serialize { + +/** + * @brief Helper method for better error reporting. Clang does not give the best errors for "auto..." + * arguments. + */ +inline void _read_msgpack_field(auto& it, auto& field) +{ + using namespace serialize; + read(it, field); +} + +/** + * @brief Automatically derived read for any object that defines .msgpack() (implicitly defined by MSGPACK_FIELDS). + * @param it The iterator to read from. + * @param func The function to call with each field as an argument. + */ +inline void read(auto& it, msgpack_concepts::HasMsgPack auto& obj) +{ + msgpack::msgpack_apply(obj, [&](auto&... obj_fields) { + // apply 'read' to each object field + (_read_msgpack_field(it, obj_fields), ...); + }); +}; + +/** + * @brief Helper method for better error reporting. Clang does not give the best errors for "auto..." + * arguments. + */ +inline void _write_msgpack_field(auto& it, const auto& field) +{ + using namespace serialize; + write(it, field); +} +/** + * @brief Automatically derived write for any object that defines .msgpack() (implicitly defined by MSGPACK_FIELDS). + * @param buf The buffer to write to. + * @param func The function to call with each field as an argument. + */ +inline void write(auto& buf, const msgpack_concepts::HasMsgPack auto& obj) +{ + using namespace serialize; + msgpack::msgpack_apply(obj, [&](auto&... obj_fields) { + // apply 'write' to each object field + (_write_msgpack_field(buf, obj_fields), ...); + }); +}; +} // namespace serialize diff --git a/barretenberg/cpp/src/barretenberg/common/streams.hpp b/barretenberg/cpp/src/barretenberg/common/streams.hpp index 94e931eb8c9..1426b07e981 100644 --- a/barretenberg/cpp/src/barretenberg/common/streams.hpp +++ b/barretenberg/cpp/src/barretenberg/common/streams.hpp @@ -19,8 +19,7 @@ inline std::ostream& operator<<(std::ostream& os, std::vector const& ar return os; } -template ::value, bool> = true, typename A> -inline std::ostream& operator<<(std::ostream& os, std::vector const& arr) +template inline std::ostream& operator<<(std::ostream& os, std::vector const& arr) { os << "["; for (auto element : arr) { @@ -30,7 +29,8 @@ inline std::ostream& operator<<(std::ostream& os, std::vector const& arr) return os; } -template ::value, bool> = true, typename A> +template + requires(!std::integral) inline std::ostream& operator<<(std::ostream& os, std::vector const& arr) { os << "[\n"; diff --git a/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.cpp b/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.cpp index 330f38557f5..6d578257d26 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/blake3s/blake3s.cpp @@ -219,23 +219,6 @@ void blake3_hasher_update(blake3_hasher* self, const uint8_t* input, size_t inpu while (input_len > BLAKE3_BLOCK_LEN) { blake3_compress_in_place(self->cv, input, BLAKE3_BLOCK_LEN, self->flags | maybe_start_flag(self)); - // static_assert(std::is_sameblocks_compressed), uint8_t>::value, "blocks compressed type err"); - // // uint8_t foo = self->blocks_compressed; - // // uint8_t bar(1U); - // std::cout << "owauefheaiufhawuifh" << std::endl; - // std::cout << "owauefheaiufhawuifh" << std::endl; - // std::cout << "owauefheaiufhawuifh" << std::endl; - // std::cout << "owauefheaiufhawuifh" << std::endl; - - // static_assert(std::is_same::value, "blocks compressed type err A "); - // static_assert(std::is_same::value, "blocks compressed type err B"); - // foo = foo + bar; - // std::cout << "owauefheaiufhawuifh" << std::endl; - // std::cout << "owauefheaiufhawuifh" << std::endl; - // std::cout << "owauefheaiufhawuifh" << std::endl; - // std::cout << "owauefheaiufhawuifh" << std::endl; - // std::cout << "owauefheaiufhawuifh" << std::endl; - self->blocks_compressed = static_cast(self->blocks_compressed + 1U); input += BLAKE3_BLOCK_LEN; input_len -= BLAKE3_BLOCK_LEN; diff --git a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp index b7a8d6f5a91..dbd33004f19 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/c_bind.cpp @@ -9,7 +9,7 @@ WASM_EXPORT void ecdsa__compute_public_key(uint8_t const* private_key, uint8_t* { auto priv_key = from_buffer(private_key); secp256k1::g1::affine_element pub_key = secp256k1::g1::one * priv_key; - write(public_key_buf, pub_key); + serialize::write(public_key_buf, pub_key); } WASM_EXPORT void ecdsa__construct_signature(uint8_t const* message, @@ -47,7 +47,7 @@ WASM_EXPORT void ecdsa__recover_public_key_from_signature(uint8_t const* message auto recovered_pub_key = crypto::ecdsa::recover_public_key( std::string((char*)message, msg_len), sig); - write(output_pub_key, recovered_pub_key); + serialize::write(output_pub_key, recovered_pub_key); } WASM_EXPORT bool ecdsa__verify_signature(uint8_t const* message, diff --git a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.hpp b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.hpp index 8275da011eb..16106a5868a 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/ecdsa/ecdsa.hpp @@ -13,13 +13,15 @@ namespace ecdsa { template struct key_pair { Fr private_key; typename G1::affine_element public_key; + // For serialization, update with any new fields + MSGPACK_FIELDS(private_key, public_key); }; struct signature { std::array r; std::array s; uint8_t v; - // for serialization, update with any new fields + // For serialization, update with any new fields MSGPACK_FIELDS(r, s, v); }; @@ -45,46 +47,6 @@ inline std::ostream& operator<<(std::ostream& os, signature const& sig) return os; } -template inline void read(B& it, signature& sig) -{ - using serialize::read; - read(it, sig.r); - read(it, sig.s); - read(it, sig.v); -} - -template inline void write(B& buf, signature const& sig) -{ - using serialize::write; - write(buf, sig.r); - write(buf, sig.s); - write(buf, sig.v); -} - -template inline void read(B& it, key_pair& keypair) -{ - read(it, keypair.private_key); - read(it, keypair.public_key); -} - -template inline void write(B& buf, key_pair const& keypair) -{ - write(buf, keypair.private_key); - write(buf, keypair.public_key); -} - -template inline void read(B& it, key_pair& keypair) -{ - read(it, keypair.private_key); - read(it, keypair.public_key); -} - -template inline void write(B& buf, key_pair const& keypair) -{ - write(buf, keypair.private_key); - write(buf, keypair.public_key); -} - } // namespace ecdsa } // namespace crypto diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp index f067c5b865f..09f8b0c7d88 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind.cpp @@ -60,7 +60,7 @@ WASM_EXPORT void pedersen__commit(uint8_t const* inputs_buffer, uint8_t* output) read(inputs_buffer, to_compress); grumpkin::g1::affine_element pedersen_hash = crypto::pedersen_commitment::commit_native(to_compress); - write(output, pedersen_hash); + serialize::write(output, pedersen_hash); } WASM_EXPORT void pedersen_plookup_commit(uint8_t const* inputs_buffer, uint8_t* output) @@ -69,7 +69,7 @@ WASM_EXPORT void pedersen_plookup_commit(uint8_t const* inputs_buffer, uint8_t* read(inputs_buffer, to_compress); grumpkin::g1::affine_element pedersen_hash = crypto::pedersen_commitment::lookup::commit_native(to_compress); - write(output, pedersen_hash); + serialize::write(output, pedersen_hash); } WASM_EXPORT void pedersen_plookup_commit_with_hash_index(uint8_t const* inputs_buffer, @@ -81,7 +81,7 @@ WASM_EXPORT void pedersen_plookup_commit_with_hash_index(uint8_t const* inputs_b grumpkin::g1::affine_element pedersen_hash = crypto::pedersen_commitment::lookup::commit_native(to_compress, hash_index); - write(output, pedersen_hash); + serialize::write(output, pedersen_hash); } WASM_EXPORT void pedersen__buffer_to_field(uint8_t const* data, size_t length, uint8_t* r) diff --git a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp index 627b2877f12..e91c36b9299 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/pedersen_commitment/c_bind_new.cpp @@ -60,7 +60,7 @@ WASM_EXPORT void pedersen___commit(fr::vec_in_buf inputs_buffer, fr::out_buf out read(inputs_buffer, to_compress); grumpkin::g1::affine_element pedersen_hash = crypto::pedersen_commitment::commit_native(to_compress); - write(output, pedersen_hash); + serialize::write(output, pedersen_hash); } WASM_EXPORT void pedersen___plookup_commit(fr::vec_in_buf inputs_buffer, fr::out_buf output) @@ -69,7 +69,7 @@ WASM_EXPORT void pedersen___plookup_commit(fr::vec_in_buf inputs_buffer, fr::out read(inputs_buffer, to_compress); grumpkin::g1::affine_element pedersen_hash = crypto::pedersen_commitment::lookup::commit_native(to_compress); - write(output, pedersen_hash); + serialize::write(output, pedersen_hash); } WASM_EXPORT void pedersen___plookup_commit_with_hash_index(fr::vec_in_buf inputs_buffer, @@ -81,7 +81,7 @@ WASM_EXPORT void pedersen___plookup_commit_with_hash_index(fr::vec_in_buf inputs grumpkin::g1::affine_element pedersen_hash = crypto::pedersen_commitment::lookup::commit_native(to_compress, ntohl(*hash_index)); - write(output, pedersen_hash); + serialize::write(output, pedersen_hash); } WASM_EXPORT void pedersen___buffer_to_field(uint8_t const* data, fr::out_buf r) diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp index d677d16f949..220887fa2eb 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind.cpp @@ -11,7 +11,7 @@ WASM_EXPORT void compute_public_key(uint8_t const* private_key, uint8_t* public_ { auto priv_key = from_buffer(private_key); grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; - write(public_key_buf, pub_key); + serialize::write(public_key_buf, pub_key); } WASM_EXPORT void negate_public_key(uint8_t const* public_key_buffer, uint8_t* output) @@ -19,7 +19,7 @@ WASM_EXPORT void negate_public_key(uint8_t const* public_key_buffer, uint8_t* ou // Negate the public key (effectively negating the y-coordinate of the public key) and return the resulting public // key. auto account_public_key = from_buffer(public_key_buffer); - barretenberg::group_elements::write(output, -account_public_key); + serialize::write(output, -account_public_key); } WASM_EXPORT void construct_signature( @@ -56,7 +56,7 @@ WASM_EXPORT void multisig_create_multisig_public_key(uint8_t const* private_key, auto agg_pubkey = multisig_public_key(key_pair); - write(multisig_pubkey_buf, agg_pubkey); + serialize::write(multisig_pubkey_buf, agg_pubkey); } WASM_EXPORT bool multisig_validate_and_combine_signer_pubkeys(uint8_t const* signer_pubkey_buf, @@ -67,7 +67,7 @@ WASM_EXPORT bool multisig_validate_and_combine_signer_pubkeys(uint8_t const* sig from_buffer>(signer_pubkey_buf); if (auto combined_key = multisig::validate_and_combine_signer_pubkeys(pubkeys); combined_key) { - write(combined_key_buf, *combined_key); + serialize::write(combined_key_buf, *combined_key); return true; } else { return false; @@ -80,8 +80,8 @@ WASM_EXPORT void multisig_construct_signature_round_1(uint8_t* round_one_public_ using multisig = crypto::schnorr::multisig; auto [public_output, private_output] = multisig::construct_signature_round_1(); - write(round_one_public_output_buf, public_output); - write(round_one_private_output_buf, private_output); + serialize::write(round_one_public_output_buf, public_output); + serialize::write(round_one_private_output_buf, private_output); } WASM_EXPORT bool multisig_construct_signature_round_2(uint8_t const* message, diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind_new.cpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind_new.cpp index 943751a7d85..b1ceb606a33 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind_new.cpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/c_bind_new.cpp @@ -13,7 +13,7 @@ WASM_EXPORT void schnorr_compute_public_key(uint8_t const* private_key, uint8_t* { auto priv_key = from_buffer(private_key); grumpkin::g1::affine_element pub_key = grumpkin::g1::one * priv_key; - write(public_key_buf, pub_key); + serialize::write(public_key_buf, pub_key); } WASM_EXPORT void schnorr_negate_public_key(uint8_t const* public_key_buffer, uint8_t* output) @@ -21,7 +21,7 @@ WASM_EXPORT void schnorr_negate_public_key(uint8_t const* public_key_buffer, uin // Negate the public key (effectively negating the y-coordinate of the public key) and return the resulting public // key. auto account_public_key = from_buffer(public_key_buffer); - barretenberg::group_elements::write(output, -account_public_key); + serialize::write(output, -account_public_key); } WASM_EXPORT void schnorr_construct_signature(uint8_t const* message_buf, @@ -62,7 +62,7 @@ WASM_EXPORT void schnorr_multisig_create_multisig_public_key(uint8_t const* priv auto agg_pubkey = multisig_public_key(key_pair); - write(multisig_pubkey_buf, agg_pubkey); + serialize::write(multisig_pubkey_buf, agg_pubkey); } WASM_EXPORT void schnorr_multisig_validate_and_combine_signer_pubkeys(uint8_t const* signer_pubkey_buf, @@ -75,10 +75,10 @@ WASM_EXPORT void schnorr_multisig_validate_and_combine_signer_pubkeys(uint8_t co auto combined_key = multisig::validate_and_combine_signer_pubkeys(pubkeys); if (combined_key) { - write(combined_key_buf, *combined_key); + serialize::write(combined_key_buf, *combined_key); *success = true; } else { - write(combined_key_buf, affine_element::one()); + serialize::write(combined_key_buf, affine_element::one()); *success = false; } } @@ -89,8 +89,8 @@ WASM_EXPORT void schnorr_multisig_construct_signature_round_1(uint8_t* round_one using multisig = crypto::schnorr::multisig; auto [public_output, private_output] = multisig::construct_signature_round_1(); - write(round_one_public_output_buf, public_output); - write(round_one_private_output_buf, private_output); + serialize::write(round_one_public_output_buf, public_output); + serialize::write(round_one_private_output_buf, private_output); } WASM_EXPORT void schnorr_multisig_construct_signature_round_2(uint8_t const* message_buf, diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.hpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.hpp index 16b497c2207..7cafe9de2b3 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/multisig.hpp @@ -7,6 +7,8 @@ #include #include +#include "barretenberg/serialize/msgpack.hpp" + #include "proof_of_possession.hpp" #include "schnorr.hpp" @@ -56,6 +58,8 @@ template cl // proof of knowledge of the secret_key for public_key ProofOfPossession proof_of_possession; + // For serialization, update with any new fields + MSGPACK_FIELDS(public_key, proof_of_possession); // restore default constructor to enable deserialization MultiSigPublicKey() = default; // create a MultiSigPublicKey with a proof of possession associated with public_key of account @@ -63,6 +67,12 @@ template cl : public_key(account.public_key) , proof_of_possession(account) {} + // Needed to appease MSGPACK_FIELDS + MultiSigPublicKey(const affine_element& public_key, + const ProofOfPossession& proof_of_possession) + : public_key(public_key) + , proof_of_possession(proof_of_possession) + {} }; struct RoundOnePrivateOutput { @@ -71,6 +81,8 @@ template cl Fr r; Fr s; + // For serialization, update with any new fields + MSGPACK_FIELDS(r, s); }; struct RoundOnePublicOutput { @@ -83,7 +95,8 @@ template cl affine_element R; // S = s⋅G affine_element S; - + // For serialization, update with any new fields + MSGPACK_FIELDS(R, S); // for std::sort bool operator<(const RoundOnePublicOutput& other) const { @@ -153,10 +166,10 @@ template cl domain_separator_nonce.begin(), domain_separator_nonce.end(), std::back_inserter(nonce_challenge_buffer)); // write the group generator - write(nonce_challenge_buffer, G1::affine_one); + serialize::write(nonce_challenge_buffer, G1::affine_one); // write X - write(nonce_challenge_buffer, aggregate_pubkey); + serialize::write(nonce_challenge_buffer, aggregate_pubkey); // we slightly deviate from the protocol when including 'm', since the length of 'm' is variable // by writing a prefix and a suffix, we prevent the message from being interpreted as coming from a different @@ -175,8 +188,8 @@ template cl // write {(R1, S1), ..., (Rn, Sn)} for (const auto& nonce : round_1_nonces) { - write(nonce_challenge_buffer, nonce.R); - write(nonce_challenge_buffer, nonce.S); + serialize::write(nonce_challenge_buffer, nonce.R); + serialize::write(nonce_challenge_buffer, nonce.S); } // uses the different hash function for proper domain separation @@ -431,46 +444,4 @@ template cl return sig; } }; - -template -inline void read(B& it, multisig::RoundOnePublicOutput& tx) -{ - read(it, tx.R); - read(it, tx.S); -} - -template -inline void write(B& buf, multisig::RoundOnePublicOutput const& tx) -{ - write(buf, tx.R); - write(buf, tx.S); -} - -template -inline void read(B& it, multisig::RoundOnePrivateOutput& tx) -{ - read(it, tx.r); - read(it, tx.s); -} - -template -inline void write(B& buf, multisig::RoundOnePrivateOutput const& tx) -{ - write(buf, tx.r); - write(buf, tx.s); -} - -template -inline void read(B& it, multisig::MultiSigPublicKey& tx) -{ - read(it, tx.public_key); - read(it, tx.proof_of_possession); -} - -template -inline void write(B& buf, multisig::MultiSigPublicKey const& tx) -{ - write(buf, tx.public_key); - write(buf, tx.proof_of_possession); -} -} // namespace crypto::schnorr \ No newline at end of file +} // namespace crypto::schnorr diff --git a/barretenberg/cpp/src/barretenberg/crypto/schnorr/proof_of_possession.hpp b/barretenberg/cpp/src/barretenberg/crypto/schnorr/proof_of_possession.hpp index 69efb5cb8ce..eea7cc202dc 100644 --- a/barretenberg/cpp/src/barretenberg/crypto/schnorr/proof_of_possession.hpp +++ b/barretenberg/cpp/src/barretenberg/crypto/schnorr/proof_of_possession.hpp @@ -106,14 +106,14 @@ template struct ProofOfPossession { std::copy(domain_separator_pop.begin(), domain_separator_pop.end(), std::back_inserter(challenge_buf)); // write the group generator - write(challenge_buf, G1::affine_one); + serialize::write(challenge_buf, G1::affine_one); // write X twice as per the spec - write(challenge_buf, public_key); - write(challenge_buf, public_key); + serialize::write(challenge_buf, public_key); + serialize::write(challenge_buf, public_key); // write R - write(challenge_buf, R); + serialize::write(challenge_buf, R); // generate the raw bits of H_reg(X,X,R) return Hash::hash(challenge_buf); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp index 52572251b35..ad4b89132a4 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp @@ -1,6 +1,7 @@ #pragma once #include "barretenberg/common/slab_allocator.hpp" #include "barretenberg/dsl/types.hpp" +#include "barretenberg/serialize/msgpack.hpp" #include "blake2s_constraint.hpp" #include "block_constraint.hpp" #include "ecdsa_secp256k1.hpp" @@ -23,24 +24,43 @@ struct acir_format { std::vector public_inputs; - std::vector fixed_base_scalar_mul_constraints; std::vector logic_constraints; std::vector range_constraints; + std::vector sha256_constraints; std::vector schnorr_constraints; std::vector ecdsa_k1_constraints; std::vector ecdsa_r1_constraints; - std::vector sha256_constraints; std::vector blake2s_constraints; std::vector keccak_constraints; std::vector keccak_var_constraints; - std::vector hash_to_field_constraints; std::vector pedersen_constraints; - std::vector block_constraints; + std::vector hash_to_field_constraints; + std::vector fixed_base_scalar_mul_constraints; std::vector recursion_constraints; // A standard plonk arithmetic constraint, as defined in the poly_triple struct, consists of selector values // for q_M,q_L,q_R,q_O,q_C and indices of three variables taking the role of left, right and output wire // This could be a large vector so use slab allocator, we don't expect the blackbox implementations to be so large. std::vector> constraints; + std::vector block_constraints; + + // For serialization, update with any new fields + MSGPACK_FIELDS(varnum, + public_inputs, + logic_constraints, + range_constraints, + sha256_constraints, + schnorr_constraints, + ecdsa_k1_constraints, + ecdsa_r1_constraints, + blake2s_constraints, + keccak_constraints, + keccak_var_constraints, + pedersen_constraints, + hash_to_field_constraints, + fixed_base_scalar_mul_constraints, + recursion_constraints, + constraints, + block_constraints); friend bool operator==(acir_format const& lhs, acir_format const& rhs) = default; }; @@ -59,49 +79,4 @@ Builder create_circuit_with_witness(const acir_format& constraint_system, void create_circuit_with_witness(Builder& builder, const acir_format& constraint_system, WitnessVector const& witness); -// Serialisation -template inline void read(B& buf, acir_format& data) -{ - using serialize::read; - read(buf, data.varnum); - read(buf, data.public_inputs); - read(buf, data.logic_constraints); - read(buf, data.range_constraints); - read(buf, data.sha256_constraints); - read(buf, data.schnorr_constraints); - read(buf, data.ecdsa_k1_constraints); - read(buf, data.ecdsa_r1_constraints); - read(buf, data.blake2s_constraints); - read(buf, data.keccak_constraints); - read(buf, data.keccak_var_constraints); - read(buf, data.pedersen_constraints); - read(buf, data.hash_to_field_constraints); - read(buf, data.fixed_base_scalar_mul_constraints); - read(buf, data.recursion_constraints); - read(buf, data.constraints); - read(buf, data.block_constraints); -} - -template inline void write(B& buf, acir_format const& data) -{ - using serialize::write; - write(buf, data.varnum); - write(buf, data.public_inputs); - write(buf, data.logic_constraints); - write(buf, data.range_constraints); - write(buf, data.sha256_constraints); - write(buf, data.schnorr_constraints); - write(buf, data.ecdsa_k1_constraints); - write(buf, data.ecdsa_r1_constraints); - write(buf, data.blake2s_constraints); - write(buf, data.keccak_constraints); - write(buf, data.keccak_var_constraints); - write(buf, data.pedersen_constraints); - write(buf, data.hash_to_field_constraints); - write(buf, data.fixed_base_scalar_mul_constraints); - write(buf, data.recursion_constraints); - write(buf, data.constraints); - write(buf, data.block_constraints); -} - } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp index 8abaee16101..637cf7431a5 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp @@ -25,21 +25,21 @@ TEST(acir_format, test_a_single_constraint_no_pub_inputs) acir_format constraint_system{ .varnum = 4, .public_inputs = {}, - .fixed_base_scalar_mul_constraints = {}, .logic_constraints = {}, .range_constraints = {}, + .sha256_constraints = {}, .schnorr_constraints = {}, .ecdsa_k1_constraints = {}, .ecdsa_r1_constraints = {}, - .sha256_constraints = {}, .blake2s_constraints = {}, .keccak_constraints = {}, .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, .pedersen_constraints = {}, - .block_constraints = {}, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, .constraints = { constraint }, + .block_constraints = {}, }; auto builder = create_circuit_with_witness(constraint_system, { 0, 0, 1 }); @@ -129,25 +129,23 @@ TEST(acir_format, test_logic_gate_from_noir_circuit) // EXPR [ (1, _4, _6) (-1, _4) 0 ] // EXPR [ (-1, _6) 1 ] - acir_format constraint_system{ - .varnum = 7, - .public_inputs = { 2 }, - .fixed_base_scalar_mul_constraints = {}, - .logic_constraints = { logic_constraint }, - .range_constraints = { range_a, range_b }, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .sha256_constraints = {}, - .blake2s_constraints = {}, - .keccak_constraints = {}, - .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, - .pedersen_constraints = {}, - .block_constraints = {}, - .recursion_constraints = {}, - .constraints = { expr_a, expr_b, expr_c, expr_d }, - }; + acir_format constraint_system{ .varnum = 7, + .public_inputs = { 2 }, + .logic_constraints = { logic_constraint }, + .range_constraints = { range_a, range_b }, + .sha256_constraints = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .keccak_constraints = {}, + .keccak_var_constraints = {}, + .pedersen_constraints = {}, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, + .recursion_constraints = {}, + .constraints = { expr_a, expr_b, expr_c, expr_d }, + .block_constraints = {} }; uint256_t inverse_of_five = fr(5).invert(); auto builder = create_circuit_with_witness(constraint_system, @@ -195,35 +193,33 @@ TEST(acir_format, test_schnorr_verify_pass) .result = 77, .signature = signature, }; + acir_format constraint_system{ .varnum = 82, + .public_inputs = {}, + .logic_constraints = {}, + .range_constraints = range_constraints, + .sha256_constraints = {}, + .schnorr_constraints = { schnorr_constraint }, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .keccak_constraints = {}, + .keccak_var_constraints = {}, + .pedersen_constraints = {}, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, + .recursion_constraints = {}, + .constraints = { poly_triple{ + .a = schnorr_constraint.result, + .b = schnorr_constraint.result, + .c = schnorr_constraint.result, + .q_m = 0, + .q_l = 0, + .q_r = 0, + .q_o = 1, + .q_c = fr::neg_one(), + } }, + .block_constraints = {} }; - acir_format constraint_system{ - .varnum = 82, - .public_inputs = {}, - .fixed_base_scalar_mul_constraints = {}, - .logic_constraints = {}, - .range_constraints = range_constraints, - .schnorr_constraints = { schnorr_constraint }, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .sha256_constraints = {}, - .blake2s_constraints = {}, - .keccak_constraints = {}, - .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, - .pedersen_constraints = {}, - .block_constraints = {}, - .recursion_constraints = {}, - .constraints = { poly_triple{ - .a = schnorr_constraint.result, - .b = schnorr_constraint.result, - .c = schnorr_constraint.result, - .q_m = 0, - .q_l = 0, - .q_r = 0, - .q_o = 1, - .q_c = fr::neg_one(), - } }, - }; uint256_t pub_x = uint256_t("17cbd3ed3151ccfd170efe1d54280a6a4822640bf5c369908ad74ea21518a9c5"); uint256_t pub_y = uint256_t("0e0456e3795c1a31f20035b741cd6158929eeccd320d299cfcac962865a6bc74"); @@ -269,23 +265,21 @@ TEST(acir_format, test_schnorr_verify_small_range) .result = 77, .signature = signature, }; - acir_format constraint_system{ .varnum = 82, .public_inputs = {}, - .fixed_base_scalar_mul_constraints = {}, .logic_constraints = {}, .range_constraints = range_constraints, + .sha256_constraints = {}, .schnorr_constraints = { schnorr_constraint }, .ecdsa_k1_constraints = {}, .ecdsa_r1_constraints = {}, - .sha256_constraints = {}, .blake2s_constraints = {}, .keccak_constraints = {}, .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, .pedersen_constraints = {}, - .block_constraints = {}, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, .constraints = { poly_triple{ .a = schnorr_constraint.result, @@ -297,7 +291,9 @@ TEST(acir_format, test_schnorr_verify_small_range) .q_o = 1, .q_c = fr::neg_one(), } }, + .block_constraints = {}, }; + uint256_t pub_x = uint256_t("17cbd3ed3151ccfd170efe1d54280a6a4822640bf5c369908ad74ea21518a9c5"); uint256_t pub_y = uint256_t("0e0456e3795c1a31f20035b741cd6158929eeccd320d299cfcac962865a6bc74"); @@ -314,4 +310,4 @@ TEST(acir_format, test_schnorr_verify_small_range) auto verifier = composer.create_ultra_with_keccak_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } -} // namespace acir_format::tests \ No newline at end of file +} // namespace acir_format::tests 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 da3f34d32d3..195998a4b08 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 @@ -129,22 +129,23 @@ void handle_blackbox_func_call(Circuit::Opcode::BlackBoxFuncCall const& arg, aci .result_y = arg.outputs[1].value, }); } else if constexpr (std::is_same_v) { - af.hash_to_field_constraints.push_back( - HashToFieldConstraint{ .inputs = map(arg.inputs, - [](auto& e) { - return HashToFieldInput{ - .witness = e.witness.value, - .num_bits = e.num_bits, - }; - }), - .result = arg.output.value }); + af.hash_to_field_constraints.push_back(HashToFieldConstraint{ + .inputs = map(arg.inputs, + [](auto& e) { + return HashToFieldInput{ + .witness = e.witness.value, + .num_bits = e.num_bits, + }; + }), + .result = arg.output.value, + }); } else if constexpr (std::is_same_v) { af.ecdsa_k1_constraints.push_back(EcdsaSecp256k1Constraint{ .hashed_message = map(arg.hashed_message, [](auto& e) { return e.witness.value; }), + .signature = map(arg.signature, [](auto& e) { return e.witness.value; }), .pub_x_indices = map(arg.public_key_x, [](auto& e) { return e.witness.value; }), .pub_y_indices = map(arg.public_key_y, [](auto& e) { return e.witness.value; }), .result = arg.output.value, - .signature = map(arg.signature, [](auto& e) { return e.witness.value; }), }); } else if constexpr (std::is_same_v) { af.ecdsa_r1_constraints.push_back(EcdsaSecp256r1Constraint{ @@ -180,8 +181,8 @@ void handle_blackbox_func_call(Circuit::Opcode::BlackBoxFuncCall const& arg, aci .num_bits = e.num_bits, }; }), - .var_message_size = arg.var_message_size.witness.value, .result = map(arg.outputs, [](auto& e) { return e.value; }), + .var_message_size = arg.var_message_size.witness.value, }); } else if constexpr (std::is_same_v) { auto c = RecursionConstraint{ @@ -224,7 +225,7 @@ void handle_memory(Circuit::MemoryBlock const& mem_block, bool is_ram, acir_form } bool access_type(uint256_t(op.q_c)); trace.push_back(MemOp{ - .access_type = access_type, + .access_type = static_cast(access_type), .index = index, .value = value, }); @@ -276,4 +277,4 @@ WitnessVector witness_buf_to_witness_data(std::vector const& buf) return wv; } -} // namespace acir_format \ No newline at end of file +} // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.hpp index a2a91def968..aec0516b271 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.hpp @@ -1,5 +1,6 @@ #pragma once #include "barretenberg/dsl/types.hpp" +#include "barretenberg/serialize/msgpack.hpp" #include #include @@ -9,6 +10,8 @@ struct Blake2sInput { uint32_t witness; uint32_t num_bits; + // For serialization, update with any new fields + MSGPACK_FIELDS(witness, num_bits); friend bool operator==(Blake2sInput const& lhs, Blake2sInput const& rhs) = default; }; @@ -16,37 +19,11 @@ struct Blake2sConstraint { std::vector inputs; std::vector result; + // For serialization, update with any new fields + MSGPACK_FIELDS(inputs, result); friend bool operator==(Blake2sConstraint const& lhs, Blake2sConstraint const& rhs) = default; }; void create_blake2s_constraints(Builder& builder, const Blake2sConstraint& constraint); -template inline void read(B& buf, Blake2sInput& constraint) -{ - using serialize::read; - read(buf, constraint.witness); - read(buf, constraint.num_bits); -} - -template inline void write(B& buf, Blake2sInput const& constraint) -{ - using serialize::write; - write(buf, constraint.witness); - write(buf, constraint.num_bits); -} - -template inline void read(B& buf, Blake2sConstraint& constraint) -{ - using serialize::read; - read(buf, constraint.inputs); - read(buf, constraint.result); -} - -template inline void write(B& buf, Blake2sConstraint const& constraint) -{ - using serialize::write; - write(buf, constraint.inputs); - write(buf, constraint.result); -} - } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp index 89a47f0f727..d24eaf63187 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp @@ -1,7 +1,7 @@ +#include "block_constraint.hpp" #include "acir_format.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" -#include "block_constraint.hpp" #include #include @@ -106,21 +106,21 @@ TEST(up_ram, TestBlockConstraint) acir_format constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, - .fixed_base_scalar_mul_constraints = {}, .logic_constraints = {}, .range_constraints = {}, + .sha256_constraints = {}, .schnorr_constraints = {}, .ecdsa_k1_constraints = {}, .ecdsa_r1_constraints = {}, - .sha256_constraints = {}, .blake2s_constraints = {}, .keccak_constraints = {}, .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, .pedersen_constraints = {}, - .block_constraints = { block }, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, .constraints = {}, + .block_constraints = { block }, }; auto builder = create_circuit_with_witness(constraint_system, witness_values); @@ -132,4 +132,4 @@ TEST(up_ram, TestBlockConstraint) auto verifier = composer.create_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } -} // namespace acir_format::tests \ No newline at end of file +} // namespace acir_format::tests diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp index a1cc8d81e3b..aaab033f884 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp @@ -1,6 +1,7 @@ #pragma once #include "barretenberg/crypto/ecdsa/ecdsa.hpp" #include "barretenberg/dsl/types.hpp" +#include "barretenberg/serialize/msgpack.hpp" #include namespace acir_format { @@ -9,6 +10,10 @@ struct EcdsaSecp256k1Constraint { // This is the byte representation of the hashed message. std::vector hashed_message; + // This is the computed signature + // + std::vector signature; + // This is the supposed public key which signed the // message, giving rise to the signature. // Since Fr does not have enough bits to represent @@ -20,10 +25,8 @@ struct EcdsaSecp256k1Constraint { // This is the result of verifying the signature uint32_t result; - // This is the computed signature - // - std::vector signature; - + // for serialization, update with any new fields + MSGPACK_FIELDS(hashed_message, signature, pub_x_indices, pub_y_indices, result); friend bool operator==(EcdsaSecp256k1Constraint const& lhs, EcdsaSecp256k1Constraint const& rhs) = default; }; @@ -37,24 +40,4 @@ crypto::ecdsa::signature ecdsa_convert_signature(Builder& builder, std::vector vector_of_bytes); -template inline void read(B& buf, EcdsaSecp256k1Constraint& constraint) -{ - using serialize::read; - read(buf, constraint.hashed_message); - read(buf, constraint.signature); - read(buf, constraint.pub_x_indices); - read(buf, constraint.pub_y_indices); - read(buf, constraint.result); -} - -template inline void write(B& buf, EcdsaSecp256k1Constraint const& constraint) -{ - using serialize::write; - write(buf, constraint.hashed_message); - write(buf, constraint.signature); - write(buf, constraint.pub_x_indices); - write(buf, constraint.pub_y_indices); - write(buf, constraint.result); -} - } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp index f216fd7ae8a..a26894dd0c7 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp @@ -1,8 +1,8 @@ +#include "ecdsa_secp256k1.hpp" #include "acir_format.hpp" #include "barretenberg/crypto/ecdsa/ecdsa.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" -#include "ecdsa_secp256k1.hpp" #include #include @@ -69,13 +69,11 @@ size_t generate_ecdsa_constraint(EcdsaSecp256k1Constraint& ecdsa_constraint, Wit offset += 1; witness_values.emplace_back(1); - ecdsa_constraint = EcdsaSecp256k1Constraint{ - .hashed_message = message_in, - .pub_x_indices = pub_x_indices_in, - .pub_y_indices = pub_y_indices_in, - .result = result_in, - .signature = signature_in, - }; + ecdsa_constraint = EcdsaSecp256k1Constraint{ .hashed_message = message_in, + .signature = signature_in, + .pub_x_indices = pub_x_indices_in, + .pub_y_indices = pub_y_indices_in, + .result = result_in }; return offset; } @@ -87,21 +85,21 @@ TEST(ECDSASecp256k1, TestECDSAConstraintSucceed) acir_format constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, - .fixed_base_scalar_mul_constraints = {}, .logic_constraints = {}, .range_constraints = {}, + .sha256_constraints = {}, .schnorr_constraints = {}, .ecdsa_k1_constraints = { ecdsa_k1_constraint }, .ecdsa_r1_constraints = {}, - .sha256_constraints = {}, .blake2s_constraints = {}, .keccak_constraints = {}, .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, .pedersen_constraints = {}, - .block_constraints = {}, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, .constraints = {}, + .block_constraints = {}, }; auto builder = create_circuit_with_witness(constraint_system, witness_values); @@ -127,22 +125,23 @@ TEST(ECDSASecp256k1, TestECDSACompilesForVerifier) acir_format constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, - .fixed_base_scalar_mul_constraints = {}, .logic_constraints = {}, .range_constraints = {}, + .sha256_constraints = {}, .schnorr_constraints = {}, .ecdsa_k1_constraints = { ecdsa_k1_constraint }, .ecdsa_r1_constraints = {}, - .sha256_constraints = {}, .blake2s_constraints = {}, .keccak_constraints = {}, .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, .pedersen_constraints = {}, - .block_constraints = {}, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, .constraints = {}, + .block_constraints = {}, }; + auto builder = create_circuit(constraint_system); } @@ -161,21 +160,21 @@ TEST(ECDSASecp256k1, TestECDSAConstraintFail) acir_format constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, - .fixed_base_scalar_mul_constraints = {}, .logic_constraints = {}, .range_constraints = {}, + .sha256_constraints = {}, .schnorr_constraints = {}, .ecdsa_k1_constraints = { ecdsa_k1_constraint }, .ecdsa_r1_constraints = {}, - .sha256_constraints = {}, .blake2s_constraints = {}, .keccak_constraints = {}, .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, .pedersen_constraints = {}, - .block_constraints = {}, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, .constraints = {}, + .block_constraints = {}, }; auto builder = create_circuit_with_witness(constraint_system, witness_values); @@ -187,4 +186,4 @@ TEST(ECDSASecp256k1, TestECDSAConstraintFail) auto verifier = composer.create_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } -} // namespace acir_format::tests \ No newline at end of file +} // namespace acir_format::tests diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp index 68d85570cbc..affb7e25c75 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp @@ -1,8 +1,8 @@ +#include "ecdsa_secp256r1.hpp" #include "acir_format.hpp" #include "barretenberg/crypto/ecdsa/ecdsa.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" -#include "ecdsa_secp256r1.hpp" #include #include @@ -120,24 +120,25 @@ TEST(ECDSASecp256r1, test_hardcoded) size_t num_variables = generate_r1_constraints(ecdsa_r1_constraint, witness_values, pub_key_x, pub_key_y, hashed_message, signature); + acir_format constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, - .fixed_base_scalar_mul_constraints = {}, .logic_constraints = {}, .range_constraints = {}, + .sha256_constraints = {}, .schnorr_constraints = {}, .ecdsa_k1_constraints = {}, .ecdsa_r1_constraints = { ecdsa_r1_constraint }, - .sha256_constraints = {}, .blake2s_constraints = {}, .keccak_constraints = {}, .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, .pedersen_constraints = {}, - .block_constraints = {}, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, .constraints = {}, + .block_constraints = {}, }; secp256r1::g1::affine_element pub_key = { pub_key_x, pub_key_y }; @@ -164,21 +165,21 @@ TEST(ECDSASecp256r1, TestECDSAConstraintSucceed) acir_format constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, - .fixed_base_scalar_mul_constraints = {}, .logic_constraints = {}, .range_constraints = {}, + .sha256_constraints = {}, .schnorr_constraints = {}, .ecdsa_k1_constraints = {}, .ecdsa_r1_constraints = { ecdsa_r1_constraint }, - .sha256_constraints = {}, .blake2s_constraints = {}, .keccak_constraints = {}, .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, .pedersen_constraints = {}, - .block_constraints = {}, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, .constraints = {}, + .block_constraints = {}, }; auto builder = create_circuit_with_witness(constraint_system, witness_values); @@ -203,21 +204,21 @@ TEST(ECDSASecp256r1, TestECDSACompilesForVerifier) acir_format constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, - .fixed_base_scalar_mul_constraints = {}, .logic_constraints = {}, .range_constraints = {}, + .sha256_constraints = {}, .schnorr_constraints = {}, .ecdsa_k1_constraints = {}, .ecdsa_r1_constraints = { ecdsa_r1_constraint }, - .sha256_constraints = {}, .blake2s_constraints = {}, .keccak_constraints = {}, .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, .pedersen_constraints = {}, - .block_constraints = {}, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, .constraints = {}, + .block_constraints = {}, }; auto builder = create_circuit(constraint_system); } @@ -237,21 +238,21 @@ TEST(ECDSASecp256r1, TestECDSAConstraintFail) acir_format constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, - .fixed_base_scalar_mul_constraints = {}, .logic_constraints = {}, .range_constraints = {}, + .sha256_constraints = {}, .schnorr_constraints = {}, .ecdsa_k1_constraints = {}, .ecdsa_r1_constraints = { ecdsa_r1_constraint }, - .sha256_constraints = {}, .blake2s_constraints = {}, .keccak_constraints = {}, .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, .pedersen_constraints = {}, - .block_constraints = {}, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, .recursion_constraints = {}, .constraints = {}, + .block_constraints = {}, }; auto builder = create_circuit_with_witness(constraint_system, witness_values); @@ -264,4 +265,4 @@ TEST(ECDSASecp256r1, TestECDSAConstraintFail) auto verifier = composer.create_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } -} // namespace acir_format::tests \ No newline at end of file +} // namespace acir_format::tests diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp index 6e80b09947c..2a7088e67ad 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp @@ -1,5 +1,6 @@ #pragma once #include "barretenberg/dsl/types.hpp" +#include "barretenberg/serialize/msgpack.hpp" #include namespace acir_format { @@ -9,25 +10,11 @@ struct FixedBaseScalarMul { uint32_t pub_key_x; uint32_t pub_key_y; + // for serialization, update with any new fields + MSGPACK_FIELDS(scalar, pub_key_x, pub_key_y); friend bool operator==(FixedBaseScalarMul const& lhs, FixedBaseScalarMul const& rhs) = default; }; void create_fixed_base_constraint(Builder& builder, const FixedBaseScalarMul& input); -template inline void read(B& buf, FixedBaseScalarMul& constraint) -{ - using serialize::read; - read(buf, constraint.scalar); - read(buf, constraint.pub_key_x); - read(buf, constraint.pub_key_y); -} - -template inline void write(B& buf, FixedBaseScalarMul const& constraint) -{ - using serialize::write; - write(buf, constraint.scalar); - write(buf, constraint.pub_key_x); - write(buf, constraint.pub_key_y); -} - } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp index 52a632051d6..605326e4ddc 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp @@ -1,5 +1,6 @@ #pragma once #include "barretenberg/dsl/types.hpp" +#include "barretenberg/serialize/msgpack.hpp" #include #include @@ -9,6 +10,8 @@ struct HashToFieldInput { uint32_t witness; uint32_t num_bits; + // For serialization, update with any new fields + MSGPACK_FIELDS(witness, num_bits); friend bool operator==(HashToFieldInput const& lhs, HashToFieldInput const& rhs) = default; }; @@ -16,37 +19,11 @@ struct HashToFieldConstraint { std::vector inputs; uint32_t result; + // For serialization, update with any new fields + MSGPACK_FIELDS(inputs, result); friend bool operator==(HashToFieldConstraint const& lhs, HashToFieldConstraint const& rhs) = default; }; void create_hash_to_field_constraints(Builder& builder, HashToFieldConstraint constraint); -template inline void read(B& buf, HashToFieldInput& constraint) -{ - using serialize::read; - read(buf, constraint.witness); - read(buf, constraint.num_bits); -} - -template inline void write(B& buf, HashToFieldInput const& constraint) -{ - using serialize::write; - write(buf, constraint.witness); - write(buf, constraint.num_bits); -} - -template inline void read(B& buf, HashToFieldConstraint& constraint) -{ - using serialize::read; - read(buf, constraint.inputs); - read(buf, constraint.result); -} - -template inline void write(B& buf, HashToFieldConstraint const& constraint) -{ - using serialize::write; - write(buf, constraint.inputs); - write(buf, constraint.result); -} - } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.hpp index bba3e280a77..fa2af398678 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.hpp @@ -1,5 +1,6 @@ #pragma once #include "barretenberg/dsl/types.hpp" +#include "barretenberg/serialize/msgpack.hpp" #include #include @@ -9,6 +10,8 @@ struct HashInput { uint32_t witness; uint32_t num_bits; + // For serialization, update with any new fields + MSGPACK_FIELDS(witness, num_bits); friend bool operator==(HashInput const& lhs, HashInput const& rhs) = default; }; @@ -16,62 +19,22 @@ struct KeccakConstraint { std::vector inputs; std::vector result; + // For serialization, update with any new fields + MSGPACK_FIELDS(inputs, result); friend bool operator==(KeccakConstraint const& lhs, KeccakConstraint const& rhs) = default; }; struct KeccakVarConstraint { std::vector inputs; - uint32_t var_message_size; std::vector result; + uint32_t var_message_size; + // For serialization, update with any new fields + MSGPACK_FIELDS(inputs, result, var_message_size); friend bool operator==(KeccakVarConstraint const& lhs, KeccakVarConstraint const& rhs) = default; }; void create_keccak_constraints(Builder& builder, const KeccakConstraint& constraint); void create_keccak_var_constraints(Builder& builder, const KeccakVarConstraint& constraint); -template inline void read(B& buf, HashInput& constraint) -{ - using serialize::read; - read(buf, constraint.witness); - read(buf, constraint.num_bits); -} - -template inline void write(B& buf, HashInput const& constraint) -{ - using serialize::write; - write(buf, constraint.witness); - write(buf, constraint.num_bits); -} - -template inline void read(B& buf, KeccakConstraint& constraint) -{ - using serialize::read; - read(buf, constraint.inputs); - read(buf, constraint.result); -} - -template inline void write(B& buf, KeccakConstraint const& constraint) -{ - using serialize::write; - write(buf, constraint.inputs); - write(buf, constraint.result); -} - -template inline void read(B& buf, KeccakVarConstraint& constraint) -{ - using serialize::read; - read(buf, constraint.inputs); - read(buf, constraint.result); - read(buf, constraint.var_message_size); -} - -template inline void write(B& buf, KeccakVarConstraint const& constraint) -{ - using serialize::write; - write(buf, constraint.inputs); - write(buf, constraint.result); - write(buf, constraint.var_message_size); -} - } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp index 7a4a480a215..37e3f30f175 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp @@ -1,5 +1,6 @@ #pragma once #include "barretenberg/dsl/types.hpp" +#include "barretenberg/serialize/msgpack.hpp" #include namespace acir_format { @@ -22,24 +23,4 @@ void create_logic_gate(Builder& builder, uint32_t a, uint32_t b, uint32_t result void xor_gate(Builder& builder, uint32_t a, uint32_t b, uint32_t result); void and_gate(Builder& builder, uint32_t a, uint32_t b, uint32_t result); - -template inline void read(B& buf, LogicConstraint& constraint) -{ - using serialize::read; - read(buf, constraint.a); - read(buf, constraint.b); - read(buf, constraint.result); - read(buf, constraint.num_bits); - read(buf, constraint.is_xor_gate); -} - -template inline void write(B& buf, LogicConstraint const& constraint) -{ - using serialize::write; - write(buf, constraint.a); - write(buf, constraint.b); - write(buf, constraint.result); - write(buf, constraint.num_bits); - write(buf, constraint.is_xor_gate); -} } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/range_constraint.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/range_constraint.hpp index 1d4e7e4dcec..7184f7106c8 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/range_constraint.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/range_constraint.hpp @@ -1,5 +1,6 @@ #pragma once #include "barretenberg/common/serialize.hpp" +#include "barretenberg/serialize/msgpack.hpp" #include namespace acir_format { @@ -8,21 +9,9 @@ struct RangeConstraint { uint32_t witness; uint32_t num_bits; + // for serialization, update with any new fields + MSGPACK_FIELDS(witness, num_bits); friend bool operator==(RangeConstraint const& lhs, RangeConstraint const& rhs) = default; }; -template inline void read(B& buf, RangeConstraint& constraint) -{ - using serialize::read; - read(buf, constraint.witness); - read(buf, constraint.num_bits); -} - -template inline void write(B& buf, RangeConstraint const& constraint) -{ - using serialize::write; - write(buf, constraint.witness); - write(buf, constraint.num_bits); -} - } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp index adb34ea6308..8ea6c938f53 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp @@ -1,7 +1,7 @@ +#include "recursion_constraint.hpp" #include "acir_format.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" -#include "recursion_constraint.hpp" #include #include @@ -77,25 +77,23 @@ Builder create_inner_circuit() .q_c = 1, }; - acir_format constraint_system{ - .varnum = 7, - .public_inputs = { 2, 3 }, - .fixed_base_scalar_mul_constraints = {}, - .logic_constraints = { logic_constraint }, - .range_constraints = { range_a, range_b }, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .sha256_constraints = {}, - .blake2s_constraints = {}, - .keccak_constraints = {}, - .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, - .pedersen_constraints = {}, - .block_constraints = {}, - .recursion_constraints = {}, - .constraints = { expr_a, expr_b, expr_c, expr_d }, - }; + acir_format constraint_system{ .varnum = 7, + .public_inputs = { 2, 3 }, + .logic_constraints = { logic_constraint }, + .range_constraints = { range_a, range_b }, + .sha256_constraints = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .keccak_constraints = {}, + .keccak_var_constraints = {}, + .pedersen_constraints = {}, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, + .recursion_constraints = {}, + .constraints = { expr_a, expr_b, expr_c, expr_d }, + .block_constraints = {} }; uint256_t inverse_of_five = fr(5).invert(); auto builder = create_circuit_with_witness(constraint_system, @@ -205,25 +203,23 @@ Builder create_outer_circuit(std::vector& inner_circuits) std::vector public_inputs(output_aggregation_object.begin(), output_aggregation_object.end()); - acir_format constraint_system{ - .varnum = static_cast(witness.size() + 1), - .public_inputs = public_inputs, - .fixed_base_scalar_mul_constraints = {}, - .logic_constraints = {}, - .range_constraints = {}, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .sha256_constraints = {}, - .blake2s_constraints = {}, - .keccak_constraints = {}, - .keccak_var_constraints = {}, - .hash_to_field_constraints = {}, - .pedersen_constraints = {}, - .block_constraints = {}, - .recursion_constraints = recursion_constraints, - .constraints = {}, - }; + acir_format constraint_system{ .varnum = static_cast(witness.size() + 1), + .public_inputs = public_inputs, + .logic_constraints = {}, + .range_constraints = {}, + .sha256_constraints = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .keccak_constraints = {}, + .keccak_var_constraints = {}, + .pedersen_constraints = {}, + .hash_to_field_constraints = {}, + .fixed_base_scalar_mul_constraints = {}, + .recursion_constraints = recursion_constraints, + .constraints = {}, + .block_constraints = {} }; auto outer_circuit = create_circuit_with_witness(constraint_system, witness); @@ -334,4 +330,4 @@ TEST(RecursionConstraint, TestFullRecursiveComposition) auto verifier = layer_3_composer.create_ultra_with_keccak_verifier(layer_3_circuit); EXPECT_EQ(verifier.verify_proof(proof), true); } -} // namespace acir_format::test \ No newline at end of file +} // namespace acir_format::test diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.hpp index c94fc3ad960..3027a9e2cfc 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.hpp @@ -1,5 +1,6 @@ #pragma once #include "barretenberg/dsl/types.hpp" +#include "barretenberg/serialize/msgpack.hpp" #include #include @@ -26,33 +27,4 @@ struct Sha256Constraint { // This function does not work (properly) because the stdlib:sha256 function is not working correctly for 512 bits // pair void create_sha256_constraints(Builder& builder, const Sha256Constraint& constraint); - -template inline void read(B& buf, Sha256Input& constraint) -{ - using serialize::read; - read(buf, constraint.witness); - read(buf, constraint.num_bits); -} - -template inline void write(B& buf, Sha256Input const& constraint) -{ - using serialize::write; - write(buf, constraint.witness); - write(buf, constraint.num_bits); -} - -template inline void read(B& buf, Sha256Constraint& constraint) -{ - using serialize::read; - read(buf, constraint.inputs); - read(buf, constraint.result); -} - -template inline void write(B& buf, Sha256Constraint const& constraint) -{ - using serialize::write; - write(buf, constraint.inputs); - write(buf, constraint.result); -} - } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/c_bind.cpp b/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/c_bind.cpp index ab654f69d06..73ece155fb7 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/grumpkin/c_bind.cpp @@ -7,6 +7,7 @@ extern "C" { WASM_EXPORT void ecc_grumpkin__mul(uint8_t const* point_buf, uint8_t const* scalar_buf, uint8_t* result) { + using serialize::write; auto point = from_buffer(point_buf); auto scalar = from_buffer(scalar_buf); grumpkin::g1::affine_element r = point * scalar; @@ -19,6 +20,7 @@ WASM_EXPORT void ecc_grumpkin__batch_mul(uint8_t const* point_buf, uint32_t num_points, uint8_t* result) { + using serialize::write; std::vector points; points.reserve(num_points); for (size_t i = 0; i < num_points; ++i) { @@ -48,4 +50,4 @@ WASM_EXPORT void ecc_grumpkin__reduce512_buffer_mod_circuit_modulus(uint8_t* inp uint512_t target_output = bigint_input % barretenberg_modulus; write(result, target_output.lo); } -} \ No newline at end of file +} diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp index cdc247afa31..8f6d60f897d 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/secp256k1/c_bind.cpp @@ -6,6 +6,7 @@ extern "C" { WASM_EXPORT void ecc_secp256k1__mul(uint8_t const* point_buf, uint8_t const* scalar_buf, uint8_t* result) { + using serialize::write; auto point = from_buffer(point_buf); auto scalar = from_buffer(scalar_buf); secp256k1::g1::affine_element r = point * scalar; diff --git a/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.hpp b/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.hpp index 7307264b38c..f88a0c19f26 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/groups/affine_element.hpp @@ -185,20 +185,6 @@ template class alignas(64) affine_el // for serialization: update with new fields MSGPACK_FIELDS(x, y); }; - -template void read(B& it, affine_element& value) -{ - read(it, value.x); - read(it, value.y); -} - -template -void write(B& buf, affine_element const& value) -{ - write(buf, value.x); - write(buf, value.y); -} - } // namespace group_elements } // namespace barretenberg diff --git a/barretenberg/cpp/src/barretenberg/ecc/serialize.test.cpp b/barretenberg/cpp/src/barretenberg/ecc/serialize.test.cpp index a36b656e748..16250c97e17 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/serialize.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/serialize.test.cpp @@ -1,4 +1,5 @@ #include "barretenberg/ecc/fields/field.hpp" +#include "barretenberg/serialize/msgpack.hpp" #include "barretenberg/serialize/test_helper.hpp" #include @@ -6,4 +7,4 @@ TEST(msgpack_tests, msgpack_field) { auto [actual, expected] = msgpack_roundtrip(barretenberg::fr{ 1ull, 2ull, 3ull, 4ull }); EXPECT_EQ(actual, expected); -} \ No newline at end of file +} diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.cpp index 46d1e375869..03cd1b0fe0a 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_tx.cpp @@ -27,7 +27,7 @@ void write(std::vector& buf, join_split_tx const& tx) write(buf, tx.account_required); write(buf, tx.account_note_index); write(buf, tx.account_note_path); - write(buf, tx.signing_pub_key); + serialize::write(buf, tx.signing_pub_key); write(buf, tx.backward_link); write(buf, tx.allow_chain); diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/native/value/value_note.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/native/value/value_note.hpp index 0dda4e26343..fc5fb4dc5ff 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/native/value/value_note.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/native/value/value_note.hpp @@ -57,7 +57,7 @@ inline void write(std::vector& buf, value_note const& note) write(buf, note.value); write(buf, note.asset_id); write(buf, note.account_required); - write(buf, note.owner); + serialize::write(buf, note.owner); write(buf, note.secret); write(buf, note.creator_pubkey); write(buf, note.input_nullifier); diff --git a/barretenberg/cpp/src/barretenberg/serialize/cbind.hpp b/barretenberg/cpp/src/barretenberg/serialize/cbind.hpp index 56f66155e6e..be7374f6d41 100644 --- a/barretenberg/cpp/src/barretenberg/serialize/cbind.hpp +++ b/barretenberg/cpp/src/barretenberg/serialize/cbind.hpp @@ -39,7 +39,7 @@ inline std::pair msgpack_encode_buffer(auto&& obj) // of a given function type T as a tuple. template constexpr auto param_tuple() { - // decltype is used to determine the type of an expression at compile-time. + // decltype is used to determine the type of the expression at compile-time. // get_func_traits() is assumed to return a structure whose ::Args member is a tuple // of argument types of function T. This function constructs an instance of that tuple and returns it. return typename decltype(get_func_traits())::Args{}; diff --git a/barretenberg/cpp/src/barretenberg/serialize/msgpack_apply.hpp b/barretenberg/cpp/src/barretenberg/serialize/msgpack_apply.hpp new file mode 100644 index 00000000000..9c45f43f207 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/serialize/msgpack_apply.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include "msgpack.hpp" +#include "msgpack_impl/drop_keys.hpp" + +namespace msgpack { +/** + * @brief Helper method for better error reporting. Clang does not give the best errors for lambdas. + */ +template void msgpack_apply(const auto& func, auto&... args) +{ + std::apply(func, msgpack::drop_keys(std::tie(args...))); +} +/** + * @brief Applies a function to the values exposed by the msgpack method. + * @param value The value whose fields to reflect over. + * @param func The function to call with each field as an argument. + */ +template void msgpack_apply(const T& value, const auto& func) +{ + auto static_checker = [&](auto&... value_args) { + static_assert(msgpack_concepts::MsgpackConstructible, + "MSGPACK_FIELDS requires a constructor that can take the types listed in MSGPACK_FIELDS. " + "Type or arg count mismatch, or member initializer constructor not available."); + }; + // We must use const_cast as our method is meant to be polymorphic over const, but there's no such concept in C++ + const_cast(value).msgpack([&](auto&... args) { // NOLINT + std::apply(static_checker, msgpack::drop_keys(std::tie(args...))); + msgpack_apply(func, args...); + }); +} +} // namespace msgpack diff --git a/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/concepts.hpp b/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/concepts.hpp index f2a295eef00..78ca01eeaa1 100644 --- a/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/concepts.hpp +++ b/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/concepts.hpp @@ -4,18 +4,15 @@ struct DoNothing { void operator()(auto...) {} }; namespace msgpack_concepts { -template concept HasMsgPack = requires(T t, DoNothing nop) -{ - t.msgpack(nop); -}; +template +concept HasMsgPack = requires(T t, DoNothing nop) { t.msgpack(nop); }; -template concept HasMsgPackSchema = requires(const T t, DoNothing nop) -{ - t.msgpack_schema(nop); -}; +template +concept HasMsgPackSchema = requires(const T t, DoNothing nop) { t.msgpack_schema(nop); }; + +template +concept HasMsgPackPack = requires(T t, DoNothing nop) { t.msgpack_pack(nop); }; +template +concept MsgpackConstructible = requires(T object, Args... args) { T{ args... }; }; -template concept HasMsgPackPack = requires(T t, DoNothing nop) -{ - t.msgpack_pack(nop); -}; } // namespace msgpack_concepts diff --git a/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/drop_keys.hpp b/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/drop_keys.hpp new file mode 100644 index 00000000000..7f60ef7e74c --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/drop_keys.hpp @@ -0,0 +1,22 @@ +#pragma once +#include + +namespace msgpack { +template auto drop_keys_impl(Tuple&& tuple, std::index_sequence) +{ + // Expand 0 to n/2 to 1 to n+1 (increments of 2) + // Use it to filter the tuple + return std::tie(std::get(std::forward(tuple))...); +} + +/** + * @brief Drops every first value pairwise of a flat argument tuple, assuming that they are keys. + */ +template auto drop_keys(std::tuple&& tuple) +{ + static_assert(sizeof...(Args) % 2 == 0, "Tuple must contain an even number of elements"); + // Compile time sequence of integers from 0 to n/2 + auto compile_time_0_to_n_div_2 = std::make_index_sequence{}; + return drop_keys_impl(tuple, compile_time_0_to_n_div_2); +} +} // namespace msgpack diff --git a/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/func_traits.hpp b/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/func_traits.hpp index b6de5809574..492dc6be8ef 100644 --- a/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/func_traits.hpp +++ b/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/func_traits.hpp @@ -7,15 +7,15 @@ template struct func_traits; // Specialization for function pointers template struct func_traits { - typedef std::tuple Args; // Define a tuple type that holds all argument types - Args args; // Args instance - R ret; // Holds return type - MSGPACK_FIELDS(args, ret); // Macro from msgpack library to serialize/deserialize fields + typedef std::tuple::type...> Args; // Define a tuple type that holds all argument types + Args args; // Args instance + R ret; // Holds return type + MSGPACK_FIELDS(args, ret); // Macro from msgpack library to serialize/deserialize fields }; // Specialization for function references template struct func_traits { - typedef std::tuple Args; + typedef std::tuple::type...> Args; Args args; R ret; MSGPACK_FIELDS(args, ret); @@ -24,7 +24,7 @@ template struct func_traits { // Specialization for member function pointers. This also includes lambda types, // as they are functors (objects with operator()) and hence have a member function pointer template struct func_traits { - typedef std::tuple Args; + typedef std::tuple::type...> Args; Args args; R ret; MSGPACK_FIELDS(args, ret); @@ -32,10 +32,9 @@ template struct func_traits concept LambdaType = requires() -{ - typename std::enable_if_t, void>; -}; +template +concept LambdaType = + requires() { typename std::enable_if_t, void>; }; // Overload for lambda (or functor) types template constexpr auto get_func_traits() diff --git a/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/schema_impl.hpp b/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/schema_impl.hpp index eaa93245a78..9729ba1bb03 100644 --- a/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/schema_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/schema_impl.hpp @@ -9,7 +9,7 @@ struct MsgpackSchemaPacker; // Forward declare for MsgpackSchemaPacker -template inline void msgpack_schema_pack_wrapper(MsgpackSchemaPacker& packer, const T& obj); +template inline void _msgpack_schema_pack(MsgpackSchemaPacker& packer, const T& obj); /** * Define a serialization schema based on compile-time information about a type being serialized. @@ -53,7 +53,7 @@ struct MsgpackSchemaPacker : msgpack::packer { * @tparam T the object's type. * @param obj the object. */ - template void pack_schema(const T& obj) { msgpack_schema_pack_wrapper(*this, obj); } + template void pack_schema(const T& obj) { _msgpack_schema_pack(*this, obj); } // Recurse over any templated containers // Outputs e.g. ['vector', ['sub-type']] @@ -66,7 +66,7 @@ struct MsgpackSchemaPacker : msgpack::packer { // Note: if this fails to compile, check first in list of template Arg's // it may need a msgpack_schema_pack specialization (particularly if it doesn't define MSGPACK_FIELDS). - (msgpack_schema_pack_wrapper(*this, Args{}), ...); /* pack schemas of all template Args */ + (_msgpack_schema_pack(*this, Args{}), ...); /* pack schemas of all template Args */ } /** * @brief Encode a type that defines msgpack based on its key value pairs. @@ -102,10 +102,8 @@ inline void _schema_pack_map_content(MsgpackSchemaPacker&) } namespace msgpack_concepts { -template concept SchemaPackable = requires(T value, MsgpackSchemaPacker packer) -{ - msgpack_schema_pack(packer, value); -}; +template +concept SchemaPackable = requires(T value, MsgpackSchemaPacker packer) { msgpack_schema_pack(packer, value); }; } // namespace msgpack_concepts // Helper for packing (key, value, key, value, ...) arguments @@ -121,8 +119,8 @@ inline void _schema_pack_map_content(MsgpackSchemaPacker& packer, std::string ke } template -requires(!msgpack_concepts::HasMsgPackSchema && - !msgpack_concepts::HasMsgPack) inline void msgpack_schema_pack(MsgpackSchemaPacker& packer, T const& obj) + requires(!msgpack_concepts::HasMsgPackSchema && !msgpack_concepts::HasMsgPack) +inline void msgpack_schema_pack(MsgpackSchemaPacker& packer, T const& obj) { packer.pack(msgpack_schema_name(obj)); } @@ -146,15 +144,17 @@ inline void msgpack_schema_pack(MsgpackSchemaPacker& packer, T const& obj) * @param object The object in question. */ template -requires(!msgpack_concepts::HasMsgPackSchema) inline void msgpack_schema_pack(MsgpackSchemaPacker& packer, - T const& object) + requires(!msgpack_concepts::HasMsgPackSchema) +inline void msgpack_schema_pack(MsgpackSchemaPacker& packer, T const& object) { std::string type = msgpack_schema_name(object); packer.pack_with_name(type, object); } -// This indirection is purely for better error reporting -template inline void msgpack_schema_pack_wrapper(MsgpackSchemaPacker& packer, const T& obj) +/** + * @brief Helper method for better error reporting. Clang does not give the best errors for argument lists. + */ +template inline void _msgpack_schema_pack(MsgpackSchemaPacker& packer, const T& obj) { static_assert(msgpack_concepts::SchemaPackable, "see the first type argument in the error trace, it might need a msgpack_schema method!"); @@ -200,7 +200,7 @@ inline void msgpack_schema_pack(MsgpackSchemaPacker& packer, std::array co packer.pack("array"); // That has a size 2 tuple as its 2nd arg packer.pack_array(2); /* param list format for consistency*/ - msgpack_schema_pack_wrapper(packer, T{}); + _msgpack_schema_pack(packer, T{}); packer.pack(N); } @@ -214,7 +214,7 @@ inline std::string msgpack_schema_to_string(auto obj) { msgpack::sbuffer output; MsgpackSchemaPacker printer{ output }; - msgpack_schema_pack_wrapper(printer, obj); + _msgpack_schema_pack(printer, obj); msgpack::object_handle oh = msgpack::unpack(output.data(), output.size()); std::stringstream pretty_output; pretty_output << oh.get() << std::endl; diff --git a/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/struct_map_impl.hpp b/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/struct_map_impl.hpp index 37d09d917d4..cd2d7c5c348 100644 --- a/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/struct_map_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/serialize/msgpack_impl/struct_map_impl.hpp @@ -7,32 +7,9 @@ #include #define MSGPACK_NO_BOOST #include "concepts.hpp" +#include "drop_keys.hpp" #include -namespace msgpack { -template auto drop_keys_impl(Tuple&& tuple, std::index_sequence) -{ - // Expand 0 to n/2 to 1 to n+1 (increments of 2) - // Use it to filter the tuple - return std::tie(std::get(std::forward(tuple))...); -} - -template auto drop_keys(std::tuple&& tuple) -{ - static_assert(sizeof...(Args) % 2 == 0, "Tuple must contain an even number of elements"); - // Compile time sequence of integers from 0 to n/2 - auto compile_time_0_to_n_div_2 = std::make_index_sequence{}; - return drop_keys_impl(tuple, compile_time_0_to_n_div_2); -} -} // namespace msgpack - -namespace msgpack { -template concept MsgpackConstructible = requires(T object, Args... args) -{ - T{ args... }; -}; -} // namespace msgpack - namespace msgpack::adaptor { // reads structs with msgpack() method from a JSON-like dictionary template struct convert { @@ -42,7 +19,7 @@ template struct convert { "MSGPACK_FIELDS requires default-constructible types (used during unpacking)"); v.msgpack([&](auto&... args) { auto static_checker = [&](auto&... value_args) { - static_assert(msgpack::MsgpackConstructible, + static_assert(msgpack_concepts::MsgpackConstructible, "MSGPACK_FIELDS requires a constructor that can take the types listed in MSGPACK_FIELDS. " "Type or arg count mismatch, or member initializer constructor not available."); }; @@ -61,7 +38,7 @@ template struct pack { "MSGPACK_FIELDS requires default-constructible types (used during unpacking)"); const_cast(v).msgpack([&](auto&... args) { auto static_checker = [&](auto&... value_args) { - static_assert(msgpack::MsgpackConstructible, + static_assert(msgpack_concepts::MsgpackConstructible, "T requires a constructor that can take the fields listed in MSGPACK_FIELDS (T will be " "in template parameters in the compiler stack trace)" "Check the MSGPACK_FIELDS macro usage in T for incompleteness or wrong order." diff --git a/barretenberg/cpp/src/barretenberg/serialize/msgpack_schema.test.cpp b/barretenberg/cpp/src/barretenberg/serialize/msgpack_schema.test.cpp index c5f50b2df06..9a035daf83b 100644 --- a/barretenberg/cpp/src/barretenberg/serialize/msgpack_schema.test.cpp +++ b/barretenberg/cpp/src/barretenberg/serialize/msgpack_schema.test.cpp @@ -54,7 +54,7 @@ TEST(msgpack_tests, msgpack_sanity_sanity) // This is great, but we need to check the underlying facility *somehow* auto checker = [&](auto&... values) { std::string incomplete_msgpack_status = "error"; - if constexpr (msgpack::MsgpackConstructible) { + if constexpr (msgpack_concepts::MsgpackConstructible) { incomplete_msgpack_status = ""; } EXPECT_EQ(incomplete_msgpack_status, "error"); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_leaf.hpp b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_leaf.hpp index d7080b48bbe..f6061a0e2c5 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_leaf.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_leaf.hpp @@ -1,5 +1,6 @@ #pragma once #include "barretenberg/crypto/pedersen_commitment/pedersen.hpp" +#include "barretenberg/serialize/msgpack.hpp" namespace proof_system::plonk { namespace stdlib { @@ -13,6 +14,8 @@ struct nullifier_leaf { index_t nextIndex; fr nextValue; + // For serialization, update with any new fields + MSGPACK_FIELDS(value, nextIndex, nextValue); bool operator==(nullifier_leaf const&) const = default; std::ostream& operator<<(std::ostream& os) @@ -21,22 +24,6 @@ struct nullifier_leaf { return os; } - void read(uint8_t const*& it) - { - using serialize::read; - read(it, value); - read(it, nextIndex); - read(it, nextValue); - } - - inline void write(std::vector& buf) - { - using serialize::write; - write(buf, value); - write(buf, nextIndex); - write(buf, nextValue); - } - barretenberg::fr hash() const { return stdlib::merkle_tree::hash_multiple_native({ value, nextIndex, nextValue }); } }; @@ -128,4 +115,4 @@ inline std::pair find_closest_leaf(std::vector class witness_t { witness_index = context->add_variable(witness); } - template || std::is_enum_v>> - witness_t(ComposerContext* parent_context, T const in) + witness_t(ComposerContext* parent_context, IntegralOrEnum auto const in) { context = parent_context; witness = barretenberg::fr{ static_cast(in), 0, 0, 0 }.to_montgomery_form(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/aggregation_state/native_aggregation_state.hpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/aggregation_state/native_aggregation_state.hpp index 7767e4c9c4f..529c1dfb0cf 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/aggregation_state/native_aggregation_state.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/aggregation_state/native_aggregation_state.hpp @@ -21,6 +21,7 @@ struct native_aggregation_state { std::vector proof_witness_indices; bool has_data = false; + // For serialization, update with new fields MSGPACK_FIELDS(P0, P1, public_inputs, proof_witness_indices, has_data); bool operator==(native_aggregation_state const& other) const { @@ -29,27 +30,6 @@ struct native_aggregation_state { }; }; -inline void read(uint8_t const*& it, native_aggregation_state& state) -{ - using serialize::read; - - read(it, state.P0); - read(it, state.P1); - read(it, state.public_inputs); - read(it, state.proof_witness_indices); - read(it, state.has_data); -}; - -template inline void write(B& buf, native_aggregation_state const& state) -{ - using serialize::write; - write(buf, state.P0); - write(buf, state.P1); - write(buf, state.public_inputs); - write(buf, state.proof_witness_indices); - write(buf, state.has_data); -} - inline std::ostream& operator<<(std::ostream& os, native_aggregation_state const& obj) { return os << "P0: " << obj.P0 << "\n" @@ -61,4 +41,4 @@ inline std::ostream& operator<<(std::ostream& os, native_aggregation_state const } // namespace recursion } // namespace stdlib -} // namespace proof_system::plonk \ No newline at end of file +} // namespace proof_system::plonk