-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Mismatching data locations are allowed in overrides #10900
Comments
I haven't been able to debug this on Remix because it hangs, but I imagine this is reinterpreting a memory pointer as a calldata pointer, or vice versa. This looks like a pretty serious bug that could be used to write underhanded code. |
The ability to use a different data location in the overriding function seems intentional (we even have syntax tests covering it: The fact that it reverts or returns zero does look like a bug though. We should investigate and also add a semantic test for that. |
This was neccessary when external functions were still restricted to calldata and public to memory. Otherwise it was impossible to override an external function with a public one. What should not be allowed is to override memory with calldata. If you do this, calling the function locally can lead to problems. In both cases, we should check that the parameter type is properly determined. |
The worst thing is such codes can be compiled by solc |
It is possible to override functions that expect
memory
arguments with implementations that expect them incalldata
. Offending code compiles with no warnings, but causes runtime errors.I've observed this behavior in both 0.7 and 0.8 versions, but haven't tested how far back it goes.
Sample contract:
I haven't tested too much the runtime issues, but I have seen some inconsistent behavior. When trying the example above on Remix, CorrectDerived works correctly as expected, but FaultyDerived returns 0 always. This is also true if
foo
is an address instead of a uint.However, on my local Hardhat environment in the project where I found this, I get reverts when attempting to access fields in the offending struct. I imagine this is related to either the fact that my structs are more complex, or that my project has already performed a few memory allocations at the moment the issue is triggered.
The text was updated successfully, but these errors were encountered: