test: announce field must be 0 or 1 in sendcmpct
What changed, and why it matters
This commit adds a new test to Bitcoin Core's functional test suite. The test verifies that if a peer sends a 'sendcmpct' message with an invalid 'announce' value (anything other than 0 or 1), the node logs an error and disconnects that peer. This is a test-only change; it does not modify the actual network handling code. It confirms existing behavior required by BIP152, the compact blocks standard.
No action required. This is a defensive regression test. Reviewers may optionally confirm that the production code already enforces the 0/1 rule and that the log message matches exactly.
Security signals we found
Tests protocol-mandated rejection of malformed P2P message field
Verifies peer disconnection on invalid boolean-like field value
References BIP152 specification requirement
Evidence from the diff
The diff adds test_invalid_sendcmpct_announce() to test/functional/p2p_compactblocks.py. It connects a test peer, sends msg_sendcmpct(announce=2, version=2), and asserts that bitcoind logs ‘invalid sendcmpct announce field’ and disconnects the peer. The test is then invoked in the main test flow before the existing invalid-cmpctblock test. No C++/Python protocol code is changed.
Changed components
test/functional/p2p_compactblocks.pyInspect captured patch +13 / −0
diff --git a/test/functional/p2p_compactblocks.py b/test/functional/p2p_compactblocks.py
index ebc83964..9b249332 100755
--- a/test/functional/p2p_compactblocks.py
+++ b/test/functional/p2p_compactblocks.py
@@ -263,6 +263,16 @@ class CompactBlocksTest(BitcoinTestFramework):
test_node.send_and_ping(msg_sendcmpct(announce=False, version=2))
check_announcement_of_new_block(node, test_node, lambda p: "cmpctblock" not in p.last_message and "headers" in p.last_message)
+ # BIP152 mandates that the announce field of a sendcmpct message is a
+ # boolean and MUST have a value of either 1 or 0. Sending any other value
+ # should be treated as misbehavior and lead to a disconnect.
+ def test_invalid_sendcmpct_announce(self):
+ node = self.nodes[0]
+ bad_peer = node.add_p2p_connection(TestP2PConn())
+ msg = msg_sendcmpct(announce=2, version=2)
+ with node.assert_debug_log(['invalid sendcmpct announce field']):
+ bad_peer.send_await_disconnect(msg)
+
# This test actually causes bitcoind to (reasonably!) disconnect us, so do this last.
def test_invalid_cmpctblock_message(self):
self.generate(self.nodes[0], COINBASE_MATURITY + 1)
@@ -1017,6 +1027,9 @@ class CompactBlocksTest(BitcoinTestFramework):
# The previous test will lead to a disconnection. Reconnect before continuing.
self.segwit_node = self.nodes[0].add_p2p_connection(TestP2PConn())
+ self.log.info("Testing invalid announce field in sendcmpct message...")
+ self.test_invalid_sendcmpct_announce()
+
self.log.info("Testing invalid index in cmpctblock message...")
self.test_invalid_cmpctblock_message()
Why this scored 23/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.