-
Notifications
You must be signed in to change notification settings - Fork 81
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
bug: RLP::decode() should return an empty string instead of "0" when decoding 0x80 #539
Conversation
Is this ready to review? |
@Quentash, so according to the website, both: "" and 0x0 are [0x80] Hence, our implementation isn't wrong I guess, is there some bug u have seen in some decoding with this approach? Would love to check that case. Otherwise, at least from the website, this seems to be the default value fo 0x0 if u are decoding an int from the decoding. |
@bajpai244 And if you look at the encoding script ; you can see that if we encode an 0, it will be encoded as 0x00, but if we encode an empty string, it will be encoded as 0x80. I am actually wondering if the example aren't a little bit incorrect or, at least, not consistent with the code examples they give. Don't hestitate to ping me on TG/disc if you wanna dive deeper into this topic ! |
@Quentash I get what u mean here and I can see the inconsistency as well, I think we can put decoding of 0x80 as empty string if u want, but then we also have to make sure that we convert decode Otherwise we will fail the RLP tests { which already seems to be the case in this PR, the tests are failing }. Can u investigate whether there are some official Ethereum tests for this this? We can then confirm whether it should be decoded "" or 0. Alloy can be a great place to check for this! So, I guess action steps can be:
After this, we should have enough evidence to take some action with confidence. |
The only failing tests are those that require a valid signature. Because I have changed the transactions to fit the modifications ( replacing "80" by "00" ) but therefore, those transactions need to be signed again because the r, s, v must be different. ( And this is where I initially needed your help ) But In those tests : https://github.com/ethereum/tests/blob/develop/RLPTests/rlptest.json You can notice that both an empty string and 0 as input expects 0x80 as output. ( Alloy-rlp also do a test where the input is 0 as u_64 and it expects 0x80 as output ). I feel like they have different implementations that would either take integers or strings as input ( https://github.com/alloy-rs/rlp/blob/main/crates/rlp/src/decode.rs ). I think our implementation is also different because we return Because if we never return an empty string, how could we differentiate an empty string and a string containing "0" ? (0x80 from 0x8100) |
@Quentash , going through this it looks like that the interpretation can depend on what we expect as output! I think depending on the type be expect to decode, if we are decoding for string, then 0x80 should be "", otherwise it looks like it should be 0 if are doing in case of uint.
I am sending u the key I used to sign this data, so that u can update ur test! Also, good research :) |
This is also what I understood. Let's do that, I'm on it, and thanks a lot Ser ! |
As discussed,
I think this is ready to be reviewed, don't hesitate to ping me if I missed something. |
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.
looks good overall
I've added a verification on the payload length. |
@Quentash this looks good to me, approving { + I guess u can change the position of the comment, although I don't have a very hard take on that. } |
|
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.
Great work 💪
The PR #500 brought a bug where the decoding of the input [0x80] returns an String containing the byte "0x00" while it should return an empty String instead.
Pull Request type
Please check the type of change your PR introduces:
What is the current behavior?
Resolves: #538
What is the new behavior?
Does this introduce a breaking change?
Some tests in eth_transaction_test.cairo uses test data that were constructed on top of this error, those tests should be corrected as well. Contacting @bajpai244 for more enlightment.