delegatecall-risks
Skill36 starsChanged 5 months agoMITView on GitHub
Detect delegatecall risks — uninitialized proxies, malicious implementations, storage-slot collisions, delegatecall to user-controlled addresses, library delegatecall pitfalls. Activate on `delegatecall`, UUPS proxy upgrades, multicall implementations, diamond facets, governor-execute patterns.
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
- 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
- selfdestruct-eip6780Skill
- 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
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 68
Never delegatecall a non-allowlisted address.
- Distinctive: line 71
Use EIP-1967 / EIP-7201 namespaced slots for proxy admin / impl.
- Very specific: line 73
After upgrading: verify storage layout via forge inspect.
≈ “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
Delegatecall risk detection
When this applies
- Any
delegatecallsite - Proxy implementations (UUPS, Transparent, Beacon, Diamond)
Multicall/Multicall3/ batch-execute on the contract itself- Governor's
execute()flow - Library
using X for *where X uses delegatecall - Generic call-forwarder / Safe modules
Detection patterns
delegatecall to user-controlled address (CRITICAL)
function exec(address impl, bytes calldata data) external {
impl.delegatecall(data); // ← attacker provides impl, owns storage + can selfdestruct
}Uninitialized UUPS implementation (CRITICAL)
The implementation contract, if uninitialized, can be initialized by anyone, then UUPS-upgraded to a selfdestruct impl, bricking the implementation. (Famous: Parity multisig.) Always _disableInitializers() in constructor.
Storage slot collision in proxy (CRITICAL)
Proxy uses slot 0 for admin, impl uses slot 0 for owner → impl writes corrupt proxy admin. Use EIP-1967 namespaced slots.
delegatecall + msg.value (MEDIUM-HIGH)
Forwarding msg.value via delegatecall to a function that doesn't expect ether → trapped funds or double-accounting.
Multicall + delegatecall + msg.sender confusion (HIGH)
Multicall via delegatecall preserves msg.sender, so signed-payload-based functions (permit, ERC-2771) can be combined in surprising ways. Audit each function for "what if called via multicall with attacker-controlled previous step?"
Diamond facet self-destruct (HIGH — pre-EIP-6780)
A malicious or buggy facet that calls selfdestruct deletes the diamond. EIP-6780 limits this to same-tx-deploy, but old diamonds remain at risk. See [[selfdestruct-eip6780]].
Library marked internal actually compiled with delegatecall (HIGH)
Solidity compiles "linked" libraries to delegatecall. Linking the wrong library (or address) bricks downstream contracts.
_authorizeUpgrade missing or weak (CRITICAL)
UUPS upgrade gate. If unguarded, anyone can upgrade the proxy.
function _authorizeUpgrade(address) internal override {} // ← no auth, anyone upgradesCross-contract delegatecall to read-only function (LOW)
Used (rarely) for pattern obfuscation; usually a code smell.
Severity rubric
| Pattern | Severity |
| delegatecall to user-supplied address | Critical |
UUPS _authorizeUpgrade unguarded | Critical |
Uninitialized UUPS impl with no _disableInitializers | Critical |
| Storage collision proxy/impl | Critical |
Forwarding msg.value to non-payable target | High |
| Multicall + signed-msg sender ambiguity | High |
| Library linkage to wrong address | High |
| Diamond facet with selfdestruct path | High (see [[selfdestruct-eip6780]]) |
Remediation patterns
- Never delegatecall a non-allowlisted address. Hardcode or maintain a strict allowlist of valid implementations.
- UUPS:
_authorizeUpgradeMUST checkonlyOwner(or stricter). - Implementation constructor:
_disableInitializers(). - Use EIP-1967 / EIP-7201 namespaced slots for proxy admin / impl.
- Multicall guard: forbid permit/auth-changing functions in batch, or limit to a non-delegatecall variant.
- After upgrading: verify storage layout via
forge inspect.
False-positive notes
- Solady
LibClone.deployERC1967and similar canonical proxy libraries are well-tested. - delegatecall to an
immutableimplementation address (set in constructor, not changeable) is much lower risk.
Related
- [[initialization]]
- [[storage-layout]]
- [[access-control]]
- [[selfdestruct-eip6780]]
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.

