From 28918f46ec8cb61b80bba5188e692dba8f5116a8 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Tue, 23 Feb 2021 20:15:55 +0100 Subject: [PATCH] test: Add device test for decreasing output amount in RBF. --- .../test_msg_signtx_replacement.py | 93 +++++++++++++++++-- tests/ui_tests/fixtures.json | 15 +-- 2 files changed, 95 insertions(+), 13 deletions(-) diff --git a/tests/device_tests/test_msg_signtx_replacement.py b/tests/device_tests/test_msg_signtx_replacement.py index 24f3a1f7f6..baac147bfb 100644 --- a/tests/device_tests/test_msg_signtx_replacement.py +++ b/tests/device_tests/test_msg_signtx_replacement.py @@ -107,12 +107,12 @@ def test_p2pkh_fee_bump(client): request_input(0), request_meta(TXHASH_50f6f1), request_orig_input(0, TXHASH_50f6f1), + messages.ButtonRequest(code=B.SignTx), request_output(0), request_orig_output(0, TXHASH_50f6f1), request_output(1), request_orig_output(1, TXHASH_50f6f1), messages.ButtonRequest(code=B.SignTx), - messages.ButtonRequest(code=B.SignTx), request_input(0), request_meta(TXHASH_beafc7), request_input(0, TXHASH_beafc7), @@ -179,12 +179,12 @@ def test_p2wpkh_finalize(client): request_input(0), request_meta(TXHASH_70f987), request_orig_input(0, TXHASH_70f987), + messages.ButtonRequest(code=B.SignTx), request_output(0), request_orig_output(0, TXHASH_70f987), request_output(1), request_orig_output(1, TXHASH_70f987), messages.ButtonRequest(code=B.SignTx), - messages.ButtonRequest(code=B.SignTx), request_input(0), request_meta(TXHASH_43d273), request_input(0, TXHASH_43d273), @@ -309,11 +309,11 @@ def test_p2wpkh_payjoin( request_meta(TXHASH_65b768), request_orig_input(0, TXHASH_65b768), request_input(1), + messages.ButtonRequest(code=B.SignTx), request_output(0), request_orig_output(0, TXHASH_65b768), request_output(1), request_orig_output(1, TXHASH_65b768), - messages.ButtonRequest(code=B.SignTx), (fee_confirm, messages.ButtonRequest(code=B.SignTx)), request_input(0), request_meta(TXHASH_e4b5b2), @@ -385,11 +385,11 @@ def test_p2wpkh_in_p2sh_remove_change(client): request_orig_input(0, TXHASH_334cd7), request_input(1), request_orig_input(1, TXHASH_334cd7), + messages.ButtonRequest(code=B.SignTx), request_output(0), request_orig_output(0, TXHASH_334cd7), request_orig_output(1, TXHASH_334cd7), messages.ButtonRequest(code=B.SignTx), - messages.ButtonRequest(code=B.SignTx), request_input(0), request_meta(TXHASH_5e7667), request_input(0, TXHASH_5e7667), @@ -421,6 +421,87 @@ def test_p2wpkh_in_p2sh_remove_change(client): ) +def test_p2wpkh_in_p2sh_fee_bump_from_external(client): + # Use the change output and an external output to bump the fee. + # Originally fee was 3780, now 108060 (94280 from change and 10000 from external). + + inp1 = messages.TxInputType( + address_n=parse_path("49h/1h/0h/0/4"), + amount=100000, + script_type=messages.InputScriptType.SPENDP2SHWITNESS, + prev_hash=TXHASH_5e7667, + prev_index=1, + orig_hash=TXHASH_334cd7, + orig_index=0, + ) + + inp2 = messages.TxInputType( + address_n=parse_path("49h/1h/0h/0/3"), + amount=998060, + script_type=messages.InputScriptType.SPENDP2SHWITNESS, + prev_hash=TXHASH_efaa41, + prev_index=0, + orig_hash=TXHASH_334cd7, + orig_index=1, + ) + + out1 = messages.TxOutputType( + # Actually m/49'/1'/0'/0/5. + address="2MvUUSiQZDSqyeSdofKX9KrSCio1nANPDTe", + amount=990000, + orig_hash=TXHASH_334cd7, + orig_index=0, + ) + + with client: + client.set_expected_responses( + [ + request_input(0), + request_meta(TXHASH_334cd7), + request_orig_input(0, TXHASH_334cd7), + request_input(1), + request_orig_input(1, TXHASH_334cd7), + messages.ButtonRequest(code=B.SignTx), + request_output(0), + request_orig_output(0, TXHASH_334cd7), + messages.ButtonRequest(code=B.ConfirmOutput), + ( + client.features.model == "1", + messages.ButtonRequest(code=B.ConfirmOutput), + ), + request_orig_output(1, TXHASH_334cd7), + messages.ButtonRequest(code=B.SignTx), + request_input(0), + request_meta(TXHASH_5e7667), + request_input(0, TXHASH_5e7667), + request_output(0, TXHASH_5e7667), + request_output(1, TXHASH_5e7667), + request_input(1), + request_meta(TXHASH_efaa41), + request_input(0, TXHASH_efaa41), + request_output(0, TXHASH_efaa41), + request_input(0), + request_input(1), + request_output(0), + request_input(0), + request_input(1), + request_finished(), + ] + ) + _, serialized_tx = btc.sign_tx( + client, + "Testnet", + [inp1, inp2], + [out1], + prev_txes=TX_CACHE_TESTNET, + ) + + assert ( + serialized_tx.hex() + == "01000000000102d64ae26dceee1e309bed0821f39275b5f6e65d0072f8e23747ae76006967765e0100000017160014039ba06270e6c6c1ad4e6940515aa5cdbad33f9effffffff35ac1adc9e0cf408013090c52527d3cf9468d51e1a6c8408f5ed673eff41aaef0000000017160014209297fb46272a0b7e05139440dbd39daea3e25affffffff01301b0f000000000017a9142369da13fee80c9d7fd8043bf1275c04deb360e68702483045022100bd303aa0d923e73300e37971d43b9cd134230f8287e0e3b702aacd19ba8ef97b02202b4368b3e9d7478b8529ea2aeea23f6612ec05854510794958d6ce58c19082ad012103bb0e339d7495b1f355c49d385b79343e52e68d99de2fe1f7f476c465c9ccd1670247304402204869b27aa926d98bfd36912f71e335c1d6afb2c1a28102407066db5257e1b8810220197bcac3c85a721547974bd7309a6ea2b809810a595cbdca2da9599af4038ba2012103c2c2e65556ca4b7371549324b99390725493c8a6792e093a0bdcbb3e2d7df4ab00000000" + ) + + @pytest.mark.skip_t1 def test_tx_meld(client): # Meld two original transactions into one, joining the change-outputs into a different one. @@ -500,6 +581,8 @@ def test_tx_meld(client): request_orig_input(1, TXHASH_334cd7), request_input(3), request_orig_input(1, TXHASH_ed89ac), + messages.ButtonRequest(code=B.SignTx), + messages.ButtonRequest(code=B.SignTx), request_output(0), request_orig_output(0, TXHASH_ed89ac), request_orig_output(1, TXHASH_ed89ac), @@ -508,8 +591,6 @@ def test_tx_meld(client): request_output(2), request_orig_output(1, TXHASH_334cd7), messages.ButtonRequest(code=B.SignTx), - messages.ButtonRequest(code=B.SignTx), - messages.ButtonRequest(code=B.SignTx), request_input(0), request_meta(TXHASH_5e7667), request_input(0, TXHASH_5e7667), diff --git a/tests/ui_tests/fixtures.json b/tests/ui_tests/fixtures.json index 9ae3becb1a..8db3354706 100644 --- a/tests/ui_tests/fixtures.json +++ b/tests/ui_tests/fixtures.json @@ -507,17 +507,18 @@ "test_msg_signtx_replacement.py::test_attack_fake_ext_input_amount": "ff8306b910f6886638e30736acd025ff7f45dde3c6648de1f6c6922bc6f590c5", "test_msg_signtx_replacement.py::test_attack_fake_int_input_amount": "ff8306b910f6886638e30736acd025ff7f45dde3c6648de1f6c6922bc6f590c5", "test_msg_signtx_replacement.py::test_attack_false_internal": "ff8306b910f6886638e30736acd025ff7f45dde3c6648de1f6c6922bc6f590c5", -"test_msg_signtx_replacement.py::test_attack_steal_change": "ff8306b910f6886638e30736acd025ff7f45dde3c6648de1f6c6922bc6f590c5", -"test_msg_signtx_replacement.py::test_p2pkh_fee_bump": "881f6491e9f4417cd747dda2dc0eaafdf1a4769a5e53aa303bb06547d6a9133b", -"test_msg_signtx_replacement.py::test_p2wpkh_finalize": "1147c6996c193b904b72d38def07c692cf48d7bdbe244343c9e98ee0db497d11", -"test_msg_signtx_replacement.py::test_p2wpkh_in_p2sh_remove_change": "f66437cc88d016ddb0b3fd4e6d2c6536d9a1745dfc92ce9cd334c3cbaaefb4a9", -"test_msg_signtx_replacement.py::test_p2wpkh_invalid_signature": "1147c6996c193b904b72d38def07c692cf48d7bdbe244343c9e98ee0db497d11", +"test_msg_signtx_replacement.py::test_attack_steal_change": "8926f69a78c675f4750d7d06bf827b29e4e994d30f52434fac18e654df4da6f4", +"test_msg_signtx_replacement.py::test_p2pkh_fee_bump": "d23d28146c205516f5135071a50e0ba9f6118285894422bbc8f27d244c2ed2e2", +"test_msg_signtx_replacement.py::test_p2wpkh_finalize": "0581c0c3b9539789fd924841e4cf03ecd767a6692af7e41b46889bea1d7c7c07", +"test_msg_signtx_replacement.py::test_p2wpkh_in_p2sh_fee_bump_from_external": "fcb907f7342b68ab12ea26555f129a5a5095c2b7c44fb1ec3bb74e0e6dd24bda", +"test_msg_signtx_replacement.py::test_p2wpkh_in_p2sh_remove_change": "1ba9741d9a1a7b5a3fae0312c9626e407b6b80e1d3b9ec91088348ca25f5161c", +"test_msg_signtx_replacement.py::test_p2wpkh_invalid_signature": "0581c0c3b9539789fd924841e4cf03ecd767a6692af7e41b46889bea1d7c7c07", "test_msg_signtx_replacement.py::test_p2wpkh_payjoin[19909659-90000-02483045022100aa1b91fb25-124c0968": "a5473b5f3931fb6530a991e45aa32507069a7b402878d1eda2ce6e8be1a673e1", "test_msg_signtx_replacement.py::test_p2wpkh_payjoin[19909718-90000-024730440220753f53049ca4-2253fa0b": "a5473b5f3931fb6530a991e45aa32507069a7b402878d1eda2ce6e8be1a673e1", "test_msg_signtx_replacement.py::test_p2wpkh_payjoin[19909800-89859-0248304502210097a42b35d3-89bd0d1d": "a5473b5f3931fb6530a991e45aa32507069a7b402878d1eda2ce6e8be1a673e1", -"test_msg_signtx_replacement.py::test_p2wpkh_payjoin[19909859-89800-02483045022100af3a874c96-7f9eee73": "fa89cef11f68c2c856b441728f70a86d4c9419cf9e327cfd3330eafb8790bc2d", +"test_msg_signtx_replacement.py::test_p2wpkh_payjoin[19909859-89800-02483045022100af3a874c96-7f9eee73": "d348b58a6c9e241cc9edef37e10a87907db00eae14a251e7ce53250967c817d5", "test_msg_signtx_replacement.py::test_p2wpkh_payjoin[19909859-89859-02483045022100eb74abb36f-42ad4639": "a5473b5f3931fb6530a991e45aa32507069a7b402878d1eda2ce6e8be1a673e1", -"test_msg_signtx_replacement.py::test_tx_meld": "5250c11a75781fa1c845f7b405b7808c5b7dce3e8405fe69096db5c723457f48", +"test_msg_signtx_replacement.py::test_tx_meld": "62dca3511ac1b7d1e905e6a6915672f5263fe77beee8909500574e3efa934fd4", "test_msg_signtx_segwit.py-test_attack_change_input_address": "5ae71202c062ef7942626a80a4ceeb8d8c4ea5065a97f0de6a97505e9cb82c2c", "test_msg_signtx_segwit.py-test_attack_mixed_inputs": "f127a4766b23d9b6dfe0c41f9cf1ed13c0a883ea4e92e55961bcaf44bd152c02", "test_msg_signtx_segwit.py-test_send_multisig_1": "958a0741070e057dcb889b2000e5487d391bc513e4a5d86193a355261c5f361b",