ethereum / wiki

The Ethereum Wiki
https://www.ethereum.org
14.75k stars 2.56k forks source link

RLP wiki inconsistency. #616

Closed maxhallhatesm3 closed 4 years ago

maxhallhatesm3 commented 6 years ago

"If the total payload of a list is more than 55 bytes long, the RLP encoding consists of a single byte with value 0xf7 plus the length in bytes of the length of the payload in binary form, followed by the length of the payload, followed by the concatenation of the RLP encodings of the items. The range of the first byte is thus [0xf8, 0xff]."

"The string "Lorem ipsum dolor sit amet, consectetur adipisicing elit" = [ 0xb8, 0x38, 'L', 'o', 'r', 'e', 'm', ' ', ... , 'e', 'l', 'i', 't' ]"

In my interpretation of the above two statements, they are mutually exclusive.

>>>len("Lorem ipsum dolor sit amet, consectetur adipisicing elit")
56
>>>hex(56)
'0x38'
>>>len(bin(56))
8
>>>def to_binary(x):
....if x == 0:
........return ''
....else: 
........return to_binary(int(x / 256)) + chr(x % 256)
........
>>>to_binary(56)
'8'
>>>hex(8)
0x8
>>>hex(8 + 0xf7)
0xff

The first byte does not fall within the allowed range declared in the preceding statement:

>>>0xf8
248
>>>0xff
255
>>>0xb8
184

Is the correct RLP encoding for the string "Lorem ipsum dolor sit amet, consectetur adipisicing elit" actually [ 0xff, 0x38, 'L', 'o', 'r', 'e', 'm', ' ', ... , 'e', 'l', 'i', 't' ] ?

or is it "The range of the first byte is thus [0xb0, 0x...]" ?

(sorry for the ultra-verbosity.)

jamesray1 commented 5 years ago

Please see https://github.com/ethereum/wiki/blob/master/ISSUE_TEMPLATE.md.