Receive Function Explained in Detail
receive() runs when a contract receives plain Ether with empty calldata. It must be marked external payable and cannot take arguments or return values.
If calldata is not empty, Solidity uses the fallback function instead when one exists.
Smart contract example
receive() external payable {
deposits[msg.sender] += msg.value;
}
The function records simple Ether transfers, but only for transfers that call receive().
Receive Function in Auditing
Ether can arrive through receive(), fallback, normal payable functions, validator coinbase payments, or selfdestruct. Auditors need to know which paths update accounting and which paths only change raw balance.
Red flags in code
-
receive()accepts Ether but does not update accounting. -
Contract assumes all Ether arrived through
deposit(). -
receive()contains complex logic or external calls. -
Fallback and receive behave differently without clear reason.
-
Raw
address(this).balanceis used as the accounting source.
How to test or review it
-
Send Ether with empty calldata, non-empty calldata, and through a normal payable function.
-
Force-send Ether with
selfdestructand check invariants. -
Verify events, accounting, and access checks match the intended deposit model.
-
Keep
receive()simple unless the design requires otherwise. -
Review gas assumptions for transfers from contracts and smart wallets.
Keep learning this topic
Fallback Function
A fallback function is a Solidity function that runs when calldata does not match any function selector or when Ether is sent without a matching receive function.
External Call
An external call is an interaction where one smart contract calls another address, creating a trust boundary and possible control-flow risk.
SELFDESTRUCT (Solidity/EVM)
selfdestruct is an EVM operation that can force-send Ether and historically removed contract code and storage under older semantics.
Delegatecall & Call Injection Attacks
Delegatecall and call injection attacks in Solidity: storage collision exploits, proxy vulnerabilities like Parity, and secure upgrade patterns.
Self Destruct Attacks
See how this vulnerability appears in real smart contract audits.
Smart Contract Audit Checklist
Use this SCH tool to turn the concept into practical audit work.
Practice this in real audit scenarios
Definitions help, but auditors need reps. SCH turns concepts like Receive Function into exploit labs, code review habits, and report-writing practice.
Start the free trial or see the full smart contract auditing course.