Home › Solidity / smart contracts › Solidity + Foundry Copilot path instructions

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

How to use

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

.github/instructions/solidity.instructions.mdDownload  
---
applyTo: "**/*.sol"
description: Solidity contract conventions
---

# Solidity (0.8.x) with Foundry

- Build/test: `forge build`, `forge test -vvv`, `forge fmt --check`, `forge coverage`. Static analysis: `slither .` if installed.
- Pin the pragma to the project's compiler (`pragma solidity 0.8.30;`), not a floating `^`.
- Use audited OpenZeppelin contracts for tokens, access control (`Ownable2Step`, `AccessControl`) and `ReentrancyGuard`; don't reimplement them.
- Checks-effects-interactions order in every function that calls out; add `nonReentrant` where external calls follow state reads.
- Custom errors (`error InsufficientBalance(uint256 have, uint256 want);`) instead of revert strings.
- Validate inputs (zero address, bounds) and emit events for every state change.
- Never use `tx.origin` for auth, `block.timestamp` for randomness, or unchecked low-level `call` return values. Use `SafeERC20` for token transfers.
- Upgradeable contracts: follow the proxy pattern in use, no constructors (use initializers), preserve storage layout.
- NatSpec (`/// @notice`, `@param`) on external functions.

## Tests
Unit tests plus fuzz tests (`function testFuzz_x(uint256 amount)`) and invariant tests for core accounting. Fork tests use a pinned block number.

Never deploy, broadcast, or use private keys from the agent.

Related rules

Angular 20 Copilot instructions

Copilot instructions for Angular 20 apps using standalone components, signals, and the new control flow.

GitHub CopilotAngular

Code review Copilot instructions

Copilot instructions focused on pull request review: what to flag, severity labels, and how to word comments.

GitHub CopilotAgent workflows

C# / .NET Copilot path instructions

Path-specific Copilot instructions for C# files on .NET 10: nullable types, async, records, and logging.

GitHub Copilot.NET / ASP.NET Core

Dockerfile Copilot path instructions

Path-specific Copilot instructions for Dockerfiles and compose files: multi-stage builds, non-root, and pinned images.

GitHub CopilotDocker

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.