---
name: solidity-a677661e91e0
slug: solidity
version: 1.0.0
description: Avoid common Solidity mistakes — reentrancy, gas traps, storage collisions, and security pitfalls.
homepage: https://clawic.com/skills/solidity
metadata:
  clawdbot:
    emoji: ⟠
    os:
    - linux
    - darwin
    - win32
    displayName: Solidity
---

## Reentrancy
- External calls before state updates — attacker can re-enter before state changes
- Checks-Effects-Interactions pattern — validate, update state, THEN external call
- `ReentrancyGuard` from OpenZeppelin — use `nonReentrant` modifier on vulnerable functions
- `transfer()` and `send()` 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).max` for 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
- `delete` refunds 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` — not `private`, derived contracts see them
- `private` doesn't mean hidden — all blockchain data is public, just not accessible from other contracts
- `tx.origin` is original sender — use `msg.sender`, `tx.origin` enables phishing attacks
- `external` can't be called internally — use `public` or `this.func()` (wastes gas)

## Ether Handling
- `payable` required to receive ether — non-payable functions reject ether
- `selfdestruct` sends 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 over `transfer()` — forward all gas, check return value

## Storage vs Memory
- `storage` persists, `memory` is temporary — storage costs gas, memory doesn't persist
- Structs/arrays parameter default to `memory` — explicit `storage` to modify state
- `calldata` for 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()` with `initializer` modifier
- Storage collision between proxy and impl — use EIP-1967 storage slots
- Never `selfdestruct` implementation — breaks all proxies pointing to it
- `delegatecall` uses 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
- `require` for user errors, `assert` for invariants — assert failures indicate bugs
- String comparison with `==` doesn't work — use `keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b))`
- Events not indexed — first 3 params can be `indexed` for efficient filtering


---
Source attribution: clawic
Original project: https://github.com/clawic/skills/blob/f825206afbf1c697202533a9187be68c7b697e0e/skills/solidity/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Ivan G. Davila

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: clawic
Original project: https://github.com/clawic/skills/blob/f825206afbf1c697202533a9187be68c7b697e0e/skills/solidity/SKILL.md
Attribution basis: Source repository record

Fields of work: Development & Engineering, Product Management
Roles: Backend Developer, ML / AI Engineer, Product Manager
Specialties: Backend
Tools: Openzeppelin
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 0114434dae1a914750c8377c54326b3595d3711eaeae77236befb8c6d735d522
