Skip to content

fix(core): adaptation related to Polkadot updates#403

Merged
somebodyLi merged 4 commits intomainfrom
4.18.0
Dec 16, 2025
Merged

fix(core): adaptation related to Polkadot updates#403
somebodyLi merged 4 commits intomainfrom
4.18.0

Conversation

@somebodyLi
Copy link
Contributor

@somebodyLi somebodyLi commented Dec 16, 2025

Summary by CodeRabbit

  • New Features

    • Added support for Hydration and Bifrost Polkadot networks.
    • Introduced USB and BLE connectivity management controls.
    • Added address prefix support for Polkadot transactions.
  • Chores

    • Updated firmware version to 4.18.0.

✏️ Tip: You can customize this high-level summary in your review settings.

@somebodyLi somebodyLi requested a review from a team as a code owner December 16, 2025 09:09
@revan-zhang
Copy link
Contributor

revan-zhang commented Dec 16, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link

coderabbitai bot commented Dec 16, 2025

Walkthrough

This PR adds support for three new Polkadot networks (hydration, bifrost, bifrost-ksm) with corresponding UI assets and deserialization logic. Updates include firmware version bump, USB/BLE state management refactoring across storage and utility modules, Polkadot prefix field additions to proto and message definitions, UI button enhancements, homescreen conditional rendering, and artifact naming changes in CI workflows.

Changes

Cohort / File(s) Summary
Polkadot Network Support
common/protob/messages-polkadot.proto, core/src/apps/polkadot/__init__.py, core/src/apps/polkadot/helper.py, core/src/apps/polkadot/sign_tx.py, core/src/apps/polkadot/transaction.py, core/src/trezor/messages.py, python/src/trezorlib/messages.py
Added prefix field to PolkadotSignTx proto/message; extended network support with hydration, bifrost, bifrost-ksm by adding new color/icon constants, coin tickers, and network-specific deserialization paths; modified get_address_type to accept optional preset_prefix parameter; updated sign_tx and transaction deserialization to route new networks through appropriate handlers.
Firmware & Versioning
core/embed/firmware/version.h, .github/workflows/build-pro.yml
Bumped firmware minor version 17→18, reset patch 1→0; renamed workflow matrix artifact suffixes bc-only→btc-only.
Storage & Device State
core/src/storage/device.py, core/src/trezor/uart.py, core/src/trezor/utils.py
Added USB/BLE public fields and accessors; introduced storage_device alias; refactored USB/airgap state management; added is_usb_enabled(), enable/disable_usb(), enable/disable_ble() helpers; renamed AIRGAP_MODE_CHANGED to USB_STATE_CHANGED.
UR Registry & Chain Handlers
core/src/apps/ur_registry/chains/base_sign_request.py, core/src/apps/ur_registry/chains/ethereum/typed_data_transacion.py, core/src/apps/ur_registry/chains/hardware_requests/get_multi_accounts.py, core/src/apps/ur_registry/crypto_multi_accounts.py, core/src/apps/ur_registry/helpers.py
Renamed sol_sign_req variable to sign_req; refactored error handling with sys.print_exception; added debug prints behind __debug__ gate; gated ETH/TRON/SOL key retrieval behind BITCOIN_ONLY conditional; updated device name derivation to use btc_legacy_pub.root_fingerprint; added "btc" suffix to device name when BITCOIN_ONLY is true.
UI Components
core/src/trezor/lvglui/scrs/components/button.py, core/src/trezor/lvglui/scrs/homescreen.py
Added disable() and enable() methods to ListItemBtn; refactored homescreen app drawer to conditionally include passkey/nft items based on BITCOIN_ONLY flag; added dynamic USB/BLE connectivity UI state; introduced passphrase initialization guard; added wallet tutorial navigation with show_wallet_tutorial() and _get_wallet_tutorial_config() helpers; gated turbo_mode visibility in Bitcoin-only mode.
Build & Tooling
tools/i18n.py
Added replace_breaks: 1 parameter to Lokalise API call for line break replacement in translations.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • core/src/apps/polkadot/transaction.py — Dense deserialization logic with multiple new network paths, address-type-aware handling, and conditional type-lookup branching require careful verification of call-routing and account ID derivation correctness.
  • core/src/trezor/lvglui/scrs/homescreen.py — Extensive interdependent changes across conditional rendering, USB/BLE state wiring, wallet tutorial routing, and passphrase initialization logic; multiple branches need integration testing.
  • core/src/storage/device.py, core/src/trezor/uart.py, core/src/trezor/utils.py — Refactored state management and storage access patterns require validation of consistency across modules, particularly USB/BLE state transitions and initialization sequencing.
  • Proto and message field additions — Verify backward/forward compatibility of new optional prefix field in PolkadotSignTx.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.17% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adaptation to Polkadot updates across multiple files including new network support, address type handling, and version bumps.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 4.18.0

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
core/src/storage/device.py (1)

