From b741560997822962b345ea8c7b7d3baa70bf82dc Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 16 Jul 2020 11:43:32 +0200 Subject: [PATCH] core/bitcoin: drop unused validate_path_for_bitcoin_public_key --- core/src/apps/bitcoin/addresses.py | 24 +------------ core/tests/test_apps.bitcoin.address.py | 46 +------------------------ 2 files changed, 2 insertions(+), 68 deletions(-) diff --git a/core/src/apps/bitcoin/addresses.py b/core/src/apps/bitcoin/addresses.py index 01774a3b81..ddd9e40eaa 100644 --- a/core/src/apps/bitcoin/addresses.py +++ b/core/src/apps/bitcoin/addresses.py @@ -4,7 +4,7 @@ from trezor.crypto.hashlib import sha256 from trezor.messages import InputScriptType from trezor.messages.MultisigRedeemScriptType import MultisigRedeemScriptType -from apps.common import HARDENED, address_type, paths +from apps.common import HARDENED, address_type from apps.common.coininfo import CoinInfo from .common import ecdsa_hash_pubkey, encode_bech32_address @@ -232,25 +232,3 @@ def validate_purpose_against_script_type( if purpose == 84 | HARDENED and script_type != InputScriptType.SPENDWITNESS: return False return True - - -def validate_path_for_bitcoin_public_key(path: list, coin: CoinInfo) -> bool: - """ - Validates derivation path to fit Bitcoin-like coins for GetPublicKey. - """ - length = len(path) - if length < 3 or length > 5: - return False - - if not validate_purpose(path[0], coin): - return False - - if path[1] != coin.slip44 | HARDENED: - return False - if path[2] < HARDENED or path[2] > 20 | HARDENED: - return False - if length > 3 and paths.is_hardened(path[3]): - return False - if length > 4 and paths.is_hardened(path[4]): - return False - return True diff --git a/core/tests/test_apps.bitcoin.address.py b/core/tests/test_apps.bitcoin.address.py index f83845bf69..5a7a080b84 100644 --- a/core/tests/test_apps.bitcoin.address.py +++ b/core/tests/test_apps.bitcoin.address.py @@ -2,7 +2,7 @@ from common import * from trezor.crypto import bip32, bip39 from trezor.utils import HashWriter -from apps.bitcoin.addresses import validate_full_path, validate_path_for_bitcoin_public_key +from apps.bitcoin.addresses import validate_full_path from apps.common.paths import HARDENED from apps.common import coins from apps.bitcoin import scripts @@ -220,50 +220,6 @@ class TestAddress(unittest.TestCase): for path, input_type in incorrect_derivation_paths: self.assertFalse(validate_full_path(path, coin, input_type)) - def test_paths_public_key(self): - incorrect_derivation_paths = [ - [49 | HARDENED], # invalid length - [49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], # too many HARDENED - [49 | HARDENED, 0 | HARDENED], # invalid length - [49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 0, 0], # invalid length - [49 | HARDENED, 123 | HARDENED, 0 | HARDENED, 0, 0, 0], # invalid slip44 - [49 | HARDENED, 0 | HARDENED, 1000 | HARDENED, 0, 0], # account too high - ] - correct_derivation_paths = [ - [44 | HARDENED, 0 | HARDENED, 0 | HARDENED], # btc is segwit coin, but non-segwit paths are allowed as well - [44 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 0], - [49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 0], - [49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 0], - [49 | HARDENED, 0 | HARDENED, 5 | HARDENED], - [84 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 0], - [84 | HARDENED, 0 | HARDENED, 5 | HARDENED, 0, 0], - [84 | HARDENED, 0 | HARDENED, 5 | HARDENED, 0, 10], - ] - coin = coins.by_name('Bitcoin') - for path in correct_derivation_paths: - self.assertTrue(validate_path_for_bitcoin_public_key(path, coin)) - - for path in incorrect_derivation_paths: - self.assertFalse(validate_path_for_bitcoin_public_key(path, coin)) - - @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") - def test_paths_public_key_nosegwit(self): - incorrect_derivation_paths = [ - [49 | HARDENED, 3 | HARDENED, 0 | HARDENED, 0, 0], # no segwit - ] - correct_derivation_paths = [ - [44 | HARDENED, 3 | HARDENED, 0 | HARDENED], - [44 | HARDENED, 3 | HARDENED, 1 | HARDENED], - [44 | HARDENED, 3 | HARDENED, 0 | HARDENED, 0], - [44 | HARDENED, 3 | HARDENED, 0 | HARDENED, 0, 0], - ] - coin = coins.by_name('Dogecoin') # segwit is disabled - for path in correct_derivation_paths: - self.assertTrue(validate_path_for_bitcoin_public_key(path, coin)) - - for path in incorrect_derivation_paths: - self.assertFalse(validate_path_for_bitcoin_public_key(path, coin)) - if __name__ == '__main__': unittest.main()