Skip to content

decode hex encoded memo data#1429

Open
addoxyz wants to merge 5 commits intomasterfrom
rlp-decode-hex
Open

decode hex encoded memo data#1429
addoxyz wants to merge 5 commits intomasterfrom
rlp-decode-hex

Conversation

@addoxyz
Copy link

@addoxyz addoxyz commented Apr 30, 2020

There are a few conversions happening when paying with a memo: In our example we use the memo 0xc8b21e166f0d1604

During the encoding we have the following process:

We go from a string to UTF8 encoded (which gives the same result) 0xc8b21e166f0d1604 -> 0xc8b21e166f0d1604

We then send it to a method called toRlp -

const dataBuffer = rlp.encode(data);
which encodes it again (this here is the issue)

Utf8 encoded result gets converted to hex (less the 0x at the start) -

const hexstring = Encoding.toHex(input);
c8b21e166f0d1604 -> 63386232316531363666306431363034
It then gets broadcasted on the blockchain as the result of 2 + 0x = 0x63386232316531363666306431363034

However, at step 2 there is a small issue with the encoding. See below

toUtf8 = 48,120,99,56,98,50,49,101,49,54,54,102,48,100,49,54,48,52
toRlp = 146,48,120,99,56,98,50,49,101,49,54,54,102,48,100,49,54,48,52

The Utf8 encoding is fine, however the toRlp adds a non-ascii character during the encoding process. In turn this results in step 3 encoding as a hex which should not be happening.

Due to the incorrect character during the toRlp encoding it causes the exception to be thrown here:

return Encoding.fromUtf8(input);

This fix decodes the data prior to running the Encoding.fromUtf8(decodedRlp); line, this removes the non-ascii character which stops the Exception being thrown.

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.

1 participant