4

Since a fallback function is a Solidity feature, how does it work if the EVM opcode CALL is used?

If msg.data is empty, how can Solidity run the fallback function? Shouldn't the EVM just transfer the Ether, since there's no function invocation involved?

In Solidity, does syntax like contractAddress.call.value(amountWei)() invoke a raw CALL opcode, or does Solidity still do something additional?

4

Any message sent to a contract, even if it is empty or just an ether transfer will invoke the code of the contract. The fallback function is run if the data sent does not start with a known function identifier (e.g. if a non-existent function is called or if the message data is empty as is the case for a simple ether transfer).

So if a contract has a fallback function, there is no way to prevent it being called (except by calling an actually existing function or not sending enough gas but no ether).

In Solidity, both .call and .send compile to the CALL opcode, just their expected arguments are different.

  • Accepted the answer but I think the key question is why this: "Any message sent to a contract, even if it is empty or just an ether transfer will invoke the code of the contract." ethereum.stackexchange.com/questions/1585/… – eth Feb 25 '16 at 0:45
  • To complete the answer: Solidity's ".transfer" also compiles to CALL. Both transfer() and send() differ from call() in that they set up a gas stipend of 2300 by default. With call(), the default is to use all remaining gas. – Alex Byrde Nov 5 '18 at 23:28

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.