psbt: classify missing Taproot script-path signatures as signer #36039

Open
btcpavao wants to merge 1 commit from fix-taproot-psbt-analyze-role into master AGit
btcpavao commented 2026-08-20 14:30:35 +00:00 (Migrated from github.com)

This is my first Bitcoin Core PR.

I originally reported #36035 after running into this while experimenting with Taproot 2-of-3 multisig on Signet. After reporting it, I wanted to see whether I could actually trace the problem in the source code and try to fix it myself.

I used ChatGPT Pro as a tool to help me navigate the codebase, understand the PSBT analysis/signing flow, and test different hypotheses. I followed the changes myself, built Bitcoin Core locally, and ran the tests rather than just submitting generated code.

The issue appears to come from the Taproot script-path signing path not recording a missing signature in missing_sigs when a Schnorr signature is not available. AnalyzePSBT() uses missing_sigs to decide whether the next role should be signer. Without it, the PSBT was classified as updater, which is also why the GUI displayed “Transaction is missing some information about inputs.”

My first attempt at the fix did not work. The regression test still returned updater, which led me to notice that SignMuSig2() can return successfully without actually producing a Taproot script-path signature. I adjusted the change so that, after the Schnorr/MuSig2 attempts, a missing signature is recorded when no script-path signature was produced.

I also added a regression test that checks that this Taproot script-path case is classified as signer.

I tested the change locally with:

test/functional/rpc_psbt.py
test/functional/wallet_musig.py
test_bitcoin --run_test=psbt_tests
test_bitcoin --run_test=miniscript_tests
git diff --check

All of these passed with the current patch.

This appears to fix the behavior I reported in #36035. Since this is my first contribution, feedback on both the approach and the implementation is very welcome.

Fixes #36035

This is my first Bitcoin Core PR. I originally reported #36035 after running into this while experimenting with Taproot 2-of-3 multisig on Signet. After reporting it, I wanted to see whether I could actually trace the problem in the source code and try to fix it myself. I used ChatGPT Pro as a tool to help me navigate the codebase, understand the PSBT analysis/signing flow, and test different hypotheses. I followed the changes myself, built Bitcoin Core locally, and ran the tests rather than just submitting generated code. The issue appears to come from the Taproot script-path signing path not recording a missing signature in missing_sigs when a Schnorr signature is not available. AnalyzePSBT() uses missing_sigs to decide whether the next role should be signer. Without it, the PSBT was classified as updater, which is also why the GUI displayed “Transaction is missing some information about inputs.” My first attempt at the fix did not work. The regression test still returned updater, which led me to notice that SignMuSig2() can return successfully without actually producing a Taproot script-path signature. I adjusted the change so that, after the Schnorr/MuSig2 attempts, a missing signature is recorded when no script-path signature was produced. I also added a regression test that checks that this Taproot script-path case is classified as signer. I tested the change locally with: test/functional/rpc_psbt.py test/functional/wallet_musig.py test_bitcoin --run_test=psbt_tests test_bitcoin --run_test=miniscript_tests git diff --check All of these passed with the current patch. This appears to fix the behavior I reported in #36035. Since this is my first contribution, feedback on both the approach and the implementation is very welcome. Fixes #36035
DrahtBot commented 2026-08-20 14:30:43 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36122 (BIP460: CISA for Taproot key path spends by fjahr)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36039 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36039.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36039#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36122](https://github.com/bitcoin/bitcoin/pull/36122) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36122.svg"></sub> (BIP460: CISA for Taproot key path spends by fjahr) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
achow101 (Migrated from github.com) reviewed 2026-08-20 18:16:42 +00:00
Lines 398-399
achow101 (Migrated from github.com) commented 2026-08-20 18:16:42 +00:00

This results in the analysis still being incorrect for transactions involving a musig.

This results in the analysis still being incorrect for transactions involving a musig.
btcpavao (Migrated from github.com) reviewed 2026-08-20 19:32:38 +00:00
Lines 398-399
btcpavao (Migrated from github.com) commented 2026-08-20 19:32:38 +00:00

