create_psbt skips full-prevtx requirement for PSBT-backed SegWit v0 inputs
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
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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bitcoindevkit/bdk-tx
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bitcoindevkit/bdk-tx#90 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
bitcoindevkit/bdk-tx#83 ·
-
Relicense to dual MIT OR Apache-2.0May be free again @notmandatory claimed this 126 days ago, and no pull request is open. Openchore
bitcoindevkit/bdk-tx#78 · 8 comments · 1 assignee ·
-
api
Difficulty 4/5 3-5 days Newbie friendliness 66/100
bitcoindevkit/bdk-tx#77 · 1 comment ·
-
Finalizer doesn't enforce BIP-174 requirements (sighash type, unknown fields)May be free again @evanlinjin claimed this 129 days ago, and no pull request is open. Openbug
bitcoindevkit/bdk-tx#75 · 1 comment · 1 assignee ·
All issues in bitcoindevkit/bdk-tx
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
zcashlabs/thus-spoke-zakura#153 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
topgrade-rs/topgrade#2395 ·
Maintainers usually reply within 1 day
-
app bug windows-os
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
matrix-org/matrix-rust-sdk#7217 ·
Maintainers usually reply within 1 day
-
editor good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
funnyboy-roks/inq#54 ·