Copy new_witness_program_unchecked into addresses
What changed, and why it matters
This commit is a straightforward internal code refactor: it copies a small private helper function into a new file so it can be reused locally. There is no security-relevant change to behavior, no new public API, and no fix for a vulnerability.
No security action required. Review as normal code-quality/refactor change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch duplicates the existing private new_witness_program_unchecked helper into addresses/src/lib.rs under the alloc feature. The duplicated function keeps the same debug_assert! length checks and the same Builder construction logic. It remains private and is intended to support Address::script_pubkey and ScriptPubKeyBufExt implementations without exposing the helper publicly. No logic changes, no validation relaxation, and no unsafe code are introduced.
Changed components
addresses/src/lib.rsInspect captured patch +21 / −0
diff --git a/addresses/src/lib.rs b/addresses/src/lib.rs
index 58655443..11e2a565 100644
--- a/addresses/src/lib.rs
+++ b/addresses/src/lib.rs
@@ -24,3 +24,24 @@ extern crate std;
#[cfg(feature = "alloc")]
pub mod witness_program;
+
+#[cfg(feature = "alloc")]
+use primitives::script::{Builder, PushBytes, ScriptBuf};
+#[cfg(feature = "alloc")]
+use primitives::witness_version::WitnessVersion;
+
+/// Generates P2WSH-type of scriptPubkey with a given [`WitnessVersion`] and the program bytes.
+/// Does not do any checks on version or program length.
+///
+/// Convenience method used by `new_p2a`, `new_p2wpkh`, `new_p2wsh`, `new_p2tr`, and `new_p2tr_tweaked`.
+#[cfg(feature = "alloc")]
+fn new_witness_program_unchecked<T: AsRef<PushBytes>, Tg>(
+ version: WitnessVersion,
+ program: T,
+) -> ScriptBuf<Tg> {
+ let program = program.as_ref();
+ debug_assert!(program.len() >= 2 && program.len() <= 40);
+ // In SegWit v0, the program must be either 20 bytes (P2WPKH) or 32 bytes (P2WSH) long.
+ debug_assert!(version != WitnessVersion::V0 || program.len() == 20 || program.len() == 32);
+ Builder::new().push_opcode(version.into()).push_slice(program).into_script()
+}
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.