mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 23:48:12 +00:00
legacy/firmware: validate script type only in full-mode known_path_check (#1216)
(cherry picked from commit 07bd330d98
)
This commit is contained in:
parent
41f5237967
commit
8c2e20c26b
@ -531,7 +531,6 @@ bool coin_known_path_check(const CoinInfo *coin, InputScriptType script_type,
|
|||||||
// m/44' : BIP44 Legacy
|
// m/44' : BIP44 Legacy
|
||||||
// m / purpose' / coin_type' / account' / change / address_index
|
// m / purpose' / coin_type' / account' / change / address_index
|
||||||
if (address_n_count > 0 && address_n[0] == (0x80000000 + 44)) {
|
if (address_n_count > 0 && address_n[0] == (0x80000000 + 44)) {
|
||||||
valid &= (script_type == InputScriptType_SPENDADDRESS);
|
|
||||||
if (full) {
|
if (full) {
|
||||||
valid &= (address_n_count == 5);
|
valid &= (address_n_count == 5);
|
||||||
} else {
|
} else {
|
||||||
@ -539,6 +538,7 @@ bool coin_known_path_check(const CoinInfo *coin, InputScriptType script_type,
|
|||||||
}
|
}
|
||||||
valid &= check_cointype(coin, address_n[1], full);
|
valid &= check_cointype(coin, address_n[1], full);
|
||||||
if (full) {
|
if (full) {
|
||||||
|
valid &= (script_type == InputScriptType_SPENDADDRESS);
|
||||||
valid &= (address_n[2] & 0x80000000) == 0x80000000;
|
valid &= (address_n[2] & 0x80000000) == 0x80000000;
|
||||||
valid &= (address_n[3] & 0x80000000) == 0;
|
valid &= (address_n[3] & 0x80000000) == 0;
|
||||||
valid &= (address_n[4] & 0x80000000) == 0;
|
valid &= (address_n[4] & 0x80000000) == 0;
|
||||||
@ -549,8 +549,8 @@ bool coin_known_path_check(const CoinInfo *coin, InputScriptType script_type,
|
|||||||
// m/45' - BIP45 Copay Abandoned Multisig P2SH
|
// m/45' - BIP45 Copay Abandoned Multisig P2SH
|
||||||
// m / purpose' / cosigner_index / change / address_index
|
// m / purpose' / cosigner_index / change / address_index
|
||||||
if (address_n_count > 0 && address_n[0] == (0x80000000 + 45)) {
|
if (address_n_count > 0 && address_n[0] == (0x80000000 + 45)) {
|
||||||
valid &= (script_type == InputScriptType_SPENDMULTISIG);
|
|
||||||
if (full) {
|
if (full) {
|
||||||
|
valid &= (script_type == InputScriptType_SPENDMULTISIG);
|
||||||
valid &= (address_n_count == 4);
|
valid &= (address_n_count == 4);
|
||||||
valid &= (address_n[1] & 0x80000000) == 0;
|
valid &= (address_n[1] & 0x80000000) == 0;
|
||||||
valid &= (address_n[2] & 0x80000000) == 0;
|
valid &= (address_n[2] & 0x80000000) == 0;
|
||||||
@ -564,9 +564,6 @@ bool coin_known_path_check(const CoinInfo *coin, InputScriptType script_type,
|
|||||||
// Electrum:
|
// Electrum:
|
||||||
// m / purpose' / coin_type' / account' / type' / change / address_index
|
// m / purpose' / coin_type' / account' / type' / change / address_index
|
||||||
if (address_n_count > 0 && address_n[0] == (0x80000000 + 48)) {
|
if (address_n_count > 0 && address_n[0] == (0x80000000 + 48)) {
|
||||||
valid &= (script_type == InputScriptType_SPENDMULTISIG) ||
|
|
||||||
(script_type == InputScriptType_SPENDP2SHWITNESS) ||
|
|
||||||
(script_type == InputScriptType_SPENDWITNESS);
|
|
||||||
if (full) {
|
if (full) {
|
||||||
valid &= (address_n_count == 5) || (address_n_count == 6);
|
valid &= (address_n_count == 5) || (address_n_count == 6);
|
||||||
} else {
|
} else {
|
||||||
@ -574,6 +571,9 @@ bool coin_known_path_check(const CoinInfo *coin, InputScriptType script_type,
|
|||||||
}
|
}
|
||||||
valid &= check_cointype(coin, address_n[1], full);
|
valid &= check_cointype(coin, address_n[1], full);
|
||||||
if (full) {
|
if (full) {
|
||||||
|
valid &= (script_type == InputScriptType_SPENDMULTISIG) ||
|
||||||
|
(script_type == InputScriptType_SPENDP2SHWITNESS) ||
|
||||||
|
(script_type == InputScriptType_SPENDWITNESS);
|
||||||
valid &= (address_n[2] & 0x80000000) == 0x80000000;
|
valid &= (address_n[2] & 0x80000000) == 0x80000000;
|
||||||
valid &= (address_n[4] & 0x80000000) == 0;
|
valid &= (address_n[4] & 0x80000000) == 0;
|
||||||
}
|
}
|
||||||
@ -583,7 +583,6 @@ bool coin_known_path_check(const CoinInfo *coin, InputScriptType script_type,
|
|||||||
// m/49' : BIP49 SegWit
|
// m/49' : BIP49 SegWit
|
||||||
// m / purpose' / coin_type' / account' / change / address_index
|
// m / purpose' / coin_type' / account' / change / address_index
|
||||||
if (address_n_count > 0 && address_n[0] == (0x80000000 + 49)) {
|
if (address_n_count > 0 && address_n[0] == (0x80000000 + 49)) {
|
||||||
valid &= (script_type == InputScriptType_SPENDP2SHWITNESS);
|
|
||||||
valid &= coin->has_segwit;
|
valid &= coin->has_segwit;
|
||||||
if (full) {
|
if (full) {
|
||||||
valid &= (address_n_count == 5);
|
valid &= (address_n_count == 5);
|
||||||
@ -592,6 +591,7 @@ bool coin_known_path_check(const CoinInfo *coin, InputScriptType script_type,
|
|||||||
}
|
}
|
||||||
valid &= check_cointype(coin, address_n[1], full);
|
valid &= check_cointype(coin, address_n[1], full);
|
||||||
if (full) {
|
if (full) {
|
||||||
|
valid &= (script_type == InputScriptType_SPENDP2SHWITNESS);
|
||||||
valid &= (address_n[2] & 0x80000000) == 0x80000000;
|
valid &= (address_n[2] & 0x80000000) == 0x80000000;
|
||||||
valid &= (address_n[3] & 0x80000000) == 0;
|
valid &= (address_n[3] & 0x80000000) == 0;
|
||||||
valid &= (address_n[4] & 0x80000000) == 0;
|
valid &= (address_n[4] & 0x80000000) == 0;
|
||||||
@ -602,7 +602,6 @@ bool coin_known_path_check(const CoinInfo *coin, InputScriptType script_type,
|
|||||||
// m/84' : BIP84 Native SegWit
|
// m/84' : BIP84 Native SegWit
|
||||||
// m / purpose' / coin_type' / account' / change / address_index
|
// m / purpose' / coin_type' / account' / change / address_index
|
||||||
if (address_n_count > 0 && address_n[0] == (0x80000000 + 84)) {
|
if (address_n_count > 0 && address_n[0] == (0x80000000 + 84)) {
|
||||||
valid &= (script_type == InputScriptType_SPENDWITNESS);
|
|
||||||
valid &= coin->has_segwit;
|
valid &= coin->has_segwit;
|
||||||
valid &= coin->bech32_prefix != NULL;
|
valid &= coin->bech32_prefix != NULL;
|
||||||
if (full) {
|
if (full) {
|
||||||
@ -612,6 +611,7 @@ bool coin_known_path_check(const CoinInfo *coin, InputScriptType script_type,
|
|||||||
}
|
}
|
||||||
valid &= check_cointype(coin, address_n[1], full);
|
valid &= check_cointype(coin, address_n[1], full);
|
||||||
if (full) {
|
if (full) {
|
||||||
|
valid &= (script_type == InputScriptType_SPENDWITNESS);
|
||||||
valid &= (address_n[2] & 0x80000000) == 0x80000000;
|
valid &= (address_n[2] & 0x80000000) == 0x80000000;
|
||||||
valid &= (address_n[3] & 0x80000000) == 0;
|
valid &= (address_n[3] & 0x80000000) == 0;
|
||||||
valid &= (address_n[4] & 0x80000000) == 0;
|
valid &= (address_n[4] & 0x80000000) == 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user