tests(clear_signing): add unit tests and a device test.
What changed, and why it matters
This commit only adds new automated tests and test data for Trezor's Ethereum 'clear signing' feature. It does not change any production firmware code, so it cannot introduce a security vulnerability or fix one in shipped devices.
No security action required; review as normal test-only commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff consists entirely of test fixtures (JSON display-format definitions for Flare/FXRP) and Python unit tests covering _to_bytes, ifNotIn visibility, mustMatch validation, and end-to-end parsing. No runtime firmware logic is modified. The tests assert that a MustMatchViolation aborts signing and is not treated as a ClearSigningFailed (i.e., it does not fall back to blind signing), which is a defensive behavior.
Changed components
core/tests/test_apps.ethereum.clear_signing.pycommon/tests/fixtures/ethereum/definitions/eth/chain-id/14/*common/tests/fixtures/ethereum/sign_tx_external_definitions.jsontests/ui_tests/fixtures.jsonInspect captured patch +868 / −532
### common/tests/fixtures/ethereum/definitions/eth/chain-id/14/display-format/ad552a648c74d49e10027ab8a618a3ad4901c5be-0000000000000000.json
@@ -0,0 +1,10 @@
+{
+ "data_type": "ETHEREUM_DISPLAY_FORMAT",
+ "message": {
+ "chain_id": 14,
+ "address": "ad552a648c74d49e10027ab8a618a3ad4901c5be",
+ "func_sig": "0000000000000000",
+ "intent": "",
+ "provider_name": "Flare Foundation: FXRP"
+ }
+}
### common/tests/fixtures/ethereum/definitions/eth/chain-id/14/display-format/d70659a6396285bf7214d7ea9673184e7c72e07e-0000000000000000.json
@@ -0,0 +1,10 @@
+{
+ "data_type": "ETHEREUM_DISPLAY_FORMAT",
+ "message": {
+ "chain_id": 14,
+ "address": "d70659a6396285bf7214d7ea9673184e7c72e07e",
+ "func_sig": "0000000000000000",
+ "intent": "",
+ "provider_name": "Flare Foundation: FXRP-OFT-Flare"
+ }
+}
### common/tests/fixtures/ethereum/definitions/eth/chain-id/14/display-format/d70659a6396285bf7214d7ea9673184e7c72e07e-c7c7f5b3.json
@@ -0,0 +1,171 @@
+{
+ "data_type": "ETHEREUM_DISPLAY_FORMAT",
+ "message": {
+ "chain_id": 14,
+ "address": "d70659a6396285bf7214d7ea9673184e7c72e07e",
+ "func_sig": "c7c7f5b3",
+ "intent": "Bridge FXRP",
+ "parameter_definitions": [
+ {
+ "tuple": {
+ "fields": [
+ {
+ "atomic": "ABI_UINT32"
+ },
+ {
+ "atomic": "ABI_BYTES32"
+ },
+ {
+ "atomic": "ABI_UINT256"
+ },
+ {
+ "atomic": "ABI_UINT256"
+ },
+ {
+ "dynamic": "ABI_BYTES"
+ },
+ {
+ "dynamic": "ABI_BYTES"
+ },
+ {
+ "dynamic": "ABI_BYTES"
+ }
+ ],
+ "is_dynamic": true
+ }
+ },
+ {
+ "tuple": {
+ "fields": [
+ {
+ "atomic": "ABI_UINT256"
+ },
+ {
+ "atomic": "ABI_UINT256"
+ }
+ ],
+ "is_dynamic": false
+ }
+ },
+ {
+ "atomic": "ABI_ADDRESS"
+ }
+ ],
+ "field_definitions": [
+ {
+ "path": {
+ "path": [
+ 0,
+ 2
+ ]
+ },
+ "label": "Amount to send",
+ "formatter": "FORMATTER_TOKEN_AMOUNT",
+ "const_token_address": "ad552a648c74d49e10027ab8a618a3ad4901c5be",
+ "lookup_address": false,
+ "lookup_token": false,
+ "lookup_contract": false
+ },
+ {
+ "path": {
+ "path": [
+ 0,
+ 3
+ ]
+ },
+ "label": "Minimum to receive",
+ "formatter": "FORMATTER_TOKEN_AMOUNT",
+ "const_token_address": "ad552a648c74d49e10027ab8a618a3ad4901c5be",
+ "lookup_address": false,
+ "lookup_token": false,
+ "lookup_contract": false
+ },
+ {
+ "path": {
+ "path": [
+ 0,
+ 0
+ ]
+ },
+ "label": "Destination",
+ "formatter": "FORMATTER_ENUM",
+ "enum_values": [
+ {
+ "key": 30101,
+ "value": "Ethereum"
+ },
+ {
+ "key": 30102,
+ "value": "BNB Chain"
+ },
+ {
+ "key": 30184,
+ "value": "Base"
+ },
+ {
+ "key": 30375,
+ "value": "Katana"
+ }
+ ],
+ "lookup_address": false,
+ "lookup_token": false,
+ "lookup_contract": false
+ },
+ {
+ "path": {
+ "path": [
+ 0,
+ 1
+ ]
+ },
+ "label": "Recipient",
+ "formatter": "FORMATTER_RAW",
+ "lookup_address": false,
+ "lookup_token": false,
+ "lookup_contract": false
+ },
+ {
+ "path": {
+ "path": [
+ 1,
+ 0
+ ]
+ },
+ "label": "Bridge fee",
+ "formatter": "FORMATTER_AMOUNT",
+ "lookup_address": false,
+ "lookup_token": false,
+ "lookup_contract": false
+ },
+ {
+ "path": {
+ "path": [
+ 2
+ ]
+ },
+ "label": "Refund to",
+ "formatter": "FORMATTER_ADDRESS_NAME",
+ "lookup_address": false,
+ "lookup_token": false,
+ "lookup_contract": false
+ },
+ {
+ "path": {
+ "path": [
+ 1,
+ 1
+ ]
+ },
+ "label": "LZ token fee",
+ "formatter": "FORMATTER_RAW",
+ "lookup_address": false,
+ "lookup_token": false,
+ "lookup_contract": false,
+ "must_match": [
+ "0000000000000000000000000000000000000000000000000000000000000000"
+ ]
+ }
+ ],
+ "provider_name": "Flare Foundation: FXRP-OFT-Flare"
+ }
+}
### common/tests/fixtures/ethereum/definitions/eth/chain-id/14/network.json
@@ -0,0 +1,9 @@
+{
+ "data_type": "ETHEREUM_NETWORK",
+ "message": {
+ "chain_id": 14,
+ "symbol": "FLR",
+ "slip44": 60,
+ "name": "Flare"
+ }
+}
### common/tests/fixtures/ethereum/definitions/eth/chain-id/14/token-ad552a648c74d49e10027ab8a618a3ad4901c5be.json
@@ -0,0 +1,10 @@
+{
+ "data_type": "ETHEREUM_TOKEN",
+ "message": {
+ "address": "ad552a648c74d49e10027ab8a618a3ad4901c5be",
+ "chain_id": 14,
+ "symbol": "FXRP",
+ "decimals": 6,
+ "name": "Flare Bridged XRP (Flare)"
+ }
+}
### common/tests/fixtures/ethereum/sign_tx_external_definitions.json
@@ -1423,6 +1423,26 @@
"sig_r": "fe4dbd5195ada16ec8b76f6bb3dda9c641bf093231df3f53f16d00c2fe56acc9",
"sig_s": "0f8bb12a0542c2c80bc03180024fd5b0c16f5042a1ec692fc7738f2c62bcefa9"
}
+ },
+ {
+ "name": "flare_FXRP_OFT_Flare_send",
+ "parameters": {
+ "comment": "supported | https://flare-explorer.flare.network/tx/0xf34572cdaac9b2b2eae91306b1b77cb6f31eaaf1fc17003313873c731b88e599",
+ "data": "c7c7f5b300000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000213b60b57b87343f55000000000000000000000000000000000000000000000000000000000000000000000000000000000000000091a4ca15642b2b55f38c7f1effcb228b9a7a87a1000000000000000000000000000000000000000000000000000000000000759500000000000000000000000091a4ca15642b2b55f38c7f1effcb228b9a7a87a10000000000000000000000000000000000000000000000000000000115d21fde0000000000000000000000000000000000000000000000000000000115d21fde00000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
+ "path": "m/44'/60'/0'/0/0",
+ "to_address": "0xd70659a6396285BF7214d7Ea9673184e7C72E07E",
+ "chain_id": 14,
+ "nonce": "0x0",
+ "gas_price": "0x1d1a94a2258",
+ "gas_limit": "0xaae60",
+ "tx_type": null,
+ "value": "0x213b60b57b87343f55"
+ },
+ "result": {
+ "sig_v": 63,
+ "sig_r": "d4acc9c84cb0e778c573385fcabfee8480638f186520596b015424b926e8ec6b",
+ "sig_s": "77c059c48945455ab554e6479bc6aa9c3b7f10e2890c20c62cdd638017ee6e01"
+ }
}
]
}
### core/tests/test_apps.ethereum.clear_signing.py
@@ -24,6 +24,7 @@
Array,
Atomic,
CalldataFormatter,
+ ClearSigningFailed,
ContainerPath,
DateFormatter,
DirtyAddress,
@@ -33,13 +34,15 @@
EnumFormatter,
FieldDefinition,
InvalidFormatDefinition,
+ MustMatchViolation,
OutOfBounds,
RawFormatter,
TokenAmountFormatter,
Tuple,
ValueOverflow,
_expand_calldata_field,
_format_field_value,
+ _to_bytes,
make_fixed_bytes_parser,
make_int_parser,
make_uint_parser,
@@ -1205,6 +1208,81 @@ def test_const_value_end_to_end(self):
self.assertIsNone(token)
self.assertIsNone(token_address)
+ # --- conditional visibility (`ifNotIn` / `mustMatch`) ---
+
+ def test_visibility_to_bytes(self):
+ # numbers (incl. bool, negatives) as the 32-byte ABI word
+ self.assertEqual(_to_bytes(0), b"\x00" * 32)
+ self.assertEqual(_to_bytes(True), b"\x00" * 31 + b"\x01")
+ self.assertEqual(_to_bytes(-1), b"\xff" * 32)
+ # bytes as-is, strings as UTF-8
+ self.assertEqual(_to_bytes(b"\xab" * 20), b"\xab" * 20)
+ self.assertEqual(_to_bytes("hi"), b"hi")
+ # no defined byte form
+ for value in (None, [0]):
+ with self.assertRaises(InvalidFormatDefinition):
+ _to_bytes(value)
+
+ def test_visibility_if_not_in(self):
+ field = FieldDefinition((0,), "Expiry", RawFormatter, if_not_in=[to_bytes(0)])
+ self.assertTrue(field.is_hidden(0))
+ self.assertFalse(field.is_hidden(5))
+ # no rule: always shown
+ self.assertFalse(FieldDefinition((0,), "X", RawFormatter).is_hidden(0))
+
+ def test_visibility_must_match(self):
+ field = FieldDefinition((0,), "Token", RawFormatter, must_match=[b"\x22" * 20])
+ self.assertTrue(field.is_hidden(b"\x22" * 20))
+ with self.assertRaises(MustMatchViolation):
+ field.is_hidden(b"\x33" * 20)
+ # must abort signing, never degrade to blind signing
+ self.assertFalse(issubclass(MustMatchViolation, ClearSigningFailed))
+
+ def test_from_proto_visibility(self):
+ info = EthereumERC7730FieldInfo(
+ path=EthereumERC7730Path(path=[0]),
+ label="Fee",
+ formatter=FT.FORMATTER_RAW,
+ if_not_in=[to_bytes(0)],
+ )
+ self.assertTrue(FieldDefinition.from_proto(info).is_hidden(0))
+
+ # a rule on a constant path is refused
+ info = EthereumERC7730FieldInfo(
+ path=EthereumERC7730Path(const_value="kmgcEURC"),
+ label="Share ticker",
+ formatter=FT.FORMATTER_RAW,
+ if_not_in=[b"kmgcEURC"],
+ )
+ with self.assertRaises(InvalidFormatDefinition):
+ FieldDefinition.from_proto(info)
+
+ def test_visibility_end_to_end(self):
+ # f(uint256 fee, uint256 amount): "Fee" hidden when 0, "Amount" must be 7
+ display_format = DisplayFormat(
+ binding_context=None,
+ func_sig=b"\x00\x00\x00\x00",
+ provider_name=None,
+ intent="Test",
+ parameter_definitions=[Atomic(parse_uint256), Atomic(parse_uint256)],
+ field_definitions=[
+ FieldDefinition((0,), "Fee", RawFormatter, if_not_in=[to_bytes(0)]),
+ FieldDefinition((1,), "Amount", RawFormatter, must_match=[to_bytes(7)]),
+ ],
+ )
+
+ def labels(fee: int, amount: int) -> list[str]:
+ calldata = memoryview(to_bytes(fee) + to_bytes(amount))
+ _, fields = await_result(
+ display_format.parse_calldata(calldata, None, None)
+ )
+ return [label for (label, _, _), _, _ in fields]
+
+ self.assertEqual(labels(3, 7), ["Fee"])
+ self.assertEqual(labels(0, 7), [])
+ with self.assertRaises(MustMatchViolation):
+ labels(3, 8)
+
# --- path byte-slices (`token.[-20:]` etc.) ---
def test_from_proto_path_slice(self):
### tests/ui_tests/fixtures.json
[binary or diff unavailable]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.