Skip to content

fix(wallet): added the validation of UTXO data for build_fee_bump #1913

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions crates/wallet/src/wallet/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ pub enum BuildFeeBumpError {
IrreplaceableTransaction(Txid),
/// Node doesn't have data to estimate a fee rate
FeeRateUnavailable,
/// Input references an invalid output index in the previous transaction
InvalidOutputIndex(OutPoint),
}

impl fmt::Display for BuildFeeBumpError {
Expand All @@ -247,6 +249,11 @@ impl fmt::Display for BuildFeeBumpError {
write!(f, "Transaction can't be replaced with txid: {}", txid)
}
Self::FeeRateUnavailable => write!(f, "Fee rate unavailable"),
Self::InvalidOutputIndex(outpoint) => write!(
f,
"Input references an invalid output index {} in transaction {}",
outpoint.vout, outpoint.txid
),
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions crates/wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,10 +1642,15 @@ impl Wallet {
.ok_or(BuildFeeBumpError::UnknownUtxo(txin.previous_output))
.map(|chain_position| (prev_tx, chain_position))
})
.map(|(prev_tx, chain_position)| {
.and_then(|(prev_tx, chain_position)| {
if txin.previous_output.vout as usize >= prev_tx.output.len() {
return Err(BuildFeeBumpError::InvalidOutputIndex(
txin.previous_output,
));
}
let txout = prev_tx.output[txin.previous_output.vout as usize].clone();
match txout_index.index_of_spk(txout.script_pubkey.clone()) {
Some(&(keychain, derivation_index)) => (
Some(&(keychain, derivation_index)) => Ok((
txin.previous_output,
WeightedUtxo {
satisfaction_weight: self
Expand All @@ -1661,14 +1666,14 @@ impl Wallet {
chain_position,
}),
},
),
)),
None => {
let satisfaction_weight = Weight::from_wu_usize(
serialize(&txin.script_sig).len() * 4
+ serialize(&txin.witness).len(),
);

(
Ok((
txin.previous_output,
WeightedUtxo {
utxo: Utxo::Foreign {
Expand All @@ -1685,7 +1690,7 @@ impl Wallet {
},
satisfaction_weight,
},
)
))
}
}
})
Expand Down
Loading