From aa283a8392b3aeea7192bde2af77e17690143406 Mon Sep 17 00:00:00 2001 From: grdddj Date: Tue, 14 Feb 2023 13:02:00 +0100 Subject: [PATCH] fix(core): remove the possibility of AssertionError in select_word In case there are less than three unique word to choose from, duplicating the last word to make the length of 3. [no changelog] --- core/src/trezor/ui/layouts/tt_v2/reset.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/trezor/ui/layouts/tt_v2/reset.py b/core/src/trezor/ui/layouts/tt_v2/reset.py index 8a02f62dc..155f34534 100644 --- a/core/src/trezor/ui/layouts/tt_v2/reset.py +++ b/core/src/trezor/ui/layouts/tt_v2/reset.py @@ -90,7 +90,6 @@ async def select_word( count: int, group_index: int | None = None, ) -> str: - assert len(words) == 3 if share_index is None: title: str = "CHECK SEED" elif group_index is None: @@ -98,6 +97,13 @@ async def select_word( else: title = f"CHECK G{group_index + 1} - SHARE {share_index + 1}" + # It may happen (with a very low probability) + # that there will be less than three unique words to choose from. + # In that case, duplicating the last word to make it three. + words = list(words) + while len(words) < 3: + words.append(words[-1]) + result = await ctx.wait( RustLayout( trezorui2.select_word(