Skip to content

fix(wallet): sign mixed taproot and non-taproot inputs - #641

Merged
noahjoeris merged 2 commits into
bitcoindevkit:masterfrom
noahjoeris:fix/mixed-taproot-signing
Nov 12, 2026
Merged

noahjoeris merged 2 commits into
bitcoindevkit:masterfrom
noahjoeris:fix/mixed-taproot-signing

Conversation

@noahjoeris

@noahjoeris noahjoeris commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fix a 3.2.0 regression where mixed Taproot/non-Taproot transactions fail signing with MissingNonWitnessUtxo.

Verify Taproot amounts against parent transactions already stored in the wallet. Skip verification only when all inputs are verified Taproot without ANYONECANPAY.

Thanks @nymius for prompting a closer look #423 (comment).

Changelog notice

Fix signing of mixed Taproot/non-Taproot transactions.

Before submitting

Since 3.2.0, the wallet refused to sign these because taproot inputs
never get `non_witness_utxo`. Verify taproot amounts against the
parent tx stored in the wallet instead. Also verify amounts when
ANYONECANPAY is used.
@noahjoeris noahjoeris added this to the Wallet 3.3.0 milestone Nov 9, 2026
@noahjoeris noahjoeris self-assigned this Nov 9, 2026
@noahjoeris
noahjoeris requested a review from a team as a code owner November 9, 2026 11:59
@github-project-automation github-project-automation Bot moved this to Triage in BDK Wallet Nov 9, 2026
@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.02%. Comparing base (91d3f8e) to head (32dd8d8).

Files with missing lines Patch % Lines
src/wallet/signer.rs 80.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #641      +/-   ##
==========================================
+ Coverage   81.87%   82.02%   +0.14%     
==========================================
  Files          25       25              
  Lines        6291     6310      +19     
  Branches      302      308       +6     
==========================================
+ Hits         5151     5176      +25     
+ Misses       1035     1031       -4     
+ Partials      105      103       -2     
Flag Coverage Δ
rust 82.02% <95.45%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fametrano fametrano left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 32dd8d8

I checked the signatures with btclib, a library I maintain, against the outputs in the wallet's own graph, not the PSBT. At 32dd8d8 the wallet signs a taproot input beside a p2wpkh or p2pkh input, once with the default sighash and once with ALL|ANYONECANPAY on every input, and each transaction verifies; on master 91d3f8e each fails with MissingNonWitnessUtxo. The two new tests fail on master, and the suite passes here.

Following nymius's point on #423 about PSBTs passed to other signers, I had a second wallet sign its p2pkh input in the same transaction: it refuses until the taproot input carries its parent, then signs, and all three inputs verify. On master that step fails with WrongSigningAlgorithm.

The probe and its output: https://gist.github.com/fametrano/a53b5adf339fce067dc8b30f894c7e73/9000bfb6205a78820260bd1e14ad201831d137f3

@notmandatory notmandatory left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 32dd8d8

I ran local tests and manually reviewed the change and ran it through LLM review. The LLM found a related issue that could be fixed in this PR or I'll open a new one, up to you.

