solidity-security
Installation
SKILL.md
Solidity Security
Defensive Solidity patterns that prevent the vulnerabilities behind 90%+ of DeFi exploits. Every section shows the broken pattern first, then the fix. Code is Solidity 0.8.20+ unless noted.
What You Probably Got Wrong
LLMs generate plausible but exploitable Solidity. These are the blind spots that cause real losses.
- USDC/USDT are 6 decimals, not 18 —
1e18assumptions silently inflate or truncate amounts by 1e12. Always readIERC20Metadata(token).decimals()onchain. - Solidity has no floating point — Writing
amount * 0.03does not compile. Use basis points:amount * 300 / 10_000. - 0.8.x does NOT prevent all overflow — Checked math covers
+,-,*,/on standard types. It does NOT protectunchecked {}blocks, assembly, bitwise ops, or casting between smaller types (uint256touint128). transfer()andsend()are not safe — They forward only 2300 gas. Since EIP-1884 repricedSLOAD, many contracts and multisigs (Gnosis Safe) cannot receive ETH viatransfer(). Usecall{value:}("")with reentrancy protection.- ERC20
approveis not universal — USDT requires resetting allowance to 0 before setting a new value. Use OpenZeppelinSafeERC20. msg.senderchanges in delegatecall — In proxy patterns,msg.senderin the implementation is the caller, not the proxy. Butaddress(this)is the proxy's address. Confusing these causes critical auth bugs.block.timestampis manipulable — Miners/validators can shift it by ~15 seconds. Never use it as sole entropy or for tight time windows.