forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(net): bound governance vote signature deserialization #7440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
PastaPastaPasta
merged 1 commit into
dashpay:develop
from
thepastaclaw:fix/governance-vote-signature-bounds
Jul 10, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // Copyright (c) 2026 The Dash Core developers | ||
| // Distributed under the MIT software license, see the accompanying | ||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| #include <governance/vote.h> | ||
| #include <primitives/transaction.h> | ||
| #include <serialize.h> | ||
| #include <streams.h> | ||
| #include <uint256.h> | ||
| #include <version.h> | ||
|
|
||
| #include <test/util/setup_common.h> | ||
|
|
||
| #include <boost/test/unit_test.hpp> | ||
|
|
||
| #include <ios> | ||
| #include <limits> | ||
| #include <vector> | ||
|
|
||
| BOOST_FIXTURE_TEST_SUITE(governance_vote_wire_tests, BasicTestingSetup) | ||
|
|
||
| namespace { | ||
| void WriteVoteHeader(CDataStream& ss) | ||
| { | ||
| ss << COutPoint{uint256::ONE, 0} << uint256::ONE | ||
| << int{1} /*outcome*/ << int{1} /*signal*/ << int64_t{1'700'000'000}; | ||
| } | ||
|
|
||
| CDataStream MakeVoteWire(size_t sig_len) | ||
| { | ||
| CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); | ||
| WriteVoteHeader(ss); | ||
| ss << std::vector<unsigned char>(sig_len, 0xAA); | ||
| return ss; | ||
| } | ||
| } // namespace | ||
|
|
||
| // Reject invalid signature lengths, including a maximal CompactSize prefix. | ||
| BOOST_AUTO_TEST_CASE(rejects_invalid_sizes) | ||
| { | ||
| for (size_t bad : {size_t{0}, size_t{64}, size_t{66}, size_t{95}, size_t{97}, size_t{128}}) { | ||
| CDataStream ss = MakeVoteWire(bad); | ||
| CGovernanceVote vote; | ||
| BOOST_CHECK_THROW(ss >> vote, std::ios_base::failure); | ||
| } | ||
|
|
||
| CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); | ||
| WriteVoteHeader(ss); | ||
| WriteCompactSize(ss, std::numeric_limits<uint64_t>::max()); | ||
| CGovernanceVote vote; | ||
| BOOST_CHECK_THROW(ss >> vote, std::ios_base::failure); | ||
| } | ||
|
|
||
| // Truncated element bytes must surface as ios_base::failure so the govobjvote | ||
| // handler scores the peer. | ||
| BOOST_AUTO_TEST_CASE(truncated_signature_throws_ios_failure) | ||
| { | ||
| CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); | ||
| WriteVoteHeader(ss); | ||
| ss << uint8_t{CGovernanceVote::BLS_SIG_SIZE}; | ||
| ss.write(MakeByteSpan(std::vector<unsigned char>(10, 0xBB))); | ||
|
|
||
| CGovernanceVote vote; | ||
| BOOST_CHECK_THROW(ss >> vote, std::ios_base::failure); | ||
| } | ||
|
|
||
| // 65-byte ECDSA and 96-byte BLS round-trip cleanly over the network. | ||
| BOOST_AUTO_TEST_CASE(accepts_legitimate_boundary_sizes) | ||
| { | ||
| for (size_t sig_len : {CGovernanceVote::COMPACT_SIG_SIZE, CGovernanceVote::BLS_SIG_SIZE}) { | ||
| CDataStream ss = MakeVoteWire(sig_len); | ||
| const size_t wire_bytes = ss.size(); | ||
|
|
||
| CGovernanceVote vote; | ||
| BOOST_REQUIRE_NO_THROW(ss >> vote); | ||
| BOOST_CHECK_EQUAL(ss.size(), 0U); | ||
|
|
||
| CDataStream out(SER_NETWORK, PROTOCOL_VERSION); | ||
| out << vote; | ||
| BOOST_CHECK_EQUAL(out.size(), wire_bytes); | ||
| } | ||
| } | ||
|
|
||
| // SER_DISK reads stay unbounded — existing on-disk data must load unchanged. | ||
| BOOST_AUTO_TEST_CASE(ser_disk_deserialization_unaffected) | ||
| { | ||
| CDataStream ss(SER_DISK, PROTOCOL_VERSION); | ||
| WriteVoteHeader(ss); | ||
| ss << std::vector<unsigned char>(128, 0xCD); | ||
|
|
||
| CGovernanceVote vote; | ||
| BOOST_REQUIRE_NO_THROW(ss >> vote); | ||
| BOOST_CHECK_EQUAL(ss.size(), 0U); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_SUITE_END() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: No test exercises the peer-misbehavior-scoring path this PR adds
All four new tests call
ss >> votedirectly and assert onstd::ios_base::failure. None of them go throughNetGovernance::ProcessMessage, which is where this PR's actual security behavior lives: catching that exception and callingPeerMisbehaving(peer.GetId(), 100, "malformed governance vote")(net_governance.cpp:199-204). As written, a regression that removes the catch, changes the penalty, or forgets thereturnafter scoring would leave every test in this file green while silently breaking peer-scoring. Add a handler-level test that feeds an oversized or truncatedgovobjvotepayload throughNetGovernance::ProcessMessageand asserts the peer accumulates 100 misbehavior points.source: ['codex']