BACK TO TEMPLATES
rulesany

Solidity Smart Contract Rules

Security-focused AGENTS.md for EVM Solidity smart contracts covering Foundry tests, Slither analysis, and reentrancy protection.

When to use this

Place this template in EVM smart contract repositories using Foundry or Hardhat to enforce zero-vulnerability security checks, gas optimization, and strict test coverage.

The template

# AGENTS.md

## Project Context

EVM smart contract codebase using Solidity 0.8.20+ and Foundry development toolkit.

## Commands

- `forge build` compile Solidity contracts
- `forge test` execute Foundry test suite
- `forge test --gas-report` generate contract gas consumption report
- `slither .` run static vulnerability scanner

Always run `forge test` and `slither .` before completing changes.

## Conventions

- Apply Checks-Effects-Interactions pattern strictly on all state-modifying functions.
- Use OpenZeppelin `ReentrancyGuard` or `ReentrancyGuardTransient` for external calls.
- Emit custom errors instead of `require()` strings to minimize deployment and execution gas.
- All public/external functions must include NatSpec comments (`@notice`, `@dev`, `@param`).

## Restrictions

- Do not use `delegatecall` without explicit security audit review.
- Do not use `tx.origin` for authentication; use `msg.sender`.

## Approval Required

- Any change to state variable layout or upgradeable contract storage slots.
- Modifying access control modifiers (`onlyOwner`, `onlyRole`).

Customization Guide

Update Solidity compiler version and framework tools to match your smart contract setup.

Last verified 2026-07-26