Skip to content

MuSig2 power - #91

Open
Sjors wants to merge 81 commits into
masterfrom
2025/06/musig2-power
Open

Sjors wants to merge 81 commits into
masterfrom
2025/06/musig2-power

Conversation

@Sjors

@Sjors Sjors commented Jun 25, 2025 •

Copy link
Copy Markdown
Owner

Combines the following:

It then introduces:

  • support the new HWI registerdescriptor command
  • store the registration, use for signing and address display
  • make musig2 signing more ergonomic (e.g. do both rounds if all signers are connected)
  • functional test for musig2 with external signer

The MuSig2-specific commits integrate with
bitcoin-core/HWI#794.

The general workflow is:

  • create an external-signer wallet and import an active
    tr(musig(...)/<0;1>/*) descriptor;
  • register it with
    bitcoin-cli -rpcwallet=<wallet> registerdescriptor "MuSig wallet";
  • verify a receive address with walletdisplayaddress;
  • fund the wallet;
  • spend with a single send call.

Bitcoin Core performs both MuSig2 signing rounds in-process. It collects public
nonces, retries signing once the nonce set is complete, collects partial
signatures, aggregates the final Schnorr signature, and broadcasts.

Descriptor registration and registered signing are fanned out to all connected
external signers. This supports wallets whose MuSig2 participants live on
multiple hardware devices. Registrations can be inspected through
getwalletinfo.external_signer_registrations.

If a signer fails after a local MuSig2 contribution was added, the returned
PSBT preserves that contribution so signing can be resumed later.

Tests:

build/bin/test_bitcoin \
  --run_test=descriptor_tests,key_io_tests,psbt_tests,script_tests,transaction_tests,txvalidationcache_tests,wallet_tests,walletload_tests,psbt_wallet_tests,scriptpubkeyman_tests,walletdb_tests,wallet_rpc_tests

python3 build/test/functional/test_runner.py \
  rpc_psbt.py \
  rpc_signer.py \
  wallet_backwards_compatibility.py \
  wallet_createwalletdescriptor.py \
  wallet_derivehdkey.py \
  wallet_descriptor.py \
  wallet_exported_watchonly.py \
  wallet_fundrawtransaction.py \
  wallet_hd.py \
  wallet_importdescriptors.py \
  wallet_listdescriptors.py \
  wallet_multisig_descriptor_psbt.py \
  wallet_musig.py \
  wallet_signer.py \
  wallet_signer_musig2.py \
  wallet_taproot.py

./ci/lint.py

The HWI end-to-end test also exercises this branch against the Ledger Bitcoin
app under Speculos: descriptor registration, address display, funding, both
MuSig2 signing rounds, broadcast, and confirmation.

@Sjors

Sjors commented Aug 1, 2025

Copy link
Copy Markdown
Owner Author

Fresh rebase after bitcoin#31244 landed.

@Sjors

Sjors commented Aug 5, 2025

Copy link
Copy Markdown
Owner Author

Added bitcoin#33135 and the latest change to bitcoin#33008 (storing one hmac record per policy and fingerprint combination).

@Sjors

Sjors commented Aug 6, 2025 •

Copy link
Copy Markdown
Owner Author

The registerpolicy will now derive the BIP388 policy and perform registration (for some basic descriptor forms). Spending still requires manually passing the PSBT(s) to HWI with bitcoin-core/HWI#794. You should no longer need MooSig, except to display an address.

The fixup commits reflect changes made to the original branches. I'll up the commit history occasionally when one of its dependencies lands.

@Sjors

Sjors commented Oct 31, 2025

Copy link
Copy Markdown
Owner Author

bitcoin#29675 landed! Waiting for bitcoin#29136 to get a rebase so I can update the stack here.

Sjors pushed a commit that referenced this pull request Dec 29, 2025
@Sjors
Sjors force-pushed the 2025/06/musig2-power branch from c1959d3 to a42a034 Compare January 5, 2026 05:02
@Sjors

Sjors commented Jan 5, 2026

Copy link
Copy Markdown
Owner Author

Rebased! bitcoin#32821 and bitcoin#33135 also landed. Down from 67 commits to 44. I haven't had a chance to manually retest the whole flow though.

@Sjors
Sjors force-pushed the 2025/06/musig2-power branch from a42a034 to 25e66d9 Compare January 22, 2026 11:46
@Sjors

Sjors commented Jan 22, 2026

Copy link
Copy Markdown
Owner Author

Rebased after bitcoin#32471 landed. Down to 37 commits.

@Sjors
Sjors force-pushed the 2025/06/musig2-power branch from 25e66d9 to b7bb56e Compare January 22, 2026 16:03
@Sjors
Sjors force-pushed the 2025/06/musig2-power branch from b7bb56e to 14c7fce Compare February 2, 2026 16:03
@Sjors
Sjors force-pushed the 2025/06/musig2-power branch from 14c7fce to 018d066 Compare February 17, 2026 08:06
@Sjors Sjors mentioned this pull request Apr 28, 2026
@Sjors
Sjors force-pushed the 2025/06/musig2-power branch from 018d066 to cf24e00 Compare April 28, 2026 10:19
@Sjors

Sjors commented Apr 28, 2026

Copy link
Copy Markdown
Owner Author

Added #110 which (very roughly) implements BIP388 policy support for displaying addresses.

@Sjors

Sjors commented Apr 28, 2026

Copy link
Copy Markdown
Owner Author

Added #111 for signing support.

@Sjors
Sjors force-pushed the 2025/06/musig2-power branch 2 times, most recently from 684b910 to 6268484 Compare April 28, 2026 17:40
Sjors added 26 commits November 9, 2026 13:00
…essing and revamp mock

# Conflicts:
#	test/functional/wallet_signer.py
…ors in one object

# Conflicts:
#	src/script/descriptor.cpp
#	src/wallet/imports.cpp
#	src/wallet/test/walletload_tests.cpp

Integration fixes carried by this merge:
- Adapt SubstituteMasterExtPubs from bitcoin/bitcoin 35377 to KeyPath
  elements and the stored hardened character, keeping the provider
  members it reads accessible.
- Adapt the bitcoin/bitcoin 35377 import and walletload test code to
  single multipath Parse() results.
- Keep serialize_hd_keypath coverage for hardened and unhardened
  key-path serialization.
- Reserve the known extended-key serialization length in bip32_tests to
  avoid a GCC 14 -Warray-bounds false positive in the 32-bit ARM build.
…ptors

# Conflicts:
#	src/wallet/test/walletload_tests.cpp

Integration fixes carried by this merge:
- Keep both walletload test descriptor overrides.
- Include <variant> for the comparison operators used by multipath
  reconstruction, satisfying IWYU.
…ionships

# Conflicts:
#	src/wallet/imports.cpp
#	test/functional/wallet_importdescriptors.py

Integration fixes carried by this merge:
- Keep both the known-key lookup from bitcoin/bitcoin 35377 and the
  multipath relationship tracking in ImportDescriptor.
- Repair the extracted importdescriptors tests: generate keys inside
  test_import_multipath and test_older, and call them and the
  bitcoin/bitcoin 35377 tests from run_test.
- Drop an unused assert_not_equal import from wallet_listdescriptors.py.
- Fix Clang -Wthread-safety errors by locking each descriptor manager when
  reading its multipath descriptor or updating its relationships.
- Snapshot local keys, cache and relative IDs before acquiring relatives'
  locks, and retain shared descriptor ownership during reconstruction.
- Reconstruct exported multipath descriptors before taking the caller's
  descriptor lock, avoiding receive/change lock-order inversions.
bitcoin/bitcoin 33112 tests walletdisplayaddress for an imported
external-signer descriptor using the same xpub as a wallet exercised earlier
in wallet_signer.py. bitcoin/bitcoin 36114 then revamps the shared external
signer mock used by the test. With #127, the imported descriptor's
known HD keys are filled immediately, so its first address is recognized as
used and the wallet advances to the next index, which the mock intentionally
maps to wrong_address for a separate error case.

Let the test configure the address echoed by the mock so it remains
independent of the derived index while preserving the mismatched-address
coverage.
Reconstruct the policy from the stored receive and change SPKM relationships
for external signer registration. Require both descriptors to reference the
same ordered pair before registering.

Read both pairing relationships under their descriptor-manager locks, then
release those locks before reconstructing the registration policy.
Exercise descriptor registration and registered address display with a
tr(musig(...)) wallet. The mock validates the opaque registration and
the derived address, including rejection of an incorrect signer
response.
Multi-round signing flows like MuSig2 take two passes: round 1 exchanges
public nonces, round 2 produces partial signatures. A single
FillPSBT(sign=true) call therefore can never complete a fresh MuSig2
spend -- the user has to feed the round-1 PSBT back into FillPSBT a
second time. The 'send' RPC, the GUI's send-coins dialog, the GUI's
PSBT-operations dialog, and the bumpfee path all suffer from this: each
makes a single sign call and returns the round-1 PSBT to the user.

Hoist the second-pass logic into CWallet::FillPSBT itself so every
caller benefits without code duplication. After the first pass leaves
the PSBT incomplete, do a structural check: every input that
participates in a MuSig2 session must already have a complete set of pub
nonces from every expected participant. If so, run the same pass again
on a copy; on success adopt it, on failure preserve the round-1 result
so the caller can ferry the PSBT out-of-band as before.

Skipped for non-MuSig2 PSBTs (no participants entries) and for MuSig2
PSBTs where some cosigner's nonces are still missing, so we don't issue
an unnecessary device-confirmation prompt.

Note: PSBT_IN_MUSIG2_PARTICIPANT_PUBKEYS entries can't be paired to
PSBT_IN_MUSIG2_PUB_NONCE entries by aggregate pubkey -- the former
stores the pre-tweak aggregate while the latter stores the post-tweak
one (after BIP32 derivations and the BIP86 taproot tweak). The
structural check sidesteps that.

Refactor the existing one-pass body into a fill_pass lambda so both
rounds share it.
Drive registered MuSig2 signing through both nonce and partial-signature
rounds, and cover structured external-signer failures. The mock
delegates to real wallets to produce valid contributions so the result
can be finalized and broadcast.
RunCommandParseJSON throws when the signer subprocess exits non-zero,
for example after a device disconnect. Fold that exception into the
same PSBTError::EXTERNAL_SIGNER_FAILED path used for a structured signer
error, and cover both paths with the MuSig2 signer mock.
Treat a signer failure as soft when the local pass adds a MuSig2
pubnonce or partial signature. This preserves the matching secret nonce
and lets a later walletprocesspsbt resume after the device returns. Keep
failures hard when the local pass made no progress, avoiding silent
no-op success.
Enumerate every connected signer for descriptor registration and
signing, storing one opaque registration per fingerprint. Registered
address display uses the first matching signer. Cover a two-device
MuSig2 wallet that registers both devices and completes signing in one
call.
@Sjors
Sjors force-pushed the 2025/06/musig2-power branch 2 times, most recently from 7799531 to b7c6b7f Compare November 9, 2026 13:41
@Sjors Sjors mentioned this pull request Nov 9, 2026
@Sjors
Sjors added this pull request to stack #133 November 9, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants