feat(ethereum): request host for known address names.
What changed, and why it matters
This commit adds a feature that lets the Trezor device ask the connected computer (the 'host') for human-readable names of Ethereum addresses it doesn't already know. The device then shows those names on its screen during transaction signing. The change also moves some helper code between files and makes address-name lookups happen in more places, such as when displaying nested contract calls and token approvals. There is no direct evidence in the commit that this fixes a security bug; it reads as a user-experience feature for clearer transaction confirmation.
Treat this as a feature commit rather than a security patch. Reviewers should verify that host-provided names are only used for display and cannot influence transaction parsing or signing logic, and that the 4-byte selector guard is consistently enforced wherever display formats are decoded.
Security signals we found
New host-request path for address names during transaction signing
Name-only display format uses a non-standard 8-byte null selector to avoid collision with real 4-byte function selectors
Added length check rejecting non-4-byte selectors in clear-signing display format parsing
Removed hardcoded vault fallback in `_handle_approve()` in favor of host-driven `lookup_known_address()`
Moved `request_definitions()` helper and updated all imports in `yielding.py` and `yielding_vaults.py`
Evidence from the diff
The patch introduces asynchronous host-driven name resolution for Ethereum addresses via request_definitions() and a new lookup_known_address() coroutine in helpers.py. When the device lacks a built-in name or hardcoded vault entry for an address, and the signing message supports definition requests, it asks the host for an EthereumDisplayFormatInfo using an 8-byte null selector, or for token definitions, and uses the returned provider_name or token name in the UI. The change also refactors lookup_vault() to take a chain_id instead of an EthereumNetworkInfo object, and moves request_definitions() from clear_signing.py to helpers.py. A guard was added in DisplayFormat.from_proto() to reject display formats whose func_sig length is not exactly 4 bytes, preventing name-only (8-byte null selector) definitions from being used for clear-signing calldata parsing.
Changed components
core/src/apps/ethereum/helpers.pycore/src/apps/ethereum/clear_signing.pycore/src/apps/ethereum/yielding.pycore/src/apps/ethereum/yielding_vaults.pyInspect captured patch +123 / −66
### core/.changelog.d/8089.added
@@ -0,0 +1 @@
+Ethereum: Show names of well known addresses.
### core/src/apps/ethereum/clear_signing.py
@@ -11,6 +11,7 @@
format_ethereum_amount,
get_account_and_path,
lookup_known_address,
+ request_definitions,
)
if TYPE_CHECKING:
@@ -19,6 +20,7 @@
from trezor.messages import (
EthereumABIValueInfo,
+ EthereumDisplayFormatInfo,
EthereumERC7730FieldInfo,
EthereumTokenInfo,
)
@@ -1114,8 +1116,14 @@ def from_encoded(cls, encoded: AnyBytes) -> Self:
from apps.common.definitions import decode_definition
- proto = decode_definition(encoded, EthereumDisplayFormatInfo)
+ return cls.from_proto(decode_definition(encoded, EthereumDisplayFormatInfo))
+ @classmethod
+ def from_proto(cls, proto: EthereumDisplayFormatInfo) -> Self:
+ # Clear signing needs a 4-byte selector. Name-only definitions (see
+ # `lookup_known_address`) use a longer one and must not be used for clear signing.
+ if len(proto.func_sig) != SC_FUNC_SIG_BYTES:
+ raise DataError("Invalid display format")
return cls(
binding_context=BindingContext([(proto.chain_id, bytes(proto.address))]),
func_sig=bytes(proto.func_sig),
@@ -1130,35 +1138,6 @@ def from_encoded(cls, encoded: AnyBytes) -> Self:
)
-async def request_definitions(
- chain_id: int, token_address: bytes, func_sig: bytes | None
-) -> tuple[Definitions | None, DisplayFormat | None]:
- from trezor.messages import EthereumDefinitionAck, EthereumDefinitionRequest
- from trezor.wire.context import call
-
- req = EthereumDefinitionRequest(
- chain_id=chain_id,
- token_address=token_address,
- func_sig=func_sig,
- )
- res = await call(req, EthereumDefinitionAck)
-
- if res.definitions is None:
- return None, None
-
- definitions = Definitions.from_encoded(
- res.definitions.encoded_network, res.definitions.encoded_token, chain_id
- )
-
- display_format = (
- DisplayFormat.from_encoded(res.definitions.encoded_display_format)
- if res.definitions.encoded_display_format is not None
- else None
- )
-
- return definitions, display_format
-
-
async def find_display_format(
func_sig: bytes, contract_address: bytes, msg: MsgInSignTx, nested: bool = False
) -> DisplayFormat | None:
@@ -1180,9 +1159,8 @@ async def find_display_format(
return display_format
if msg.supports_definition_request:
- _, display_format = await request_definitions(
- msg.chain_id, contract_address, func_sig
- )
+ _, proto = await request_definitions(msg.chain_id, contract_address, func_sig)
+ display_format = DisplayFormat.from_proto(proto) if proto is not None else None
if display_format is not None and display_format.matches_call(
func_sig, msg.chain_id, contract_address
):
@@ -1270,26 +1248,28 @@ async def _expand_one_subcall(
if index is not None:
subcall = f"{subcall} #{index}"
- def callee_str() -> str:
- return lookup_known_address(msg.chain_id, callee) or address_from_bytes(
- callee, defs.network
+ async def callee_str() -> str:
+ # already inside a subcall: no tertiary lookups
+ known = await lookup_known_address(
+ msg.chain_id, callee, None if nested else msg
)
+ return known or address_from_bytes(callee, defs.network)
- def raw_rows() -> list[RenderedField]:
+ async def raw_rows() -> list[RenderedField]:
"""No subparsing. Show the callee and the raw hex blob."""
to_label = TR.ethereum__subcall_to
blob_label = field_definition.label
if index is not None:
to_label = f"({subcall}) {TR.ethereum__to}"
blob_label = f"({subcall}) {blob_label}"
return [
- ((to_label, callee_str(), None), None, None),
+ ((to_label, await callee_str(), None), None, None),
((blob_label, blob.hex(), None), None, None),
]
if nested:
# already inside a subcall: no tertiary lookups
- return raw_rows()
+ return await raw_rows()
if formatter.selector is not None:
# per ERC-7730, an explicit selector means the blob is args-only
@@ -1299,12 +1279,12 @@ def raw_rows() -> list[RenderedField]:
func_sig = bytes(blob[:SC_FUNC_SIG_BYTES])
body = memoryview(blob)[SC_FUNC_SIG_BYTES:]
else:
- return raw_rows()
+ return await raw_rows()
try:
inner_format = await find_display_format(func_sig, callee, msg, nested=True)
if inner_format is None:
- return raw_rows()
+ return await raw_rows()
_, inner_fields = await inner_format.parse_calldata(
body, msg, defs, nested=True, override_callee=callee
)
@@ -1318,13 +1298,13 @@ def raw_rows() -> list[RenderedField]:
field_definition.label,
type(e).__name__,
)
- return raw_rows()
+ return await raw_rows()
rows: list[RenderedField] = [
(
(
f"({subcall}) {TR.words__provider}",
- inner_format.provider_name or callee_str(),
+ inner_format.provider_name or await callee_str(),
None,
),
None,
@@ -1418,7 +1398,6 @@ async def _handle_approve(
fee_items: Iterable[StrPropertyType],
) -> None:
from .layout import require_confirm_approve
- from .yielding_vaults import UNKNOWN_VAULT, lookup_vault
# approve() is not payable; surface any native ETH sent along with it.
native_value = int.from_bytes(msg.value, "big")
@@ -1448,18 +1427,10 @@ async def _handle_approve(
assert isinstance(arg1_raw_value, int)
- recipient_str = (
- lookup_known_address(msg.chain_id, arg0_raw_value)
- if display_format.provider_name is None
- else display_format.provider_name
- )
+ recipient_str = display_format.provider_name
- # Ideally our vault name and definition should also be added in the ERC-7730 registry
- # Until that is verified, we'll keep our vault information hardcoded.
if recipient_str is None:
- vault = lookup_vault(defs.network, arg0_raw_value)
- if vault is not UNKNOWN_VAULT:
- recipient_str = vault.name
+ recipient_str = await lookup_known_address(msg.chain_id, arg0_raw_value, msg)
# In revocation, the approved amount is set to zero:
is_revoke = arg1_raw_value == 0
@@ -1599,7 +1570,10 @@ async def _handle_generic_ui(
properties_to_confirm.append(token_address_property)
contract_name = (
- (lookup_known_address(msg.chain_id, bytes_from_address(msg.to)) or msg.to)
+ (
+ await lookup_known_address(msg.chain_id, bytes_from_address(msg.to), msg)
+ or msg.to
+ )
if display_format.provider_name is None
else display_format.provider_name
)
### core/src/apps/ethereum/helpers.py
@@ -8,10 +8,16 @@
from buffer_types import AnyBytes
from collections.abc import Awaitable, Callable, Sequence
- from trezor.messages import EthereumFieldType, EthereumTokenInfo
+ from trezor.messages import (
+ EthereumDisplayFormatInfo,
+ EthereumFieldType,
+ EthereumTokenInfo,
+ )
from trezor.ui.layouts import StrPropertyType
from trezor.utils import HashWriter
+ from .definitions import Definitions
+ from .keychain import MsgInSignTx
from .networks import EthereumNetworkInfo
# Fetch the next calldata chunk from host.
@@ -75,15 +81,93 @@ def bytes_from_address(address: str) -> bytes:
raise wire.ProcessError("Ethereum: Invalid address length")
-def lookup_known_address(chain_id: int, address: bytes) -> str | None:
+async def request_definitions(
+ chain_id: int, token_address: bytes, func_sig: bytes | None
+) -> tuple[Definitions | None, EthereumDisplayFormatInfo | None]:
+ """Ask the host for definitions of the network and the token at the address,
+ or for the display format of `func_sig` called on the address."""
+ from trezor.messages import (
+ EthereumDefinitionAck,
+ EthereumDefinitionRequest,
+ EthereumDisplayFormatInfo,
+ )
+ from trezor.wire.context import call
+
+ from apps.common.definitions import decode_definition
+
+ from .definitions import Definitions
+
+ req = EthereumDefinitionRequest(
+ chain_id=chain_id,
+ token_address=token_address,
+ func_sig=func_sig,
+ )
+ res = await call(req, EthereumDefinitionAck)
+
+ if res.definitions is None:
+ return None, None
+
+ definitions = Definitions.from_encoded(
+ res.definitions.encoded_network, res.definitions.encoded_token, chain_id
+ )
+
+ display_format = (
+ decode_definition(
+ res.definitions.encoded_display_format, EthereumDisplayFormatInfo
+ )
+ if res.definitions.encoded_display_format is not None
+ else None
+ )
+
+ return definitions, display_format
+
+
+async def lookup_known_address(
+ chain_id: int, address: bytes, msg: MsgInSignTx | None = None
+) -> str | None:
"""Return a human-readable name of a well-known smart contract,
or `None` if the address is not known.
+
+ Built-in names and known vaults are tried first. If `msg` is given, the host is then asked
+ for a display format of the address, whose provider name is used, and failing that,
+ for a token definition of the address, whose name is used.
"""
from .sc_constants import known_address_iterator
+ from .yielding_vaults import UNKNOWN_VAULT, lookup_vault
for known_chain_id, known_address, name in known_address_iterator():
if chain_id == known_chain_id and address == known_address:
return name
+
+ vault = lookup_vault(chain_id, address)
+ if vault is not UNKNOWN_VAULT:
+ return vault.name
+
+ if msg is not None and msg.supports_definition_request:
+ from .tokens import UNKNOWN_TOKEN
+
+ # Host can send any display formatter, we just care about the provider name.
+ # TODO: definitions should have a simple 000.. display formatter for each contract we clear sign, potentially even unsupported providers.
+ # Name-only definitions use an 8-byte null selector, so they can't collide with a real 4-byte one.
+ _, display_format = await request_definitions(
+ chain_id, address, b"\x00\x00\x00\x00\x00\x00\x00\x00"
+ )
+
+ if (
+ display_format is not None
+ and display_format.chain_id == chain_id
+ and bytes(display_format.address) == address
+ and display_format.provider_name is not None
+ ):
+ return display_format.provider_name
+
+ # No display format: the address may be an ERC-20 token.
+ definitions, _ = await request_definitions(chain_id, address, None)
+ if definitions is not None:
+ token = definitions.get_token(address)
+ if token is not UNKNOWN_TOKEN:
+ return token.name
+
return None
### core/src/apps/ethereum/yielding.py
@@ -211,13 +211,13 @@ async def get_approver(
else:
return None
- vault = lookup_vault(defs.network, address_bytes)
+ vault = lookup_vault(msg.chain_id, address_bytes)
if func_sig == FUNC_SIG_REDEEM:
# redeem() amount is denominated in vault shares
token = vault.vault_token
if vault is UNKNOWN_VAULT and msg.supports_definition_request:
- from .clear_signing import request_definitions
+ from .helpers import request_definitions
token_defs, _ = await request_definitions(msg.chain_id, address_bytes, None)
if token_defs is not None:
@@ -259,8 +259,8 @@ async def _get_asset_token(
from .clear_signing import (
TokenAmountFormatter,
find_display_format,
- request_definitions,
)
+ from .helpers import request_definitions
from .tokens import UNKNOWN_TOKEN
ext_display_format = await find_display_format(func_sig, address_bytes, msg)
### core/src/apps/ethereum/yielding_vaults.py
@@ -158,7 +158,7 @@ async def get_token_label(
return "MORPHO"
if try_fetch_definitions and msg.supports_definition_request:
- from .clear_signing import request_definitions
+ from .helpers import request_definitions
addr = bytes(token_addr)
received_definitions, _ = await request_definitions(
@@ -172,13 +172,11 @@ async def get_token_label(
return "UNKNOWN"
-def lookup_vault(
- network: EthereumNetworkInfo, vault_addr: AnyBytes
-) -> EthereumVaultInfo:
- """Returns the vault info for the given address and network"""
+def lookup_vault(chain_id: int, vault_addr: AnyBytes) -> EthereumVaultInfo:
+ """Returns the vault info for the given address and chain"""
for vault in KNOWN_VAULTS:
- if network.chain_id == vault.chain_id and vault_addr == vault.address:
+ if chain_id == vault.chain_id and vault_addr == vault.address:
return vault
return UNKNOWN_VAULTWhy this scored 27/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.