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

Ledger Review Fixes #3

Merged
merged 69 commits into from
Feb 12, 2024
Merged

Ledger Review Fixes #3

merged 69 commits into from
Feb 12, 2024

Conversation

chris124567
Copy link
Member

WIP PR to house fixes in response to Ledger's review.

Currently have added NanoSP support, added confirmation/cancellation status screen when generating address/pubkey, and adds developer information to the about page in the app. The issue regarding transaction signing on Stax in siacentral web wallet still needs to be resolved.

@chris124567 chris124567 marked this pull request as draft May 21, 2023 01:13
chris124567 and others added 22 commits May 20, 2023 21:25
…w, where transaction hash confirmation page would get stuck if cancelled
…nanos, redo test golden run (subtle differences in rendering)
…command due to uninitialized variable elementIndex in the context, make error handling consistent across devices
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
src/blake2b.c Outdated Show resolved Hide resolved
src/calcTxnHash_nbgl.c Outdated Show resolved Hide resolved
src/main.c Outdated Show resolved Hide resolved
src/sia.c Show resolved Hide resolved
src/signHash.c Show resolved Hide resolved
tests/test_sign_txn_cmd.py Outdated Show resolved Hide resolved
@chris124567
Copy link
Member Author

chris124567 commented Jan 19, 2024

format_hex returns uppercase hex which is not what users are used to and makes it different to visually compare things like addresses.

I was unable to get snprintf to work (always returned 0 and no error emitted with HAVE_SNPRINTF_DEBUG) but looking at the code anyways it doesn't seem like it supports uint64s: https://github.com/LedgerHQ/nanos-secure-sdk/blob/0532bf20fbbb11dd08dada62060f8337097b6078/src/os_printf.c#L572 as there is no unsigned long long / 'l' formatter.

Re: glyphs, icon_validate is used in the UI for txn signing on Nano S / Nano X:

UX_STEP_VALID(ux_sign_txn_flow_2_step,
              pb,
              io_seproxyhal_touch_txn_hash_ok(),
              {&C_icon_validate, "Approve"});

Everything else I can fix.

@xchapron-ledger
Copy link

format_hex returns uppercase hex which is not what users are used to and makes it different to visually compare things like addresses.

True, we should add a lower case version in the SDK someday...

looking at the code anyways it doesn't seem like it supports uint64s

Indeed, I missed that you where looking to display big numbers like this. Though I'm still not sure this is really needed?

Re: glyphs, icon_validate is used in the UI for txn signing on Nano S / Nano X:

You could use C_icon_validate_14 from the SDK instead: https://github.com/LedgerHQ/ledger-secure-sdk/blob/master/lib_ux/glyphs/icon_validate_14.gif

@chris124567
Copy link
Member Author

The first failure is because the version of clang-format I have locally formats slightly different for some reason. The second is caused by what appears to be invisible rendering differences on the nanosp (maybe I need to update speculos?). I'll investigate that more.

Other than maybe trying to get snprintf to work, these are the main remaining things I need to do:

It would be better to stop using TRY / CATCH / THROW mechanism, and replace it with error cascading or LEDGER_ASSERT() when the error doesn't need to be cascaded. It helps the readability of the app error handling flow and would remove some magical things from sia_main().
There is no public key comparison screen on Stax, so the behavior is different, though this is usually not how we do pk comparison on our Apps but it can depend on software wallet implementation I guess.
The sign hash UI is probably not compliant on Stax, you should have a hold to sign.
It would be great if the tests include a transaction signature with more fields, which justify the need for streaming and custom NBGL usage.

@xchapron-ledger
Copy link

The first failure is because the version of clang-format I have locally formats slightly different for some reason.

You can probably update the version either on your setup on the CI workflow file?

The second is caused by what appears to be invisible rendering differences on the nanosp (maybe I need to update speculos?)

This is probably because on your setup your are generation snapshot for NanoSP 1.1.0. There is a new version of the SDK / ledger-app-builder docker image which support NanoSP 1.1.1 with very small font changes.

@chris124567
Copy link
Member Author

