diff --git a/src/apps/wallet/sign_tx/scripts.py b/src/apps/wallet/sign_tx/scripts.py index 6f33211e3..8d8980f62 100644 --- a/src/apps/wallet/sign_tx/scripts.py +++ b/src/apps/wallet/sign_tx/scripts.py @@ -43,12 +43,15 @@ def output_script_p2sh(scripthash: bytes) -> bytearray: def script_replay_protection_bip115(block_hash: bytes, block_height: bytes) -> bytearray: - block_height_size = len(block_height) # SIZE in bytes block heigh (should be 3) + block_height_size = len(block_height) # size in bytes of block_height (should be 3) s = bytearray(38) s[0] = 0x20 # 32 bytes for block hash s[1:33] = block_hash # block hash s[33] = 0x03 # 3 bytes for block height - s[34:37] = (block_height if (block_height_size == 3) else block_height[:3 - block_height_size]) # MUST BE ONLY 3 BYTES FOR BLOCKHEIGHT + if block_height_size == 3: + s[34:37] = block_height + else: + s[34:37] = block_height[:3 - block_height_size] # must be only 3 bytes s[37] = 0xB4 # OP_CHECKBLOCKHIGHT return s diff --git a/src/apps/wallet/sign_tx/signing.py b/src/apps/wallet/sign_tx/signing.py old mode 100755 new mode 100644 index 697a8eae9..17e37e40e --- a/src/apps/wallet/sign_tx/signing.py +++ b/src/apps/wallet/sign_tx/signing.py @@ -276,7 +276,7 @@ async def sign_tx(tx: SignTx, root: bip32.HDNode): txi_sign.multisig.m) elif txi_sign.script_type == InputScriptType.SPENDADDRESS: txi_sign.script_sig = output_script_p2pkh(ecdsa_hash_pubkey(key_sign_pub)) - if(coin.bip115 and txi_sign.prev_block_hash_bip115 is not None): + if coin.bip115: txi_sign.script_sig += script_replay_protection_bip115(txi_sign.prev_block_hash_bip115, txi_sign.prev_block_height_bip115) else: raise SigningError(FailureType.ProcessError, @@ -514,12 +514,18 @@ def output_derive_script(o: TxOutputType, coin: CoinInfo, root: bip32.HDNode) -> if address_type.check(coin.address_type, raw_address): # p2pkh pubkeyhash = address_type.strip(coin.address_type, raw_address) - return (output_script_p2pkh(pubkeyhash) + script_replay_protection_bip115(o.block_hash_bip115, o.block_height_bip115) if coin.bip115 else output_script_p2pkh(pubkeyhash)) + script = output_script_p2pkh(pubkeyhash) + if coin.bip115: + script += script_replay_protection_bip115(o.block_hash_bip115, o.block_height_bip115) + return script elif address_type.check(coin.address_type_p2sh, raw_address): # p2sh scripthash = address_type.strip(coin.address_type_p2sh, raw_address) - return (output_script_p2sh(scripthash) + script_replay_protection_bip115(o.block_hash_bip115, o.block_height_bip115) if coin.bip115 else output_script_p2sh(scripthash)) + script = output_script_p2sh(scripthash) + if coin.bip115: + script += script_replay_protection_bip115(o.block_hash_bip115, o.block_height_bip115) + return script raise SigningError(FailureType.DataError, 'Invalid address type') diff --git a/src/trezor/messages/TxInputType.py b/src/trezor/messages/TxInputType.py old mode 100755 new mode 100644 diff --git a/tests/test_apps.wallet.signtx.py b/tests/test_apps.wallet.signtx.py index 96920aaa5..8e96c327b 100644 --- a/tests/test_apps.wallet.signtx.py +++ b/tests/test_apps.wallet.signtx.py @@ -20,7 +20,6 @@ from apps.wallet.sign_tx import signing class TestSignTx(unittest.TestCase): # pylint: disable=C0301 - # signer.send(None) def test_one_one_fee(self): # tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 @@ -97,10 +96,11 @@ class TestSignTx(unittest.TestCase): root = bip32.from_seed(seed, 'secp256k1') signer = signing.sign_tx(tx, root) + for request, response in chunks(messages, 2): - req = signer.send(request) - self.assertEqualEx(req, response) - # print(req.details.tx_hash,response.details.tx_hash ) + res = signer.send(request) + self.assertEqualEx(res, response) + with self.assertRaises(StopIteration): signer.send(None)