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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions RLPTests/invalidRLPTest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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

"in": "INVALID",
"out": ""
},

"lessThanShortLengthArray1": {
"in": "INVALID",
"out": "81"
},

"lessThanShortLengthArray2": {
"in": "INVALID",
"out": "a0000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e"
},

"lessThanShortLengthList1": {
"in": "INVALID",
"out": "c5010203"
},

"lessThanShortLengthList2": {
"in": "INVALID",
"out": "e201020304050607"
},

"lessThanLongLengthArray1": {
"in": "INVALID",
"out": "ba010000aabbccddeeff"
},

"lessThanLongLengthArray2": {
"in": "INVALID",
"out": "b840ffeeddccbbaa99887766554433221100"
},

"lessThanLongLengthList1": {
"in": "INVALID",
"out": "f90180"
},

"lessThanLongLengthList2": {
"in": "INVALID",
"out": "ffffffffffffffffff0001020304050607"
}

}