Let's say we have a function such as:

function tokenFallback(address sender, uint tokenAmount)

And some other contract decides to call it with:

contract.tokenFallback(sender, tokenAmount, data)

There are only two arguments in the tokenFallback, but the call includes three arguments. The tokenFallback function doesn't include the _data. What happens? Can the tokenFallback still execute like normal and ignore the _data variable that it received?


No, the called contract will revert. This is because when you write a contract call in solidity, it will calculate the hash of the called function signature. Here's how this is done (official python implementation):

sig = sha3("tokenFallback(address,uint)")

This signature hash is then truncated to 4 bytes and sent to the receiving contract without the actual function name.

Since the signature hash depends on the parameter types, its different from what the called contract expects, so it will revert.

You may be able to force a certain signature hash with assembly, but I'm not sure how that works.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.