What changed, and why it matters
This commit is a routine code cleanup for the Ethereum app in Trezor firmware. It replaces several hand-written number-parsing functions with a single factory that generates them automatically, and moves the address parser earlier in the file. There is no indication this fixes a security bug or introduces a vulnerability.
No security action required. Treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff refactors core/src/apps/ethereum/clear_signing.py. A new _make_uint_parser(bit_width) factory creates parsers for unsigned integers of various widths (8–248 bits). Existing functions parse_uint160 and parse_uint24 are redefined through this factory, preserving the same validation (_check_padding_zero then parse_uint256). Additional width variants are added. parse_address is relocated and now uses a const(20) constant for the address byte width, but its logic is unchanged. parse_bool and parse_bytes are untouched.
Changed components
core/src/apps/ethereum/clear_signing.pyInspect captured patch +32 / −17
diff --git a/core/src/apps/ethereum/clear_signing.py b/core/src/apps/ethereum/clear_signing.py
index db1964b6..5dd01742 100644
--- a/core/src/apps/ethereum/clear_signing.py
+++ b/core/src/apps/ethereum/clear_signing.py
@@ -82,24 +82,46 @@ def _check_padding_zero(
raise exc
-def parse_uint256(raw_data: memoryview) -> Value:
+def parse_address(raw_data: memoryview) -> Value:
+ _ZERO_PADDING = const(20)
if len(raw_data) < 32:
raise OutOfBounds
- return int.from_bytes(raw_data, "big")
+ _check_padding_zero(raw_data, _ZERO_PADDING, DirtyAddress)
+ return bytes(raw_data[32 - _ZERO_PADDING :])
-def parse_uint160(raw_data: memoryview) -> Value:
+def parse_uint256(raw_data: memoryview) -> Value:
if len(raw_data) < 32:
raise OutOfBounds
- _check_padding_zero(raw_data, 160 // 8)
- return parse_uint256(raw_data)
+ return int.from_bytes(raw_data, "big")
-def parse_uint24(raw_data: memoryview) -> Value:
- if len(raw_data) < 32:
- raise OutOfBounds
- _check_padding_zero(raw_data, 24 // 8)
- return parse_uint256(raw_data)
+def _make_uint_parser(bit_width: int) -> "Parser":
+ byte_width = bit_width // 8
+
+ def parser(raw_data: memoryview) -> Value:
+ if len(raw_data) < 32:
+ raise OutOfBounds
+ _check_padding_zero(raw_data, byte_width)
+ return parse_uint256(raw_data)
+
+ return parser
+
+
+parse_uint248 = _make_uint_parser(248)
+parse_uint160 = _make_uint_parser(160)
+parse_uint128 = _make_uint_parser(128)
+parse_uint120 = _make_uint_parser(120)
+parse_uint112 = _make_uint_parser(112)
+parse_uint96 = _make_uint_parser(96)
+parse_uint72 = _make_uint_parser(72)
+parse_uint64 = _make_uint_parser(64)
+parse_uint48 = _make_uint_parser(48)
+parse_uint40 = _make_uint_parser(40)
+parse_uint32 = _make_uint_parser(32)
+parse_uint24 = _make_uint_parser(24)
+parse_uint16 = _make_uint_parser(16)
+parse_uint8 = _make_uint_parser(8)
def parse_bool(raw_data: memoryview) -> Value:
@@ -111,13 +133,6 @@ def parse_bool(raw_data: memoryview) -> Value:
return uint_value == 1
-def parse_address(raw_data: memoryview) -> Value:
- if len(raw_data) < 32:
- raise OutOfBounds
- _check_padding_zero(raw_data, 20, DirtyAddress)
- return bytes(raw_data[32 - 20 :])
-
-
def parse_bytes(raw_data: memoryview) -> Value:
return bytes(raw_data)
Why this scored 12/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.