Comment thread src/wallet/mod.rs
{
return match input.witness_utxo.as_ref() {
Some(witness) if witness != prevout => Err(SignerError::InvalidNonWitnessUtxo),
_ => Ok(()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ => Ok(()),
Some(_) => Ok(()),
None => Err(SignerError::MissingWitnessUtxo),

LLM found issue where this should throw an error if no witness_utxo exists. Example test:

/// A missing later UTXO must not leave signatures from earlier ANYONECANPAY inputs.
#[test]
fn test_psbt_taproot_anyone_can_pay_missing_later_utxo_does_not_sign() {
    use bitcoin::sighash::TapSighashType;

    let descriptor = get_test_tr_single_sig_xprv();
    let (mut wallet, _) = get_funded_wallet_single(descriptor);
    receive_output_in_latest_block(&mut wallet, Amount::from_sat(30_000));
    let recipient = wallet.next_unused_address(KeychainKind::External);
    let mut builder = wallet.build_tx();
    builder
        .drain_to(recipient.script_pubkey())
        .drain_wallet()
        .sighash(TapSighashType::AllPlusAnyoneCanPay.into());
    let mut psbt = builder.finish().unwrap();
    assert_eq!(psbt.inputs.len(), 2);
    assert!(psbt.inputs[1].non_witness_utxo.is_none());
    psbt.inputs[1].witness_utxo = None;

    let signers = signers_from_descriptor(&wallet, descriptor);
    let result = wallet.sign_with_signers(
        &mut psbt,
        &[&signers],
        SignOptions {
            allow_all_sighashes: true,
            ..Default::default()
         },
    );

    assert!(matches!(result, Err(SignerError::MissingWitnessUtxo)));
    assert!(
        psbt.inputs
            .iter()
            .all(|input| input.tap_key_sig.is_none() && input.tap_script_sigs.is_empty()),                                                                                         "a failed signing attempt must not leave signatures behind"
    );
}

@Musab1258

Musab1258 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

tACK 32dd8d8

I ran just pre-push (nightly fmt, check, clippy -D warnings, stable and unstable test suites, doc build): all pass.

I traced that the all_taproot gate is present in v3.2.0 (git show v3.2.0:src/wallet/mod.rs | grep -n all_taproot), and git log -S'all_taproot' upstream/release/3.x points to the signing refactor 5f0432f, which git tag --contains show was first shipped in v3.2.0 (7031448 on master). Is a 3.2.x backport planned?

I see the backport is already open in PR #643.

@noahjoeris
noahjoeris merged commit b8f6b1f into bitcoindevkit:master Nov 12, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Review to Done in BDK Wallet Nov 12, 2026
noahjoeris added a commit that referenced this pull request Nov 17, 2026
…ackport #641)

cb20372 test(wallet): sign mixed taproot and non-taproot inputs (Noah Joeris)
896224f fix(wallet): sign mixed taproot and non-taproot inputs (Noah Joeris)

Pull request description:

  ### Description

  Backport of #641 to `release/3.x`.

  Cherry-picked from #641: d01c07d, 32dd8d8.

  Depends on #636.

  ### Changelog notice

  Fixed signing of mixed taproot/non-taproot inputs.

  ### Before submitting

  - [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk_wallet/blob/master/CONTRIBUTING.md)

ACKs for top commit:
  Musab1258:
    tACK cb20372
  reez:
    ACK cb20372
  notmandatory:
    ACK cb20372

Tree-SHA512: da7488479cf3c83ab7543a01f16a440250c74c2cf9fdaf814831e8b96e523e7f1d6a99da66547c71851ded91db7849f78ef151271bf97c5f66f9b9bb5926ef87
noahjoeris added a commit that referenced this pull request Nov 19, 2026
…igning

5ed098b test(wallet): cover missing taproot witness utxo with anyonecanpay (Noah Joeris)
7eca236 fix(wallet): reject missing taproot witness utxo before signing (Noah Joeris)

Pull request description:

  ### Description

  A missing `witness_utxo` on a later Taproot ANYONECANPAY input could leave earlier inputs signed before returning an error.

  Reject missing `witness_utxo` during input amount validation, before signing. Add a regression test checking that no signatures remain.

  Addresses [notmandatory’s review comment](#641 (comment)). Targets `release/3.x`.

  ### Changelog notice

  #### Fixed

  - Reject missing Taproot witness UTXOs before signing ANYONECANPAY inputs.

  ### Before submitting

  - [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk_wallet/blob/master/CONTRIBUTING.md)
  - [ ] This PR breaks the existing API

Top commit has no ACKs.

Tree-SHA512: e80e52d129c13c1dff91248bc123bd9af87909a16030539fbf157dda4c875e0f984e6c3c766681f88b088d63f3905a2147371ee2b1b2fe7dec879279771c22c5
This was referenced Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants