-
Notifications
You must be signed in to change notification settings - Fork 323
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
Conversation
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": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty string is 80
https://github.com/ethereum/tests/blob/develop/RLPTests/rlptest.json#L2
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the empty string is expected to be 80
https://github.com/ethereum/tests/blob/develop/RLPTests/rlptest.json#L2
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: