-
Notifications
You must be signed in to change notification settings - Fork 2
Fix function selector & argument encoding #39
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
Conversation
596a572 to
e3723e7
Compare
| } | ||
|
|
||
| #[test] | ||
| fn test_encoded_input_bool() { |
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.
Removed this since the matterlabs parser doesn't support parsing of booleans and we've aligned our parsing implementation with theirs.
| } | ||
|
|
||
| #[test] | ||
| fn test_encoded_input_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.
Removed this since the matterlabs parser doesn't support parsing of strings and we've aligned our parsing implementation with theirs.
| } | ||
|
|
||
| #[test] | ||
| fn test_encoded_input_uint256_array() { |
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.
Removed this since the matterlabs parser doesn't support parsing of arbitrary length arrays and we've aligned our parsing implementation with theirs.
| // add logic that does their resolution in the future, perhaps through some kind of system | ||
| // context API that we pass down to the resolution function that allows it to make calls to | ||
| // the node to perform these resolutions. | ||
| let is_unsupported = [ |
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.
Highlighting this bit for reviewers. We don't currently support these variables in our testing framework. It's certainly possible to support them. I think that the best way would be for us to add some kind of ResolverApi in the future that is passed to the resolve function that allows for it to fetch such information.
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.
I'd assume they can be fetched via the ethereum RPC?
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.
Yup, I think that we should be able to get all of this information from the RPC. I was hoping to first implement #40 to make async communication with the RPC slightly simpler before adding support for them. What do you think?
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.
Cargo.toml
Outdated
| "json", | ||
| "env-filter", | ||
| ] } | ||
| web3 = { version = "0.19.0", default-features = false } |
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.
Is there anything missing in alloy which the web3 crate provides? I don't think so and would like to stick with alloy only (also this was last released 2 years ago).
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.
Good point, I think that we can do the same with alloy::primitives::U256. Initially, I wanted to not modify the matterlabs implementation as to have an easier way to verify its correctness, but you're right a lot of these methods have counterparts in alloy::primitives::U256.
I have made this change so we're no longer using the web3 crate.
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.
Ah I see. Very nice thanks. Helps maintainability greatly to have only a single crate for helpers like this.
| // add logic that does their resolution in the future, perhaps through some kind of system | ||
| // context API that we pass down to the resolution function that allows it to make calls to | ||
| // the node to perform these resolutions. | ||
| let is_unsupported = [ |
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.
I'd assume they can be fetched via the ethereum RPC?
Summary
This PR fixes some issues that we had in computing the function selector and in the encoding of arguments for functions
Description
I encountered an issue where the function selector that we computed didn't seem to be correct as can be seen from the following logs:
After doing some digging, I discovered that we were attempting to compute the function selector from the function name alone and without making use of the function arguments types.
I corrected that to align more with the matter-labs-tester: now we obtain the function selector from the ABI by function name. It looks like the matter-labs team do not account for function overloads, and therefore we didn't account for them either. It seems like they enforce that there will never be function overloads in tests (at least in the functions that gets called from the tests).
I then faced the following error after correcting the way that we compute the function selector:
Digging deeper, it looked like our implementation for argument encoding different from the implementation of matter-labs where we were trying to support more types than they support. Additionally, we attempt to decode the arguments based on the ABI of the method whereas they decode the arguments without the ABI context at all. In this case, I think that it's also best that we align with their implementation since they author the test suite and therefore it's better that our parser aligns with theirs. Therefore, I changed the implementation of
Input -> Calldatato not rely on the ABI and to have the same parsing logic as them.These two changes have fixed the issues that I've been seeing, and I think that I finally got my first test case to work 🎉!