Rules › Solidity

selfdestruct in contract code

mediumSolidityRule sol-selfdestruct

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

ToolDetector or reference
Slithersuicidal
Solhintavoid-suicide
SWC registrySWC-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.

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.