Returnbomb
Detects external calls vulnerable to returnbomb attacks where a malicious callee returns excessive data to cause out-of-gas reverts.
Returnbomb
Overview
The returnbomb detector identifies external calls where the caller copies return data to memory without bounding its size. A malicious callee can return an arbitrarily large byte array (e.g., 1MB), and the memory copy operation (RETURNDATACOPY) consumes gas quadratically with size — enough to exhaust all available gas and force a revert.
This is particularly dangerous in multi-call patterns (batch operations, relay contracts) where a single malicious target can cause the entire batch to fail.
Why This Is an Issue
When a contract captures return data with (bool success, bytes memory data) = target.call(...), the EVM copies the full return data into memory. Memory costs grow quadratically, so a 1MB return consumes roughly 3 billion gas — far exceeding any block gas limit. An attacker who controls the callee can weaponize this to grief callers, block withdrawals, or cause denial of service in protocols that rely on external calls succeeding.
How to Resolve
// Before: Vulnerable — unbounded return data copy
(bool success, bytes memory data) = target.call(payload);
// After: Option 1 — ignore return data
(bool success, ) = target.call{gas: 50000}(payload);
// After: Option 2 — bound return data size with assembly
assembly {
let success := call(gas(), target, value, 0, calldatasize(), 0, 0)
let size := returndatasize()
if gt(size, 256) { revert(0, 0) } // Cap at 256 bytes
returndatacopy(0, 0, size)
}
Detection Methodology
- External call identification: Locates CALL, STATICCALL, and DELEGATECALL instructions targeting user-controlled or untrusted addresses.
- Return data handling: Tracks whether RETURNDATASIZE is used to allocate memory and RETURNDATACOPY is used without a size bound.
- Bounds check detection: Looks for comparison instructions that limit the return data size before the copy operation.
- Compiler version awareness: Solidity 0.8.17+ includes built-in protection; contracts compiled with earlier versions are at higher risk.
Limitations
False positives: Calls to trusted, immutable contract addresses (e.g., well-known tokens) are flagged even though the callee is not malicious. False negatives: Custom assembly-level return data handling with non-standard bounds patterns may not be recognized.
Related Detectors
- Unchecked Call — detects missing return value checks
- DoS — detects denial-of-service patterns broadly
- Gas Optimization — detects gas-related inefficiencies