Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`PsbtUtils::fee_amount` panics when PSBT outputs exceed inputs

Aperta Adatta ai principianti
#558 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@shubham5080 ci sta già lavorando.

Dal 16/9/2026.

  • #564 di @shubham5080 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
api, backend

Direzione di ricerca

Inizia in src/psbt/mod.rs, su PsbtUtils::fee_amount, e ispeziona la documentazione del trait e la delega a fee_rate. Aggiungi un test di regressione usando il caso outputs-exceed-inputs fornito, quindi verifica che il comportamento scelto e visibile al chiamante sia coperto e che fee_amount e fee_rate non causino più panic.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Describe the bug

PsbtUtils::fee_amount (src/psbt/mod.rs) computes the fee as input_amount.checked_sub(output_amount).expect("input amount must be greater than output amount"). When the PSBT's outputs sum to more than its inputs, checked_sub returns None and the expect panics. fee_rate delegates to fee_amount, so it panics too.

The trait docs only say None is returned when a TxOut is missing for an input; there is no documented precondition that outputs are bounded by inputs. Since PSBTs are commonly received from other parties (coinjoin, payjoin, externally produced PSBTs), callers displaying a fee before signing can hit this on well-formed but inconsistent input.

This issue was found by AI.

To Reproduce

use bdk_wallet::psbt::PsbtUtils;
use bitcoin::{Amount, OutPoint, Psbt, ScriptBuf, Transaction, TxIn, TxOut, absolute, transaction};

#[test]
fn fee_amount_when_outputs_exceed_inputs() {
    let prev_tx = Transaction {
        version: transaction::Version::TWO,
        lock_time: absolute::LockTime::ZERO,
        input: vec![TxIn::default()],
        output: vec![TxOut {
            value: Amount::from_sat(50_000),
            script_pubkey: ScriptBuf::default(),
        }],
    };
    let unsigned_tx = Transaction {
        version: transaction::Version::TWO,
        lock_time: absolute::LockTime::ZERO,
        input: vec![TxIn {
            previous_output: OutPoint::new(prev_tx.compute_txid(), 0),
            ..Default::default()
        }],
        output: vec![TxOut {
            value: Amount::from_sat(90_000),
            script_pubkey: ScriptBuf::default(),
        }],
    };
    let mut psbt = Psbt::from_unsigned_tx(unsigned_tx).unwrap();
    psbt.inputs[0].non_witness_utxo = Some(prev_tx);

    // panics at src/psbt/mod.rs:79: "input amount must be greater than output amount"
    let _ = psbt.fee_amount();
}

Expected behavior

fee_amount / fee_rate should not panic on a PSBT whose outputs exceed its inputs; the condition should be signalled to the caller (e.g. via the return value) or documented as a precondition.

Build environment

  • BDK tag/commit: 6fc68462 (master)

Which backend(s) are relevant (if any)?

  • None / not backend-related (e.g. bdk_chain, bdk_core)

Is this blocking production use?

  • No
Lingua principale
Rust
Stelle
61
Fork
116
Merge medio
7h 29m
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bitcoindevkit/bdk_wallet

Tutte le issue di bitcoindevkit/bdk_wallet

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.