p2p: remove deprecated encoders in V1NetworkMessage constructor
What changed, and why it matters
This is a small internal cleanup in the rust-bitcoin library's peer-to-peer message code. It swaps an older, deprecated way of computing a SHA256 double checksum for a newer helper function. The behavior should be equivalent, and the change removes a deprecated API call rather than fixing a security bug.
No security action required. Treat as routine maintenance/refactoring. Reviewers may optionally verify that sha2_checksum produces the same first-four-byte checksum as the previous implementation, but the diff strongly suggests equivalence.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors V1NetworkMessage::new in p2p/src/message.rs. It replaces a manual consensus_encode() into a sha256d::Hash::engine with a call to sha2_checksum(&payload), which internally uses hashes::encode_to_engine(). The doc comment is updated to remove the ‘encoding fails’ panic path because the new helper no longer exposes an engine error path. There is no evidence in the diff or commit message of a security vulnerability, memory safety issue, or behavior change beyond the intended deprecation cleanup.
Changed components
p2p/src/message.rsV1NetworkMessage::newInspect captured patch +3 / −7
diff --git a/p2p/src/message.rs b/p2p/src/message.rs
index 92075181..fce82858 100644
--- a/p2p/src/message.rs
+++ b/p2p/src/message.rs
@@ -892,14 +892,10 @@ impl V1NetworkMessage {
///
/// # Panics
///
- /// Panics if message encoding fails or if the payload length exceeds `u32::MAX`.
+ /// Panics if the payload length exceeds `u32::MAX`.
pub fn new(magic: Magic, payload: NetworkMessage) -> Self {
- let mut engine = sha256d::Hash::engine();
- let payload_len = payload.consensus_encode(&mut engine).expect("engine doesn't error");
- let payload_len = u32::try_from(payload_len).expect("network message use u32 as length");
- let checksum = sha256d::Hash::from_engine(engine);
- let checksum = checksum.to_byte_array();
- let checksum = [checksum[0], checksum[1], checksum[2], checksum[3]];
+ let (bytes_hashed, checksum) = sha2_checksum(&payload);
+ let payload_len = u32::try_from(bytes_hashed).expect("network message use u32 as length");
Self { magic, payload, payload_len, checksum }
}
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.