Thanks, I reproduced this with a Taproot script-path MuSig2 case. My previous change was incorrectly treating the aggregate key as an ordinary missing Schnorr signature.

I updated the patch to distinguish when SignMuSig2() actually matched a MuSig2 aggregate, and only add missing_sigs for the non-MuSig case. I also added a regression check for the MuSig2 script-path case. wallet_musig.py, rpc_psbt.py, psbt_tests, and miniscript_tests pass locally.

Thanks, I reproduced this with a Taproot script-path MuSig2 case. My previous change was incorrectly treating the aggregate key as an ordinary missing Schnorr signature. I updated the patch to distinguish when `SignMuSig2()` actually matched a MuSig2 aggregate, and only add `missing_sigs` for the non-MuSig case. I also added a regression check for the MuSig2 script-path case. `wallet_musig.py`, `rpc_psbt.py`, `psbt_tests`, and `miniscript_tests` pass locally.
First-time contributor

Base: a829aeaac1aff6cb786aab7d2514b49eb233334b
Head: 641b52828ad93ed5ff33f5789908802f1e4fbfde

Design and approach

Clarify signer classification when a Taproot hash preimage is missing (src/script/sign.cpp:405, head)

For a Tapscript satisfaction that requires both a signature and a hash preimage, Miniscript can attempt the signature even when the preimage is unavailable. This change records missing_sigs, but AnalyzePSBT does not check the missing-preimage state when selecting signer. Should the input remain updater until the preimage is supplied, or does signer mean a signer can contribute despite another missing satisfaction item? Add a mixed signature/hash-preimage analysis test and, if the intended role is updater, include the missing preimage in the role decision. No concrete producer of this mixed Taproot PSBT was identified, so its production frequency is unconfirmed.

Define the role for MuSig2 script-path nonce publication (src/script/sign.cpp:404, head)

SignMuSig2 marks a matching aggregate as MuSig2 before producing a script-path signature, so this guard can suppress missing_sigs for a fresh MuSig2 script-path input. The added functional test consequently expects updater, and the subsequent wallet-processing flow begins public-nonce exchange. Clarify whether nonce publication is updater work or whether signer is intended to include it. If publication is updater work, the guard and expectation are appropriate; if signer should cover that stage, aggregate recognition alone should not suppress the missing-signature classification.

💡 Suggestion

Assert the missing-signature diagnostic (test/functional/rpc_psbt.py:1347, head)

This regression test verifies the signer role but does not check the missing.signatures entry produced by this path. Assert the expected key ID derived from the Taproot script key to cover the diagnostic's x-only-key mapping and RPC exposure while preserving the existing role assertion.

Review coverage was incomplete. The archaeology review had incomplete evidence. The adversarial review had incomplete evidence. The adversarial_glm review did not complete.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> Base: `a829aeaac1aff6cb786aab7d2514b49eb233334b` Head: `641b52828ad93ed5ff33f5789908802f1e4fbfde` ##### Design and approach **Clarify signer classification when a Taproot hash preimage is missing** (src/script/sign.cpp:405, head) For a Tapscript satisfaction that requires both a signature and a hash preimage, Miniscript can attempt the signature even when the preimage is unavailable. This change records `missing_sigs`, but `AnalyzePSBT` does not check the missing-preimage state when selecting `signer`. Should the input remain `updater` until the preimage is supplied, or does `signer` mean a signer can contribute despite another missing satisfaction item? Add a mixed signature/hash-preimage analysis test and, if the intended role is `updater`, include the missing preimage in the role decision. No concrete producer of this mixed Taproot PSBT was identified, so its production frequency is unconfirmed. **Define the role for MuSig2 script-path nonce publication** (src/script/sign.cpp:404, head) `SignMuSig2` marks a matching aggregate as MuSig2 before producing a script-path signature, so this guard can suppress `missing_sigs` for a fresh MuSig2 script-path input. The added functional test consequently expects `updater`, and the subsequent wallet-processing flow begins public-nonce exchange. Clarify whether nonce publication is updater work or whether `signer` is intended to include it. If publication is updater work, the guard and expectation are appropriate; if `signer` should cover that stage, aggregate recognition alone should not suppress the missing-signature classification. ##### 💡 Suggestion **Assert the missing-signature diagnostic** (test/functional/rpc_psbt.py:1347, head) This regression test verifies the `signer` role but does not check the `missing.signatures` entry produced by this path. Assert the expected key ID derived from the Taproot script key to cover the diagnostic's x-only-key mapping and RPC exposure while preserving the existing role assertion. Review coverage was incomplete. The archaeology review had incomplete evidence. The adversarial review had incomplete evidence. The adversarial_glm review did not complete. [Full review report](<https://review.fish.foo/traces/36039-641b52828ad93ed5ff33f5789908802f1e4fbfde-280-1.html>)
achow101 (Migrated from github.com) reviewed 2026-10-02 21:24:22 +00:00
achow101 (Migrated from github.com) commented 2026-10-02 21:24:22 +00:00

