iov-core icon indicating copy to clipboard operation
iov-core copied to clipboard

decode hex encoded memo data

Open AdamREQ opened this issue 5 years ago • 0 comments

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 - https://github.com/iov-one/iov-core/blob/89f462d218cf5babda4fdea9eab9ffaa1c72c552/packages/iov-ethereum/src/encoding.ts#L8 which encodes it again (this here is the issue)

Utf8 encoded result gets converted to hex (less the 0x at the start) - https://github.com/iov-one/iov-core/blob/ccf3ec60590f68986db0bb8b6ad77cc86876a6c6/packages/iov-ethereum/src/ethereumcodec.ts#L85 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: https://github.com/iov-one/iov-core/blob/ccf3ec60590f68986db0bb8b6ad77cc86876a6c6/packages/iov-ethereum/src/ethereumcodec.ts#L83

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.

AdamREQ avatar Apr 30 '20 15:04 AdamREQ