Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition in SEPH with automation on LNX #241

Open
Saltari opened this issue Aug 4, 2021 · 1 comment
Open

Race condition in SEPH with automation on LNX #241

Saltari opened this issue Aug 4, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@Saltari
Copy link
Contributor

Saltari commented Aug 4, 2021

This was observed when running tests with automation on the Mina application:
There is not enough time for speculos to receive general status and display packets end up being appended one after the other:
In the following log you can observe that after the approval flow triggered by an apdu, we go back to the idle flow of the app which is the home screen but another apdu is received before the idle flow could be displayed and the idle flow and approval flow of the following apdu ends up being concatenated by the Nanox OCR part of the code

15:52:33.846:automation: getting actions for "Mina" (51, 28)
15:52:33.846:automation: getting actions for "is readyGetAddress" (44, 42)

seph_automation.log

It looks like speculos is on heavy load at this time because all the missed general status are received a few milliseconds after this (but too late)

Would there be any way to add some synchronization so that we don't perform new button events as long as all the display status of the current screen have not been received and ended by a general status ?
Or be able to detect the display status used to draw a rectangle to prepare for the next screen and consider all the display packets after that as a new text event ?

jspada pushed a commit to jspada/ledger-app-mina that referenced this issue Aug 4, 2021
Workaround speculos issue (LedgerHQ/speculos#241)
@greenknot
Copy link
Contributor

Thanks for the detailed issue.

Could you please test this patch?

diff --git a/speculos/mcu/nanox_ocr.py b/speculos/mcu/nanox_ocr.py
index 423e5d7..b08f110 100644
--- a/speculos/mcu/nanox_ocr.py
+++ b/speculos/mcu/nanox_ocr.py
@@ -132,6 +132,7 @@ def find_char_from_bitmap(bitmap: BitMap):
 class NanoXOCR:
     def __init__(self):
         self.events = []
+        self.new_event = False
 
     def analyze_bitmap(self, data: bytes):
         if data[0] != 0:
@@ -145,11 +146,15 @@ class NanoXOCR:
 
         char = find_char_from_bitmap(bitmap)
         if char:
-            if self.events and y <= self.events[-1].y:
+            if not self.new_event and self.events and y == self.events[-1].y:
                 self.events[-1].text += char
             else:
                 # create a new TextEvent if there are no events yet or if there is a new line
                 self.events.append(TextEvent(char, x, y))
+            self.new_event = False
+        else:
+            # if a bitmap which isn't a character was displayed, assume that the string is terminated
+            self.new_event = True
 
     def get_events(self) -> List[TextEvent]:
         events = self.events.copy()

@greenknot greenknot added the bug Something isn't working label Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants