-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Function signatures do not take return type into account #3131
Comments
The function selector only has four bytes, so there is no bijection between function selector and the type of the function anyway. If you call functions on contracts that are not compiled from the source code you assume they are compiled from, such attacks are also possible if you take the return parameters into the selector. |
...you know I never thought about this, but why weren't outputs included in the original function signature sha3? |
Function overloading can have a hard time determining what expressions are valid (function as right hand side vs. lvalue) and more importantly if the return value is not assigned to anything which one to take from a return-overloaded case? Thus many languages (such as C++) doesn't support it. I assume Solidity took a good chunk of early decisions from C++. |
@elenadimitrova do you want to incorporate this last comment in to the documentation? |
@axic I do believe that there is an important difference between supporting 'parametric return types' (which is what your C++ comment is hinting at and which indeed requires a quite powerful compiler) vs incorporating the return type in the resulting function signature's SHA3-hash (since this is a separate step that happens after the compilation itself, right?) |
I agree that it would have been more consistent with the ABI to include the return types in the signature and other languages may utilise that feature. The function selector on its own is not supposed to be used though, but in rather a JSON description of the ABI exists of which the clients calculate the hash themselves. This contains both inputs and outputs. See https://solidity.readthedocs.io/en/develop/abi-spec.html#json |
From the Solidity documentation
It seems that the return type of the function is not taken into account. Does this mean that a contract that returns something that the caller contract does not expect is able to exploit problems with implicit type conversions?
I have not yet had the time to create a test case to try what happens in practice, but it seems very odd to
not have the return type be part of the function signature/function selector that is used to decide what function is called (and if it is possible at all to call a function on a certain contract).
Am I missing something?
The text was updated successfully, but these errors were encountered: