From 2c478df912e615a3084e6bfef38d6caede243432 Mon Sep 17 00:00:00 2001 From: Kevin Heifner <heifnerk@objectcomputing.com> Date: Thu, 31 Aug 2023 16:41:28 -0500 Subject: [PATCH 1/8] GH-1523 Remove unneeded uniqueness check for description. Add 256 limit to description. --- libraries/chain/webassembly/privileged.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libraries/chain/webassembly/privileged.cpp b/libraries/chain/webassembly/privileged.cpp index dc3992709f..5b036e832b 100644 --- a/libraries/chain/webassembly/privileged.cpp +++ b/libraries/chain/webassembly/privileged.cpp @@ -6,6 +6,7 @@ #include <eosio/chain/resource_limits.hpp> #include <eosio/chain/apply_context.hpp> #include <eosio/chain/finalizer_set.hpp> +#include <eosio/chain/finalizer_authority.hpp> #include <fc/io/datastream.hpp> @@ -156,24 +157,21 @@ namespace eosio { namespace chain { namespace webassembly { fc::datastream<const char*> ds( packed_finalizer_set.data(), packed_finalizer_set.size() ); finalizer_set finset; fc::raw::unpack(ds, finset); - vector<finalizer_authority> & finalizers = finset.finalizers; + vector<finalizer_authority>& finalizers = finset.finalizers; // TODO: check version and increment it or verify correct EOS_ASSERT( finalizers.size() <= config::max_finalizers, wasm_execution_error, "Finalizer set exceeds the maximum finalizer count for this chain" ); EOS_ASSERT( finalizers.size() > 0, wasm_execution_error, "Finalizer set cannot be empty" ); std::set<fc::crypto::blslib::bls_public_key> unique_finalizer_keys; -#warning REVIEW: Is checking for unique finalizer descriptions at all relevant? - std::set<std::string> unique_finalizers; uint64_t f_weight_sum = 0; for (const auto& f: finalizers) { f_weight_sum += f.fweight; unique_finalizer_keys.insert(f.public_key); - unique_finalizers.insert(f.description); + EOS_ASSERT( f.description.size() <= 256, wasm_execution_error, "Finalizer description greater than 256" ); } - EOS_ASSERT( finalizers.size() == unique_finalizers.size(), wasm_execution_error, "Duplicate finalizer description in finalizer set" ); EOS_ASSERT( finalizers.size() == unique_finalizer_keys.size(), wasm_execution_error, "Duplicate finalizer bls key in finalizer set" ); EOS_ASSERT( finset.fthreshold > f_weight_sum / 2, wasm_execution_error, "Finalizer set threshold cannot be met by finalizer weights" ); From c6aa35832a8e84381f35b9f88a0547d9c3d12437 Mon Sep 17 00:00:00 2001 From: Kevin Heifner <heifnerk@objectcomputing.com> Date: Thu, 31 Aug 2023 16:42:43 -0500 Subject: [PATCH 2/8] GH-1523 Add hs_finalizer_set_extension and refactor to prevent inclusion of bls12-381 headers in header files. --- libraries/chain/CMakeLists.txt | 1 + libraries/chain/finalizer_set.cpp | 27 +++++++ .../eosio/chain/finalizer_authority.hpp | 19 +++++ .../include/eosio/chain/finalizer_set.hpp | 70 ++++++++----------- 4 files changed, 77 insertions(+), 40 deletions(-) create mode 100644 libraries/chain/finalizer_set.cpp create mode 100644 libraries/chain/include/eosio/chain/finalizer_authority.hpp diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index e44014b39c..7e362a0528 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -122,6 +122,7 @@ add_library( eosio_chain ${CHAIN_WEBASSEMBLY_SOURCES} authority.cpp + finalizer_set.cpp trace.cpp transaction_metadata.cpp protocol_state_object.cpp diff --git a/libraries/chain/finalizer_set.cpp b/libraries/chain/finalizer_set.cpp new file mode 100644 index 0000000000..293b7523fe --- /dev/null +++ b/libraries/chain/finalizer_set.cpp @@ -0,0 +1,27 @@ +#include <eosio/chain/finalizer_set.hpp> +#include <eosio/chain/finalizer_authority.hpp> +#include <fc/crypto/bls_public_key.hpp> + +namespace eosio::chain { + + /** + * These definitions are all here to avoid including bls_public_key.hpp which includes <bls12-381/bls12-381.hpp> + * and pulls in bls12-381 types. This keeps bls12-381 out of libtester. + */ + + finalizer_set::finalizer_set() = default; + finalizer_set::~finalizer_set() = default; + + finalizer_set::finalizer_set(const finalizer_set&) = default; + finalizer_set::finalizer_set(finalizer_set&&) = default; + + finalizer_set& finalizer_set::operator=(const finalizer_set&) = default; + finalizer_set& finalizer_set::operator=(finalizer_set&&) = default; + + auto finalizer_set::operator<=>(const finalizer_set&) const = default; + + + hs_finalizer_set_extension::hs_finalizer_set_extension(const finalizer_set& s) + : finalizer_set(s) {} + +} /// eosio::chain diff --git a/libraries/chain/include/eosio/chain/finalizer_authority.hpp b/libraries/chain/include/eosio/chain/finalizer_authority.hpp new file mode 100644 index 0000000000..e0a0628e15 --- /dev/null +++ b/libraries/chain/include/eosio/chain/finalizer_authority.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include <fc/crypto/bls_public_key.hpp> +#include <string> + +namespace eosio::chain { + + struct finalizer_authority { + + std::string description; + uint64_t fweight = 0; // weight that this finalizer's vote has for meeting fthreshold + fc::crypto::blslib::bls_public_key public_key; + + auto operator<=>(const finalizer_authority&) const = default; + }; + +} /// eosio::chain + +FC_REFLECT( eosio::chain::finalizer_authority, (description)(fweight)(public_key) ) diff --git a/libraries/chain/include/eosio/chain/finalizer_set.hpp b/libraries/chain/include/eosio/chain/finalizer_set.hpp index ca5630ade1..b3399f4228 100644 --- a/libraries/chain/include/eosio/chain/finalizer_set.hpp +++ b/libraries/chain/include/eosio/chain/finalizer_set.hpp @@ -1,59 +1,49 @@ #pragma once -#include <eosio/chain/config.hpp> #include <eosio/chain/types.hpp> -#include <chainbase/chainbase.hpp> -#include <eosio/chain/authority.hpp> -#include <eosio/chain/snapshot.hpp> - -#include <fc/crypto/bls_public_key.hpp> namespace eosio::chain { - struct finalizer_authority { - - std::string description; - uint64_t fweight = 0; // weight that this finalizer's vote has for meeting fthreshold - fc::crypto::blslib::bls_public_key public_key; - - friend bool operator == ( const finalizer_authority& lhs, const finalizer_authority& rhs ) { - return tie( lhs.description, lhs.fweight, lhs.public_key ) == tie( rhs.description, rhs.fweight, rhs.public_key ); - } - friend bool operator != ( const finalizer_authority& lhs, const finalizer_authority& rhs ) { - return !(lhs == rhs); - } - }; + struct finalizer_authority; struct finalizer_set { - finalizer_set() = default; + finalizer_set(); + ~finalizer_set(); + + finalizer_set(const finalizer_set&); + finalizer_set(finalizer_set&&); - finalizer_set( uint32_t version, uint64_t fthreshold, std::initializer_list<finalizer_authority> finalizers ) - :version(version) - ,fthreshold(fthreshold) - ,finalizers(finalizers) - {} + finalizer_set& operator=(const finalizer_set&); + finalizer_set& operator=(finalizer_set&&); uint32_t version = 0; ///< sequentially incrementing version number uint64_t fthreshold = 0; // vote fweight threshold to finalize blocks vector<finalizer_authority> finalizers; // Instant Finality voter set - friend bool operator == ( const finalizer_set& a, const finalizer_set& b ) - { - if( a.version != b.version ) return false; - if( a.fthreshold != b.fthreshold ) return false; - if ( a.finalizers.size() != b.finalizers.size() ) return false; - for( uint32_t i = 0; i < a.finalizers.size(); ++i ) - if( ! (a.finalizers[i] == b.finalizers[i]) ) return false; - return true; - } - - friend bool operator != ( const finalizer_set& a, const finalizer_set& b ) - { - return !(a==b); - } + auto operator<=>(const finalizer_set&) const; + }; + + using finalizer_set_ptr = std::shared_ptr<finalizer_set>; + + /** + * Block Header Extension Compatibility + */ + struct hs_finalizer_set_extension : finalizer_set { + + static constexpr uint16_t extension_id() { return 2; } // TODO 3 instead? + static constexpr bool enforce_unique() { return true; } + + hs_finalizer_set_extension() = default; + hs_finalizer_set_extension(const hs_finalizer_set_extension&) = default; + hs_finalizer_set_extension( hs_finalizer_set_extension&& ) = default; + + hs_finalizer_set_extension& operator=(const hs_finalizer_set_extension&) = default; + hs_finalizer_set_extension& operator=(hs_finalizer_set_extension&&) = default; + + hs_finalizer_set_extension(const finalizer_set& s); }; } /// eosio::chain -FC_REFLECT( eosio::chain::finalizer_authority, (description)(fweight)(public_key) ) FC_REFLECT( eosio::chain::finalizer_set, (version)(fthreshold)(finalizers) ) +FC_REFLECT_DERIVED( eosio::chain::hs_finalizer_set_extension, (eosio::chain::finalizer_set), ) \ No newline at end of file From ef8069db18ed830b68dce54406c5a1e45eef22a5 Mon Sep 17 00:00:00 2001 From: Kevin Heifner <heifnerk@objectcomputing.com> Date: Thu, 31 Aug 2023 18:36:01 -0500 Subject: [PATCH 3/8] GH-1523 Use 65536 for max_finalizers and 256 for max finalizer description. Remove generation from finalizer_set used by CDT/ABI. --- libraries/chain/controller.cpp | 1 + libraries/chain/include/eosio/chain/config.hpp | 3 ++- libraries/chain/include/eosio/chain/finalizer_set.hpp | 8 ++++---- libraries/chain/webassembly/privileged.cpp | 11 ++++++++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index b9e4042a62..1fa7cbb1aa 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -1980,6 +1980,7 @@ struct controller_impl { void set_finalizers_impl(const finalizer_set& fin_set) { // TODO store in chainbase current_finalizer_set = fin_set; + ++current_finalizer_set.generation; } /** diff --git a/libraries/chain/include/eosio/chain/config.hpp b/libraries/chain/include/eosio/chain/config.hpp index c3f91d9cbe..a841c53f7a 100644 --- a/libraries/chain/include/eosio/chain/config.hpp +++ b/libraries/chain/include/eosio/chain/config.hpp @@ -133,7 +133,8 @@ static_assert(maximum_tracked_dpos_confirmations >= ((max_producers * 2 / 3) + 1 /** * Maximum number of finalizers in the finalizer set */ -const static int max_finalizers = max_producers; +const static size_t max_finalizers = 64*1024; +const static size_t max_finalizer_description = 256; /** * The number of blocks produced per round is based upon all producers having a chance diff --git a/libraries/chain/include/eosio/chain/finalizer_set.hpp b/libraries/chain/include/eosio/chain/finalizer_set.hpp index b3399f4228..cfc8207ac8 100644 --- a/libraries/chain/include/eosio/chain/finalizer_set.hpp +++ b/libraries/chain/include/eosio/chain/finalizer_set.hpp @@ -16,9 +16,9 @@ namespace eosio::chain { finalizer_set& operator=(const finalizer_set&); finalizer_set& operator=(finalizer_set&&); - uint32_t version = 0; ///< sequentially incrementing version number - uint64_t fthreshold = 0; // vote fweight threshold to finalize blocks - vector<finalizer_authority> finalizers; // Instant Finality voter set + uint32_t generation = 0; ///< sequentially incrementing version number + uint64_t fthreshold = 0; ///< vote fweight threshold to finalize blocks + std::vector<finalizer_authority> finalizers; ///< Instant Finality voter set auto operator<=>(const finalizer_set&) const; }; @@ -45,5 +45,5 @@ namespace eosio::chain { } /// eosio::chain -FC_REFLECT( eosio::chain::finalizer_set, (version)(fthreshold)(finalizers) ) +FC_REFLECT( eosio::chain::finalizer_set, (generation)(fthreshold)(finalizers) ) FC_REFLECT_DERIVED( eosio::chain::hs_finalizer_set_extension, (eosio::chain::finalizer_set), ) \ No newline at end of file diff --git a/libraries/chain/webassembly/privileged.cpp b/libraries/chain/webassembly/privileged.cpp index 5b036e832b..9872905313 100644 --- a/libraries/chain/webassembly/privileged.cpp +++ b/libraries/chain/webassembly/privileged.cpp @@ -156,10 +156,15 @@ namespace eosio { namespace chain { namespace webassembly { EOS_ASSERT(!context.trx_context.is_read_only(), wasm_execution_error, "set_proposed_finalizers not allowed in a readonly transaction"); fc::datastream<const char*> ds( packed_finalizer_set.data(), packed_finalizer_set.size() ); finalizer_set finset; - fc::raw::unpack(ds, finset); + // contract finalizer_set does not include uint32_t generation + // struct abi_finalizer_set { + // uint64_t fthreshold + // vector<finalizer_authority> finalizers; } + fc::raw::unpack(ds, finset.fthreshold); + fc::raw::unpack(ds, finset.finalizers); + vector<finalizer_authority>& finalizers = finset.finalizers; - // TODO: check version and increment it or verify correct EOS_ASSERT( finalizers.size() <= config::max_finalizers, wasm_execution_error, "Finalizer set exceeds the maximum finalizer count for this chain" ); EOS_ASSERT( finalizers.size() > 0, wasm_execution_error, "Finalizer set cannot be empty" ); @@ -169,7 +174,7 @@ namespace eosio { namespace chain { namespace webassembly { for (const auto& f: finalizers) { f_weight_sum += f.fweight; unique_finalizer_keys.insert(f.public_key); - EOS_ASSERT( f.description.size() <= 256, wasm_execution_error, "Finalizer description greater than 256" ); + EOS_ASSERT( f.description.size() <= config::max_finalizer_description, wasm_execution_error, "Finalizer description greater than 256" ); } EOS_ASSERT( finalizers.size() == unique_finalizer_keys.size(), wasm_execution_error, "Duplicate finalizer bls key in finalizer set" ); From bbc04936d5af3675d2f5bbe9777f894588e2f76f Mon Sep 17 00:00:00 2001 From: Kevin Heifner <heifnerk@objectcomputing.com> Date: Fri, 1 Sep 2023 07:59:14 -0500 Subject: [PATCH 4/8] Minor cleanup --- libraries/chain/webassembly/privileged.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/webassembly/privileged.cpp b/libraries/chain/webassembly/privileged.cpp index 9872905313..70720a5a3b 100644 --- a/libraries/chain/webassembly/privileged.cpp +++ b/libraries/chain/webassembly/privileged.cpp @@ -153,7 +153,7 @@ namespace eosio { namespace chain { namespace webassembly { } void interface::set_finalizers(span<const char> packed_finalizer_set) { - EOS_ASSERT(!context.trx_context.is_read_only(), wasm_execution_error, "set_proposed_finalizers not allowed in a readonly transaction"); + EOS_ASSERT(!context.trx_context.is_read_only(), wasm_execution_error, "set_finalizers not allowed in a readonly transaction"); fc::datastream<const char*> ds( packed_finalizer_set.data(), packed_finalizer_set.size() ); finalizer_set finset; // contract finalizer_set does not include uint32_t generation @@ -172,9 +172,9 @@ namespace eosio { namespace chain { namespace webassembly { uint64_t f_weight_sum = 0; for (const auto& f: finalizers) { + EOS_ASSERT( f.description.size() <= config::max_finalizer_description, wasm_execution_error, "Finalizer description greater than 256" ); f_weight_sum += f.fweight; unique_finalizer_keys.insert(f.public_key); - EOS_ASSERT( f.description.size() <= config::max_finalizer_description, wasm_execution_error, "Finalizer description greater than 256" ); } EOS_ASSERT( finalizers.size() == unique_finalizer_keys.size(), wasm_execution_error, "Duplicate finalizer bls key in finalizer set" ); From 48a268b4a18ba4aed1cfe98058b69a3dbd844dd1 Mon Sep 17 00:00:00 2001 From: Kevin Heifner <heifnerk@objectcomputing.com> Date: Fri, 1 Sep 2023 10:16:30 -0500 Subject: [PATCH 5/8] GH-1523 Change contract bls_public_key format to JacobianLE --- libraries/chain/webassembly/privileged.cpp | 32 ++++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/libraries/chain/webassembly/privileged.cpp b/libraries/chain/webassembly/privileged.cpp index 70720a5a3b..25d00e1440 100644 --- a/libraries/chain/webassembly/privileged.cpp +++ b/libraries/chain/webassembly/privileged.cpp @@ -152,18 +152,24 @@ namespace eosio { namespace chain { namespace webassembly { } } + // format for packed_finalizer_set + struct abi_finalizer_authority { + std::string description; + uint64_t fweight = 0; // weight that this finalizer's vote has for meeting fthreshold + std::array<uint8_t, 144> public_key_g1_jacobian; + }; + struct abi_finalizer_set { + uint64_t fthreshold = 0; + vector<abi_finalizer_authority> finalizers; + }; + void interface::set_finalizers(span<const char> packed_finalizer_set) { EOS_ASSERT(!context.trx_context.is_read_only(), wasm_execution_error, "set_finalizers not allowed in a readonly transaction"); fc::datastream<const char*> ds( packed_finalizer_set.data(), packed_finalizer_set.size() ); - finalizer_set finset; - // contract finalizer_set does not include uint32_t generation - // struct abi_finalizer_set { - // uint64_t fthreshold - // vector<finalizer_authority> finalizers; } - fc::raw::unpack(ds, finset.fthreshold); - fc::raw::unpack(ds, finset.finalizers); + abi_finalizer_set abi_finset; + fc::raw::unpack(ds, abi_finset); - vector<finalizer_authority>& finalizers = finset.finalizers; + vector<abi_finalizer_authority>& finalizers = abi_finset.finalizers; EOS_ASSERT( finalizers.size() <= config::max_finalizers, wasm_execution_error, "Finalizer set exceeds the maximum finalizer count for this chain" ); EOS_ASSERT( finalizers.size() > 0, wasm_execution_error, "Finalizer set cannot be empty" ); @@ -171,10 +177,15 @@ namespace eosio { namespace chain { namespace webassembly { std::set<fc::crypto::blslib::bls_public_key> unique_finalizer_keys; uint64_t f_weight_sum = 0; + finalizer_set finset; + finset.fthreshold = abi_finset.fthreshold; for (const auto& f: finalizers) { EOS_ASSERT( f.description.size() <= config::max_finalizer_description, wasm_execution_error, "Finalizer description greater than 256" ); f_weight_sum += f.fweight; - unique_finalizer_keys.insert(f.public_key); + std::optional<bls12_381::g1> pk = bls12_381::g1::fromJacobianBytesLE(f.public_key_g1_jacobian); + EOS_ASSERT( pk, wasm_execution_error, "Invalid public key for: ${d}", ("d", f.description) ); + finset.finalizers.push_back(finalizer_authority{.description = std::move(f.description), .fweight = f.fweight, .public_key{*pk}}); + unique_finalizer_keys.insert(finset.finalizers.back().public_key); } EOS_ASSERT( finalizers.size() == unique_finalizer_keys.size(), wasm_execution_error, "Duplicate finalizer bls key in finalizer set" ); @@ -257,3 +268,6 @@ namespace eosio { namespace chain { namespace webassembly { }); } }}} // ns eosio::chain::webassembly + +FC_REFLECT(eosio::chain::webassembly::abi_finalizer_authority, (description)(fweight)(public_key_g1_jacobian)); +FC_REFLECT(eosio::chain::webassembly::abi_finalizer_set, (fthreshold)(finalizers)); \ No newline at end of file From f24626a389413784c0a772953f1c17bd847ef59a Mon Sep 17 00:00:00 2001 From: Kevin Heifner <heifnerk@objectcomputing.com> Date: Fri, 1 Sep 2023 10:43:36 -0500 Subject: [PATCH 6/8] GH-1523 bls_public_key has explicit constructor --- libraries/chain/webassembly/privileged.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/webassembly/privileged.cpp b/libraries/chain/webassembly/privileged.cpp index 25d00e1440..c9189ed6fc 100644 --- a/libraries/chain/webassembly/privileged.cpp +++ b/libraries/chain/webassembly/privileged.cpp @@ -184,7 +184,7 @@ namespace eosio { namespace chain { namespace webassembly { f_weight_sum += f.fweight; std::optional<bls12_381::g1> pk = bls12_381::g1::fromJacobianBytesLE(f.public_key_g1_jacobian); EOS_ASSERT( pk, wasm_execution_error, "Invalid public key for: ${d}", ("d", f.description) ); - finset.finalizers.push_back(finalizer_authority{.description = std::move(f.description), .fweight = f.fweight, .public_key{*pk}}); + finset.finalizers.push_back(finalizer_authority{.description = std::move(f.description), .fweight = f.fweight, .public_key{fc::crypto::blslib::bls_public_key{*pk}}}); unique_finalizer_keys.insert(finset.finalizers.back().public_key); } From decb6c27713ccfd168d700151a2ae852cd93c56e Mon Sep 17 00:00:00 2001 From: Kevin Heifner <heifnerk@objectcomputing.com> Date: Fri, 1 Sep 2023 10:58:31 -0500 Subject: [PATCH 7/8] GH-1523 Minor cleanup --- libraries/chain/finalizer_set.cpp | 8 ++----- .../chain/include/eosio/chain/config.hpp | 2 +- .../include/eosio/chain/finalizer_set.hpp | 22 +++++-------------- libraries/chain/webassembly/privileged.cpp | 9 ++++---- 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/libraries/chain/finalizer_set.cpp b/libraries/chain/finalizer_set.cpp index 293b7523fe..6fa56a2b0a 100644 --- a/libraries/chain/finalizer_set.cpp +++ b/libraries/chain/finalizer_set.cpp @@ -13,15 +13,11 @@ namespace eosio::chain { finalizer_set::~finalizer_set() = default; finalizer_set::finalizer_set(const finalizer_set&) = default; - finalizer_set::finalizer_set(finalizer_set&&) = default; + finalizer_set::finalizer_set(finalizer_set&&) noexcept = default; finalizer_set& finalizer_set::operator=(const finalizer_set&) = default; - finalizer_set& finalizer_set::operator=(finalizer_set&&) = default; + finalizer_set& finalizer_set::operator=(finalizer_set&&) noexcept = default; auto finalizer_set::operator<=>(const finalizer_set&) const = default; - - hs_finalizer_set_extension::hs_finalizer_set_extension(const finalizer_set& s) - : finalizer_set(s) {} - } /// eosio::chain diff --git a/libraries/chain/include/eosio/chain/config.hpp b/libraries/chain/include/eosio/chain/config.hpp index a841c53f7a..d46df346e5 100644 --- a/libraries/chain/include/eosio/chain/config.hpp +++ b/libraries/chain/include/eosio/chain/config.hpp @@ -134,7 +134,7 @@ static_assert(maximum_tracked_dpos_confirmations >= ((max_producers * 2 / 3) + 1 * Maximum number of finalizers in the finalizer set */ const static size_t max_finalizers = 64*1024; -const static size_t max_finalizer_description = 256; +const static size_t max_finalizer_description_size = 256; /** * The number of blocks produced per round is based upon all producers having a chance diff --git a/libraries/chain/include/eosio/chain/finalizer_set.hpp b/libraries/chain/include/eosio/chain/finalizer_set.hpp index cfc8207ac8..ced75ca27c 100644 --- a/libraries/chain/include/eosio/chain/finalizer_set.hpp +++ b/libraries/chain/include/eosio/chain/finalizer_set.hpp @@ -11,16 +11,16 @@ namespace eosio::chain { ~finalizer_set(); finalizer_set(const finalizer_set&); - finalizer_set(finalizer_set&&); + finalizer_set(finalizer_set&&) noexcept; finalizer_set& operator=(const finalizer_set&); - finalizer_set& operator=(finalizer_set&&); - - uint32_t generation = 0; ///< sequentially incrementing version number - uint64_t fthreshold = 0; ///< vote fweight threshold to finalize blocks - std::vector<finalizer_authority> finalizers; ///< Instant Finality voter set + finalizer_set& operator=(finalizer_set&&) noexcept; auto operator<=>(const finalizer_set&) const; + + uint32_t generation = 0; ///< sequentially incrementing version number + uint64_t fthreshold = 0; ///< vote fweight threshold to finalize blocks + std::vector<finalizer_authority> finalizers; ///< Instant Finality voter set }; using finalizer_set_ptr = std::shared_ptr<finalizer_set>; @@ -29,18 +29,8 @@ namespace eosio::chain { * Block Header Extension Compatibility */ struct hs_finalizer_set_extension : finalizer_set { - static constexpr uint16_t extension_id() { return 2; } // TODO 3 instead? static constexpr bool enforce_unique() { return true; } - - hs_finalizer_set_extension() = default; - hs_finalizer_set_extension(const hs_finalizer_set_extension&) = default; - hs_finalizer_set_extension( hs_finalizer_set_extension&& ) = default; - - hs_finalizer_set_extension& operator=(const hs_finalizer_set_extension&) = default; - hs_finalizer_set_extension& operator=(hs_finalizer_set_extension&&) = default; - - hs_finalizer_set_extension(const finalizer_set& s); }; } /// eosio::chain diff --git a/libraries/chain/webassembly/privileged.cpp b/libraries/chain/webassembly/privileged.cpp index c9189ed6fc..52dd87cbcf 100644 --- a/libraries/chain/webassembly/privileged.cpp +++ b/libraries/chain/webassembly/privileged.cpp @@ -159,8 +159,8 @@ namespace eosio { namespace chain { namespace webassembly { std::array<uint8_t, 144> public_key_g1_jacobian; }; struct abi_finalizer_set { - uint64_t fthreshold = 0; - vector<abi_finalizer_authority> finalizers; + uint64_t fthreshold = 0; + std::vector<abi_finalizer_authority> finalizers; }; void interface::set_finalizers(span<const char> packed_finalizer_set) { @@ -169,7 +169,7 @@ namespace eosio { namespace chain { namespace webassembly { abi_finalizer_set abi_finset; fc::raw::unpack(ds, abi_finset); - vector<abi_finalizer_authority>& finalizers = abi_finset.finalizers; + std::vector<abi_finalizer_authority>& finalizers = abi_finset.finalizers; EOS_ASSERT( finalizers.size() <= config::max_finalizers, wasm_execution_error, "Finalizer set exceeds the maximum finalizer count for this chain" ); EOS_ASSERT( finalizers.size() > 0, wasm_execution_error, "Finalizer set cannot be empty" ); @@ -180,7 +180,8 @@ namespace eosio { namespace chain { namespace webassembly { finalizer_set finset; finset.fthreshold = abi_finset.fthreshold; for (const auto& f: finalizers) { - EOS_ASSERT( f.description.size() <= config::max_finalizer_description, wasm_execution_error, "Finalizer description greater than 256" ); + EOS_ASSERT( f.description.size() <= config::max_finalizer_description_size, wasm_execution_error, + "Finalizer description greater than ${s}", ("s", config::max_finalizer_description_size) ); f_weight_sum += f.fweight; std::optional<bls12_381::g1> pk = bls12_381::g1::fromJacobianBytesLE(f.public_key_g1_jacobian); EOS_ASSERT( pk, wasm_execution_error, "Invalid public key for: ${d}", ("d", f.description) ); From 060b5bad5a0d908799cde57b5d072b90d2fdc6df Mon Sep 17 00:00:00 2001 From: Kevin Heifner <heifnerk@objectcomputing.com> Date: Fri, 1 Sep 2023 12:33:57 -0500 Subject: [PATCH 8/8] GH-1523 Minor cleanup --- libraries/chain/webassembly/privileged.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/chain/webassembly/privileged.cpp b/libraries/chain/webassembly/privileged.cpp index 52dd87cbcf..ec704da324 100644 --- a/libraries/chain/webassembly/privileged.cpp +++ b/libraries/chain/webassembly/privileged.cpp @@ -174,7 +174,7 @@ namespace eosio { namespace chain { namespace webassembly { EOS_ASSERT( finalizers.size() <= config::max_finalizers, wasm_execution_error, "Finalizer set exceeds the maximum finalizer count for this chain" ); EOS_ASSERT( finalizers.size() > 0, wasm_execution_error, "Finalizer set cannot be empty" ); - std::set<fc::crypto::blslib::bls_public_key> unique_finalizer_keys; + std::set<bls12_381::g1> unique_finalizer_keys; uint64_t f_weight_sum = 0; finalizer_set finset; @@ -185,8 +185,10 @@ namespace eosio { namespace chain { namespace webassembly { f_weight_sum += f.fweight; std::optional<bls12_381::g1> pk = bls12_381::g1::fromJacobianBytesLE(f.public_key_g1_jacobian); EOS_ASSERT( pk, wasm_execution_error, "Invalid public key for: ${d}", ("d", f.description) ); - finset.finalizers.push_back(finalizer_authority{.description = std::move(f.description), .fweight = f.fweight, .public_key{fc::crypto::blslib::bls_public_key{*pk}}}); - unique_finalizer_keys.insert(finset.finalizers.back().public_key); + finset.finalizers.push_back(finalizer_authority{.description = std::move(f.description), + .fweight = f.fweight, + .public_key{fc::crypto::blslib::bls_public_key{*pk}}}); + unique_finalizer_keys.insert(*pk); } EOS_ASSERT( finalizers.size() == unique_finalizer_keys.size(), wasm_execution_error, "Duplicate finalizer bls key in finalizer set" );