test: V1NetworkMessage sendcmpct should be either 1 or 0
What changed, and why it matters
This commit only adds a new unit test. It does not change any production code, so it cannot by itself introduce or fix a security vulnerability. The test verifies that an invalid 'sendcmpct' network message (with a mode byte other than 0 or 1) is rejected during decoding. If the underlying code already rejects such messages, the test merely documents that behavior. If it did not, the test would fail and the vulnerability would remain unfixed.
No immediate action required for this commit. If the goal is to ensure sendcmpct mode-byte strictness, verify separately that the production decoder (not shown here) already rejects non-canonical mode bytes; if it does not, a follow-up production-code fix is needed.
Security signals we found
Test-only change: no production code modified
Topic: P2P message parsing strictness for sendcmpct mode byte
No patch to decoder/validation logic visible in diff
Evidence from the diff
The diff adds a single test, sendcmpct_v1_network_message_with_invalid_mode_bit, in p2p/src/message.rs. It constructs a raw P2P wire message for sendcmpct with mode byte 0x12 (invalid; only 0x00 or 0x01 are canonical per BIP 152) and asserts that decoding into V1NetworkMessage returns an error. No production parsing, validation, or consensus logic is modified. The commit is purely test coverage.
Changed components
p2p/src/message.rs (test module only)Inspect captured patch +16 / −0
diff --git a/p2p/src/message.rs b/p2p/src/message.rs
index 3ef48f0f..318cbde2 100644
--- a/p2p/src/message.rs
+++ b/p2p/src/message.rs
@@ -2858,6 +2858,22 @@ mod test {
assert_eq!(encoded, expected_bytes);
}
+ #[test]
+ #[rustfmt::skip]
+ fn sendcmpct_v1_network_message_with_invalid_mode_bit() {
+ // Wire data has a non-canonical `send_compact` (0x12 instead of 0x01 or 0).
+ let raw_msg = [
+ 0xf9, 0xbe, 0xb4, 0xd9,
+ 0x73, 0x65, 0x6e, 0x64, 0x63, 0x6d, 0x70, 0x63, 0x74, 0x00, 0x00, 0x00,
+ 0x09, 0x00, 0x00, 0x00,
+ 0xf9, 0x9c, 0x95, 0x43,
+ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x0c, // Mode byte (0x12)
+ ];
+
+ let msg = encoding::decode_from_slice::<V1NetworkMessage>(&raw_msg);
+ assert!(msg.is_err());
+ }
+
#[test]
#[rustfmt::skip] // Keep readable byte layout with comments.
fn v1_message_rejects_invalid_checksum_with_noncanonical_encoding() {
Why this scored 12/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.