The issue is with the push_slice API in recent versions of rust-bitcoin (≥ 0.30).
ScriptBuf::builder().push_slice (and Builder::push_slice) now requires T: AsRef for safety—it enforces Bitcoin’s push-data limits at compile time where possible and prevents oversized pushes. &[u8] (what redeem_script.as_bytes() returns) no longer satisfies that bound directly.
Fix
Convert the redeem script bytes to PushBytesBuf (the owned version) using TryFrom:
use bitcoin::script::{Builder, PushBytesBuf, ScriptBuf}; // or the full path: bitcoin::blockdata::script::*
// ... your redeem_script construction (this part is already correct) ...
let redeem_script = Script::builder()
.push_opcode(OP_PUSHNUM_1)
.push_key(&pubkey1)
.push_opcode(OP_PUSHNUM_1)
.push_opcode(OP_CHECKMULTISIG)
.into_script();
// Build the scriptSig for the P2SH spend (1-of-1 multisig redeem script)
let mut script_sig = Builder::new()
.push_opcode(OP_0) // dummy 0 for CHECKMULTISIG
.push_slice(&signature1.serialize()) // signature (already a valid push)
.push_slice(
PushBytesBuf::try_from(redeem_script.as_bytes())
.expect("redeem script too large to push") // will never fail for normal multisig
)
.into_script();
tx.input[0].script_sig = script_sig; // or however you're attaching it
Why this works
PushBytesBuf::try_from(&[u8])(or&PushBytes::try_from(&[u8])if you prefer a reference) validates the length and gives you a type that implementsAsRef.- For a 1-of-1 P2MS redeem script the size is tiny (~36 bytes), so the
expect/unwrapis safe. In production you can handle thePushBytesErrorif you want to be extra defensive. - The resulting
script_sigwill be a valid P2SH unlocking script:<0>(all pushes).
Alternative one-liners (if you prefer)
.push_slice(PushBytesBuf::from(redeem_script.as_bytes())) // panics on >4 GiB (impossible)
or
.push_slice(redeem_script.as_bytes().try_into().unwrap())
(using the TryInto impl that PushBytesBuf provides).
This is the idiomatic way in current rust-bitcoin. Your redeem script builder and overall P2SH flow look correct—only the final push needed the type adjustment.