Do you know what this build error is caused by? It's failing to remove build artifacts before upload and I've never seen that error before. All I changed was code formatting and fixed the test images for the NanoSP. There was a change in https://github.com/LedgerHQ/ledger-app-workflows/commits/master/ earlier today but it has to do with Rust and shouldn't affect this.

@xchapron-ledger
Copy link

Do you know what this build error is caused by? It's failing to remove build artifacts before upload and I've never seen that error before. All I changed was code formatting and fixed the test images for the NanoSP. There was a change in https://github.com/LedgerHQ/ledger-app-workflows/commits/master/ earlier today but it has to do with Rust and shouldn't affect this.

Humf, that's our fault, I'm on it.

@xchapron-ledger
Copy link

@chris124567 Thanks for the notice, should be good now (I think you might need to relaunch the whole CI jobs, not just failings ones). Sorry for the issue :/

@chris124567
Copy link
Member Author

chris124567 commented Feb 5, 2024

Sorry for the delays... one of my lungs spontaneously collapsed. I should be able to work on these issues over the next couple weeks but may be a bit slower because it will take a while for me to get back to 100%. Then we can do the app update submission.

Still need to remove exceptions from transaction parsing and a couple other things.

@chris124567
Copy link
Member Author

OK, on second thought, I'm not sure removing TRY/CATCH from txn.c actually improves readability. I would say removing it improved things in the other files but I'm not really seeing the benefits in this case. I started writing code to do it but it's starting to get ugly. We'd basically have to store an error status in the txn_state_t object and check it in a number of locations, which for instance would make every call to need_at_least require a corresponding check (every function that calls those functions need would also need to check the status code), and it would require passing the transaction state to functions that don't operate on it directly like cur2dec or changing the return value semantics in those cases.

@xchapron-ledger
Copy link

xchapron-ledger commented Feb 6, 2024

OK, on second thought, I'm not sure removing TRY/CATCH from txn.c actually improves readability. I would say removing it improved things in the other files but I'm not really seeing the benefits in this case. I started writing code to do it but it's starting to get ugly. We'd basically have to store an error status in the txn_state_t object and check it in a number of locations, which for instance would make every call to need_at_least require a corresponding check (every function that calls those functions need would also need to check the status code), and it would require passing the transaction state to functions that don't operate on it directly like cur2dec or changing the return value semantics in those cases.

Hello, are you aware of the recently introduced LEDGER_ASSERT() macro? You can learn more about it here: https://github.com/LedgerHQ/ledger-secure-sdk/blob/master/include/ledger_assert.h
Basically it's a non catch-able throw.
It can be used for error that shouldn't occurs under nominal conditions. That might apply to the cur2dec checks?

For the one in need_at_least I agree the alternative is a bit verbose...
You could change need_at_least and calling functions (seek, readInt, ..., __txn_next_elem) return type from void to txnDecoderState_e and use a macro like:

#define TXN_CHECK(call)                 \
    do {                                \
        txnDecoderState_e error = call; \
        if (error) {                    \
            return error;               \
        }                               \
    } while (0)

But does that make the code easier to follow than the current version, that's up to you! I'm not sure if I would have done it or not.

@chris124567
Copy link
Member Author

I realized there actually is a public key confirmation page on Stax. You can see it in the snapshots folder under ./tests/snapshots/stax/test_get_public_key_confirm_accepted or for addresses ./tests/snapshots/stax/test_get_address_confirm_accepted. To be honest, I think modifying the transaction handling code is likely to introduce issues especially due to the number of places we'd have to add these checks.

Do you think we are OK to do the app submission now?

Copy link

@xchapron-ledger xchapron-ledger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have two additional comments:

Otherwise, kudos for the work of bringing this app to the new standard! IMO the code quality have greatly improved.

Makefile Outdated Show resolved Hide resolved
src/app_main.c Outdated Show resolved Hide resolved
@chris124567 chris124567 marked this pull request as ready for review February 12, 2024 17:51
@chris124567 chris124567 merged commit 38daa71 into master Feb 12, 2024
35 checks passed
@chris124567 chris124567 mentioned this pull request Feb 22, 2024
3 tasks
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.

3 participants