Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RLP encoding of 0 (zero) as 0x80 #4284

Closed
pinges opened this issue Aug 22, 2022 · 4 comments · Fixed by #4388
Closed

RLP encoding of 0 (zero) as 0x80 #4284

pinges opened this issue Aug 22, 2022 · 4 comments · Fixed by #4388
Assignees
Labels
mainnet snack Smaller coding task - less than a day for an experienced dev TeamRevenant GH issues worked on by Revenant Team

Comments

@pinges
Copy link
Contributor

pinges commented Aug 22, 2022

Description

I have created a PR to fix a problem with Nethermind clients (#4283), where Besu cannot decode the Hello message sent by Nethermind because it contains a capability for the witness protocol with version 0. This 0 was encoded 0x80, which is the encoding for a zero length string but in this case needs to be interpreted as the integer value 0.
I learned that this is (probably) the right way to encode the value 0.

The following should be done:

  • research where 0x80 is the right way to encode the value 0 and, if necessary, fix the RLP encoding in Besu
  • fix RLP decoding where necessary
@pinges pinges added TeamRevenant GH issues worked on by Revenant Team mainnet labels Aug 22, 2022
@pinges
Copy link
Contributor Author

pinges commented Aug 22, 2022

https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/ :
"Deserialized positive integers with leading zeroes get treated as invalid. The integer representation of string length must also be encoded this way, as well as integers in the payload."

@macfarla
Copy link
Contributor

Ethereum yellow paper spells out the removal of all leading zeros in appendix B just below equation 197, and that zero scaler writes as 0x80 is explicitly tested for in the ethereum reference tests. and a number of invalid tests flag 0x00 as a scalar length as invalid.

@iamhsk iamhsk added the snack Smaller coding task - less than a day for an experienced dev label Aug 22, 2022
@shemnon
Copy link
Contributor

shemnon commented Aug 22, 2022

The above was from the original bug - #4279 (comment)

@pinges
Copy link
Contributor Author

pinges commented Aug 23, 2022

In the WireMessagesSedesTest we are currently disabling a check because we are encoding the version number zero as 0x00, not 0x80. As part of the ticket that check might be enabled again.

pinges added a commit to pinges/besu that referenced this issue Aug 23, 2022
…bled again when ticket hyperledger#4284 is worked on

Signed-off-by: Stefan <stefan.pingel@consensys.net>
@mark-terry mark-terry self-assigned this Sep 4, 2022
@mark-terry mark-terry mentioned this issue Sep 13, 2022
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mainnet snack Smaller coding task - less than a day for an experienced dev TeamRevenant GH issues worked on by Revenant Team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants