feat(clear_signing,test): added script to update the latest definitions from prod
What changed, and why it matters
This commit adds two helper scripts for Trezor's internal testing workflow. They download or convert signed Ethereum/Solana definition files and verify their digital signatures before converting them into JSON test fixtures. There is no change to the firmware that runs on customer devices, no change to how signatures are verified in production code, and no disclosed security issue.
No security action required. Reviewers may optionally confirm that the signature verification logic correctly uses production keys and that the --dev flag is not accidentally used in CI for production fixtures.
Security signals we found
Signature verification is performed before decoding definitions
Trailing data and unknown protobuf fields are explicitly rejected
Only test fixtures / developer tooling are affected, not device firmware
No changelog entry, but commit title and message describe routine test-infrastructure work
Evidence from the diff
The commit introduces tools/snippets/eth_defs_refresh_json.py and tools/snippets/eth_defs_dat_to_json.py, plus README updates. eth_defs_refresh_json.py refreshes test fixtures from data.trezor.io, verifies production signatures via trezorlib.definitions, and reports missing upstream definitions. eth_defs_dat_to_json.py converts a single signed .dat definition to JSON fixture format, also verifying the signature (production by default, –dev for development keys). Both scripts reject definitions that fail signature verification or contain trailing/unknown data. The code is additive test tooling only.
Changed components
tools/snippets/eth_defs_refresh_json.pytools/snippets/eth_defs_dat_to_json.pytools/snippets/README.mdInspect captured patch +188 / −0
### tools/snippets/README.md
@@ -22,6 +22,17 @@ These scripts do not need to have a high standard, but each of those should have
- Unpacks the definitions from a `definitions-sparse.zip` that does not contain the
Merkle proofs for space-saving. This format is not currently distributed.
+## [eth_defs_refresh_json.py](./eth_defs_refresh_json.py)
+- Refreshes the JSON Ethereum definitions used by the device tests
+ (`common/tests/fixtures/ethereum/definitions`) with the latest production ones
+ from `data.trezor.io`, so the tests reflect what customers see.
+- Verifies the production signatures; definitions missing upstream are kept and reported.
+
+## [eth_defs_dat_to_json.py](./eth_defs_dat_to_json.py)
+- Converts a single signed `.dat` definition into the JSON fixture format, reusing
+ `dat_to_dict` from `eth_defs_refresh_json.py`.
+- Verifies the signature (production keys, or `--dev`); writes next to the input, to `-o FILE`, or to stdout with `-o -`.
+
## [recalc_optiga_for_emulator.py](./recalc_optiga_for_emulator.py)
- Takes a valid Infineon certificate from an Optiga and replaces its public key with
a pubkey for private key 0x01000000..., so that the staging HSM can sign the resulting
### tools/snippets/eth_defs_dat_to_json.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+
+# This file is part of the Trezor project.
+#
+# Copyright (C) SatoshiLabs and contributors
+#
+# This library is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the License along with this library.
+# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+
+import click
+from eth_defs_refresh_json import dat_to_dict
+
+
+@click.command()
+@click.argument(
+ "dat_file",
+ type=click.Path(exists=True, dir_okay=False, resolve_path=True, path_type=Path),
+)
+@click.option(
+ "-o",
+ "--output",
+ type=click.Path(dir_okay=False, writable=True, allow_dash=True, path_type=Path),
+ help="Output JSON file, or '-' for stdout. [default: DAT_FILE with .json suffix]",
+)
+@click.option(
+ "--dev",
+ is_flag=True,
+ help="Verify against the development signing keys instead of the production ones.",
+)
+def dat_to_json(dat_file: Path, output: Path | None, dev: bool) -> None:
+ """Convert a signed Ethereum/Solana definition DAT_FILE into the JSON
+ fixture format used by the tests.
+
+ The signature is verified before decoding; definitions that fail the
+ verification are rejected."""
+ try:
+ converted = dat_to_dict(dat_file.read_bytes(), dev=dev)
+ except Exception as e:
+ raise click.ClickException(f"{dat_file.name}: {e}") from e
+ text = json.dumps(converted, indent=2) + "\n"
+
+ if str(output) == "-":
+ click.echo(text, nl=False)
+ return
+
+ if output is None:
+ output = dat_file.with_suffix(".json")
+ output.write_text(text)
+ click.echo(f"written: {output}", err=True)
+
+
+if __name__ == "__main__":
+ dat_to_json()
### tools/snippets/eth_defs_refresh_json.py
@@ -0,0 +1,110 @@
+#!/usr/bin/env python3
+
+# This file is part of the Trezor project.
+#
+# Copyright (C) SatoshiLabs and contributors
+#
+# This library is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the License along with this library.
+# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
+
+from __future__ import annotations
+
+import io
+import json
+from pathlib import Path
+
+import click
+
+from trezorlib import definitions, messages, protobuf
+
+PROD_URL = "https://data.trezor.io/firmware/definitions/v2/"
+
+MESSAGE_TYPES: dict[messages.DefinitionType, type[protobuf.MessageType]] = {
+ messages.DefinitionType.ETHEREUM_NETWORK: messages.EthereumNetworkInfo,
+ messages.DefinitionType.ETHEREUM_TOKEN: messages.EthereumTokenInfo,
+ messages.DefinitionType.SOLANA_TOKEN: messages.SolanaTokenInfo,
+ messages.DefinitionType.ETHEREUM_DISPLAY_FORMAT: messages.EthereumDisplayFormatInfo,
+}
+
+DEFAULT_DIR = (
+ Path(__file__).resolve().parents[2]
+ / "common"
+ / "tests"
+ / "fixtures"
+ / "ethereum"
+ / "definitions"
+)
+
+
+def dat_to_dict(dat: bytes, dev: bool = False) -> dict:
+ """Verify a signed definition (production keys unless `dev`) and decode it
+ into the JSON fixture format (definition type and message)."""
+ definition = definitions.Definition.parse(dat)
+ if len(definition.build()) != len(dat):
+ raise ValueError("trailing data after the definition")
+ definition.verify(dev=dev)
+ payload = definition.payload
+ msg_type = MESSAGE_TYPES[payload.data_type]
+ msg = protobuf.load_message(io.BytesIO(payload.data), msg_type)
+ # unknown fields are silently skipped when loading, so make sure that
+ # re-encoding yields the signed bytes, i.e. nothing was left unread
+ reencoded = io.BytesIO()
+ protobuf.dump_message(reencoded, msg)
+ if reencoded.getvalue() != payload.data:
+ raise ValueError("definition has fields unknown to trezorlib")
+ return {"data_type": payload.data_type.name, "message": protobuf.to_dict(msg)}
+
+
+@click.command()
+@click.argument(
+ "directory",
+ type=click.Path(exists=True, file_okay=False, resolve_path=True, path_type=Path),
+ default=DEFAULT_DIR,
+)
+@click.option("-u", "--url", default=PROD_URL, show_default=True, help="Base URL.")
+def refresh(directory: Path, url: str) -> None:
+ """Refresh the JSON definitions under DIRECTORY with the latest ones
+ published at URL, i.e. what customers currently see.
+
+ Only existing files are refreshed; definitions that are missing upstream
+ are left untouched and reported. DIRECTORY defaults to the Ethereum
+ definitions in the common test fixtures."""
+ source = definitions.UrlSource(url)
+ updated, missing = [], []
+ json_files = sorted(directory.rglob("*.json"))
+ for json_path in json_files:
+ rel = json_path.relative_to(directory)
+ dat = source.fetch_path(*rel.with_suffix(".dat").parts)
+ if dat is None:
+ missing.append(rel)
+ continue
+ try:
+ converted = dat_to_dict(dat)
+ except Exception as e:
+ raise click.ClickException(f"{rel}: {e}") from e
+ new_text = json.dumps(converted, indent=2) + "\n"
+ if json_path.read_text() != new_text:
+ json_path.write_text(new_text)
+ updated.append(rel)
+
+ for rel in updated:
+ click.echo(f"updated: {rel}")
+ for rel in missing:
+ click.echo(f"missing upstream: {rel}")
+ click.echo(
+ f"{len(json_files)} files: {len(updated)} updated, {len(missing)} missing, "
+ f"{len(json_files) - len(updated) - len(missing)} unchanged."
+ )
+
+
+if __name__ == "__main__":
+ refresh()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.