Magickbase / neuron-public-issues

Neuron Issues
6 stars 3 forks source link

Debug timeout of `LedgerHQ/app-nervos` #406

Closed Keith-CY closed 1 month ago

Keith-CY commented 3 months ago

There are 2 components for connection between Neuron and Ledger Wallet

  1. SDK running in the Client: https://github.com/obsidiansystems/hw-app-ckb
  2. App running in the Ledger Device: https://github.com/LedgerHQ/app-nervos

The App is being maintained at https://github.com/LedgerHQ/app-nervos and it was forked from https://github.com/obsidiansystems/ledger-app-nervos

Recently, the ledger team has tried to enable the CI of building the app(https://github.com/LedgerHQ/app-nervos/blob/develop/.github/workflows/continuous-integration-workflow.yml) but it failed (https://github.com/LedgerHQ/app-nervos/actions/runs/9211189099/job/25340021172) because of timeout.

The tests are written in JavaScript, so they want us to check if we can fix it.

Keith-CY commented 3 months ago

I've run the CI of the original repo, and it failed due to the same reason https://github.com/obsidiansystems/ledger-app-nervos/blob/develop/.github/workflows/continuous-integration-workflow.yml

homura commented 2 months ago

Setup the Development Environment

  1. git clone https://github.com/LedgerHQ/speculos.git
  2. docker build -f build.Dockerfile -t speculos-builder:latest .
  3. Patch Dockerfile
diff --git a/Dockerfile b/Dockerfile
index 1ab457b..8305c93 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,7 +4,7 @@
 #
 # Building the Speculos environment
-FROM ghcr.io/ledgerhq/speculos-builder:latest AS builder
+FROM speculos-builder:latest AS builder
  1. docker build -f Dockerfile -t speculos:latest .

Get the Compiled File from GitHub Artifact

Choose a app file from the workflow https://github.com/LedgerHQ/app-nervos/actions/workflows/continuous-integration-workflow.yml

image

Try the Speculos

docker run \
  -it \
  --rm \
  -v \
  $(pwd)/apps:/speculos/apps \ 
  --publish 8888:8888 \
  --publish 8899:8899 \
  --publish 9999:9999 \
    speculos apps/app.elf \
    --sdk 2.0 \
    --display headless \
    --button-port 8888 \
    --automation-port 8899 \
    --apdu-port 9999

Problems

Async Calls are not Robust

https://github.com/LedgerHQ/app-nervos/blob/5089b38d1551205928aba41a1c72b623e04b9d35/tests/sudt.js#L194-L202

      while((policy = await screens.next()).header != "Allow contract data") {
        speculos.button("Rr");
      }
      while(policy.body != target) {
        speculos.button("RLrl");
        policy = await screens.next();
      }
      do { speculos.button("Rr") } while((await screens.next()).body != "Main menu");
      speculos.button("RLrl");

The code here attempts to press buttons to navigate to a specific screen. However, the async function is not always predictable. The test snippet above shows its attempt to press the Rr button to reach a screen displaying "Allow contract data", but it might skip the target screen if Speculos fails to respond in time, resulting in pressing the button twice

Exit with the Code 255

ledger-app

Some necessary sleep is required after pressing a button, or the Ledger may not react in time, which could cause unexpected operations

Invalid Address

ckb1qpw9q60tppt7l3j7r09qcp7lxnp3vcanvgha8pmvsa3jplykxn32s4l9ycxc8xncdtp2jzgcrhu6ggl3a7lgv0gzysy32

image image image image image image image

homura commented 2 months ago

https://github.com/LedgerHQ/app-nervos/pull/31