chore(ethereum): move lookup_address logic to helper
What changed, and why it matters
This commit is a simple internal code cleanup: it moves a helper function that looks up well-known Ethereum smart contract names from one file to another and renames a private generator function to be public. There is no change to user-facing behavior, no bug fix, and no security improvement or regression.
No security action required; treat as routine maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors lookup_known_address out of sc_constants.py (and its Mako template) into helpers.py, importing it where needed in clear_signing.py. It also renames _known_address_iterator to known_address_iterator and updates callers. The logic, data set, and semantics are unchanged.
Changed components
core/src/apps/ethereum/clear_signing.pycore/src/apps/ethereum/helpers.pycore/src/apps/ethereum/sc_constants.pycore/src/apps/ethereum/sc_constants.py.makoInspect captured patch +17 / −27
### core/src/apps/ethereum/clear_signing.py
@@ -10,6 +10,7 @@
bytes_from_address,
format_ethereum_amount,
get_account_and_path,
+ lookup_known_address,
)
if TYPE_CHECKING:
@@ -1257,7 +1258,6 @@ async def _expand_one_subcall(
callee and the raw hex blob, instead of failing the outer transaction.
`index` is the subcall's 1-based position when it comes from an array of
subcalls, reflected in the label prefix: "(Subcall #<index>)"."""
- from .sc_constants import lookup_known_address
if not isinstance(blob, bytes):
# Calldata should be a bytes field
@@ -1418,7 +1418,6 @@ async def _handle_approve(
fee_items: Iterable[StrPropertyType],
) -> None:
from .layout import require_confirm_approve
- from .sc_constants import lookup_known_address
from .yielding_vaults import UNKNOWN_VAULT, lookup_vault
# approve() is not payable; surface any native ETH sent along with it.
@@ -1570,7 +1569,6 @@ async def _handle_generic_ui(
from .helpers import bytes_from_address
from .layout import require_confirm_clear_signing
from .networks import UNKNOWN_NETWORK
- from .sc_constants import lookup_known_address
# Surface the native ETH value in the summary when non-zero - unless one of
# the display format's own fields already renders it (e.g. a swap's "Amount
### core/src/apps/ethereum/helpers.py
@@ -75,6 +75,18 @@ 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:
+ """Return a human-readable name of a well-known smart contract,
+ or `None` if the address is not known.
+ """
+ from .sc_constants import known_address_iterator
+
+ for known_chain_id, known_address, name in known_address_iterator():
+ if chain_id == known_chain_id and address == known_address:
+ return name
+ return None
+
+
def get_type_name(field: EthereumFieldType) -> str:
"""Create a string from type definition (like uint256 or bytes16)."""
from trezor.enums import EthereumDataType
### core/src/apps/ethereum/sc_constants.py
@@ -9,18 +9,8 @@
from collections.abc import Iterator
-def lookup_known_address(chain_id: int, address: bytes) -> str | None:
- """Return a human-readable name of a well-known smart contract,
- or `None` if the address is not known.
- """
- for known_chain_id, known_address, name in _known_address_iterator():
- if chain_id == known_chain_id and address == known_address:
- return name
- return None
-
-
-def _known_address_iterator() -> Iterator[tuple[int, bytes, str]]:
- # NOTE: implementing the `_known_address_iterator` as a generator instead of an if-tree of `return` statements saves flash size (Same trick as in `apps.ethereum.tokens`.)
+def known_address_iterator() -> Iterator[tuple[int, bytes, str]]:
+ # NOTE: implementing the `known_address_iterator` as a generator instead of an if-tree of `return` statements saves flash size (Same trick as in `apps.ethereum.tokens`.)
yield (1, b"\x68\xb3\x46\x58\x33\xfb\x72\xa7\x0e\xcd\xf4\x85\xe0\xe4\xc7\xbd\x86\x65\xfc\x45", "Uniswap V3 Router")
yield (1, b"\xe5\x92\x42\x7a\x0a\xec\xe9\x2d\xe3\xed\xee\x1f\x18\xe0\x15\x7c\x05\x86\x15\x64", "Uniswap V3 Router")
### core/src/apps/ethereum/sc_constants.py.mako
@@ -53,18 +53,8 @@ WETH_DEPLOYMENTS = [
%>
-def lookup_known_address(chain_id: int, address: bytes) -> str | None:
- """Return a human-readable name of a well-known smart contract,
- or `None` if the address is not known.
- """
- for known_chain_id, known_address, name in _known_address_iterator():
- if chain_id == known_chain_id and address == known_address:
- return name
- return None
-
-
-def _known_address_iterator() -> Iterator[tuple[int, bytes, str]]:
- # NOTE: implementing the `_known_address_iterator` as a generator instead of an if-tree of `return` statements saves flash size (Same trick as in `apps.ethereum.tokens`.)
+def known_address_iterator() -> Iterator[tuple[int, bytes, str]]:
+ # NOTE: implementing the `known_address_iterator` as a generator instead of an if-tree of `return` statements saves flash size (Same trick as in `apps.ethereum.tokens`.)
% for chain_id, addr, name in KNOWN_ADDRESSES:
yield (${chain_id}, ${fmt_addr(addr)}, "${name}")Why this scored 15/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.