Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

create_psbt skips full-prevtx requirement for PSBT-backed SegWit v0 inputs

Open Beginner friendly
#89 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
blockchain

Research direction

Read the PSBT input handling in src/selection.rs, especially the early return in Selection::create_psbt_with_rng and the later non_witness_utxo checks. Add the reproduction test from the issue to the src/selection.rs test module and run cargo test. Done means the test returns MissingFullTxForSegwitV0Input for a PSBT-backed SegWit v0 input with only witness_utxo.

Written by the indexing model from the issue text.

Description

bug

Describe the bug

PsbtParams::mandate_full_tx_for_segwit_v0 defaults to true and is documented as
requiring the full previous transaction (non_witness_utxo) for SegWit v0 inputs.
However, Selection::create_psbt_with_rng returns early for inputs added via
Input::from_psbt_input: it copies the supplied psbt::Input and continues before
reaching the non_witness_utxo checks (src/selection.rs:280-308 on master). A SegWit
v0 input carrying only a witness_utxo therefore produces a PSBT with no
non_witness_utxo, even with default params, so the prevout amount goes unverified
against a full previous transaction.

This issue was found by AI.

To Reproduce

Add to the src/selection.rs test module and run cargo test:

#[test]
fn test_psbt_input_still_requires_full_tx_for_segwit_v0() -> anyhow::Result<()> {
    let secp = Secp256k1::new();
    let (desc, _) = Descriptor::<DescriptorPublicKey>::parse_descriptor(
        &secp,
        &format!("wpkh({TEST_HEX_PK})"),
    )?;
    let prev_txout = TxOut {
        script_pubkey: desc.at_derivation_index(0)?.script_pubkey(),
        value: Amount::from_sat(100_000),
    };
    let input = Input::from_psbt_input(
        OutPoint::null(),
        Sequence::ENABLE_RBF_NO_LOCKTIME,
        bitcoin::psbt::Input {
            witness_utxo: Some(prev_txout),
            ..Default::default()
        },
        100,
        None,
        false,
        None,
    )?;
    let selection = Selection::new(
        vec![input],
        vec![Output::with_script(ScriptBuf::new(), Amount::from_sat(90_000))],
    );

    assert!(matches!(
        selection.create_psbt(PsbtParams::default()),
        Err(CreatePsbtError::MissingFullTxForSegwitV0Input(_))
    ));

    Ok(())
}

On master (b00f35b) this fails: create_psbt returns Ok and the emitted PSBT
input has non_witness_utxo: None.

Expected behavior

The full-previous-transaction requirement for SegWit v0 inputs should apply
consistently, including for inputs imported from an existing PSBT.

Build environment

  • bdk_tx tag/commit: b00f35b (master)

Additional context

The same code path also exists in the open refactors #73 (TxTemplate::build_psbt),
#82 and #85, so a fix should cover those if they land first.

Dominant language
Rust
Stars
13
Forks
17
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bitcoindevkit/bdk-tx

All issues in bitcoindevkit/bdk-tx

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.