# Defi invariant check

> Defi invariant check is an open-source agent skill for security. Authors and falsifies DeFi invariants for AMMs, lending, vaults and perps. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/mtarcure/claude-vibe-squad/tree/main/.agents/skills/defi-invariant-check
- **Repository:** https://github.com/mtarcure/claude-vibe-squad
- **GitHub stars:** 227
- **License:** MIT
- **Skill name:** defi-invariant-check
- **Collection:** https://github.com/mtarcure/claude-vibe-squad
- **Categories:** [security](https://ai-powered.com/categories/security)
- **Listing updated:** 2026-12-02

## About

This skill guides an agent auditing a DeFi protocol through property-based testing. It covers the economic properties that generic fuzzing campaigns tend to miss, including token conservation, constant-product behavior, share accounting, collateralization, and oracle deviation checks. The workflow has the agent write Echidna properties, run Echidna and then Medusa, simulate flash-loan attack sequences in Forge, test oracle and NAV manipulation, check timelock and role-change bypasses, and fuzz rounding at zero-supply and dust boundaries.

The skill is written for a sub-workflow inside a broader EVM audit flow and assumes the native host CLIs (echidna, medusa, forge, halmos) run in the target project directory. It also points to halmos for bounded formal checks on critical properties and warns against invariants that pass only by construction or against treating a fuzzer's clean run as proof.

It expects a Solidity project with access to those tools and a protocol whose class (AMM, lending, vault, bridge, stablecoin or perps) is known before starting. The skill is a single SKILL.md file with no bundled scripts.

## When your agent uses it

> Use when the audit target is a DeFi protocol — AMM, lending market, yield vault, stablecoin, or perps — and you must author the economic properties generic campaigns miss, such as token-conservation, constant-product k, share accounting, collateralization, and oracle-deviation invariants, then falsify them.

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/mtarcure/claude-vibe-squad/tree/HEAD/.agents/skills/defi-invariant-check)
- [License: MIT](https://github.com/mtarcure/claude-vibe-squad/tree/HEAD/.agents/skills/defi-invariant-check)

## Features

- **Token accounting invariants:** Checklists for supply conservation, constant-product k, lending solvency and vault share consistency.
- **Oracle manipulation checks:** Guidance for spot versus TWAP divergence, thin-market collateral and NAV manipulation bounds.
- **Governance timelock tests:** Steps to queue privileged operations and confirm delays and role changes cannot be bypassed.
- **Rounding and dust fuzzing:** Covers zero-supply initialization, one-unit deposits and division boundaries in share math.
- **Flash-loan attack simulation:** Instructions for building a Forge attacker contract and checking invariants after the attack sequence.
- **Fuzzer workflow and pivots:** Ordered steps for running Echidna and Medusa, with fixes for setup and vacuous properties.

## Good for

- Audit an AMM for constant-product violations under flash-loan attacks
- Check a lending market for bad debt created by liquidations
- Write Echidna properties for a yield vault's share accounting
- Test whether a DeFi protocol's oracle can be manipulated to borrow unsafely
- Verify that a protocol's timelock delay cannot be shortened by role changes

## Install

### Claude Code

Copy the skill folder to `~/.claude/skills/defi-invariant-check` to use it in all your projects:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/mtarcure/claude-vibe-squad.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/defi-invariant-check &&
cp -R "$tmp/.agents/skills/defi-invariant-check" ~/.claude/skills/defi-invariant-check &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/defi-invariant-check` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/defi-invariant-check` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/mtarcure/claude-vibe-squad.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/defi-invariant-check &&
cp -R "$tmp/.agents/skills/defi-invariant-check" ~/.agents/skills/defi-invariant-check &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/defi-invariant-check` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/defi-invariant-check` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/mtarcure/claude-vibe-squad.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/defi-invariant-check &&
cp -R "$tmp/.agents/skills/defi-invariant-check" ~/.cursor/skills/defi-invariant-check &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/defi-invariant-check` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/mtarcure/claude-vibe-squad.git --path .agents/skills/defi-invariant-check
```

Or copy the folder to `~/.gemini/skills/defi-invariant-check` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/defi-invariant-check`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/mtarcure/claude-vibe-squad.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/defi-invariant-check &&
cp -R "$tmp/.agents/skills/defi-invariant-check" ~/.copilot/skills/defi-invariant-check &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/defi-invariant-check` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/mtarcure/claude-vibe-squad.git
```

Then copy `claude-vibe-squad/.agents/skills/defi-invariant-check` into your agent's skills folder as `defi-invariant-check`. Agents that support SKILL.md read one folder per skill.

## FAQ

### What tools does Defi invariant check require?

It runs the native echidna, medusa, forge and halmos CLIs in the target project directory, with no wrapper layer.

### Which DeFi protocol types does Defi invariant check cover?

AMMs, lending markets, yield vaults, stablecoins, perps, and bridges are named as protocol classes.

### Does Defi invariant check prove a protocol is correct?

No. The skill states that Echidna is a fuzzer rather than a prover and recommends halmos for bounded formal checks on critical properties.

### Is Defi invariant check a standalone skill?

It is described as a sub-skill used during an evm-audit-flow when the target is a DeFi protocol.

### How do I install Defi invariant check in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/defi-invariant-check to use it in all your projects, or to .claude/skills/defi-invariant-check in one project.

### Does Defi invariant check run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Defi invariant check?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Defi invariant check?

The closest alternatives to Defi invariant check are Defi amm security, Signature validation audit, Evm audit flow, Read only reentrancy check and Secure workflow guide.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Defi amm security](https://ai-powered.com/skills/defi-amm-security): Defi amm security is an open-source agent skill for security.
- [Signature validation audit](https://ai-powered.com/skills/signature-validation-audit): Signature validation audit is an open-source agent skill for security.
- [Evm audit flow](https://ai-powered.com/skills/evm-audit-flow): Evm audit flow is an open-source agent skill for security.
- [Read only reentrancy check](https://ai-powered.com/skills/read-only-reentrancy-check): Read only reentrancy check is an open-source agent skill for security.
- [Secure workflow guide](https://ai-powered.com/skills/secure-workflow-guide): Secure workflow guide is an open-source agent skill for security.
- [Solana audit flow](https://ai-powered.com/skills/solana-audit-flow): Solana audit flow is an open-source agent skill for security.
- [Pre audit threat model](https://ai-powered.com/skills/pre-audit-threat-model): Pre audit threat model is an open-source agent skill for security.
- [Cosmos SDK audit checklist](https://ai-powered.com/skills/cosmos-sdk-audit-checklist): Cosmos SDK audit checklist is an open-source agent skill for security.

---
Source: https://ai-powered.com/skills/defi-invariant-check
