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

Make Back Button Work #4

Merged
merged 16 commits into from
Nov 28, 2023
Merged

Conversation

chris124567
Copy link
Member

This PR allows us to use backward and forward navigation in the Stax app. To do that, it required changing the code that streams in the transaction to read the whole transaction in at once. Unfortunately this means we have to store a fixed size buffer of transaction elements. The code currently stores only the elements that we actually need to display.

The limit to how many elements you can store varies by device but when you make too the limit large, you get this kind of error when building:

ld.lld: error: section '.bss' will not fit in region 'SRAM': overflowed by 1228 bytes

For most devices (NanoX, NanoSP, Stax) I just settled on 64 maximum elements as 96 and 128 were too large. But the Nano S has a ridiculously small amount of RAM and can only store 6 elements. So I was unsure how to proceed here without causing large amounts of code duplication. I hope we are able to just leave the Nano S build based on the older version of the code as is.

@chris124567
Copy link
Member Author

Looks like some of the cryptography functions we used are now deprecated but not yet removed which is causing a bunch of CI errors. Will look into the replacements!

src/txn.h Outdated Show resolved Hide resolved
uint8_t valLen; // length of outVal
uint8_t outAddr[77]; // most-recently-seen address
} txn_elem_t;

// txn_state_t is a helper object for computing the SigHash of a streamed
// transaction.
typedef struct {
uint8_t buf[510]; // holds raw tx bytes; large enough for two 0xFF reads
Copy link
Member

Choose a reason for hiding this comment

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

if we're no longer streaming, perhaps we could use a union here? As in, use the same memory to store both buf and elements. The unparsed elements in buf should always take up more space than their parsed equivalent, so we shouldn't be at risk of overwriting unparsed bytes.

Copy link
Member Author

Choose a reason for hiding this comment

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

But there can be multiple reads. So if we're the Nano S and we've read in say 10 elements (10*(4 + 24 + 32) = 600 bytes) but we still need to read in more elements then we'd have a problem. Also I think it might be undefined behavior to use a union like that. Or maybe I'm misunderstanding something.

Copy link
Member

Choose a reason for hiding this comment

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

ah, right

src/txn.h Outdated Show resolved Hide resolved
src/txn.h Outdated Show resolved Hide resolved
src/txn.h Outdated Show resolved Hide resolved
@chris124567
Copy link
Member Author

chris124567 commented Nov 21, 2023

Alright, I think I got it. I am going to test this on a physical Nano S and figure out why the ragger tests aren't running tomorrow. Then this should be good to merge.

@chris124567
Copy link
Member Author

I was not able to test on my physical Ledger S because I couldn't get my computer to recognize the device so that I could flash the app despite trying a bunch of different things. But I don't see any reason why it wouldn't work given that speculos is a nearly perfect emulator.

@chris124567
Copy link
Member Author

Unless anyone has additional suggestions (which if there are any on the memory saving changes I just made I'd appreciate it) I think this should be OK to merge. Technically you can compile with a slightly higher element limit for the Nano S but the app will crash if you do more than one action. I did not encounter crashes at 22 elements (but I did at 24) so I went with 20 to have some margin of safety.

@lukechampine
Copy link
Member

20 should be fine 👍🏻

@lukechampine lukechampine merged commit 791bbad into ledger-review-fixes Nov 28, 2023
31 of 36 checks passed
chris124567 pushed a commit that referenced this pull request Jul 26, 2024
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.

2 participants