Skip to content

fix(wallet): added the validation of previous tx outputs for get_psbt_input #1911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions crates/wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2153,11 +2153,23 @@ impl Wallet {

let prev_output = utxo.outpoint;
if let Some(prev_tx) = self.indexed_graph.graph().get_tx(prev_output.txid) {
if desc.is_witness() || desc.is_taproot() {
psbt_input.witness_utxo = Some(prev_tx.output[prev_output.vout as usize].clone());
}
if !desc.is_taproot() && (!desc.is_witness() || !only_witness_utxo) {
psbt_input.non_witness_utxo = Some(prev_tx.as_ref().clone());
// First validate that the vout index is within bounds
let vout_index = prev_output.vout as usize;
let outputs_len = prev_tx.output.len();

if vout_index < outputs_len {
if desc.is_witness() || desc.is_taproot() {
psbt_input.witness_utxo = Some(prev_tx.output[vout_index].clone());
}
if !desc.is_taproot() && (!desc.is_witness() || !only_witness_utxo) {
psbt_input.non_witness_utxo = Some(prev_tx.as_ref().clone());
}
} else {
// Use the existing UtxoUpdateError::IndexOutOfBounds variant
return Err(MiniscriptPsbtError::UtxoUpdate(
miniscript::psbt::UtxoUpdateError::UtxoCheck,
)
.into());
}
}
Ok(psbt_input)
Expand Down