Skip to content

Conversation

benma
Copy link
Collaborator

@benma benma commented Sep 22, 2025

@NickeZ the two middle commits are not usable by themselves, but in separate commits for easier review. Will squash in the end.

There is a brief flash of the "See the BitBoxApp" after unlock is done, before it switches to the normal BitBox02 logo screen. This was present before this PR, but it lingers a bit longer after this PR. I already have a prototype of how to remove that flash completely, I'll open a separate PR for that after this one. edit: fixed in #1618

@benma benma force-pushed the async-bip39 branch 4 times, most recently from ed0c490 to 0e925b3 Compare September 23, 2025 09:53
We use our fork that has two custom patches:
- fix bitcoin_hashes transitive dep version to avoid duplicates
- add async version of the function to derive a bip39 seed

This will be used to convert our BIP39 unlock to be an async
operation, not blocking the mainloop.
This uses `to_seed_normalized_async(...).await` over
`to_seed_normalized(...)` in bip39 unlocking, propagating the
async/await keywords up the stack.

This commit by itself is not functional yet, as the unlock animation
is still timer-interrupt based, which leads to chaos. The next commit
converts the animation into an async task of its own, not depending on
interrupts.

The bip39 unlock loop is made to yield to the executor in each of the
2048 PBKDF2 stretch rounds. In the simulator however, we don't yield
and finish the computation in a blocking fashion like before, due to a
limitation of the simulator: it does not busy-loop the
mainloop (otherwise CPU would be at 100%), but only when there is an
incoming USB packet, so yielding in BIP39 would make unlocking in the
simulator *very* slow. Running the mainloop quicker in the simulator
does not work well: either CPU load is too high, or unlock is too slow.
Remove timer interrupt, but use the screen render counter to determine
the animation duration. Currently it is tweaked to finish in slightly
longer than it takes BIP39 unlock to finish. This computation is
accurate, as it uses the number of unlock steps, not actual timings.
@benma benma requested a review from NickeZ September 29, 2025 09:39
@benma benma marked this pull request as ready for review September 29, 2025 09:39
We join the bip39 async task and the unlock animation task to run in
tandem until both are finished.

The old interrupt-timer based lock animation is now unused and deleted.
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.

1 participant