1649-1730: Missing cache clears.

Add _USB_ENABLED_VALUE and _BLE_ENABLED_BACKUP_VALUE to this function. You clear _BLE_ENABLED_VALUE but not the new ones.

     global _TREZOR_COMPATIBLE_VALUE
     global _DEVICE_NAME_DISPLAY_ENABLED_VALUE
+    global _USB_ENABLED_VALUE
+    global _BLE_ENABLED_BACKUP_VALUE

     _LANGUAGE_VALUE = None
     _SERIAL_NUMBER_VALUE = None
     _TREZOR_COMPATIBLE_VALUE = None
     _DEVICE_NAME_DISPLAY_ENABLED_VALUE = None
+    _USB_ENABLED_VALUE = None
+    _BLE_ENABLED_BACKUP_VALUE = None
♻️ Duplicate comments (1)
core/src/apps/ur_registry/chains/hardware_requests/get_multi_accounts.py (1)

38-39: Paths logged in debug mode.

Same issue. Remove path data from debug output.

🧹 Nitpick comments (1)
core/src/apps/ur_registry/chains/ethereum/typed_data_transacion.py (1)

261-263: Use tuple form for readability.

Replace with chain_id_origin.startswith(("0x", "0X")).

-                        if chain_id_origin.startswith(
-                            "0x"
-                        ) or chain_id_origin.startswith("0X"):
+                        if chain_id_origin.startswith(("0x", "0X")):
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e01716b and b7d7d93.

