fix(clear_signing): show unknown tokens as UKWN even when native addr provided.
What changed, and why it matters
This update fixes how Trezor hardware wallets display Ethereum token amounts when a transaction descriptor does not specify which token is involved. Previously, the device rejected such descriptors outright. The fix makes the device show the raw amount with an 'unknown token' label (UNKN) instead of either failing or accidentally treating it as the network's native currency (like ETH). This prevents a malicious or sloppy descriptor from tricking the user into thinking they are sending a known token or native currency when the device actually cannot identify the token contract.
Treat this as a security-relevant fix and include it in the next firmware release. Users relying on Ethereum clear-signing should update. Wallet/definition authors should ensure descriptors either explicitly identify tokens or are prepared for the new UNKN fallback display. No immediate incident response is indicated, but the change should be communicated in release notes because it alters confirmation-screen behavior.
Security signals we found
UI misrepresentation risk: missing token could previously be misread as native currency if native_currency_address matched the default zero/sentinel address
Transaction signing flow: amount formatting is part of the user confirmation screen for Ethereum clear-signing transactions
Changelog explicitly tagged as security: core/.changelog.d/clear-signing.security added with text 'Ethereum: Parse unknown tokens properly.'
Behavioral change from exception to safe fallback: unknown token rendering instead of descriptor rejection
Test additions assert that unknown-token amounts never expose a contract address and never render as native currency
Evidence from the diff
In core/src/apps/ethereum/clear_signing.py, TokenAmountFormatter.format() no longer raises InvalidFormatDefinition when neither const_token_address nor token_path is provided. Instead it sets token_address to None and uses UNKNOWN_TOKEN. Native-currency detection is now only applied when a token address is actually present and matches native_currency_address. The UI path in _handle_generic_ui now only appends a token contract address property when actual_token is UNKNOWN_TOKEN and actual_token_address is not None. Tests were added to verify that missing-token amounts render as ‘Wei UNKN’, never as native currency, and that subcalls with tokenless amounts do not degrade to raw hex.
Changed components
core/src/apps/ethereum/clear_signing.pycore/tests/test_apps.ethereum.clear_signing.pyEthereum clear-signing token amount displayInspect captured patch +151 / −43
### core/.changelog.d/clear-signing.security
@@ -0,0 +1 @@
+Ethereum: Parse unknown tokens properly.
### core/src/apps/ethereum/clear_signing.py
@@ -385,6 +385,7 @@ async def format(
if not isinstance(amount, int):
raise InvalidFormatDefinition
+ token_address: AnyBytes | None
if self.const_token_address is not None:
# token given as a literal constant address
token_address = self.const_token_address
@@ -394,47 +395,36 @@ async def format(
raise InvalidFormatDefinition
token_address = walked
else:
- raise InvalidFormatDefinition
-
- # TODO: Dead code. We don't pull this externally but we should.
- if self.native_currency_address is not None:
- if token_address in self.native_currency_address:
- if self.threshold is not None and amount >= self.threshold:
- return (
- AboveThreshold(self.threshold_message or TR.words__unlimited),
- None,
- None,
- )
- else:
- return (
- format_ethereum_amount(amount, None, defs.network),
- None,
- None,
+ # The descriptor does not say which token this is. Per ERC-7730,
+ # show the raw value as an unknown token.
+ token_address = None
+
+ token: EthereumTokenInfo | None
+ if token_address is None:
+ token = UNKNOWN_TOKEN
+ elif (
+ # Addresses the descriptor declares as the native currency.
+ # Typically zero's (0x000..), or ERC-7528 (0xeeee..) address.
+ self.native_currency_address is not None
+ and token_address in self.native_currency_address
+ ):
+ token = None
+ token_address = None
+ else:
+ token = defs.get_token(token_address)
+ if token is UNKNOWN_TOKEN:
+ if msg.supports_definition_request:
+ received_definitions, _ = await request_definitions(
+ msg.chain_id, token_address, func_sig=None
)
-
- # Non-native currency - dealing with tokens
-
- token = defs.get_token(token_address)
- if token is UNKNOWN_TOKEN:
- if msg.supports_definition_request:
- received_definitions, _ = await request_definitions(
- msg.chain_id, token_address, func_sig=None
- )
- if received_definitions is not None:
- token = received_definitions.get_token(token_address)
+ if received_definitions is not None:
+ token = received_definitions.get_token(token_address)
if self.threshold is not None and amount >= self.threshold:
- return (
- AboveThreshold(self.threshold_message or TR.words__unlimited),
- token,
- token_address,
- )
+ formatted = AboveThreshold(self.threshold_message or TR.words__unlimited)
else:
- return (
- format_ethereum_amount(amount, token, defs.network),
- token,
- token_address,
- )
+ formatted = format_ethereum_amount(amount, token, defs.network)
+ return formatted, token, token_address
class UnitFormatter(FieldFormatter):
@@ -1575,8 +1565,8 @@ async def _handle_generic_ui(
if amount is not None and formatted == amount:
value_shown_as_field = True
properties_to_confirm.append((label, formatted, is_mono))
- if actual_token is tokens.UNKNOWN_TOKEN:
- assert actual_token_address is not None
+ # a tokenless amount has no contract address to show
+ if actual_token is tokens.UNKNOWN_TOKEN and actual_token_address is not None:
token_address_str = address_from_bytes(actual_token_address, defs.network)
token_address_property: StrPropertyType = (
TR.ethereum__token_contract,
### core/tests/test_apps.ethereum.clear_signing.py
@@ -15,6 +15,7 @@
EthereumERC7730FieldInfo,
EthereumERC7730Path,
)
+ from trezor.ui.layouts.properties import AboveThreshold
from apps.ethereum import clear_signing_definitions
from apps.ethereum.clear_signing import (
@@ -48,6 +49,7 @@
parse_string,
parse_uint256,
)
+ from apps.ethereum.tokens import UNKNOWN_TOKEN
parse_bytes4 = make_fixed_bytes_parser(4)
parse_bytes8 = make_fixed_bytes_parser(8)
@@ -1158,11 +1160,98 @@ def get_token(self, address):
self.assertIn("stETH", formatted)
self.assertIn("2", formatted)
- def test_token_amount_no_token_source_rejected(self):
- # Neither token_path nor const_token_address set -> cannot resolve a token.
+ # --- tokenAmount without a token (neither token_path nor const_token_address) ---
+
+ ZERO_ADDRESS = b"\x00" * 20
+ NATIVE_SENTINEL = b"\xee" * 20
+
+ @staticmethod
+ def _eth_defs():
+ class _Defs:
+ network = make_eth_network(symbol="ETH")
+
+ def get_token(self, address):
+ raise AssertionError("a tokenless amount must not look up a token")
+
+ return _Defs()
+
+ def test_from_proto_token_amount_without_token(self):
+ info = EthereumERC7730FieldInfo(
+ path=EthereumERC7730Path(path=[0]),
+ label="Minimum to Receive",
+ formatter=FT.FORMATTER_TOKEN_AMOUNT,
+ native_currency_address=[self.ZERO_ADDRESS, self.NATIVE_SENTINEL],
+ )
+ fmt = FieldDefinition.from_proto(info).get_formatter()
+ self.assertIsInstance(fmt, TokenAmountFormatter)
+ self.assertIsNone(fmt.token_path)
+ self.assertIsNone(fmt.const_token_address)
+
+ def test_token_amount_without_token_is_unknown(self):
+ # Rendered as the raw integer with the unknown-token ticker, and no
+ # token address, so the confirm screen cannot claim a token contract.
fmt = TokenAmountFormatter()
- with self.assertRaises(InvalidFormatDefinition):
- await_result(fmt.format(1, None, None, None))
+ formatted, token, addr = await_result(
+ fmt.format(995 * 10**15, None, self._eth_defs(), None)
+ )
+ self.assertEqual(formatted, "995,000,000,000,000,000 Wei UNKN")
+ self.assertIs(token, UNKNOWN_TOKEN)
+ self.assertIsNone(addr)
+
+ def test_token_amount_without_token_is_never_native(self):
+ # Even when the descriptor lists the zero address as native currency,
+ # a missing token must not be rendered as ETH.
+ fmt = TokenAmountFormatter(
+ native_currency_address=[self.ZERO_ADDRESS, self.NATIVE_SENTINEL]
+ )
+ formatted, token, addr = await_result(
+ fmt.format(995 * 10**15, None, self._eth_defs(), None)
+ )
+ self.assertEqual(formatted, "995,000,000,000,000,000 Wei UNKN")
+ self.assertIs(token, UNKNOWN_TOKEN)
+ self.assertIsNone(addr)
+
+ def test_token_amount_without_token_threshold(self):
+ # `threshold` is compared against the raw amount, independent of
+ # decimals: above it the message is shown, below it the raw value.
+ fmt = TokenAmountFormatter(threshold=1000, threshold_message="Unlimited")
+ formatted, token, addr = await_result(
+ fmt.format(1000, None, self._eth_defs(), None)
+ )
+ self.assertIsInstance(formatted, AboveThreshold)
+ self.assertEqual(formatted.message, "Unlimited")
+ self.assertIs(token, UNKNOWN_TOKEN)
+ self.assertIsNone(addr)
+
+ formatted, token, addr = await_result(
+ fmt.format(999, None, self._eth_defs(), None)
+ )
+ self.assertEqual(formatted, "999 Wei UNKN")
+ self.assertIs(token, UNKNOWN_TOKEN)
+ self.assertIsNone(addr)
+
+ def test_token_amount_without_token_multi_value(self):
+ fmt = TokenAmountFormatter()
+ formatted, token, addr = await_result(
+ _format_field_value(fmt, [1, 2], None, self._eth_defs(), None)
+ )
+ self.assertEqual(formatted, "1 Wei UNKN\n2 Wei UNKN")
+ self.assertIs(token, UNKNOWN_TOKEN)
+ self.assertIsNone(addr)
+
+ def test_token_amount_explicit_zero_token_is_native(self):
+ # An explicit `token: 0x000...` listed in nativeCurrencyAddress is a
+ # legitimate way to denote the native currency.
+ fmt = TokenAmountFormatter(
+ const_token_address=self.ZERO_ADDRESS,
+ native_currency_address=[self.ZERO_ADDRESS, self.NATIVE_SENTINEL],
+ )
+ formatted, token, addr = await_result(
+ fmt.format(2 * 10**18, None, self._eth_defs(), None)
+ )
+ self.assertEqual(formatted, "2 ETH")
+ self.assertIsNone(token)
+ self.assertIsNone(addr)
# --- `calldata` fields (nested invocations) ---
@@ -1527,6 +1616,34 @@ def test_calldata_inner_failure_degrades_to_raw(self):
self._assert_raw_fallback(fields, blob)
+ def test_calldata_inner_token_amount_without_token(self):
+ # A tokenless amount inside a subcall renders as an unknown token (no
+ # token address) instead of degrading the subcall to raw hex.
+ blob = b"\x12\x34\x56\x78" + to_bytes(995)
+ inner_format = DisplayFormat(
+ binding_context=None,
+ func_sig=b"\x12\x34\x56\x78",
+ intent="Inner",
+ parameter_definitions=[Atomic(parse_uint256)],
+ field_definitions=[
+ FieldDefinition((0,), "Minimum to Receive", TokenAmountFormatter())
+ ],
+ )
+
+ original = clear_signing_definitions.all_display_formats
+ clear_signing_definitions.all_display_formats = lambda: iter([inner_format])
+ try:
+ fields = self._expand(blob)
+ finally:
+ clear_signing_definitions.all_display_formats = original
+
+ self.assertEqual(len(fields), 3)
+ (label, formatted, _), token, token_address = fields[2]
+ self.assertEqual(label, "(Subcall) Minimum to Receive")
+ self.assertEqual(formatted, "995 Wei UNKN")
+ self.assertIs(token, UNKNOWN_TOKEN)
+ self.assertIsNone(token_address)
+
# --- arrays of subcalls (`bytes[] data`, e.g. a multicall) ---
@staticmethodWhy this scored 64/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.