Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test unchained paths #4382

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions legacy/firmware/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -573,6 +559,30 @@ 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_SPENDADDRESS ||
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);
Expand Down
13 changes: 13 additions & 0 deletions tests/device_tests/bitcoin/test_unchained_paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path


def test_singlesig_p2wsh(client: Client):
btc.get_address(
client,
"Bitcoin",
parse_path("m/45h/0/0/0/0/0"),
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
show_display=True,
)
Loading