Describe the bug
bitcoin::Psbt::spend_utxo in the bitcoin 0.32.x line indexes non_witness_utxo.output[vout] without a bounds check, so Psbt::sign (and sighash_ecdsa) panic on a PSBT input whose non_witness_utxo has fewer outputs than previous_output.vout (e.g. a wrong or truncated previous transaction). This was fixed upstream on master in rust-bitcoin/rust-bitcoin#5500 (returns MissingSpendUtxo instead), but the fix is not in the 0.32.x branches as of 0.32.8.
Wallet::sign_with_signers is not affected, since it validates non_witness_utxo against the outpoint before signing. However, since #505 the recommended flow in docs and examples is to call bitcoin::Psbt::sign directly, which does reach the panic when given a malformed PSBT.
This issue tracks picking up the upstream fix (backport to 0.32.x or bump to a release that includes it).
This issue was found by AI.
To Reproduce
// psbt built by the wallet with a single wpkh input, then corrupted:
let mut psbt = builder.finish().unwrap();
psbt.inputs[0].witness_utxo = None;
psbt.inputs[0].non_witness_utxo = Some(Transaction {
version: transaction::Version::TWO,
lock_time: absolute::LockTime::ZERO,
input: vec![],
output: vec![], // no outputs
});
psbt.sign(&xpriv, wallet.secp_ctx()); // panics: index out of bounds at bitcoin-0.32.8/src/psbt/mod.rs:626
Expected behavior
Signing a PSBT with an inconsistent non_witness_utxo should return an error rather than panic.
Build environment
- BDK tag/commit:
6fc68462 (master), bitcoin 0.32.8
Which backend(s) are relevant (if any)?
Is this blocking production use?
Describe the bug
bitcoin::Psbt::spend_utxoin thebitcoin0.32.x line indexesnon_witness_utxo.output[vout]without a bounds check, soPsbt::sign(andsighash_ecdsa) panic on a PSBT input whosenon_witness_utxohas fewer outputs thanprevious_output.vout(e.g. a wrong or truncated previous transaction). This was fixed upstream on master in rust-bitcoin/rust-bitcoin#5500 (returnsMissingSpendUtxoinstead), but the fix is not in the 0.32.x branches as of0.32.8.Wallet::sign_with_signersis not affected, since it validatesnon_witness_utxoagainst the outpoint before signing. However, since #505 the recommended flow in docs and examples is to callbitcoin::Psbt::signdirectly, which does reach the panic when given a malformed PSBT.This issue tracks picking up the upstream fix (backport to 0.32.x or bump to a release that includes it).
This issue was found by AI.
To Reproduce
Expected behavior
Signing a PSBT with an inconsistent
non_witness_utxoshould return an error rather than panic.Build environment
6fc68462(master),bitcoin0.32.8Which backend(s) are relevant (if any)?
bdk_chain,bdk_core)Is this blocking production use?