selfdestruct-eip6780
Skill36 starsChanged 5 months agoMITView on GitHub
Detect selfdestruct misuse and EIP-6780 implications post-Cancun — bricked contracts, broken `assert(balance == X)` invariants, factory patterns relying on redeploy, deployment-tx-only selfdestruct corner cases. Activate on `selfdestruct`, `suicide`, `CREATE2` factories, contracts asserting on `address(this).balance`.
In this repository44 other files it gives its agents.
- access-controlSkill
- approval-issuesSkill
- caching-and-incrementalSkill
- centralization-riskSkill
- confidence-scoringSkill
- cosmwasmSkill
- cross-chain-messagingSkill
- cross-contract-stateSkill
- delegatecall-risksSkill
- diamond-eip2535Skill
- dos-vectorsSkill
- erc1271-contract-signaturesSkill
- erc4337-account-abstractionSkill
- erc4626-inflationSkill
- false-positive-feedback-loopSkill
- fee-on-transferSkill
- flash-loan-attacksSkill
- initializationSkill
- inline-assemblySkill
- integer-issuesSkill
- intents-erc7683Skill
- known-good-comparisonSkill
- liquidation-cascadeSkill
- mev-frontrunningSkill
- mev-pbsSkill
- multi-pass-self-critiqueSkill
- oracle-manipulationSkill
- oracle-redundancySkill
- permit2-patternsSkill
- pragma-and-addressesSkill
- progress-and-streamingSkill
- reentrancySkill
- restaking-eigenlayerSkill
- signature-malleabilitySkill
- signature-replaySkill
- solana-anchorSkill
- storage-layoutSkill
- stylus-rustSkill
- token-compatibilitySkill
- tx-context-misuseSkill
- unchecked-callsSkill
- ve-lock-governanceSkill
- vyper-specificSkill
- zk-verifier-bugsSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
After Cancun (March 2024), selfdestruct no longer deletes the contract's code or storage *unless* called in the same transaction as the …
- Very specific: line 64
Don't use address(this).balance as part of any invariant.
- Very specific: line 66
Remove selfdestruct from production contracts unless absolutely needed.
- Distinctive: line 67
If retained, guard heavily (multi-sig + timelock).
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
selfdestruct / EIP-6780 detection
EIP-6780 background
After Cancun (March 2024), selfdestruct no longer deletes the contract's code or storage unless called in the same transaction as the contract's deployment. It does still transfer all ether to the recipient. This changes the security model substantially:
- Pre-6780: any
selfdestructcould brick a contract → many DoS attacks. - Post-6780:
selfdestructoutside the deploy-tx only forwards ether. Code/storage survives.
When this applies
- Any
selfdestructcall - Contracts that assert
address(this).balance == X(someone can force-add ether viaselfdestruct) CREATE2factories relying on redeploy at same address (now broken — code persists)- Diamonds / proxies with implementation-side selfdestruct
- Pre-Cancun deployed contracts (legacy semantics still apply at runtime)
Detection patterns
Forced-ether DoS on balance-equality assumption (HIGH — still relevant)
require(address(this).balance == expected); // ← attacker can `selfdestruct` ether to break thisTrack expected balance in a state variable, not via address(this).balance.
CREATE2 redeploy pattern broken (HIGH)
// Pattern: deploy logic to deterministic addr, selfdestruct to "upgrade", redeploy.
// ← Post-6780, code persists. Redeploy at same address fails or reverts.Migrate to true proxy patterns.
selfdestruct in deploy-tx (still has full power) (HIGH)
A constructor that selfdestructs in the deploy tx truly deletes code+storage. Some "metamorphic" tricks abuse this.
Library / facet with selfdestruct path reachable (HIGH)
Pre-6780-deployed diamond facets with selfdestruct paths remain dangerous. Even post-6780, a facet selfdestruct that orphans ether still costs.
selfdestruct sending ether to known-revert recipient (LOW)
Selfdestruct still forwards ether — recipient cannot revert on receive (selfdestruct bypasses fallback). So this isn't a DoS for the destructor, but can leave the recipient with unexpected balance.
Recovery via selfdestruct on stuck-fund contract (LOW-MEDIUM)
Sometimes a useful pattern — note intent.
Severity rubric
| Pattern | Severity |
address(this).balance == X invariant | High |
Public selfdestruct path on deployed contract | High |
| CREATE2 redeploy/upgrade pattern (post-Cancun broken) | High |
| Diamond facet selfdestruct reachable | High |
| Constructor metamorphic selfdestruct | High (may be intentional, document) |
selfdestruct to known revert-on-receive recipient | Low |
selfdestruct as legitimate recovery, properly guarded | Info |
Remediation patterns
- Don't use
address(this).balanceas part of any invariant. Track received ether explicitly. - Migrate metamorphic / CREATE2-redeploy patterns to standard proxies (UUPS / Transparent).
- Remove
selfdestructfrom production contracts unless absolutely needed. - If retained, guard heavily (multi-sig + timelock).
False-positive notes
- A contract using
selfdestructonly in a test-helper or migration script → not deployable, ignore. selfdestructwhose recipient is the contract's own address — does nothing useful, comment as code smell.
Related
- [[delegatecall-risks]]
- [[dos-vectors]]
- [[access-control]]
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

