From 15967a312b525e01e58847df4835ebf99485fb7c Mon Sep 17 00:00:00 2001 From: obrusvit Date: Mon, 27 Jan 2025 15:33:38 +0100 Subject: [PATCH] fix(core): explicitly delete keyboard layout - seems that keyboard LayoutObj was not properly deallocated resulting in MemoryError. Fix by calling the dunder `del` method explicitly fixes the issue - the problem was on Model T (Bolt), but applying it for all layouts to prevent similar problem --- core/.changelog.d/4537.fixed | 1 + core/src/trezor/ui/layouts/bolt/recovery.py | 15 +++++++++------ core/src/trezor/ui/layouts/caesar/recovery.py | 15 ++++++++------- core/src/trezor/ui/layouts/delizia/recovery.py | 14 +++++++++----- 4 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 core/.changelog.d/4537.fixed diff --git a/core/.changelog.d/4537.fixed b/core/.changelog.d/4537.fixed new file mode 100644 index 00000000000..e3ce204e6aa --- /dev/null +++ b/core/.changelog.d/4537.fixed @@ -0,0 +1 @@ +[T2T1] Fixed a bug resulting in restarting the recovery flow when inputting 33-word mnemonic. diff --git a/core/src/trezor/ui/layouts/bolt/recovery.py b/core/src/trezor/ui/layouts/bolt/recovery.py index a2528c60826..614b35f135a 100644 --- a/core/src/trezor/ui/layouts/bolt/recovery.py +++ b/core/src/trezor/ui/layouts/bolt/recovery.py @@ -32,21 +32,24 @@ async def request_word( ) -> str: prompt = TR.recovery__type_word_x_of_y_template.format(word_index + 1, word_count) can_go_back = word_index > 0 + if is_slip39: keyboard = trezorui_api.request_slip39( prompt=prompt, prefill_word=prefill_word, can_go_back=can_go_back ) - else: keyboard = trezorui_api.request_bip39( prompt=prompt, prefill_word=prefill_word, can_go_back=can_go_back ) - word: str = await interact( - keyboard, - "mnemonic" if send_button_request else None, - ButtonRequestType.MnemonicInput, - ) + try: + word: str = await interact( + keyboard, + "mnemonic" if send_button_request else None, + ButtonRequestType.MnemonicInput, + ) + finally: + keyboard.__del__() return word diff --git a/core/src/trezor/ui/layouts/caesar/recovery.py b/core/src/trezor/ui/layouts/caesar/recovery.py index 4ab3dd33e38..36b45057817 100644 --- a/core/src/trezor/ui/layouts/caesar/recovery.py +++ b/core/src/trezor/ui/layouts/caesar/recovery.py @@ -31,24 +31,25 @@ async def request_word( prefill_word: str = "", ) -> str: prompt = TR.recovery__word_x_of_y_template.format(word_index + 1, word_count) - can_go_back = word_index > 0 if is_slip39: keyboard = trezorui_api.request_slip39( prompt=prompt, prefill_word=prefill_word, can_go_back=can_go_back ) - else: keyboard = trezorui_api.request_bip39( prompt=prompt, prefill_word=prefill_word, can_go_back=can_go_back ) - word: str = await interact( - keyboard, - "mnemonic" if send_button_request else None, - ButtonRequestType.MnemonicInput, - ) + try: + word: str = await interact( + keyboard, + "mnemonic" if send_button_request else None, + ButtonRequestType.MnemonicInput, + ) + finally: + keyboard.__del__() return word diff --git a/core/src/trezor/ui/layouts/delizia/recovery.py b/core/src/trezor/ui/layouts/delizia/recovery.py index 1f2ddfa267d..82019bff4d9 100644 --- a/core/src/trezor/ui/layouts/delizia/recovery.py +++ b/core/src/trezor/ui/layouts/delizia/recovery.py @@ -33,6 +33,7 @@ async def request_word( ) -> str: prompt = TR.recovery__word_x_of_y_template.format(word_index + 1, word_count) can_go_back = word_index > 0 + if is_slip39: keyboard = trezorui_api.request_slip39( prompt=prompt, prefill_word=prefill_word, can_go_back=can_go_back @@ -42,11 +43,14 @@ async def request_word( prompt=prompt, prefill_word=prefill_word, can_go_back=can_go_back ) - word: str = await interact( - keyboard, - "mnemonic" if send_button_request else None, - ButtonRequestType.MnemonicInput, - ) + try: + word: str = await interact( + keyboard, + "mnemonic" if send_button_request else None, + ButtonRequestType.MnemonicInput, + ) + finally: + keyboard.__del__() return word