refactor(core): allow using custom `Layout` for menu flows
What changed, and why it matters
This is a small, safe code cleanup in the user-interface layer of the Trezor firmware. It lets menu screens use a different visual layout type in the future, but does not change any existing behavior or fix a security problem. There is no indication of a vulnerability.
No security action needed. Treat as normal refactoring review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors interact_with_menu and confirm_with_menu in core/src/trezor/ui/layouts/menu.py to accept an optional layout_type keyword argument (defaulting to the existing Layout class) and forwards it to the common interact() helper. This is a pure plumbing change to support future custom layouts (mentioned as ‘N4W1 layouts’). No logic, validation, or security-critical behavior is altered.
Changed components
core/src/trezor/ui/layouts/menu.pyInspect captured patch +11 / −2
diff --git a/core/src/trezor/ui/layouts/menu.py b/core/src/trezor/ui/layouts/menu.py
index 15ff8900..a9adafe7 100644
--- a/core/src/trezor/ui/layouts/menu.py
+++ b/core/src/trezor/ui/layouts/menu.py
@@ -2,6 +2,7 @@ from typing import TYPE_CHECKING, Awaitable
import trezorui_api
from trezor.enums import ButtonRequestType
+from trezor.ui import Layout
from trezor.ui.layouts.common import interact
from trezor.wire import ActionCancelled
@@ -111,9 +112,13 @@ async def interact_with_menu(
br_name: str | None,
br_code: ButtonRequestType = ButtonRequestType.Other,
raise_on_cancel: ExceptionType = ActionCancelled,
+ *,
+ layout_type: type[Layout] = Layout,
) -> T:
while True:
- result = await interact(main, br_name, br_code, raise_on_cancel)
+ result = await interact(
+ main, br_name, br_code, raise_on_cancel, layout_type=layout_type
+ )
br_name = None # ButtonRequest should be sent once (for the main layout)
if result is trezorui_api.INFO:
await show_menu(menu, raise_on_cancel)
@@ -127,12 +132,16 @@ async def confirm_with_menu(
br_name: str | None,
br_code: ButtonRequestType = ButtonRequestType.Other,
raise_on_cancel: ExceptionType = ActionCancelled,
+ *,
+ layout_type: type[Layout] = Layout,
) -> None:
"""
Make sure the layout result is CONFIRMED (or raises an exception).
In order to handle other results (such as BACK), use `interact_with_menu`.
"""
- result = await interact_with_menu(main, menu, br_name, br_code, raise_on_cancel)
+ result = await interact_with_menu(
+ main, menu, br_name, br_code, raise_on_cancel, layout_type=layout_type
+ )
# use this function when the layout may only return CONFIRMED on success (or raise an exception)
assert result is trezorui_api.CONFIRMED
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.