GithubHelp home page GithubHelp logo

Comments (8)

hamdiallam avatar hamdiallam commented on June 10, 2024

It seems like in the tests, 0 is treated as a null value. This goes against the spec from what I understand.

Can I submit a PR fixing this?

from rlp.

axic avatar axic commented on June 10, 2024

Yes please! Can you also give a reference to the part in the spec (Yellow Paper) to ease the reviewers job.

from rlp.

hamdiallam avatar hamdiallam commented on June 10, 2024

Awesome, will do.

from rlp.

holgerd77 avatar holgerd77 commented on June 10, 2024

Just as a note here for reference: there are also 0-issues in ethereumjs-tx https://github.com/ethereumjs/ethereumjs-tx/issues/112 which in my perception are urgent to address and trickle down to ethereumjs-util https://github.com/ethereumjs/ethereumjs-util/issues/141 (this is not the direct issue but one eventually tackling the problem, one has to look into the code to get the connections here).

These have to be addressed and might be connected to the issue here.

from rlp.

holgerd77 avatar holgerd77 commented on June 10, 2024

(as an on-top note: the issues in ethereumjs-tx for me seems to be so grave that I am totally puzzled why this hasn't been discovered before)

from rlp.

sc0Vu avatar sc0Vu commented on June 10, 2024

Found wiki here: https://github.com/ethereum/wiki/wiki/RLP
After try, 0x80 decode to empty buffer. It should be application logic to judge the type (empty string or number 0)?

from rlp.

gzm55 avatar gzm55 commented on June 10, 2024

when using rlp, we need two level ser/der protocol:

  • high level objects <---> rlp objects ( byte string or nest string )
  • rlp objects <---> byte string

The RLP spec most describe the latter one, leaving the high level protocol to decide how to convert the high level objects to rlp objects. The exception is that how the unsigned integer as a high level object should converte to rlp objects, this is used to encode the list length. According to the implementation, the unsigned integer is convert to byte string by removing all the prefix 0s from the big-endian bytes. So

hl objects rlp objects byte string
integer 0 '' (a zero-length byte string) 0x80 (using rule 2)
integer 1 '\x01' 0x01 (using rule 1)
byte list [ ] '' (a zero-length byte string) 0x00 (using rule 2)
byte list [ 0x00 ] '\x00' 0x00 (using rule 1)

When doing rlp decoding, the output should be in the scope of rlp objects, so the Buffer.from([]) seems reasonable. And the the high level decoding is left to the protocol implementation.

The real problem, imo, is that rlp and all implementations do not distinguish the null and common default values (0, empty list). Out of the ethereum scene, missing null should introduce some minor problems.

In our own rlp implementation, each high level object type is defined as a byte-string type (integer, string, float, etc) or a nest-list type (list, map, struct), and convert to null as following:

hl objects rlp objects byte string
null (a byte-string type) [] (an empty nest list) 0xC0
null (a nest-list type) '' (an empty byte string) 0x80

from rlp.

ryanio avatar ryanio commented on June 10, 2024

Copying my comment from #32:

Since https://eth.wiki/en/fundamentals/rlp now has these examples I will consider this conversation resolved:

The integer 0 = [ 0x80 ]
The encoded integer 0 (’\x00’) = [ 0x00 ]

Thanks to everyone for participating

from rlp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.