wallet: Fix MaxSatisfactionWeight calculation for Taproot descriptors #34314

pull tboy1337 wants to merge 1 commits into bitcoin:master from tboy1337:fix-tr-descriptor-weight changing 3 files +79 −19
  1. tboy1337 commented at 7:17 am on January 16, 2026: none

    This PR fixes a bug in the MaxSatisfactionWeight calculation for Taproot descriptors. Previously, the implementation contained a FIXME comment and only calculated keypath spend weight, leading to significant underestimations for script path spending.

    What Changed:

    1. TaprootDescriptor::MaxSatisfactionWeight - Replaced the placeholder implementation with proper script path weight calculation:

    • Now iterates through all subdescriptors to find the heaviest script path
    • Uses MaxSatSize() instead of MaxSatisfactionWeight() for subdescriptors (Taproot SegWit v1 has a 1:1 ratio between witness bytes and weight units, unlike the 4:1 ratio in legacy SegWit v0)
    • Accounts for satisfaction size, script size, and control block size
    • Returns the maximum of keypath (66 weight units) and all script paths

    2. PKDescriptor::MaxSatSize - Corrected Schnorr signature size from 65 to 64 bytes (SIGHASH_DEFAULT is omitted in Schnorr signatures)

    3. MultiADescriptor::MaxSatSize - Corrected Schnorr signature size from 65 to 64 bytes

    4. Added comprehensive unit tests - New test case descriptor_tr_max_satisfaction_weight with:

    • Test for tr(key, pk(key)) verifying script path weight (134) exceeds keypath weight (66)
    • Test for tr(key, sortedmulti_a(2, K1, K2)) verifying complex script path calculation (235 weight units)
    • Detailed comments explaining the weight calculations for each component

    Why:

    Accurate weight estimation for Taproot descriptors is critical for:

    • Fee calculation - Underestimated weights lead to insufficient fees and transaction rejection
    • Transaction size estimation - Affects PSBT construction and validation
    • Wallet coin selection - Incorrect weights cause suboptimal UTXO selection

    The tests demonstrate the bug (old code would return 66 for both cases) and prove the fix produces correct weight estimates.

  2. DrahtBot added the label Wallet on Jan 16, 2026
  3. DrahtBot commented at 7:17 am on January 16, 2026: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34314.

    Reviews

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #32861 (Have createwalletdescriptor auto-detect an unused(KEY) by Sjors)
    • #32857 (wallet: allow skipping script paths by Sjors)
    • #32784 (wallet: derivehdkey RPC to get xpub at arbitrary path by Sjors)
    • #29136 (wallet: addhdkey RPC to add just keys to wallets via new unused(KEY) descriptor by achow101)

    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.

  4. DrahtBot added the label CI failed on Jan 16, 2026
  5. tboy1337 force-pushed on Jan 17, 2026
  6. tboy1337 force-pushed on Jan 17, 2026
  7. tboy1337 marked this as ready for review on Jan 17, 2026
  8. Fix MaxSatisfactionWeight calculation for Taproot descriptors
    - Fix MaxSatisfactionWeight calculation for Taproot descriptors
    - Update wallet_taproot.py to allow customizable fee rates in sendtoaddress and PSBT tests
    - Refactor confirmation assertions in WalletTaprootTest to use assert_greater_than
    - Increase -maxtxfee for wallet_taproot.py test to accommodate larger weight estimates
    
    The corrected MaxSatisfactionWeight calculation results in larger (but accurate) weight estimates for Taproot descriptors. For the test case with MAX_PUBKEYS_PER_MULTI_A-1 H_POINTs (~34KB script), using fee_rate=2000 sat/vB with the correct weight exceeds the default -maxtxfee limit of 0.1 BTC. Increase -maxtxfee to 1 BTC to allow the test to proceed with the higher fees.
    4725a48cb3
  9. tboy1337 force-pushed on Jan 20, 2026
  10. tboy1337 commented at 1:36 pm on January 20, 2026: none
    CI was failing before the most recent updates to wallet_taproot.py.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-01-22 09:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me