Zondax / ledger-stacks

Apache License 2.0
17 stars 7 forks source link

Use varuint encoding for message prefix #123

Closed kyranjamie closed 1 year ago

kyranjamie commented 1 year ago

As discussed in https://github.com/Zondax/ledger-stacks/issues/90 and this previous bug on geth, the message prefix should be encoded using a variable length integer.

I'm learning as I go, but as far as I understand, this is because ascii decimal encoding presents the issue that ...\n12... is ambiguous. Is it length 1 with value 2, or 12. And that using a varuint encoding fixes this.

Stacks.js implementation using this encoding

:link: zboto Link

neithanmo commented 1 year ago

our implementation in a sense uses this approach.. the parser reads the first digit and checks if it matches the remaining data len, if not, it moves to the next digit, and now reads both as a len, and check if it matches the remaining data len and so on. but we can adjust to use this new approach, which is faster than read, check, advance and check again..

kyranjamie commented 1 year ago

I believe so, yes

For the message Hello world! we'd expect: \x17Stacks Signed Message:\n\fHello world!