Prevent registration of policies with musigs we cannot fully sign
What changed, and why it matters
This commit adds a safety check in Ledger's Bitcoin app to stop users from registering wallet policies that contain a MuSig2 group with more than one Ledger-managed internal key. The app can only produce one partial signature per MuSig2 group, so such policies would be impossible to fully sign later. The change rejects the registration early with a clear error code, preventing users from accidentally creating a wallet they could not spend from.
No immediate action required for users. This is a hardening change. Developers should ensure the new validation is also applied to any other code paths that parse or accept wallet policies, and consider whether similar restrictions are needed for signing-time policy acceptance.
Security signals we found
New error code for unsupported MuSig2 configuration
Registration-time policy validation added
Test cases explicitly exercise the rejected MuSig2 multi-internal-key case
Evidence from the diff
The patch introduces a new registration-time validation in src/handler/register_wallet.c. It walks all key expressions in the wallet policy and, for each musig() expression, counts how many of its participant keys are marked as internal (PUBKEY_TYPE_INTERNAL). If any musig() contains more than one internal key, registration is rejected with SW_NOT_SUPPORTED and a new extended error code EC_REGISTER_WALLET_MUSIG_WITH_MULTIPLE_INTERNAL_KEYS (0x0003). A corresponding test is added in tests/test_register_wallet.py covering multiple descriptor templates where two internal keys appear inside the same musig().
Changed components
Ledger Bitcoin app wallet registration handlerMuSig2 policy signing pathsrc/handler/register_wallet.csrc/error_codes.hInspect captured patch +78 / −0
### src/error_codes.h
@@ -18,6 +18,9 @@
// No key in the wallet policy was recognized as internal.
#define EC_REGISTER_WALLET_POLICY_HAS_NO_INTERNAL_KEY 0x0002
+// A musig() key expression in the wallet policy has more than one internal key.
+#define EC_REGISTER_WALLET_MUSIG_WITH_MULTIPLE_INTERNAL_KEYS 0x0003
+
/**
* SIGN_PSBT
*/
### src/handler/register_wallet.c
@@ -21,6 +21,7 @@
/* SDK headers */
#include "bip32.h"
#include "cx.h"
+#include "ledger_assert.h"
#include "os.h"
#include "read.h"
#include "write.h"
@@ -45,6 +46,9 @@
static bool is_policy_acceptable(const policy_node_t *policy);
static bool is_policy_name_acceptable(const char *name, size_t name_len);
+static bool has_musig_with_multiple_internal_keys(
+ const policy_node_t *policy,
+ const key_type_e keys_type[static MAX_N_KEYS_IN_WALLET_POLICY]);
static const uint8_t BIP0341_NUMS_PUBKEY[] = {0x02, 0x50, 0x92, 0x9b, 0x74, 0xc1, 0xa0, 0x49, 0x54,
0xb7, 0x8b, 0x4b, 0x60, 0x35, 0xe9, 0x7a, 0x5e, 0x07,
@@ -169,6 +173,13 @@ __attribute__((noinline)) static void confirm_and_register_wallet(
return;
}
+ // MuSig2 signing produces at most one partial signature per musig() key expression, so a
+ // musig() would be tricky to spend: we reject it instead. Not useful anyway.
+ if (has_musig_with_multiple_internal_keys(policy, keys_type)) {
+ SEND_SW_EC(dc, SW_NOT_SUPPORTED, EC_REGISTER_WALLET_MUSIG_WITH_MULTIPLE_INTERNAL_KEYS);
+ return;
+ }
+
// Try to compute the cleartext spending-path lines. If the descriptor
// doesn't classify (DC_OTHER), has non-canonical derivations, or its
// confusion score exceeds the threshold, the cleartext block is skipped
@@ -334,3 +345,34 @@ static bool is_policy_name_acceptable(const char *name, size_t name_len) {
return true;
}
+
+/**
+ * Returns true if any musig() key expression of the policy has more than one internal key.
+ */
+static bool has_musig_with_multiple_internal_keys(
+ const policy_node_t *policy,
+ const key_type_e keys_type[static MAX_N_KEYS_IN_WALLET_POLICY]) {
+ int n_key_expressions = get_keyexpr_by_index(policy, 0, NULL, NULL);
+ LEDGER_ASSERT(n_key_expressions >= 0, "Unexpected error retrieving key expression");
+
+ for (int i = 0; i < n_key_expressions; i++) {
+ policy_node_keyexpr_t *key_expr;
+ int ret = get_keyexpr_by_index(policy, i, NULL, &key_expr);
+ LEDGER_ASSERT(ret >= 0, "Unexpected error retrieving key expression");
+ if (key_expr->type != KEY_EXPRESSION_MUSIG) {
+ continue;
+ }
+
+ const musig_aggr_key_info_t *musig_info = key_expr->m.musig_info;
+ int n_internal_keys = 0;
+ for (int j = 0; j < musig_info->n; j++) {
+ if (keys_type[musig_info->key_indexes[j]] == PUBKEY_TYPE_INTERNAL) {
+ ++n_internal_keys;
+ }
+ }
+ if (n_internal_keys > 1) {
+ return true;
+ }
+ }
+ return false;
+}
### tests/test_register_wallet.py
@@ -227,6 +227,39 @@ def test_register_wallet_unsupported_policy(navigator: Navigator, firmware: Firm
assert len(e.value.data) == 0
+def test_register_wallet_musig_multiple_internal_keys(client: RaggerClient):
+ # The device can only produce one partial signature per musig() key expression, therefore
+ # musig() key expressions with more than one internal key are not supported.
+
+ # defined in error_codes.h
+ EC_REGISTER_WALLET_MUSIG_WITH_MULTIPLE_INTERNAL_KEYS = 0x0003
+
+ keys_info = [
+ # @0 and @1 are both internal
+ "[f5acc2fd/48'/1'/0'/2']tpubDFAqEGNyad35aBCKUAXbQGDjdVhNueno5ZZVEn3sQbW5ci457gLR7HyTmHBg93oourBssgUxuWz1jX5uhc1qaqFo9VsybY1J5FuedLfm4dK",
+ "[f5acc2fd/48'/1'/0'/1']tpubDFAqEGNyad35YgH8zxvxFZqNUoPtr5mDojs7wzbXQBHTZ4xHeVXG6w2HvsKvjBpaRpTmjYDjdPg5w2c6Wvu8QBkyMDrmBWdCyqkDM7reSsY",
+ "tpubDE7NQymr4AFtewpAsWtnreyq9ghkzQBXpCZjWLFVRAvnbf7vya2eMTvT2fPapNqL8SuVvLQdbUbMfWLVDCZKnsEBqp6UK93QEzL8Ck23AwF",
+ ]
+
+ for descriptor_template in [
+ "tr(musig(@0,@1)/**,pk(@2/**))",
+ "tr(musig(@2,@0,@1)/**)",
+ "tr(@0/**,pk(musig(@1,@2,@0)/**))",
+ "tr(@2/**,multi_a(1,@0/<2;3>/*,musig(@0,@1)/**))",
+ ]:
+ with pytest.raises(ExceptionRAPDU) as e:
+ client.register_wallet(WalletPolicy(
+ name="Musig with 2 internal keys",
+ descriptor_template=descriptor_template,
+ keys_info=keys_info,
+ ))
+
+ assert DeviceException.exc.get(e.value.status) == NotSupportedError
+ assert len(e.value.data) == 2
+ error_code = int.from_bytes(e.value.data, 'big')
+ assert error_code == EC_REGISTER_WALLET_MUSIG_WITH_MULTIPLE_INTERNAL_KEYS
+
+
def test_register_miniscript_long_policy(navigator: Navigator, firmware: Firmware, client:
RaggerClient, test_name: str, speculos_globals):
# This test makes sure that policies longer than 256 bytes work as expected on all devicesWhy this scored 39/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.