def test_not_enough_funds(self): self.setup_mnemonic_nopin_nopassphrase() # tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 # input 0: 0.0039 BTC inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e # amount=390000, prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'), prev_index=0, ) out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1', amount=400000, script_type=proto_types.PAYTOADDRESS, ) with self.client: self.client.set_expected_responses([ proto.TxRequest(request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0)), proto.TxRequest(request_type=proto_types.TXMETA, details=proto_types.TxRequestDetailsType(tx_hash=binascii.unhexlify("d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"))), proto.TxRequest(request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0, tx_hash=binascii.unhexlify("d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"))), proto.TxRequest(request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=1, tx_hash=binascii.unhexlify("d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"))), proto.TxRequest(request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0, tx_hash=binascii.unhexlify("d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"))), proto.TxRequest(request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0)), proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput), proto.Failure(code=proto_types.Failure_NotEnoughFunds) ]) try: self.client.sign_tx('Bitcoin', [inp1, ], [out1, ]) except CallException as e: self.assertEqual(e.args[0], proto_types.Failure_NotEnoughFunds) else: self.assert_(False, "types.Failure_NotEnoughFunds expected")
def test_nonzero_opreturn(self): self.setup_mnemonic_nopin_nopassphrase() # tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882 # input 0: 0.0039 BTC inp1 = proto_types.TxInputType(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e # amount=390000, prev_hash=binascii.unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'), prev_index=0, ) out1 = proto_types.TxOutputType(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1', amount=390000 - 10000 - 10000, script_type=proto_types.PAYTOADDRESS, ) out1 = proto_types.TxOutputType(op_return_data=b'test of the op_return data', amount=10000, script_type=proto_types.PAYTOOPRETURN, ) with self.client: self.client.set_expected_responses([ proto.TxRequest(request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0)), proto.TxRequest(request_type=proto_types.TXMETA, details=proto_types.TxRequestDetailsType(tx_hash=binascii.unhexlify("d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"))), proto.TxRequest(request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0, tx_hash=binascii.unhexlify("d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"))), proto.TxRequest(request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=1, tx_hash=binascii.unhexlify("d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"))), proto.TxRequest(request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0, tx_hash=binascii.unhexlify("d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882"))), proto.TxRequest(request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0)), proto.Failure() ]) self.assertRaises(CallException, self.client.sign_tx, 'Bitcoin', [inp1, ], [out1, ])
def test_vuln(self): self.requires_firmware("6.4.1") PREVHASH_1 = unhexlify( "b6973acd5876ba8b050ae2d4c7d8b5c710ee4879af938be3c2c61a262f1730e0") PREVHASH_2 = unhexlify( "3a3322e60f2f4c55394fe05dddacafd6e55ff6d40859fd98d64adefc8c169ac8") PREVHASH_3 = unhexlify( "d58af7adaf3f04a0d5d30c145e8cfb48e863f49c8de594a8927c19c460fee9a3") PREVHASH_4 = unhexlify( "3b586fcc54424f1df5669828f9d828e888298669a50a5983fd0d71e7f4d38110") self.setup_mnemonic_vuln20007() inp1 = proto_types.TxInputType( # amount=150.0 address_n=parse_path("m/49'/1'/0'/0/0"), prev_hash=PREVHASH_1, amount=15000000000, prev_index=1, script_type=proto_types.SPENDP2SHWITNESS, ) inp2 = proto_types.TxInputType( # amount=50.00000001, address_n=parse_path("m/49'/1'/0'/0/1"), prev_hash=PREVHASH_2, amount=5000000001, prev_index=1, script_type=proto_types.SPENDP2SHWITNESS, ) inp3 = proto_types.TxInputType( # amount=0.00000001, address_n=parse_path("m/49'/1'/0'/0/2"), prev_hash=PREVHASH_3, amount=1, prev_index=1, script_type=proto_types.SPENDP2SHWITNESS, ) inp4 = proto_types.TxInputType( # amount=, address_n=parse_path("m/49'/1'/0'/0/3"), prev_hash=PREVHASH_4, amount=20000000000, prev_index=1, script_type=proto_types.SPENDP2SHWITNESS, ) out = proto_types.TxOutputType( address='2NA62MxEdTcBhSBN51QjD4LEam2J34ufotY', amount=2000000000, script_type=proto_types.PAYTOADDRESS, ) self.client.set_tx_api(tx_api.TxApiTestnet) with self.client: self.client.set_expected_responses([ proto.TxRequest( request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0)), proto.TxRequest( request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=1)), proto.TxRequest( request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0)), proto.ButtonRequest( code=proto_types.ButtonRequest_ConfirmOutput), proto.ButtonRequest( code=proto_types.ButtonRequest_FeeOverThreshold), proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx), proto.TxRequest( request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0)), proto.TxRequest( request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=1)), proto.TxRequest( request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0)), proto.TxRequest( request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0)), proto.TxRequest( request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=1)), proto.TxRequest(request_type=proto_types.TXFINISHED), ]) (signatures, serialized_tx) = self.client.sign_tx('Testnet', [inp1, inp2], [ out, ]) with self.client: self.client.set_expected_responses([ proto.TxRequest( request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=0)), proto.TxRequest( request_type=proto_types.TXINPUT, details=proto_types.TxRequestDetailsType(request_index=1)), proto.TxRequest( request_type=proto_types.TXOUTPUT, details=proto_types.TxRequestDetailsType(request_index=0)), proto.ButtonRequest( code=proto_types.ButtonRequest_ConfirmOutput), proto.ButtonRequest(code=proto_types.ButtonRequest_Other), proto.Failure(code=proto_types.Failure_ActionCancelled), ]) self.assertRaises(CallException, self.client.sign_tx, 'Testnet', [inp3, inp4], [ out, ])