Solidity
Avoid common Solidity mistakes — reentrancy, gas traps, storage collisions, and security pitfalls.
- License 许可
- AGPL-3.0
- 最近更新
- 2026-11-12
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- Solidity
- metadata
- { "clawdbot": { "os": [ "linux", "darwin", "win32" ], "emoji": "⟠" } }
- description
- Avoid common Solidity mistakes — reentrancy, gas traps, storage collisions, and security pitfalls.
02 资源文件 4
- 参考文档_meta.json127 B
- 参考文档skill-card.md1.7 KB
- 参考文档SOURCE.md246 B
- 参考文档TRUST.auto.yaml2.1 KB
03 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
Visibility and Access
- State variables default to
internal— notprivate, derived contracts see them privatedoesn't mean hidden — all blockchain data is public, just not accessible from other contractstx.originis original sender — usemsg.sender,tx.originenables phishing attacksexternalcan't be called internally — usepublicorthis.func()(wastes gas)
Ether Handling
payablerequired to receive ether — non-payable functions reject etherselfdestructsends ether bypassing fallback — contract can receive ether without receive function- Check return value of
send()— returns false on failure, doesn't revert call{value: x}("")preferred overtransfer()— forward all gas, check return value
Storage vs Memory
storagepersists,memoryis temporary — storage costs gas, memory doesn't persist- Structs/arrays parameter default to
memory— explicitstorageto modify state calldatafor external function inputs — read-only, cheaper than memory- Storage layout matters for upgrades — never reorder or remove storage variables
Upgradeable Contracts
- Constructors don't run in proxies — use
initialize()withinitializermodifier - Storage collision between proxy and impl — use EIP-1967 storage slots
- Never
selfdestructimplementation — breaks all proxies pointing to it delegatecalluses caller's storage — impl contract storage layout must match proxy
Common Mistakes
- Block timestamp can be manipulated slightly — don't use for randomness or precise timing
requirefor user errors,assertfor invariants — assert failures indicate bugs- String comparison with
==doesn't work — usekeccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b)) - Events not indexed — first 3 params can be
indexedfor efficient filtering
04 同仓库更多 Skills
recipe-performance
Diagnose a specific MetaMask user flow's real-app performance and Sentry critical-user-flow telemetry with deterministic mm-harness recipes. Use for CUF boundaries, cold/warm/background-resume behavior, latency regressions, lifecycle tags, duplicate or blocking network requests, long tasks, layout/paint cost, screen redraws, React rerenders, or browser trace analysis where tests alone cannot prove the real app.
mexc-spot-websocket
MEXC Spot WebSocket workflows for public streams, protobuf handling, depth maintenance, listen keys, and private streams without exposing API keys.
mexc-spot-rest
MEXC Spot REST workflows for public data, signed account requests, orders, wallet/admin actions, and secure signing without exposing API keys.
mexc-futures-websocket
MEXC Futures WebSocket workflows for public streams, private account/order/position streams, ping/pong, subscriptions, and depth maintenance.
0xklen-version-and-refresh-sanctions-lists
暂无简介
verify-tests-cover-changed-lines
Use when a PR adds code that the existing suite may not exercise. Measures patch coverage — the share of newly changed lines hit by tests — before approving.