Skip to content

rpc, wallet: Support BIP322 simple message signing - #36809

Open
jaromil wants to merge 7 commits into
bitcoin:masterfrom
jaromil:bip322-segwit
Open

jaromil wants to merge 7 commits into
bitcoin:masterfrom
jaromil:bip322-segwit

Conversation

@jaromil

@jaromil jaromil commented Nov 9, 2026 •

Copy link
Copy Markdown
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.

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.
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.
@DrahtBot

DrahtBot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • #36808 (iwyu: Fix warnings in src/test/fuzz and treat them as errors by hebasto)
  • #36074 (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.

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)

2026-11-09 16:07:24

@DrahtBot

DrahtBot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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

Hints

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.

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.
@jaromil
jaromil marked this pull request as draft November 9, 2026 08:26
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.
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.
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.
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.
@DrahtBot

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants