1

I have a rlp encoded data and am trying to decode it with Accurast library

Utils = sp.io.import_script_from_url("https://raw.githubusercontent.com/Acurast/acurast-hyperdrive/main/contracts/tezos/libs/utils.py")

data = "0xf8c8b83d6274703a2f2f30783232382e6172637469632f307831313131313131313131313131313131313131313131313131313131313131313131313131313131b8396274703a2f2f3078312e69636f6e2f6378303030303030303030303030303030303030303030303030303030303030303030303030303030348362747381f6b846f844b83d6274703a2f2f30783232382e6172637469632f307861313434326339303132304138393163336465393739336361433730393638436162313133323335c483627473"
decode_string(sp.bytes(data))

the output is not being shown as expected the output is showing something like this, '�=btp://0x228.arctic/0x1111111111111111111111111111111111111111�

, how can we solve this ?

2
  • Update: I had to encode_list instead of encode_string, but there are certain prefixes that are being added on each element of the list, actual expected value was ["0x6274703a2f2f30783232382e6172637469632f307831313131313131313131313131313131313131313131313131313131313131313131313131313131","0x6274703a2f2f3078312e69636f6e2f637830303030303030303030303030303030303030303030303030303030303030303030303030303034","0x627473","0xf6","0xf844b83d6274703a2f2f30783232382e6172637469632f307861313434326339303132304138393163336465393739336361433730393638436162313133323335c483627473"]
    – Kin
    Apr 27 at 8:25
  • I got the following value with some values added as a prefix , what are these prefixes , {0 : sp.bytes('0xb83d6274703a2f2f30783232382e6172637469632f307831313131313131313131313131313131313131313131313131313131313131313131313131313131'), 1 : sp.bytes('0xb8396274703a2f2f3078312e69636f6e2f637830303030303030303030303030303030303030303030303030303030303030303030303030303034'), 2 : sp.bytes('0x83627473'), 3 : sp.bytes('0x81f6'), 4 : sp.bytes('0xb846f844b83d6274703a2f2f30783232382e6172637469632f307861313434326339303132304138393163336465393739336361433730393638436162313133323335c483627473')}
    – Kin
    Apr 27 at 8:26

1 Answer 1

0

Strings/Lists with more than 55 in length were being incorrectly encoded.

I submitted a MR that fixes the issue.

You can test the encodings with: https://codechain-io.github.io/rlp-debugger

The following example should now produce the correct encoding.

import smartpy as sp

Utils = sp.io.import_script_from_url("https://raw.githubusercontent.com/Acurast/acurast-hyperdrive/main/contracts/tezos/libs/utils.py")

@sp.add_test("Tests")
def test():
 sc = sp.test_scenario()
    
 link = "btp://0x228.arctic/0x1111111111111111111111111111111111111111"
 encode_string = sp.build_lambda(Utils.RLP.Encoder.encode_string)
 rlpEncodedString = encode_string(link)
    
 sc.show(rlpEncodedString)
    
 decode_string = sp.build_lambda(Utils.RLP.Decoder.decode_string)
 sc.show(decode_string(rlpEncodedString))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.