diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index 0f4699c009..4e8bb8e1e0 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -526,9 +526,10 @@ nano::confirm_req::confirm_req (nano::network_constants const & constants, std:: message (constants, nano::message_type::confirm_req), roots_hashes (roots_hashes_a) { + debug_assert (roots_hashes.size () <= nano::vote::max_hashes); + // not_a_block (1) block type for hashes + roots request header.block_type_set (nano::block_type::not_a_block); - debug_assert (roots_hashes.size () < 16); header.count_set (static_cast (roots_hashes.size ())); } @@ -537,9 +538,10 @@ nano::confirm_req::confirm_req (nano::network_constants const & constants, nano: roots_hashes (std::vector> (1, std::make_pair (hash_a, root_a))) { debug_assert (!roots_hashes.empty ()); + debug_assert (roots_hashes.size () <= nano::vote::max_hashes); + // not_a_block (1) block type for hashes + roots request header.block_type_set (nano::block_type::not_a_block); - debug_assert (roots_hashes.size () < 16); header.count_set (static_cast (roots_hashes.size ())); } @@ -684,7 +686,6 @@ nano::confirm_ack::confirm_ack (nano::network_constants const & constants, std:: vote (vote_a) { header.block_type_set (nano::block_type::not_a_block); - debug_assert (vote_a->hashes.size () < 16); header.count_set (static_cast (vote_a->hashes.size ())); } diff --git a/nano/secure/vote.cpp b/nano/secure/vote.cpp index 2a7a669334..0fa9d41d97 100644 --- a/nano/secure/vote.cpp +++ b/nano/secure/vote.cpp @@ -13,11 +13,15 @@ nano::vote::vote (nano::account const & account_a, nano::raw_key const & prv_a, timestamp_m{ packed_timestamp (timestamp_a, duration) }, account{ account_a } { + debug_assert (hashes.size () <= max_hashes); + signature = nano::sign_message (prv_a, account_a, hash ()); } void nano::vote::serialize (nano::stream & stream_a) const { + debug_assert (hashes.size () <= max_hashes); + write (stream_a, account); write (stream_a, signature); write (stream_a, boost::endian::native_to_little (timestamp_m)); @@ -36,7 +40,7 @@ bool nano::vote::deserialize (nano::stream & stream_a) nano::read (stream_a, signature.bytes); nano::read (stream_a, timestamp_m); - while (stream_a.in_avail () > 0) + while (stream_a.in_avail () > 0 && hashes.size () < max_hashes) { nano::block_hash block_hash; nano::read (stream_a, block_hash); diff --git a/nano/secure/vote.hpp b/nano/secure/vote.hpp index b20fcb3671..cd8f2c8943 100644 --- a/nano/secure/vote.hpp +++ b/nano/secure/vote.hpp @@ -57,6 +57,8 @@ class vote final static uint64_t constexpr timestamp_min = { 0x0000'0000'0000'0010ULL }; static uint8_t constexpr duration_max = { 0x0fu }; + static std::size_t constexpr max_hashes = 256; + /* Check if timestamp represents a final vote */ static bool is_final_timestamp (uint64_t timestamp);