From cd86f9f47798f55c9e64b288d5ecf69c9d44d7c4 Mon Sep 17 00:00:00 2001 From: matejcik Date: Fri, 31 Jul 2020 15:52:30 +0200 Subject: [PATCH] core/bitcoin: make change check more robust against short paths --- core/src/apps/bitcoin/sign_tx/bitcoin.py | 3 ++- core/src/apps/bitcoin/sign_tx/matchcheck.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/apps/bitcoin/sign_tx/bitcoin.py b/core/src/apps/bitcoin/sign_tx/bitcoin.py index f02731da99..585cd33a65 100644 --- a/core/src/apps/bitcoin/sign_tx/bitcoin.py +++ b/core/src/apps/bitcoin/sign_tx/bitcoin.py @@ -17,7 +17,7 @@ from apps.common import coininfo, seed from apps.common.writers import write_bitcoin_varint from .. import addresses, common, multisig, scripts, writers -from ..common import SIGHASH_ALL, ecdsa_sign +from ..common import BIP32_WALLET_DEPTH, SIGHASH_ALL, ecdsa_sign from ..ownership import verify_nonownership from ..verification import SignatureVerifier from . import approvers, helpers, progress @@ -541,6 +541,7 @@ class Bitcoin: return False return ( self.wallet_path.output_matches(txo) + and len(txo.address_n) >= BIP32_WALLET_DEPTH and txo.address_n[-2] <= _BIP32_CHANGE_CHAIN and txo.address_n[-1] <= _BIP32_MAX_LAST_ELEMENT and txo.amount > 0 diff --git a/core/src/apps/bitcoin/sign_tx/matchcheck.py b/core/src/apps/bitcoin/sign_tx/matchcheck.py index 48c8590d7e..738275e5c7 100644 --- a/core/src/apps/bitcoin/sign_tx/matchcheck.py +++ b/core/src/apps/bitcoin/sign_tx/matchcheck.py @@ -79,7 +79,7 @@ class MatchChecker: class WalletPathChecker(MatchChecker): def attribute_from_tx(self, txio: Union[TxInputType, TxOutputType]) -> Any: - if not txio.address_n: + if len(txio.address_n) < BIP32_WALLET_DEPTH: return None return txio.address_n[:-BIP32_WALLET_DEPTH]