Comments (8)
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.
Yes please! Can you also give a reference to the part in the spec (Yellow Paper) to ease the reviewers job.
from rlp.
Awesome, will do.
from rlp.
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.
(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.
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.
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.
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)
- Move from Travis to Circleci HOT 3
- ES5 Compatibility HOT 2
- Recursive Typings HOT 2
- Question, why is decode(encode([0])) empty buffer? HOT 1
- Add test case title output on official test runs
- Analyze new listofbinaries RLP test case HOT 2
- Update TypeScript to turn off allowSyntheticDefaultImports HOT 1
- Error using [email protected] as a CLI command HOT 2
- Missing type exports: RLPInput, RLPDecoded HOT 8
- Is the Dictionary type necessary? HOT 2
- Cannot find module 'bn.js' error when requiring after clean install HOT 1
- [BUG] rlp.encode([]) throws invalid type Error in the Truffle console HOT 4
- rlp.encode(-1) should throw an Error. HOT 1
- encode differs from pyrlp HOT 2
- Encoding and Decoding RLP lists when part of a buffer HOT 5
- Improve type definitions for decode HOT 1
- Handle negative numbers HOT 2
- Add Ethereum name or address to package.json HOT 1
- Some love for CLI tool
- how to docode hex to string HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rlp.