Remove all uses of extension traits from Address
What changed, and why it matters
This is a small internal code cleanup in the rust-bitcoin library. It changes how Bitcoin addresses are built for certain SegWit-compatible pay-to-script-hash addresses, replacing one internal helper method with a direct opcode call. There is no indication this fixes a security bug or changes user-visible behavior.
No security action required. Treat as ordinary refactoring/cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit removes uses of the BuilderExt::push_int_unchecked(0) helper in bitcoin/src/address/mod.rs and replaces them with push_opcode(OP_PUSHBYTES_0) when constructing P2SH-wrapped SegWit scriptPubKeys (p2shwpkh and p2shwsh). The resulting script bytes are functionally equivalent: pushing a zero-length byte array as the witness version. The change reduces dependency on extension traits and aligns the implementation with primitives. No security vulnerability is described or evident from the diff.
Changed components
bitcoin/src/address/mod.rsAddress::p2shwpkhAddress::p2shwshInspect captured patch +7 / −5
diff --git a/bitcoin/src/address/mod.rs b/bitcoin/src/address/mod.rs
index 54041ec4..e5134c7d 100644
--- a/bitcoin/src/address/mod.rs
+++ b/bitcoin/src/address/mod.rs
@@ -60,13 +60,14 @@ use crate::crypto::key::{
XOnlyPublicKey,
};
use crate::network::{Network, NetworkKind, Params};
+use crate::opcodes::all::OP_PUSHBYTES_0;
use crate::prelude::{String, ToOwned};
use crate::script::witness_program::WitnessProgram;
use crate::script::witness_version::WitnessVersion;
use crate::script::{
- self, BuilderExt as _, RedeemScriptSizeError, Script, ScriptExt as _, ScriptHash,
- ScriptHashableTag, ScriptPubKey, ScriptPubKeyBuf, ScriptPubKeyBufExt as _, WScriptHash,
- WitnessScript, WitnessScriptSizeError,
+ self, RedeemScriptSizeError, Script, ScriptExt as _, ScriptHash, ScriptHashableTag,
+ ScriptPubKey, ScriptPubKeyBuf, ScriptPubKeyBufExt as _, WScriptHash, WitnessScript,
+ WitnessScriptSizeError,
};
use crate::taproot::TapNodeHash;
@@ -545,7 +546,8 @@ impl Address {
///
/// This is a SegWit address type that looks familiar (as p2sh) to legacy clients.
pub fn p2shwpkh(pk: FullPublicKey, network: impl Into<NetworkKind>) -> Self {
- let builder = ScriptPubKey::builder().push_int_unchecked(0).push_slice(pk.wpubkey_hash());
+ let builder =
+ ScriptPubKey::builder().push_opcode(OP_PUSHBYTES_0).push_slice(pk.wpubkey_hash());
let script_hash = builder.as_script().script_hash().expect("script is less than 520 bytes");
Self::p2sh_from_hash(script_hash, network)
}
@@ -574,7 +576,7 @@ impl Address {
network: impl Into<NetworkKind>,
) -> Result<Self, WitnessScriptSizeError> {
let hash = witness_script.wscript_hash()?;
- let builder = ScriptPubKey::builder().push_int_unchecked(0).push_slice(hash);
+ let builder = ScriptPubKey::builder().push_opcode(OP_PUSHBYTES_0).push_slice(hash);
let script_hash = builder.as_script().script_hash().expect("script is less than 520 bytes");
Ok(Self::p2sh_from_hash(script_hash, network))
}
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.