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

Add RLP invalid tests for insufficient bytes. #614

Merged
merged 1 commit into from
Feb 22, 2020

Conversation

acoglio
Copy link
Member

@acoglio acoglio commented Jul 23, 2019

These new proposed tests are for invalid encodings that do not have enough bytes
for the lengths indicated in the first few bytes.

The following, repeated from (now merged) PR #611, apply here as well:

These new proposed tests are for invalid encodings that do not have enough bytes
for the lengths indicated in the first few bytes.
@@ -82,6 +82,51 @@
"nonOptimalLongLengthList2": {
"in": "INVALID",
"out": "f803112233"
},

"emptyEncoding": {
Copy link
Collaborator

@winsvega winsvega Jul 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a test for the empty encoding, not the empty string. An RLP encoding (i.e. the result of an RLP encoder) is never empty, it always has at least one byte. So if an RLP decoder is presented with the empty sequence of bytes, it should reject it because it is not a valid encoding. This test is meant to cover this case. Perhaps we can use a different name if it causes confusion with the test for encoding the empty string.

Copy link
Collaborator

@winsvega winsvega Jul 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to tell the difference in the tests?
this PR requires aleth changes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that RLP tests of the form
{"in" : "INVALID", "out" : <encoding>}
are meant to test that whether the decoder rejects <encoding>, while RLP tests of the form
{"in" : <string-or-list>, "out" : <encoding>}
are meant to test whether (1) the encoder produces <encoding> given <string-or-list> and (2) the decoder produces <string-or-list> given <encoding>.

If that's the case, then the test for the empty encoding is
{"in" : "INVALID", "out" : ""}
as above, while the test for the empty string is
{"in" : "", "out" : "80"}
Does this address your question, or have I misunderstood what you were asking?

If aleth accepts the empty encoding, I would argue that it's a bug. The specification of RLP encoding prescribes that both strings and lists start with a byte that describes the type and either the length or the length of the length. So encodings are never empty. If an RLP decoder is given a purported encoding that is empty, it must reject it because it does not encode anything. Do you agree?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
I still will have to change aleth to treat empty string in this test as empty byte input

Copy link
Collaborator

@winsvega winsvega left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@winsvega winsvega requested a review from gumb0 February 20, 2020 19:42
@winsvega winsvega added the expire soon outdated PR/Issue needs to be resolve or closed label Feb 20, 2020
@winsvega winsvega merged commit 7497b11 into ethereum:develop Feb 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expire soon outdated PR/Issue needs to be resolve or closed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants