1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

src/apps/wallet/sign_tx: fix bip115 code in last commit

This commit is contained in:
Pavol Rusnak 2018-07-02 14:29:58 +02:00
parent 3b345f3c76
commit 9f90ca21a9
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
4 changed files with 18 additions and 9 deletions

View File

@ -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

12
src/apps/wallet/sign_tx/signing.py Executable file → Normal file
View File

@ -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')

0
src/trezor/messages/TxInputType.py Executable file → Normal file
View File

View File

@ -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)