Solidity
Installation
SKILL.md
Reentrancy
- External calls before state updates — attacker can re-enter before state changes
- Checks-Effects-Interactions pattern — validate, update state, THEN external call
ReentrancyGuardfrom OpenZeppelin — usenonReentrantmodifier on vulnerable functionstransfer()andsend()have 2300 gas limit — but don't rely on this for security
Integer Handling
- Solidity 0.8+ reverts on overflow — but
unchecked {}blocks bypass this - Division truncates toward zero —
5 / 2 = 2, no decimals - Use fixed-point math for precision — multiply before divide, or use libraries
type(uint256).maxfor max value — don't hardcode large numbers
Gas Gotchas
- Unbounded loops can exceed block gas limit — paginate or limit iterations
- Storage writes cost 20k gas — memory/calldata much cheaper
deleterefunds gas but has limits — refund capped, don't rely on it- Reading storage in loop — cache in memory variable first