Home › Solidity / smart contracts › Solidity smart contract security CLAUDE.md

Solidity smart contract security CLAUDE.md

CLAUDE.md for reviewing and writing Solidity contracts safely: threat checklist, Foundry tests, and no-deploy rules.

Claude Code (CLAUDE.md)Solidity / smart contracts

How to use

Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

CLAUDE.mdDownload  
# CLAUDE.md: Smart contract work (Solidity)

## Hard rules
- Never deploy, broadcast transactions, sign messages, or read private keys/mnemonics. No `forge script --broadcast`, no `cast send`. Local `anvil` only.
- Don't add new dependencies without naming their audit status. Prefer OpenZeppelin Contracts at a pinned version.

## Commands
`forge build` · `forge test -vvv` · `forge test --match-test testFuzz` · `forge coverage` · `forge snapshot` (gas) · `slither .` · `forge fmt`

## Checklist for every change
- **Access control:** who can call each external/public function? Admin functions use roles or `Ownable2Step`; initializers can only run once.
- **Reentrancy:** state updated before external calls; `nonReentrant` on functions that move value; consider read-only reentrancy for view functions used by others.
- **Math and units:** decimals handled explicitly; rounding direction favors the protocol; no precision loss from dividing before multiplying.
- **External calls and tokens:** `SafeERC20`, handle fee-on-transfer/rebasing tokens or document they're unsupported; check return values.
- **Oracles:** no spot prices from AMMs for valuation; check staleness and decimals of price feeds.
- **DoS:** no unbounded loops over user-controlled arrays; pull over push payments.
- **Upgrades:** storage layout preserved (`forge inspect <C> storageLayout`), `_disableInitializers()` in implementation constructors.
- **Events** for all state changes; custom errors for reverts.

## Tests
Unit + fuzz + invariant tests (`invariant_totalSupplyMatchesBalances`). Every bug fix starts with a failing test reproducing the exploit.

## Report
List findings by severity (critical/high/medium/low/info) with the affected function and a suggested fix.

More: all Solidity / smart contracts rules · all Claude Code (CLAUDE.md) rules

Related rules

Solidity + Foundry Copilot path instructions

Path-specific Copilot instructions for Solidity 0.8.x contracts with Foundry: security patterns, fuzz tests, and gas.

GitHub CopilotSolidity / smart contracts

ESP32 ESP-IDF firmware CLAUDE.md

CLAUDE.md for ESP32 firmware on ESP-IDF 5.x in C: components, FreeRTOS tasks, error handling, and logging.

Claude Code (CLAUDE.md)Embedded / firmware

Modern C++ with CMake rules

Cursor rules for modern C++ (C++20/23) projects built with CMake presets: RAII, ownership, warnings, and tests.

CursorC++

Embedded C (bare metal / RTOS) AGENTS.md

AGENTS.md for embedded C firmware (bare metal, Zephyr, FreeRTOS): safety-minded C rules, memory, and hardware access.

AGENTS.mdEmbedded / firmware

Arduino / PlatformIO rules

Cursor rules for microcontroller projects with PlatformIO and the Arduino framework: non-blocking loops, memory, pins.

CursorEmbedded / firmware

Zig AGENTS.md

AGENTS.md for Zig 0.15 projects: build.zig, explicit allocators, error unions, defer cleanup, and zig test.

AGENTS.mdZig

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.