Skip to content

Commit a5bd502

Browse files
committed
Fix unreachable error bug during iteration of funding utxos
1 parent 4f9301e commit a5bd502

1 file changed

Lines changed: 57 additions & 1 deletion

File tree

bitcoin/src/psbt/mod.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl Psbt {
191191
) -> Result<Transaction, ExtractTxError> {
192192
let fee = match self.fee() {
193193
Ok(fee) => fee,
194-
Err(Error::MissingUtxo) =>
194+
Err(Error::MissingUtxo) | Err(Error::PsbtUtxoOutOfbounds) =>
195195
return Err(ExtractTxError::MissingInputAmount { tx: self.internal_extract_tx() }),
196196
Err(Error::NegativeFee) => return Err(ExtractTxError::SendingTooMuch { psbt: self }),
197197
Err(Error::FeeOverflow) =>
@@ -2502,6 +2502,62 @@ mod tests {
25022502
}
25032503
}
25042504

2505+
#[test]
2506+
fn test_psbt_utxo_out_of_bounds() {
2507+
let prev_tx = Transaction {
2508+
version: transaction::Version::TWO,
2509+
lock_time: absolute::LockTime::ZERO,
2510+
inputs: vec![],
2511+
outputs: vec![
2512+
TxOut {
2513+
amount: Amount::default(),
2514+
script_pubkey: ScriptPubKeyBuf::new()
2515+
}
2516+
],
2517+
};
2518+
2519+
let unsigned_tx = Transaction {
2520+
version: transaction::Version::TWO,
2521+
lock_time: absolute::LockTime::ZERO,
2522+
inputs: vec![
2523+
TxIn {
2524+
previous_output: OutPoint {
2525+
txid: prev_tx.compute_txid(),
2526+
vout: 5, // This doesn't have a corresponding output
2527+
},
2528+
script_sig: ScriptSigBuf::new(),
2529+
sequence: Sequence::default(),
2530+
witness: Witness::new(),
2531+
}
2532+
],
2533+
outputs: vec![
2534+
TxOut {
2535+
amount: Amount::default(),
2536+
script_pubkey: ScriptPubKeyBuf::new(),
2537+
}
2538+
],
2539+
};
2540+
2541+
let psbt = Psbt {
2542+
unsigned_tx,
2543+
version: 0,
2544+
xpub: Default::default(),
2545+
proprietary: Default::default(),
2546+
unknown: Default::default(),
2547+
inputs: vec![
2548+
Input {
2549+
non_witness_utxo: Some(prev_tx),
2550+
witness_utxo: None,
2551+
..Default::default()
2552+
}
2553+
],
2554+
outputs: vec![Output::default()],
2555+
};
2556+
2557+
assert!(matches!(psbt.fee(), Err(Error::PsbtUtxoOutOfbounds)));
2558+
assert!(matches!(psbt.internal_extract_tx_with_fee_rate_limit(FeeRate::MAX), Err(ExtractTxError::MissingInputAmount { tx: _ })))
2559+
}
2560+
25052561
#[test]
25062562
#[cfg(all(feature = "rand", feature = "std"))]
25072563
fn hashmap_can_sign_taproot() {

0 commit comments

Comments
 (0)