From f160812102e140e91a28d17d8ba2a3358574954d Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 5 Nov 2024 16:37:50 -0900 Subject: [PATCH 1/4] feat: check for multisig or segwit on Unchained path. chore: add changelog --- legacy/firmware/.changelog.d/4324.added | 2 ++ legacy/firmware/crypto.c | 39 +++++++++++++++---------- 2 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 legacy/firmware/.changelog.d/4324.added diff --git a/legacy/firmware/.changelog.d/4324.added b/legacy/firmware/.changelog.d/4324.added new file mode 100644 index 0000000000..a5573f9e44 --- /dev/null +++ b/legacy/firmware/.changelog.d/4324.added @@ -0,0 +1,2 @@ + +Unchained paths for p2wsh multisig diff --git a/legacy/firmware/crypto.c b/legacy/firmware/crypto.c index 5d1f4ae907..0ac89810da 100644 --- a/legacy/firmware/crypto.c +++ b/legacy/firmware/crypto.c @@ -517,7 +517,7 @@ bool coin_path_check(const CoinInfo *coin, InputScriptType script_type, return valid; } - if (address_n[0] == PATH_HARDENED + 45) { + if (address_n[0] == PATH_HARDENED + 45 && address_n_count != 6) { if (address_n_count == 4) { // m/45' - BIP45 Copay Abandoned Multisig P2SH // m / purpose' / cosigner_index / change / address_index @@ -546,20 +546,6 @@ bool coin_path_check(const CoinInfo *coin, InputScriptType script_type, valid = valid && (address_n[3] <= PATH_MAX_CHANGE); valid = valid && (address_n[4] <= PATH_MAX_ADDRESS_INDEX); } - } else if (address_n_count == 6) { - // Unchained Capital compatibility pattern. Will be removed in the - // future. - // m/45'/coin_type'/account'/[0-1000000]/change/address_index - // m/45'/coin_type/account/[0-1000000]/change/address_index - valid = valid && - check_cointype(coin, PATH_HARDENED | address_n[1], full_check); - valid = valid && ((address_n[1] & PATH_HARDENED) == - (address_n[2] & PATH_HARDENED)); - valid = - valid && ((address_n[2] & PATH_UNHARDEN_MASK) <= PATH_MAX_ACCOUNT); - valid = valid && (address_n[3] <= 1000000); - valid = valid && (address_n[4] <= PATH_MAX_CHANGE); - valid = valid && (address_n[5] <= PATH_MAX_ADDRESS_INDEX); } else { return false; } @@ -573,6 +559,29 @@ bool coin_path_check(const CoinInfo *coin, InputScriptType script_type, return valid; } + if (address_n[0] == PATH_HARDENED + 45 && address_n_count == 6) { + // Unchained Capital compatibility pattern. + // m/45'/coin_type'/account'/[0-1000000]/change/address_index + // m/45'/coin_type/account/[0-1000000]/change/address_index + valid = + valid && check_cointype(coin, PATH_HARDENED | address_n[1], full_check); + valid = valid && + ((address_n[1] & PATH_HARDENED) == (address_n[2] & PATH_HARDENED)); + valid = valid && ((address_n[2] & PATH_UNHARDEN_MASK) <= PATH_MAX_ACCOUNT); + valid = valid && (address_n[3] <= 1000000); + valid = valid && (address_n[4] <= PATH_MAX_CHANGE); + valid = valid && (address_n[5] <= PATH_MAX_ADDRESS_INDEX); + valid = valid && has_multisig; + + if (full_check) { + valid = valid && (script_type == InputScriptType_SPENDMULTISIG || + script_type == InputScriptType_SPENDWITNESS); + valid = valid && has_multisig; + } + + return valid; + } + if (address_n[0] == PATH_HARDENED + 48) { valid = valid && (address_n_count == 5 || address_n_count == 6); valid = valid && check_cointype(coin, address_n[1], full_check); From 2915d6e6be9cbb5f5fa680f31fe249ac0979ca0c Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 20 Nov 2024 12:34:35 -0900 Subject: [PATCH 2/4] fix: address feedback concerning a possible regression from previous --- legacy/firmware/crypto.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/legacy/firmware/crypto.c b/legacy/firmware/crypto.c index 0ac89810da..13ae025f24 100644 --- a/legacy/firmware/crypto.c +++ b/legacy/firmware/crypto.c @@ -574,7 +574,8 @@ bool coin_path_check(const CoinInfo *coin, InputScriptType script_type, valid = valid && has_multisig; if (full_check) { - valid = valid && (script_type == InputScriptType_SPENDMULTISIG || + valid = valid && (script_type == InputScriptType_SPENDADDRESS || + script_type == InputScriptType_SPENDMULTISIG || script_type == InputScriptType_SPENDWITNESS); valid = valid && has_multisig; } From 8ae3a80f9c65bddf156c1b9805ff0c97f2ab618d Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 28 Nov 2024 13:13:57 -0900 Subject: [PATCH 3/4] chore: remove empty leading line from changelog --- legacy/firmware/.changelog.d/4324.added | 1 - 1 file changed, 1 deletion(-) diff --git a/legacy/firmware/.changelog.d/4324.added b/legacy/firmware/.changelog.d/4324.added index a5573f9e44..7cdb440516 100644 --- a/legacy/firmware/.changelog.d/4324.added +++ b/legacy/firmware/.changelog.d/4324.added @@ -1,2 +1 @@ - Unchained paths for p2wsh multisig From 8e124415f7bdf095ea25267772d7bb27d6ed7d01 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 28 Nov 2024 13:22:15 -0900 Subject: [PATCH 4/4] fix: remove extraneous has_multisig check --- legacy/firmware/crypto.c | 1 - 1 file changed, 1 deletion(-) diff --git a/legacy/firmware/crypto.c b/legacy/firmware/crypto.c index 13ae025f24..08f457b182 100644 --- a/legacy/firmware/crypto.c +++ b/legacy/firmware/crypto.c @@ -571,7 +571,6 @@ bool coin_path_check(const CoinInfo *coin, InputScriptType script_type, valid = valid && (address_n[3] <= 1000000); valid = valid && (address_n[4] <= PATH_MAX_CHANGE); valid = valid && (address_n[5] <= PATH_MAX_ADDRESS_INDEX); - valid = valid && has_multisig; if (full_check) { valid = valid && (script_type == InputScriptType_SPENDADDRESS ||