12

An empty message still invokes the code of the contract and is the mechanism that allows Solidity to implement a feature of a fallback function per contract.

But when msg.data is empty, why does contract code still need to execute?

If a caller leaves msg.data empty, meaning they don't want to pass any data or call any functions at all on a contract, why does the contract code still need to run?

2 Answers 2

12

To keep the core protocol of Ethereum simple and generic, the protocol has the rule that a message always executes the code of an account. Simple and generic allows the critical consensus protocol to be smaller and decrease the risk of consensus bugs.

This means that a detail, such as the Ethereum Contract ABI, does not need to be defined in the core Ethereum protocol. The ABI is an abstraction and improvements or alternatives to the ABI have no effect on the Ethereum protocol or the Ethereum Virtual Machine, EVM. Without the rule that "account code always executes", the protocol itself would then need to define what triggers account code, or parts of the account code, to execute: the protocol would become the opposite of simple and generic.

4

Code is run as a response to a transaction. This always happens when there is code in the account. msg.data being empty doesn't mean no code should be called, there is no such "rule", it only means there is no input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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