From 252f946f409fc87d6b9f462682ef36219b96ece3 Mon Sep 17 00:00:00 2001 From: strmci <36126939+strmci@users.noreply.github.com> Date: Mon, 12 Nov 2018 16:27:56 +0100 Subject: [PATCH] Add a test case for segwit inputs/outputs with very high amounts (#337) Add a test case for segwit inputs/outputs with very high amount, fixes #332 --- .../tests/device_tests/test_msg_signtx.py | 28 ++++++++++ .../device_tests/test_msg_signtx_segwit.py | 51 +++++++++++++++++++ ...63f63ac7b7df9d8ba67b4682bba4e514d0f0c.json | 1 + 3 files changed, 80 insertions(+) create mode 100644 trezorlib/tests/txcache/insight_testnet_tx_2bac7ad1dec654579a71ea9555463f63ac7b7df9d8ba67b4682bba4e514d0f0c.json diff --git a/trezorlib/tests/device_tests/test_msg_signtx.py b/trezorlib/tests/device_tests/test_msg_signtx.py index 5b6fb5fa81..2eccb5b7f8 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx.py +++ b/trezorlib/tests/device_tests/test_msg_signtx.py @@ -62,6 +62,9 @@ TXHASH_e5040e = bytes.fromhex( TXHASH_50f6f1 = bytes.fromhex( "50f6f1209ca92d7359564be803cb2c932cde7d370f7cee50fd1fad6790f6206d" ) +TXHASH_2bac7a = bytes.fromhex( + "2bac7ad1dec654579a71ea9555463f63ac7b7df9d8ba67b4682bba4e514d0f0c" +) def check_sign_tx(client, coin_name, inputs, outputs, fee_too_high=False, failure=None): @@ -508,6 +511,31 @@ class TestMsgSigntx(TrezorTest): == "0100000001a3fb2d38322c3b327e54005cebc0686d52fcdf536e53bb5ef481a7de8056aa54010000006b4830450221009e020b0390ccad533b73b552f8a99a9d827212c558e4f755503674d07c92ad4502202d606f7316990e0461c51d4add25054f19c697aa3e3c2ced4d568f0b2c57e62f0121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0170f305000000000017a9147f844bdb0b8fd54b64e3d16c85dc1170f1ff97c18700000000" ) + def test_testnet_big_amount(self): + self.setup_mnemonic_allallall() + + # This test is testing transaction with amount bigger than fits to uint32 + + # tx: 2bac7ad1dec654579a71ea9555463f63ac7b7df9d8ba67b4682bba4e514d0f0c:1 + # input 1: 411102528330 Satoshi + + inp1 = proto.TxInputType( + address_n=parse_path("m/44'/1'/0'/0/0"), + amount=411102528330, + prev_hash=TXHASH_2bac7a, + prev_index=1, + ) + out1 = proto.TxOutputType( + address="mopZWqZZyQc3F2Sy33cvDtJchSAMsnLi7b", # seed allallall, bip32: m/44'/1'/0'/0/1 + amount=411102528330, + script_type=proto.OutputScriptType.PAYTOADDRESS, + ) + _, serialized_tx = check_sign_tx(self.client, "Testnet", [inp1], [out1]) + assert ( + serialized_tx.hex() + == "01000000010c0f4d514eba2b68b467bad8f97d7bac633f465595ea719a5754c6ded17aac2b010000006b4830450221008e3b926f04d8830bd5b67698af25c9e00c9db1b1ef3e5d69af794446753da94a02202d4a7509f26bba29ff643a7ac0d43fb128c1a632cc502b8f44eada8930fb9c9b0121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0ffffffff014ac39eb75f0000001976a9145b157a678a10021243307e4bb58f36375aa80e1088ac00000000" + ) + def test_attack_change_outputs(self): # This unit test attempts to modify data sent during ping-pong of streaming signing. # Because device is asking for human confirmation only during first pass (first input), diff --git a/trezorlib/tests/device_tests/test_msg_signtx_segwit.py b/trezorlib/tests/device_tests/test_msg_signtx_segwit.py index f89c237d78..568df3704c 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_segwit.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_segwit.py @@ -163,6 +163,57 @@ class TestMsgSigntxSegwit(TrezorTest): == "0100000000010137c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca8702483045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000" ) + def test_testnet_segwit_big_amount(self): + self.setup_mnemonic_allallall() + + # This test is testing transaction with amount bigger than fits to uint32 + + inp1 = proto.TxInputType( + address_n=parse_path("m/49'/1'/0'/0/0"), + amount=2 ** 32 + 1, + prev_hash=b"\xff" * 32, + prev_index=0, + script_type=proto.InputScriptType.SPENDP2SHWITNESS, + ) + out1 = proto.TxOutputType( + address="2Mt7P2BAfE922zmfXrdcYTLyR7GUvbwSEns", # seed allallall, bip32: m/49'/1'/0'/0/1, script type:p2shsegwit + amount=2 ** 32 + 1, + script_type=proto.OutputScriptType.PAYTOADDRESS, + ) + with self.client: + self.client.set_expected_responses( + [ + proto.TxRequest( + request_type=proto.RequestType.TXINPUT, + details=proto.TxRequestDetailsType(request_index=0), + ), + proto.TxRequest( + request_type=proto.RequestType.TXOUTPUT, + details=proto.TxRequestDetailsType(request_index=0), + ), + proto.ButtonRequest(code=proto.ButtonRequestType.ConfirmOutput), + proto.ButtonRequest(code=proto.ButtonRequestType.SignTx), + proto.TxRequest( + request_type=proto.RequestType.TXINPUT, + details=proto.TxRequestDetailsType(request_index=0), + ), + proto.TxRequest( + request_type=proto.RequestType.TXOUTPUT, + details=proto.TxRequestDetailsType(request_index=0), + ), + proto.TxRequest( + request_type=proto.RequestType.TXINPUT, + details=proto.TxRequestDetailsType(request_index=0), + ), + proto.TxRequest(request_type=proto.RequestType.TXFINISHED), + ] + ) + _, serialized_tx = btc.sign_tx(self.client, "Testnet", [inp1], [out1]) + assert ( + serialized_tx.hex() + == "01000000000101ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000171600140099a7ecbd938ed1839f5f6bf6d50933c6db9d5cffffffff01010000000100000017a914097c569095163e84475d07aa95a1f736df895b7b8702483045022100cb9d3aa7a8064702e6b61c20c7fb9cb672c69d3786cf5efef8ad6d90136ca7d8022065119ff6c6e6e6960e6508fc5360359bb269bb25ef8d90019decaa0a050cc45a0121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000" + ) + def test_send_multisig_1(self): self.setup_mnemonic_allallall() nodes = map( diff --git a/trezorlib/tests/txcache/insight_testnet_tx_2bac7ad1dec654579a71ea9555463f63ac7b7df9d8ba67b4682bba4e514d0f0c.json b/trezorlib/tests/txcache/insight_testnet_tx_2bac7ad1dec654579a71ea9555463f63ac7b7df9d8ba67b4682bba4e514d0f0c.json new file mode 100644 index 0000000000..edc83015ef --- /dev/null +++ b/trezorlib/tests/txcache/insight_testnet_tx_2bac7ad1dec654579a71ea9555463f63ac7b7df9d8ba67b4682bba4e514d0f0c.json @@ -0,0 +1 @@ +{"txid": "2bac7ad1dec654579a71ea9555463f63ac7b7df9d8ba67b4682bba4e514d0f0c", "version": 2, "locktime": 1442661, "vin": [{"txid": "7cc9463285e06dd464357c9775c1666078b04da914270c224640023cbd9d663b", "vout": 0, "sequence": 4294967294, "n": 0, "scriptSig": {"hex": "1600149872cad5fa80293ad1f2faf1ceb238830fa01404"}, "addresses": ["2NGJtNdBoorpBegD9C2SHoFxMB6SmkHgYwo"], "value": "4111.11772162"}], "vout": [{"value": "0.09226912", "n": 0, "scriptPubKey": {"hex": "76a914ed510ecb8a6e8aea8e34b44dfea4f0a30ae2a88788ac", "addresses": ["n39mYWemUp2eahhGvr5hq3ENjNUge1yXFW"]}, "spent": false}, {"value": "4111.0252833", "n": 1, "scriptPubKey": {"hex": "a914713134226fb873dcef4826ad826bbf1e7b005d1387", "addresses": ["2N3ZjHgzcmaJsgVzSrjAJ8qqspre9STxKNm"]}, "spent": true}], "blockhash": "00000000000000e5aec7282e7dbabb1530b76d27a4b028ea7adbbb944ac85fb9", "blockheight": 1442662, "confirmations": 11, "blocktime": 1541766205, "valueOut": "4111.11755242", "valueIn": "4111.11772162", "fees": "0.0001692", "hex": "020000000001013b669dbd3c024046220c2714a94db0786066c175977c3564d46de0853246c97c00000000171600149872cad5fa80293ad1f2faf1ceb238830fa01404feffffff02a0ca8c00000000001976a914ed510ecb8a6e8aea8e34b44dfea4f0a30ae2a88788ac4ac39eb75f00000017a914713134226fb873dcef4826ad826bbf1e7b005d138702473044022017bae642cf9c67040ce0559152c026f6a1326e5a586ad1153eb149a1f27b42df022024de091fc9b2bbb0791527a0e0f4783e34659178a8773f1c356f1394184821d7012102f401ed0fe28b9e3946a2bf658d1f54e06663e3b5fb0d41a1bfcbcfa44f4a551065031600"} \ No newline at end of file