invariant

invariant is a command for Claude Code from omermaksutii/RugProof. It costs 19 tokens per session (808 once invoked), scanned A, original, MIT.

A command that creates invariant tests for Foundry, a toolkit for testing Ethereum smart contracts. Invariant tests repeatedly try many actions to check that important rules always remain true.

In plain words
What is it for?
Use it to test rules such as token supply conservation, vault accounting, trading-pool reserves, lending safety limits, and governance voting behavior.
Why use it?
Example-based tests cover selected scenarios, while invariant tests can expose bugs that appear only after unusual sequences of actions.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter. Also seen: mentions subagents.

Part of the rugproof plugin — 35 commands, 23 agents shipped together

Good fit Use it to test rules such as token supply conservation, vault accounting…

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/omermaksutii/rugproof/invariant
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.

Clone the repo
git clone --depth 1 https://github.com/omermaksutii/RugProof

Made for: Claude Code.

Or install rugproof, the plugin that ships this one along with the rest of its 35 commands, 23 agents.

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

README.md
[![agentmods](https://agentmods.dev/badge/commands/omermaksutii/rugproof/invariant.svg)](https://agentmods.dev/commands/omermaksutii/rugproof/invariant)
Your own site
<a href="https://agentmods.dev/commands/omermaksutii/rugproof/invariant"><img src="https://agentmods.dev/badge/commands/omermaksutii/rugproof/invariant.svg" alt="Measured on agentmods" height="20"></a>
Per session 19 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 808 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00019 $0.00808
Opus 5 $0.00010 $0.00404
Sonnet 5 $0.00004 $0.00162
Haiku 4.5 $0.00002 $0.00081

Measured 6d ago against content hash f95ed7d2cba2, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

invariant 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 6d 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.

commands/invariant.md · 100 lines

How it starts

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

/invariant — generate invariant tests

Property-based testing in Foundry. The single highest-leverage test artifact you can produce — invariants catch bugs no example-based test does.

Procedure

Step 1 — Identify invariants

Dispatch invariant-writer subagent. It reads the contract and proposes invariants based on protocol type:

Token / ERC-20:

  • totalSupply() == sum(balanceOf(a) for a in all_addrs)
  • balances never overflow
  • transfers preserve totalSupply (no minting / burning)

Vault / ERC-4626:

  • totalAssets() >= sum(convertToAssets(balanceOf(a)) for a in all_holders)
  • previewDeposit + previewWithdraw round-trip ≤ initial value
  • totalSupply == 0 ⇒ totalAssets == 0
  • shares only mintable via deposit/mint, only burnable via withdraw/redeem

AMM:

  • K = reserve0 * reserve1 non-decreasing after fee-paying swaps
  • LP token supply ratio matches reserves ratio over time

Lending:

  • sumDebt <= sumCollateralValue * MAX_LTV (modulo bad debt)
  • borrow + repay is value-preserving
  • no negative balances

Governance:

  • vote weight is snapshotted; can't be modified after proposal creation
  • timelock delay always elapses before execution

Step 2 — Generate Foundry invariant harness

contract VaultInvariants is Test {
    Vault vault;
    Handler handler;   // ← actor that calls arbitrary fns with bounded random inputs

    function setUp() public {
        vault = new Vault();
        handler = new Handler(vault);
        targetContract(address(handler));
    }

    function invariant_TotalAssetsCoversShares() public {
        uint256 sum;
        address[] memory users = handler.getActors();
        for (uint i; i < users.length; ++i) {
            sum += vault.convertToAssets(vault.balanceOf(users[i]));
        }
        assertGe(vault.totalAssets(), sum, "vault would be insolvent");
    }
}

Plus a Handler contract that has deposit, withdraw, transfer, etc. — each bounded to realistic random inputs.

Read the full file on GitHub · 100 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. 6d ago First seen · 100 lines · 19 tokens per session scan A f95ed7d2cba2

Subscribe to this mod's changes

invariant is a command published in the GitHub repository omermaksutii/RugProof (9 stars, last pushed 1mo ago), licensed MIT. It adds 19 tokens to every session and 808 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-31.