feat(clear_signing): support conditional visibility
What changed, and why it matters
This commit adds a new feature to Trezor's Ethereum 'clear signing' system that lets wallet metadata definitions hide or require certain transaction fields based on their decoded values. It introduces two new conditions: 'ifNotIn' (hide the field if its value is not in an allowed list) and 'mustMatch' (raise an error if the value does not match an expected list). The change is a feature implementation, not a bug fix, and there is no vendor statement that it fixes a security vulnerability.
Treat as a feature commit rather than a vulnerability fix. Review whether metadata definitions using ifNotIn/mustMatch are cryptographically signed and validated before use, since a tampered definition could hide warnings or trigger denial-of-service by failing mustMatch checks. Consider adding tests for adversarial metadata and user-interface review to ensure hidden fields cannot conceal critical transaction details.
Security signals we found
New exception path (MustMatchViolation) can abort transaction rendering if a metadata-supplied mustMatch list is not satisfied
Conditional hiding (ifNotIn) could be abused by a malicious or compromised metadata definition to suppress security-relevant fields from the user interface
Constant paths are explicitly rejected when combined with ifNotIn/mustMatch, suggesting awareness of metadata-manipulation risk
No changelog entry and no vendor security framing in commit message
Evidence from the diff
The patch extends core/src/apps/ethereum/clear_signing.py to support conditional field visibility in ERC-7730-style metadata. It adds a MustMatchViolation exception, a _to_bytes() helper that canonicalizes decoded values for comparison, and if_not_in/must_match parameters on FieldDefinition. During rendering, each field’s decoded value is checked: if must_match is set and the value is absent from the list, an exception is raised; if if_not_in is set and the value is in the list, the field is hidden. Constant paths combined with these filters are rejected as invalid format definitions. The commit is tagged [no changelog] and framed as a feature.
Changed components
core/src/apps/ethereum/clear_signing.pyEthereum clear-signing / ERC-7730 metadata rendering pathInspect captured patch +48 / −2
### core/src/apps/ethereum/clear_signing.py
@@ -117,6 +117,10 @@ class InvalidFormatDefinition(ClearSigningFailed):
pass
+class MustMatchViolation(ValueError):
+ pass
+
+
def _check_padding_zero(
raw_data: memoryview, used_bytes: int, exc: type[ValueOverflow] = ValueOverflow
) -> None:
@@ -200,6 +204,21 @@ def _word_bytes(value: AnyValue) -> AnyValue:
return value
+def _to_bytes(value: AnyValue) -> bytes:
+ """Byte form of a decoded value as compared against `ifNotIn` /
+ `mustMatch`: ints (uint/int/bool/@.value) as a 32-byte two's-complement
+ word, strings as UTF-8, address/bytesN/bytes/slices as-is. Anything else
+ (None, arrays) is rejected."""
+ # bool listed explicitly: in MicroPython it is not an int subclass
+ if isinstance(value, (int, bool)):
+ return (value % (1 << _EVM_WORD_BITS)).to_bytes(_EVM_WORD_SIZE, "big")
+ if isinstance(value, str):
+ return value.encode()
+ if isinstance(value, (bytes, bytearray)):
+ return bytes(value)
+ raise InvalidFormatDefinition # Arrays not expected.
+
+
def parse_bool(raw_data: memoryview) -> Value:
if len(raw_data) < _EVM_WORD_SIZE:
raise OutOfBounds
@@ -858,10 +877,24 @@ def __init__(
path: Path,
label: str,
formatter: FieldFormatter | type[FieldFormatter],
+ if_not_in: list[bytes] | None = None,
+ must_match: list[bytes] | None = None,
) -> None:
self.path = path
self.label = label
self.formatter = formatter
+ self.if_not_in = if_not_in
+ self.must_match = must_match
+
+ def is_hidden(self, value: AnyValue) -> bool:
+ """Raise if mustMatch is violated, return True if ifNotIn suggests hiding"""
+ if self.must_match:
+ if _to_bytes(value) not in self.must_match:
+ raise MustMatchViolation
+ return True
+ if self.if_not_in:
+ return _to_bytes(value) in self.if_not_in
+ return False
@staticmethod
def from_proto(info: EthereumERC7730FieldInfo) -> "FieldDefinition":
@@ -884,6 +917,11 @@ def decode_path(p: EthereumERC7730Path) -> Path:
return tuple(steps)
path = decode_path(info.path)
+ if isinstance(path, str) and (info.if_not_in or info.must_match):
+ # Constant path = metadata stuff. No validation required.
+ # Definitions should drop it already
+ # https://github.com/trezor/definitions/pull/156
+ raise InvalidFormatDefinition
fmt_type = info.formatter
if fmt_type == FT.FORMATTER_ADDRESS_NAME:
@@ -941,7 +979,13 @@ def decode_path(p: EthereumERC7730Path) -> Path:
else:
raise InvalidFormatDefinition
- return FieldDefinition(path=path, label=info.label, formatter=formatter)
+ return FieldDefinition(
+ path=path,
+ label=info.label,
+ formatter=formatter,
+ if_not_in=[bytes(b) for b in info.if_not_in],
+ must_match=[bytes(b) for b in info.must_match],
+ )
def get_formatter(self) -> FieldFormatter:
# instantiate formatters only if needed
@@ -1087,6 +1131,9 @@ def get_value_for_path(path: Path) -> AnyValue:
fields: list[RenderedField] = []
for field_definition in self.field_definitions:
try:
+ value = get_value_for_path(field_definition.path)
+ if field_definition.is_hidden(value):
+ continue
formatter = field_definition.get_formatter()
if isinstance(formatter, CalldataFormatter):
# Expands into multiple rows (the subcall's provider and
@@ -1103,7 +1150,6 @@ def get_value_for_path(path: Path) -> AnyValue:
)
)
continue
- value = get_value_for_path(field_definition.path)
formatted, token, token_address = await _format_field_value(
formatter, value, msg, defs, get_value_for_path
)Why this scored 26/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.