rpc, wallet: Support BIP322 simple message signing #36809

pull jaromil wants to merge 7 commits into bitcoin:master from jaromil:bip322-segwit changing 19 files +2277 −31
  1. jaromil commented at 2:04 AM on November 9, 2026: contributor

    Description

    The message RPCs currently support legacy compact signatures for P2PKH addresses. This adds BIP322 simple proofs for native P2WPKH, P2WSH and P2TR addresses, allowing users to sign and verify messages for these addresses without creating an on-chain transaction.

    signmessage uses the wallet’s existing descriptor signing machinery and requires a complete satisfaction. This includes P2WSH multisig and supported Miniscript satisfactions, and Taproot key and script paths. It returns smp followed by the base64-encoded serialized witness stack.

    verifymessage uses Core’s script interpreter to check the proof against the address and message. Verification requires no wallet or chain data and accepts both prefixed and older unprefixed simple proofs. Malformed base64 or witness serialization raises an RPC error; invalid proofs, unsupported signature formats and inconclusive results return false.

    The RPC names and argument counts are unchanged. P2PKH compact signatures and signmessagewithprivkey retain their existing behavior. Full signatures, proofs of funds and P2SH addresses, including wrapped SegWit, are outside this change. Signing remains limited to satisfactions available to the wallet.

    No consensus rules or signing-provider interfaces are changed. Help and release notes describe the supported formats and limitations.

    Related earlier work: #24058.

    Tests

    A shared fixture imports the applicable CC0 vectors from the pinned BIP: eight simple rows containing ten proofs, three hash cases and sixteen error cases. Published proofs are checked independently of locally generated signatures.

    Coverage includes:

    • bip322_tests and bip322_wallet_tests: transaction construction, parsing bounds, address binding, sighash and script rules, descriptor signing, incomplete satisfactions and wallet locking.
    • rpc_bip322.py: published proofs in both encodings, invalid proofs and network-specific address parsing.
    • Both existing message tests: legacy behavior, RPC errors and native witness signing.
    • rpc_help.py: updated help.
  2. util: Add BIP322 simple proof verification
    Add wallet-independent BIP322 simple proof verification for native P2WPKH,
    P2WSH and P2TR challenges. Construct the tagged message hash and virtual
    transactions, and verify witnesses with Core's script interpreter under
    the BIP's required and upgradeable rules.
    
    Use a local signature checker for the permitted sighash types. Distinguish
    invalid proofs from inconclusive upgrade mechanisms, and accept current
    smp signatures and pre-final unprefixed proofs, including witnesses whose
    Base64 text starts with a variant name. Existing legacy message routines
    retain their behavior.
    
    Include pinned BIP322 2.1.0 test vectors with CC0 provenance, regressions for
    encoding, commitments and script rules, and structured message fuzz inputs.
    The verification helpers provide the basis for wallet and RPC integration.
    5ca7dbaa62
  3. wallet: Sign BIP322 simple messages
    Sign native P2WPKH, P2WSH and P2TR message challenges with the wallet's
    descriptor data. Supply the zero-valued virtual output to the existing
    transaction signer and request SIGHASH_ALL for each supported type.
    
    Require a complete witness and successful BIP322 verification before
    returning an smp proof. Preserve the caller's output on failure, including
    when keys or script data are unavailable or the wallet is locked.
    
    Cover the published vector inputs, multisig thresholds, compound
    Miniscript and Taproot key and script paths. Add failure tests for partial
    signatures, encryption, unsupported destinations and timelocked policies.
    6d34a84df2
  4. DrahtBot commented at 2:04 AM on November 9, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36808 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36808.svg"></sub> (iwyu: Fix warnings in src/test/fuzz and treat them as errors by hebasto)
    • #36074 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36074.svg"></sub> (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)

    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-->

    LLM Linter (✨ experimental)

    Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

    • src/test/bip322_tests.cpp: SignatureHash(script, txs.to_sign, 0, hash_type, 0, SigVersion::WITNESS_V0)
    • src/test/bip322_tests.cpp: SignatureHashSchnorr(hash, exec, txs.to_sign, 0, hash_type, ...)
    • src/test/bip322_tests.cpp (OrdinaryVerify): data.Init(tx, {txs.to_spend.vout[0]}, true)
    • src/test/bip322_tests.cpp (SignSchnorr): data.Init(txs.to_sign, {txs.to_spend.vout[0]}, true)
    • src/test/bip322_tests.cpp: MakeTapProof(CScript() << OP_1, {}, 0xc2)
    • src/test/bip322_tests.cpp: MakeTapProof(CScript() << OP_CODESEPARATOR, {}, 0xc2)
    • src/wallet/test/bip322_wallet_tests.cpp (musig_nonce_lifetime): data.Init(tx, {txs.to_spend.vout[0]}, true)
    • src/wallet/test/bip322_wallet_tests.cpp (forbidden_script_commitments): data.Init(tx, {txs.to_spend.vout[0]}, true)

    <sup>2026-11-09 16:07:24</sup>

  5. DrahtBot added the label CI failed on Nov 9, 2026
  6. DrahtBot commented at 3:04 AM on November 9, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task lint: https://github.com/bitcoin/bitcoin/actions/runs/42548857757/job/128939706261</sub> <sub>LLM reason (✨ experimental): CI failed because the locale-dependence lint flagged std::to_string in src/wallet/test/bip322_wallet_tests.cpp.</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  7. rpc: Support BIP322 simple message signatures
    Route native P2WPKH, P2WSH and P2TR message signing and verification
    through the BIP322 simple proof helpers. Keep legacy P2PKH behavior.
    
    Add published-vector RPC tests, descriptor-wallet coverage and help
    describing the supported formats and signing limits.
    2aa9f02337
  8. jaromil force-pushed on Nov 9, 2026
  9. jaromil marked this as a draft on Nov 9, 2026
  10. wallet: Keep transaction signing nonces local
    Transaction-only signing exports scripts and witnesses but discards the
    public nonce data needed to resume a MuSig2 signing session. Give the merged
    provider call-local secret nonce storage so incomplete key-path attempts
    and successful script fallback release unused nonces when the call returns.
    The existing MuSig2SecNonce wrapper preserves secure allocation and cleanup.
    
    Keep persistent provider storage for ongoing PSBT sessions. Add repeated
    BIP322 and raw transaction signing regressions, and verify that split-wallet
    and all-local PSBT sessions survive intervening one-shot signing calls.
    21b05162ba
  11. common: Verify valid BIP322 proofs once
    Try required and upgrade rules together so valid BIP322 proofs need only one
    signature verification pass. On failure, retry the required rules and preserve
    required-error precedence and the original upgrade error.
    
    Keep commitment validation before the CODESEPARATOR scan and preserve annex
    and unknown-version classification. Pin Result/ScriptError precedence and the
    exact transaction-weight limit with regression tests.
    
    Validated with BIP322 unit and published-vector tests, full wallet-enabled
    CTest, and the three message-signing functional tests. An isolated checker-count
    probe confirms one delegated check for each valid single-signature proof form.
    b8a0cf6fba
  12. wallet: Compact BIP322 proofs and explain limits
    Request SIGHASH_DEFAULT for wallet message proofs to omit the extra
    Taproot sighash byte. Keep witness-v0 signatures on SIGHASH_ALL and
    check that their deterministic proof bytes match explicit ALL signing.
    
    Explain the fixed simple-proof transaction fields and incompatible
    timelock requirements in RPC help and release notes, while allowing
    other satisfiable script branches or Taproot key paths.
    3463180937
  13. test: Fuzz scripts with matching commitments
    Generate bounded script-derived P2WSH proofs and depth-zero Taproot
    proofs with matching output keys and control blocks. Preserve the
    existing program/proof parser and legacy message checks so existing
    corpus inputs retain their behavior.
    
    Verify execution and classification using deterministic seeds,
    source coverage, sanitizer fuzzing and the branch-wide test gates.
    4874938957
  14. DrahtBot removed the label CI failed on Nov 9, 2026
  15. jaromil marked this as ready for review on Nov 9, 2026
  16. jaromil force-pushed on Nov 9, 2026
  17. DrahtBot added the label Needs rebase on Nov 10, 2026
  18. DrahtBot commented at 1:47 PM on November 10, 2026: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.


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-11-18 16:51 UTC

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