diff --git a/src/apps/common/coininfo.py b/src/apps/common/coininfo.py index 34535a9dd8..321ac1ccac 100644 --- a/src/apps/common/coininfo.py +++ b/src/apps/common/coininfo.py @@ -644,6 +644,26 @@ COINS = [ decred=False, curve_name='secp256k1-groestl', ), + CoinInfo( + coin_name="Komodo", + coin_shortcut="KMD", + address_type=60, + address_type_p2sh=85, + maxfee_kb=1000000, + signed_message_header="Komodo Signed Message:\n", + xpub_magic=0x0488b21e, + xpub_magic_segwit_p2sh=None, + xpub_magic_segwit_native=None, + bech32_prefix=None, + cashaddr_prefix=None, + slip44=141, + segwit=False, + fork_id=None, + force_bip143=False, + bip115=False, + decred=False, + curve_name='secp256k1', + ), CoinInfo( coin_name="Koto", coin_shortcut="KOTO", diff --git a/src/apps/wallet/sign_tx/signing.py b/src/apps/wallet/sign_tx/signing.py index ef37fbae38..474ab0de12 100644 --- a/src/apps/wallet/sign_tx/signing.py +++ b/src/apps/wallet/sign_tx/signing.py @@ -66,9 +66,9 @@ async def check_tx_fee(tx: SignTx, keychain: seed.Keychain): tx_ser = TxRequestSerializedType() elif tx.overwintered: if tx.version == 3: - hash143 = zcash.Zip143() # ZIP-0143 transaction hashing + hash143 = zcash.Zip143(tx.branch_id) # ZIP-0143 transaction hashing elif tx.version == 4: - hash143 = zcash.Zip243() # ZIP-0243 transaction hashing + hash143 = zcash.Zip243(tx.branch_id) # ZIP-0243 transaction hashing else: raise SigningError( FailureType.DataError, diff --git a/src/apps/wallet/sign_tx/zcash.py b/src/apps/wallet/sign_tx/zcash.py index 366b35ac83..a192922a2e 100644 --- a/src/apps/wallet/sign_tx/zcash.py +++ b/src/apps/wallet/sign_tx/zcash.py @@ -1,3 +1,4 @@ +import ustruct as struct from micropython import const from trezor.crypto.hashlib import blake2b @@ -45,7 +46,8 @@ def derive_script_code(txi: TxInputType, pubkeyhash: bytes) -> bytearray: class Zip143: - def __init__(self): + def __init__(self, branch_id): + self.branch_id = branch_id self.h_prevouts = HashWriter(blake2b(outlen=32, personal=b"ZcashPrevoutHash")) self.h_sequence = HashWriter(blake2b(outlen=32, personal=b"ZcashSequencHash")) self.h_outputs = HashWriter(blake2b(outlen=32, personal=b"ZcashOutputsHash")) @@ -78,8 +80,10 @@ class Zip143: sighash: int, ) -> bytes: h_preimage = HashWriter( - blake2b(outlen=32, personal=b"ZcashSigHash\x19\x1b\xa8\x5b") - ) # BRANCH_ID = 0x5ba81b19 / Overwinter + blake2b( + outlen=32, personal=b"ZcashSigHash" + struct.pack(" bytes: h_preimage = HashWriter( - blake2b(outlen=32, personal=b"ZcashSigHash\xbb\x09\xb8\x76") - ) # BRANCH_ID = 0x76b809bb / Sapling + blake2b( + outlen=32, personal=b"ZcashSigHash" + struct.pack(" None: self.outputs_count = outputs_count self.inputs_count = inputs_count @@ -27,6 +28,7 @@ class SignTx(p.MessageType): self.overwintered = overwintered self.version_group_id = version_group_id self.timestamp = timestamp + self.branch_id = branch_id @classmethod def get_fields(cls): @@ -40,4 +42,5 @@ class SignTx(p.MessageType): 7: ('overwintered', p.BoolType, 0), 8: ('version_group_id', p.UVarintType, 0), 9: ('timestamp', p.UVarintType, 0), + 10: ('branch_id', p.UVarintType, 0), } diff --git a/src/trezor/messages/TransactionType.py b/src/trezor/messages/TransactionType.py index 6acb65156e..4bb3de1eed 100644 --- a/src/trezor/messages/TransactionType.py +++ b/src/trezor/messages/TransactionType.py @@ -30,6 +30,7 @@ class TransactionType(p.MessageType): overwintered: bool = None, version_group_id: int = None, timestamp: int = None, + branch_id: int = None, ) -> None: self.version = version self.inputs = inputs if inputs is not None else [] @@ -44,6 +45,7 @@ class TransactionType(p.MessageType): self.overwintered = overwintered self.version_group_id = version_group_id self.timestamp = timestamp + self.branch_id = branch_id @classmethod def get_fields(cls): @@ -61,4 +63,5 @@ class TransactionType(p.MessageType): 11: ('overwintered', p.BoolType, 0), 12: ('version_group_id', p.UVarintType, 0), 13: ('timestamp', p.UVarintType, 0), + 14: ('branch_id', p.UVarintType, 0), } diff --git a/tests/test_apps.wallet.zcash.zip143.py b/tests/test_apps.wallet.zcash.zip143.py index 3c55320a35..0d8b174797 100644 --- a/tests/test_apps.wallet.zcash.zip143.py +++ b/tests/test_apps.wallet.zcash.zip143.py @@ -151,7 +151,7 @@ class TestZcashZip143(unittest.TestCase): overwintered=(v["version"] >= 3), version_group_id=v["version_group_id"], ) - zip143 = Zip143() + zip143 = Zip143(0x5ba81b19) # Overwinter for i in v["inputs"]: txi = TxInputType() txi.amount = i["amount"] diff --git a/tests/test_apps.wallet.zcash.zip243.py b/tests/test_apps.wallet.zcash.zip243.py index ce43e3985b..cb6a9848a1 100644 --- a/tests/test_apps.wallet.zcash.zip243.py +++ b/tests/test_apps.wallet.zcash.zip243.py @@ -185,7 +185,7 @@ class TestZcashZip243(unittest.TestCase): overwintered=(v["version"] >= 3), version_group_id=v["version_group_id"], ) - zip243 = Zip243() + zip243 = Zip243(0x76b809bb) # Sapling for i in v["inputs"]: txi = TxInputType() txi.amount = i["amount"] diff --git a/vendor/trezor-common b/vendor/trezor-common index ee25c4a6f4..4b41d2e638 160000 --- a/vendor/trezor-common +++ b/vendor/trezor-common @@ -1 +1 @@ -Subproject commit ee25c4a6f4d8e36770b4bc2d6b962076547260aa +Subproject commit 4b41d2e63841517bf701618434c018acf4f1bca2 diff --git a/vendor/trezor-crypto b/vendor/trezor-crypto index d1c52401e4..21391dc5be 160000 --- a/vendor/trezor-crypto +++ b/vendor/trezor-crypto @@ -1 +1 @@ -Subproject commit d1c52401e4c76c74a10455682ace0655b7aa644c +Subproject commit 21391dc5be9917bc32a518cf98376f79103727af