diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index a41587717..d1bfddea0 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added - CoinJoin preauthorization and signing flow. [#1053] - Value of the `safety-checks` setting to the `Features` message. [#1193] +- ERC20 tokens show contract address for confirmation. Unknown ERC20 tokens show wei amount. [#800] ### Changed - The `safety-checks` setting gained new possible value `PromptTemporarily` which overrides safety checks until device reboot. [#1133] diff --git a/core/src/apps/ethereum/layout.py b/core/src/apps/ethereum/layout.py index 363c81bd7..b1c5b7a1f 100644 --- a/core/src/apps/ethereum/layout.py +++ b/core/src/apps/ethereum/layout.py @@ -40,6 +40,14 @@ async def require_confirm_fee( await require_hold_to_confirm(ctx, text, ButtonRequestType.SignTx) +async def require_confirm_unknown_token(ctx, address_bytes): + text = Text("Unknown token", ui.ICON_SEND, ui.ORANGE, new_lines=False) + text.normal(ui.GREY, "Contract:", ui.FG) + contract_address_hex = "0x" + hexlify(address_bytes).decode() + text.mono(*split_data(contract_address_hex)) + await require_confirm(ctx, text, ButtonRequestType.SignTx) + + def split_data(data): return chunks(data, 18) @@ -56,9 +64,10 @@ async def require_confirm_data(ctx, data, data_total): def format_ethereum_amount(value: int, token, chain_id: int, tx_type=None): - if token: - if token is tokens.UNKNOWN_TOKEN: - return "Unknown token value" + if token is tokens.UNKNOWN_TOKEN: + suffix = "Wei UNKN" + decimals = 0 + elif token: suffix = token[2] decimals = token[3] else: diff --git a/core/src/apps/ethereum/sign_tx.py b/core/src/apps/ethereum/sign_tx.py index 7751f6587..852c462e5 100644 --- a/core/src/apps/ethereum/sign_tx.py +++ b/core/src/apps/ethereum/sign_tx.py @@ -11,7 +11,12 @@ from apps.common import paths from . import address, tokens from .keychain import with_keychain_from_chain_id -from .layout import require_confirm_data, require_confirm_fee, require_confirm_tx +from .layout import ( + require_confirm_data, + require_confirm_fee, + require_confirm_tx, + require_confirm_unknown_token, +) # maximum supported chain id MAX_CHAIN_ID = 2147483629 @@ -41,6 +46,9 @@ async def sign_tx(ctx, msg, keychain): recipient = msg.data_initial_chunk[16:36] value = int.from_bytes(msg.data_initial_chunk[36:68], "big") + if token is tokens.UNKNOWN_TOKEN: + await require_confirm_unknown_token(ctx, address_bytes) + await require_confirm_tx(ctx, recipient, value, msg.chain_id, token, msg.tx_type) if token is None and msg.data_length > 0: await require_confirm_data(ctx, msg.data_initial_chunk, data_total) diff --git a/tests/device_tests/test_msg_ethereum_signtx.py b/tests/device_tests/test_msg_ethereum_signtx.py index a2cb7575f..41ea06af0 100644 --- a/tests/device_tests/test_msg_ethereum_signtx.py +++ b/tests/device_tests/test_msg_ethereum_signtx.py @@ -119,6 +119,7 @@ class TestMsgEthereumSigntx: with client: client.set_expected_responses( [ + messages.ButtonRequest(code=messages.ButtonRequestType.SignTx), messages.ButtonRequest(code=messages.ButtonRequestType.SignTx), messages.ButtonRequest(code=messages.ButtonRequestType.SignTx), messages.EthereumTxRequest(data_length=None), diff --git a/tests/ui_tests/fixtures.json b/tests/ui_tests/fixtures.json index 044f9abdd..876449f4d 100644 --- a/tests/ui_tests/fixtures.json +++ b/tests/ui_tests/fixtures.json @@ -139,7 +139,7 @@ "test_msg_ethereum_signtx.py-test_ethereum_signtx_message": "f15bfcd910b3a315515a07babc1f1bbfb30a78a9304b0fa4646cfc91911a638c", "test_msg_ethereum_signtx.py-test_ethereum_signtx_newcontract": "b8672006a9590fa69b4a882830810734ddbf120327780d59e51dd894afa383cc", "test_msg_ethereum_signtx.py-test_ethereum_signtx_nodata": "9d69b61aee19c42c22651cd9912d8a29b2ac6987b552966a6659e3505d4869e7", -"test_msg_ethereum_signtx.py-test_ethereum_signtx_unknown_erc20_token": "74ccd107e69bfd5d08355636f4d5814a9e4f2d2153f63a4a10bfab39c4ff60a1", +"test_msg_ethereum_signtx.py-test_ethereum_signtx_unknown_erc20_token": "1c35295d3216ba377a73e152d506033896c7d958775f4c9cfd13dd3cd5e3cfd2", "test_msg_ethereum_signtx.py-test_ethereum_signtx_wanchain": "4abb87c2b2836601971af8483fb95ff0f5913bdf912ff3e17a20c8c34872470a", "test_msg_ethereum_signtx_eip155.py::test_chain_ids[1-60-sig0]": "4fb0b0b8fb5f803132a422d8b26d51e46ee6976c04ad0de29230adfc63d0e44c", "test_msg_ethereum_signtx_eip155.py::test_chain_ids[2018-2018-sig4]": "1eaf3c481d105f3c5da45e3455f6af13ac7c77a3796a9b69fdd38adae89a0401",