Rules › Solidity
selfdestruct in contract code
selfdestruct is deprecated and, since EIP-6780, no longer deletes code except in the deploying transaction; if reachable by the wrong caller it still sends away all ETH.
Why it matters
selfdestruct is deprecated. Since EIP-6780 (Dencun) it only removes code when called in the same transaction that created the contract; otherwise it just sends the whole balance to the target. Contracts that rely on it to "kill" themselves no longer work as intended, and an unprotected one is a one-call drain.
Vulnerable
function kill() external {
selfdestruct(payable(msg.sender));
}
Fixed
// Use a pause switch and an owner-only withdrawal instead.
function emergencyWithdraw(address to) external onlyOwner whenPaused {
(bool ok, ) = to.call{value: address(this).balance}("");
if (!ok) revert TransferFailed();
}
What other tools call it
| Tool | Detector or reference |
|---|---|
| Slither | suicidal |
| Solhint | avoid-suicide |
| SWC registry | SWC-106 |
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
- delegatecall to an address the caller controls
- Initializer anyone can call
- Privileged function without access control
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.