What changed, and why it matters
This is a small internal code cleanup in the rust-bitcoin library. It changes how two hash-like types (transaction merkle node and witness merkle node) are encoded so that they reference existing data instead of making a copy. There is no security issue here—it's a performance/maintainability improvement that makes the code consistent with how other hash types are already encoded.
No security action needed. Treat as a normal code-quality/performance improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit replaces ArrayEncoder<32> with ArrayRefEncoder<'e, 32> for TxMerkleNode and WitnessMerkleNode encoders, and switches from self.to_byte_array() (which copies) to self.as_byte_array() (which borrows). This is a zero-copy optimization and aligns these two types with the encoding pattern already used by other hash types in the crate. The change is purely internal and does not alter serialization output or public behavior.
Changed components
primitives/src/hash_types/transaction_merkle_node.rsprimitives/src/hash_types/witness_merkle_node.rsInspect captured patch +6 / −6
diff --git a/primitives/src/hash_types/transaction_merkle_node.rs b/primitives/src/hash_types/transaction_merkle_node.rs
index ed911f9a..14e2b648 100644
--- a/primitives/src/hash_types/transaction_merkle_node.rs
+++ b/primitives/src/hash_types/transaction_merkle_node.rs
@@ -52,14 +52,14 @@ impl TxMerkleNode {
encoding::encoder_newtype_exact! {
/// The encoder for the [`TxMerkleNode`] type.
- pub struct TxMerkleNodeEncoder<'e>(encoding::ArrayEncoder<32>);
+ pub struct TxMerkleNodeEncoder<'e>(encoding::ArrayRefEncoder<'e, 32>);
}
impl encoding::Encodable for TxMerkleNode {
type Encoder<'e> = TxMerkleNodeEncoder<'e>;
fn encoder(&self) -> Self::Encoder<'_> {
- TxMerkleNodeEncoder::new(encoding::ArrayEncoder::without_length_prefix(
- self.to_byte_array(),
+ TxMerkleNodeEncoder::new(encoding::ArrayRefEncoder::without_length_prefix(
+ self.as_byte_array(),
))
}
}
diff --git a/primitives/src/hash_types/witness_merkle_node.rs b/primitives/src/hash_types/witness_merkle_node.rs
index 95cc5d94..0e685610 100644
--- a/primitives/src/hash_types/witness_merkle_node.rs
+++ b/primitives/src/hash_types/witness_merkle_node.rs
@@ -52,14 +52,14 @@ impl WitnessMerkleNode {
encoding::encoder_newtype_exact! {
/// The encoder for the [`WitnessMerkleNode`] type.
- pub struct WitnessMerkleNodeEncoder<'e>(encoding::ArrayEncoder<32>);
+ pub struct WitnessMerkleNodeEncoder<'e>(encoding::ArrayRefEncoder<'e, 32>);
}
impl encoding::Encodable for WitnessMerkleNode {
type Encoder<'e> = WitnessMerkleNodeEncoder<'e>;
fn encoder(&self) -> Self::Encoder<'_> {
- WitnessMerkleNodeEncoder::new(encoding::ArrayEncoder::without_length_prefix(
- self.to_byte_array(),
+ WitnessMerkleNodeEncoder::new(encoding::ArrayRefEncoder::without_length_prefix(
+ self.as_byte_array(),
))
}
}
Why this scored 15/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.