Rules › Solidity
delegatecall to an address the caller controls
delegatecall runs foreign code with this contract's storage and balance; a caller-chosen target can take it over.
Why it matters
delegatecall runs another contract's code in this contract's context: its storage, its balance, its msg.sender. If the caller chooses the target, they can run code that overwrites the owner slot, drains funds, or self-destructs. Only delegatecall into fixed, trusted implementations (proxies, libraries).
Vulnerable
function execute(address impl, bytes calldata data) external {
(bool ok, ) = impl.delegatecall(data);
require(ok);
}
Fixed
address public immutable implementation;
function execute(bytes calldata data) external onlyOwner {
(bool ok, ) = implementation.delegatecall(data);
if (!ok) revert CallFailed();
}
What other tools call it
| Tool | Detector or reference |
|---|---|
| Slither | controlled-delegatecall |
| Solhint | avoid-low-level-calls |
| Aderyn | delegate-call-in-loop |
| SWC registry | SWC-112 |
Check your code
Paste a contract into the in-browser checker, or let the Claude Code plugin scan before every deploy. The quick check for this rule is a pattern match: treat a hit as "look here", and a miss as no guarantee.
Related rules
- tx.origin used for authorization
- State written after an external call (reentrancy)
- Return value of a low-level call is ignored
- Initializer anyone can call
- Privileged function without access control
- selfdestruct in contract code
Static analysis finds known bug classes; it can't prove code is safe and isn't an audit. Get a professional audit before deploying code that will hold value.