Skip to content

Commit 00a57cf

Browse files
ItshMohevanlinjin
authored andcommitted
fix: Validate prevouts in get_psbt_input
Co-authored-by: 志宇 <hello@evanlinjin.me>
1 parent 606a34d commit 00a57cf

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

wallet/src/wallet/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,8 +2211,12 @@ impl Wallet {
22112211

22122212
let prev_output = utxo.outpoint;
22132213
if let Some(prev_tx) = self.indexed_graph.graph().get_tx(prev_output.txid) {
2214+
// We want to check that the prevout actually exists in the tx before continuing.
2215+
let prevout = prev_tx.output.get(prev_output.vout as usize).ok_or(
2216+
MiniscriptPsbtError::UtxoUpdate(miniscript::psbt::UtxoUpdateError::UtxoCheck),
2217+
)?;
22142218
if desc.is_witness() || desc.is_taproot() {
2215-
psbt_input.witness_utxo = Some(prev_tx.output[prev_output.vout as usize].clone());
2219+
psbt_input.witness_utxo = Some(prevout.clone());
22162220
}
22172221
if !desc.is_taproot() && (!desc.is_witness() || !only_witness_utxo) {
22182222
psbt_input.non_witness_utxo = Some(prev_tx.as_ref().clone());

0 commit comments

Comments
 (0)