In 641b52828a "psbt: classify missing Taproot script-path signatures as signer"

Adding an output parameter here is entirely unnecessary. SignMuSig2 has access to sigdata, it can update the fields itself if no signature was made.

In 641b52828ad93ed5ff33f5789908802f1e4fbfde "psbt: classify missing Taproot script-path signatures as signer" Adding an output parameter here is entirely unnecessary. `SignMuSig2` has access to `sigdata`, it can update the fields itself if no signature was made.
fametrano commented 2026-10-03 20:33:16 +00:00 (Migrated from github.com)

Tested 641b52828a: with a tr(H,pk(K)) script-path input carrying witness UTXO, leaf script, control block, internal key and merkle root but no signature, analyzepsbt says updater on the parent commit and signer with this PR, with missing.signatures naming K; a wallet holding only K signs and finalizes that PSBT unchanged, so a signature was all it lacked. psbt_tests, psbt_wallet_tests, miniscript_tests, script_tests and rpc_psbt.py, wallet_musig.py, wallet_taproot.py pass.

One thing to keep in mind for the restructure achow101 asked for: once SignMuSig2 records the missing signature itself, the key path gets the same treatment, because make_keypath_sig in SignTaproot calls SignMuSig2 too. Today a tr(K) input with PSBT_IN_TAP_INTERNAL_KEY and PSBT_IN_TAP_BIP32_DERIVATION and no signature is updater on both binaries, and the same wallet signs it; after the move it becomes signer, which is right. Two details follow from it. make_keypath_sig runs twice, with the internal key and then with the output key, so an unsigned tr(K) input would list both keys unless the second push is skipped once the first has listed a key; CreateSig already lists every key of a multisig, so either is defensible. And a key-path case in rpc_psbt.py would then belong in this PR, since its behaviour changes.

Tested 641b52828ad93ed5ff33f5789908802f1e4fbfde: with a `tr(H,pk(K))` script-path input carrying witness UTXO, leaf script, control block, internal key and merkle root but no signature, `analyzepsbt` says `updater` on the parent commit and `signer` with this PR, with `missing.signatures` naming `K`; a wallet holding only `K` signs and finalizes that PSBT unchanged, so a signature was all it lacked. `psbt_tests`, `psbt_wallet_tests`, `miniscript_tests`, `script_tests` and `rpc_psbt.py`, `wallet_musig.py`, `wallet_taproot.py` pass. One thing to keep in mind for the restructure achow101 asked for: once `SignMuSig2` records the missing signature itself, the key path gets the same treatment, because `make_keypath_sig` in `SignTaproot` calls `SignMuSig2` too. Today a `tr(K)` input with `PSBT_IN_TAP_INTERNAL_KEY` and `PSBT_IN_TAP_BIP32_DERIVATION` and no signature is `updater` on both binaries, and the same wallet signs it; after the move it becomes `signer`, which is right. Two details follow from it. `make_keypath_sig` runs twice, with the internal key and then with the output key, so an unsigned `tr(K)` input would list both keys unless the second push is skipped once the first has listed a key; `CreateSig` already lists every key of a multisig, so either is defensible. And a key-path case in `rpc_psbt.py` would then belong in this PR, since its behaviour changes.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36039
No description provided.