Skip to content

fix(psbt): return None from fee_amount on overflow or negative fee - #564

Open
shubham5080 wants to merge 1 commit into
bitcoindevkit:masterfrom
shubham5080:fix/psbt-fee-amount
Open

shubham5080 wants to merge 1 commit into
bitcoindevkit:masterfrom
shubham5080:fix/psbt-fee-amount

Conversation

@shubham5080

Copy link
Copy Markdown

Description

PsbtUtils::fee_amount panics or wraps on hostile/inconsistent PSBTs:

fee_rate delegates to fee_amount, so it fails the same way. PSBTs often come from another party (coinjoin, payjoin, an external builder), so this is reachable before signing.

This change uses checked_add / checked_sub and returns None when the fee cannot be computed. Callers already treat None as "unknown fee".

Fixes #558
Fixes #559

Notes to the reviewers

Kept using get_utxo_for rather than delegating to rust-bitcoin's Psbt::fee(), so the existing txid / vout checks on non_witness_utxo still apply.

Return type is unchanged (Option<Amount>). Invalid PSBTs that previously panicked now return None.

Changelog notice

Fixed

Before submitting

PsbtUtils::fee_amount summed Amounts with Iterator::sum and then
checked_sub(...).expect(...). A PSBT whose outputs exceed its inputs
panicked, and summing past u64::MAX overflowed (panic in debug, wrap in
release). fee_rate delegates to fee_amount so it hit the same bugs.

Use checked_add / checked_sub and return None when the fee cannot be
computed. Callers already treat None as "unknown fee".

Fixes bitcoindevkit#558
Fixes bitcoindevkit#559
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

PsbtUtils::fee_amount overflows when summing input or output amounts PsbtUtils::fee_amount panics when PSBT outputs exceed inputs

1 participant