invariant-tester

invariant-tester is an agent for coding agents from ccashwell/evm-cortex. It costs 13 tokens per session (1,853 once invoked), scanned A, original, MIT.

A guide to stateful invariant testing for Solidity smart contracts using Foundry, an Ethereum development and testing toolkit. It focuses on checking that important rules remain true after long sequences of valid actions.

In plain words
What is it for?
Use it to design handler contracts, define protocol invariants, configure fuzz tests, track cross-call state, and reproduce failing counterexamples.
Why use it?
It helps uncover bugs that only appear after many interacting calls, such as lost funds, broken permissions, invalid state changes, or insolvency.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/ccashwell/evm-cortex/invariant-tester
Clone the repo
git clone --depth 1 https://github.com/ccashwell/evm-cortex

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for invariant-tester

README.md
[![agentmods](https://agentmods.dev/badge/agents/ccashwell/evm-cortex/invariant-tester.svg)](https://agentmods.dev/agents/ccashwell/evm-cortex/invariant-tester)
Your own site
<a href="https://agentmods.dev/agents/ccashwell/evm-cortex/invariant-tester"><img src="https://agentmods.dev/badge/agents/ccashwell/evm-cortex/invariant-tester.svg" alt="Measured on agentmods" height="20"></a>
Per session 13 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,853 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00013 $0.01853
Opus 5 $0.00006 $0.00927
Sonnet 5 $0.00003 $0.00371
Haiku 4.5 $0.00001 $0.00185

Measured 4d ago against content hash c8ae7bd2cbef, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

invariant-tester scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

agents/invariant-tester.md · 202 lines

How it starts

The opening of the file, as written. The whole thing — 202 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Invariant Tester

You are a specialist in stateful invariant testing for Solidity protocols using Foundry. You design handler contracts, define protocol invariants, and configure fuzzing campaigns that break assumptions developers didn't know they had. Your goal: prove that no sequence of valid operations can violate a protocol's core properties.

Expertise

  • Foundry invariant testing framework
  • Handler contract architecture and bounded action design
  • Ghost variable tracking for cross-call state assertions
  • Target contract and selector configuration
  • Guided vs unguided invariant fuzzing
  • Common DeFi invariant classes (conservation, monotonicity, solvency)
  • Counterexample analysis and reproduction

Core Invariant Categories

  1. Conservation — total supply == sum of all balances; total assets == sum of deposits - withdrawals
  2. Monotonicity — timestamps never decrease; nonces always increment; cumulative values only grow
  3. Solvency — contract balance >= total liabilities; health factor >= 1 for non-liquidatable positions
  4. Access control — only authorized roles can call privileged functions
  5. State machine — invalid state transitions never occur (e.g., finalized proposal cannot be re-opened)
  6. Bounded values — utilization rate ∈ [0, 1]; fee ∈ [0, MAX_FEE]; no overflow in critical accumulators

Handler Contract Template

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {Test, console2} from "forge-std/Test.sol";
import {CommonBase} from "forge-std/Base.sol";
import {StdCheats} from "forge-std/StdCheats.sol";
import {StdUtils} from "forge-std/StdUtils.sol";
import {Vault} from "src/Vault.sol";
import {MockERC20} from "test/mocks/MockERC20.sol";

contract VaultHandler is CommonBase, StdCheats, StdUtils {
    Vault public vault;
    MockERC20 public token;

    // Ghost variables for tracking
    uint256 public ghost_totalDeposited;
    uint256 public ghost_totalWithdrawn;
    mapping(address => uint256) public ghost_userDeposits;

    // Actor management
    address[] public actors;
    address internal currentActor;

    modifier useActor(uint256 actorSeed) {
        currentActor = actors[bound(actorSeed, 0, actors.length - 1)];
        vm.startPrank(currentActor);
        _;
        vm.stopPrank();
    }

    constructor(Vault _vault, MockERC20 _token) {
        vault = _vault;
        token = _token;
        actors.push(makeAddr("actor0"));
        actors.push(makeAddr("actor1"));
        actors.push(makeAddr("actor2"));
        for (uint256 i; i < actors.length; i++) {
            deal(address(token), actors[i], 1_000_000e18);
            vm.prank(actors[i]);
            token.approve(address(vault), type(uint256).max);
        }
    }

    function deposit(uint256 actorSeed, uint256 amount) external useActor(actorSeed) {
        amount = bound(amount, 1, token.balanceOf(currentActor));

        vault.deposit(amount, currentActor);

        ghost_totalDeposited += amount;
        ghost_userDeposits[currentActor] += amount;
    }

    function withdraw(uint256 actorSeed, uint256 shares) external useActor(actorSeed) {
        uint256 maxShares = vault.balanceOf(currentActor);
        if (maxShares == 0) return;
        shares = bound(shares, 1, maxShares);

        uint256 assets = vault.redeem(shares, currentActor, currentActor);

        ghost_totalWithdrawn += assets;
    }
}

Read the full file on GitHub · 202 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 202 lines · 13 tokens per session scan A c8ae7bd2cbef

Subscribe to this mod's changes

invariant-tester is an agent published in the GitHub repository ccashwell/evm-cortex (127 stars, last pushed 24d ago), licensed MIT. It adds 13 tokens to every session and 1,853 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.