# Foundry invariant starter · for smart contracts

> Starter scaffold for invariant testing in Foundry · handlers, ghost variables, 8 patterns with ready code. MIT.

Starter scaffold for invariant testing in Foundry · handlers, ghost variables, 8 patterns with ready code. MIT.

Foundry invariant-test scaffold · base Handler, ghost state, pre/post-delta asserts, cross-function coupling test, conservation, monotonicity, bounded-state. Ready with 200k fuzz runs.

## What the file contains

- Base Handler contract template
- 8 invariant patterns with ready Foundry code
- Ghost-variable pattern for property tracking
- forge-config + optimal fuzz-run parameters
- CI integration · GitHub Actions workflow

## What to take away

- Base Handler contract template
- 8 invariant patterns with ready Foundry code
- Ghost-variable pattern for property tracking
- forge-config + optimal fuzz-run parameters
- CI integration · GitHub Actions workflow

## Tags

template, Solidity + Markdown, blockchain, foundry, invariant, audit

## Read the full write-up

/resources/smart-contract-invariant-starter-foundry.md

## Terms used in this piece

- https://dfieldsolutions.com/en/glossary/foundry.md
- https://dfieldsolutions.com/en/glossary/fuzz.md

## We build this for clients

https://dfieldsolutions.com/en/services/blockchain

## More from the lab

- https://dfieldsolutions.com/en/lab/smart-contract-threat-model-template.md — Smart contract threat model template
- https://dfieldsolutions.com/en/lab/erc-4337-paymaster-starter.md — ERC-4337 paymaster starter
- https://dfieldsolutions.com/en/lab/solana-rpc-costs.md — What Solana RPC actually costs once the prototype works
- https://dfieldsolutions.com/en/lab/solana-anchor-footguns.md — Solana foot-guns Anchor does not remove

---

Source: https://dfieldsolutions.com/en/lab/smart-contract-invariant-starter-foundry
DField Solutions — Torony köz 5-1.a, 2120 Dunakeszi, Hungary — +36 20 722 0002 — dezso@dfieldsolutions.com
Booking: see https://dfieldsolutions.com/en/contact