⛔ Files ignored due to path filters (5)
  • core/src/trezor/lvglui/res/chain-bifrost-ksm.png is excluded by !**/*.png
  • core/src/trezor/lvglui/res/chain-bifrost.png is excluded by !**/*.png
  • core/src/trezor/lvglui/res/chain-dot.png is excluded by !**/*.png
  • core/src/trezor/lvglui/res/chain-hydration.png is excluded by !**/*.png
  • core/src/trezor/lvglui/res/chain-kusama.png is excluded by !**/*.png
📒 Files selected for processing (20)
  • .github/workflows/build-pro.yml (2 hunks)
  • common/protob/messages-polkadot.proto (1 hunks)
  • core/embed/firmware/version.h (1 hunks)
  • core/src/apps/polkadot/__init__.py (1 hunks)
  • core/src/apps/polkadot/helper.py (5 hunks)
  • core/src/apps/polkadot/sign_tx.py (1 hunks)
  • core/src/apps/polkadot/transaction.py (6 hunks)
  • core/src/apps/ur_registry/chains/base_sign_request.py (1 hunks)
  • core/src/apps/ur_registry/chains/ethereum/typed_data_transacion.py (2 hunks)
  • core/src/apps/ur_registry/chains/hardware_requests/get_multi_accounts.py (1 hunks)
  • core/src/apps/ur_registry/crypto_multi_accounts.py (1 hunks)
  • core/src/apps/ur_registry/helpers.py (2 hunks)
  • core/src/storage/device.py (6 hunks)
  • core/src/trezor/lvglui/scrs/components/button.py (1 hunks)
  • core/src/trezor/lvglui/scrs/homescreen.py (14 hunks)
  • core/src/trezor/messages.py (1 hunks)
  • core/src/trezor/uart.py (14 hunks)
  • core/src/trezor/utils.py (5 hunks)
  • python/src/trezorlib/messages.py (2 hunks)
  • tools/i18n.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (8)
core/src/apps/polkadot/sign_tx.py (1)
core/src/apps/polkadot/helper.py (1)
  • get_address_type (164-170)
core/src/storage/device.py (1)
core/src/storage/common.py (2)
  • get (24-25)
  • set_bool (45-49)
core/src/apps/ur_registry/chains/base_sign_request.py (2)
core/src/apps/ur_registry/chains/base_signature.py (2)
  • get_tag (19-20)
  • decode (68-81)
core/src/apps/ur_registry/crypto_key_path.py (1)
  • CryptoKeyPath (49-192)
core/src/trezor/uart.py (1)
core/mocks/generated/trezorio/__init__.pyi (3)
  • state (538-541)
  • ctrl (15-18)
  • ctrl (379-382)
python/src/trezorlib/messages.py (1)
python/src/trezorlib/protobuf.py (1)
  • Field (148-179)
core/src/trezor/lvglui/scrs/components/button.py (4)
core/src/trezor/lvglui/scrs/widgets/style.py (4)
  • StyleWrapper (4-211)
  • bg_color (44-46)
  • text_color (16-18)
  • bg_opa (48-50)
core/src/trezor/lvglui/lv_colors.py (1)
  • lv_colors (9-69)
core/src/trezor/lvglui/scrs/address.py (1)
  • STATE (16-22)
core/src/trezor/lvglui/scrs/components/slider.py (1)
  • enable (79-107)
core/src/apps/polkadot/transaction.py (3)
core/src/apps/polkadot/codec/base.py (4)
  • ScaleBytes (5-64)
  • get_next_bytes (22-25)
  • get_next_bytes (145-147)
  • decode (165-192)
core/src/apps/polkadot/helper.py (1)
  • ss58_encode (57-95)
core/src/apps/polkadot/codec/types.py (1)
  • Compact (4-42)
core/src/trezor/lvglui/scrs/homescreen.py (8)
core/src/storage/device.py (6)
  • ble_enabled (487-495)
  • is_usb_enabled (624-632)
  • is_passphrase_enabled (1031-1035)
  • is_passphrase_pin_enabled (1594-1602)
  • is_airgap_mode (1408-1412)
  • enable_airgap_mode (1415-1423)
core/src/trezor/utils.py (2)
  • is_usb_enabled (236-243)
  • enable_airgap_mode (300-310)
core/src/trezor/lvglui/scrs/components/button.py (5)
  • disable (72-76)
  • disable (210-218)
  • disable (295-312)
  • enable (78-82)
  • enable (314-331)
core/src/trezor/qr.py (1)
  • retrieval_encoder (284-285)
core/src/trezor/lvglui/scrs/template.py (5)
  • ConnectWalletTutorial (5530-5617)
  • destroy (4402-4403)
  • destroy (5435-5436)
  • destroy (5464-5465)
  • destroy (5526-5527)
core/src/trezor/lvglui/scrs/initscreen.py (1)
  • destroy (193-197)
core/src/trezor/lvglui/scrs/components/container.py (1)
  • ContainerFlexCol (8-48)
core/src/trezor/lvglui/scrs/widgets/style.py (4)
  • align (12-14)
  • StyleWrapper (4-211)
  • bg_color (44-46)
  • bg_opa (48-50)
🪛 Ruff (0.14.8)
core/src/apps/ur_registry/chains/base_sign_request.py

150-150: Create your own exception

(TRY002)


150-150: Avoid specifying long messages outside the exception class

(TRY003)


157-157: Create your own exception

(TRY002)


157-157: Avoid specifying long messages outside the exception class

(TRY003)

core/src/trezor/lvglui/scrs/homescreen.py

2720-2720: Avoid specifying long messages outside the exception class

(TRY003)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Style check
  • GitHub Check: Defs check
  • GitHub Check: Gen check
🔇 Additional comments (8)
core/embed/firmware/version.h (1)

12-13: Clean version bump.

.github/workflows/build-pro.yml (1)

30-31: LGTM!

Naming is clearer and consistent.

Also applies to: 42-43

python/src/trezorlib/messages.py (1)

9910-9931: No action needed. Optional fields are the standard protobuf mechanism for cross-version compatibility. The prefix field is correctly marked as optional and will be safely ignored by older firmware versions.

core/src/apps/polkadot/helper.py (2)

132-155: LGTM.

New network branches follow the existing pattern.


164-169: LGTM.

The preset_prefix parameter and early break are clean additions.

core/src/apps/polkadot/transaction.py (3)

26-50: LGTM.

The skip_type_lookup parameter cleanly handles networks without type-lookup bytes.


230-266: Verify hydration callPrivIdx values.

Ensure 1792, 1794, 1795, 1796 match the Hydration chain's actual pallet indices.


286-293: LGTM.

Routing logic is clear. Bifrost networks reuse manta deserialization with correct address types.

@somebodyLi somebodyLi enabled auto-merge (squash) December 16, 2025 09:51
@somebodyLi somebodyLi merged commit d58f686 into main Dec 16, 2025
9 checks passed
@somebodyLi somebodyLi deleted the 4.18.0 branch December 16, 2025 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments