state-invariant-detection

Detect broken state variable invariants in smart contracts.

Updated Feb 25, 2026
One-click install
npx skills add https://github.com/dajneem23/codex-skills --skill state-invariant-detection-dajneem23
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: state-invariant-detection
Source: https://github.com/dajneem23/codex-skills/tree/main/state-invariant-detection
Command: npx skills add https://github.com/dajneem23/codex-skills --skill state-invariant-detection-dajneem23

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill automatically detects critical vulnerabilities in smart contracts by identifying mathematical relationships between state variables that are broken by certain functions, leading to exploits like unauthorized minting or accounting errors.

Core Features & Use Cases

  • Invariant Inference: Automatically discovers mathematical relationships (e.g., totalSupply = Σ balances, constant product k) between state variables.
  • Violation Detection: Pinpoints functions that violate these inferred invariants, indicating potential exploits.
  • Use Case: Audit a DeFi protocol to ensure that its tokenomics and accounting logic remain mathematically sound, preventing exploits that could drain funds or inflate supply.

Quick Start

Analyze the provided smart contract code to detect any state-state invariant violations.

Frequently Asked Questions about state-invariant-detection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I detect broken math in smart contracts during a DeFi audit?

To detect broken math in smart contracts, you can infer mathematical invariants between state variables and identify functions that violate them, exposing vulnerabilities like unauthorized minting or accounting desynchronization.

What are state variable invariants in smart contract vulnerability analysis?

State variable invariants in smart contract vulnerability analysis are mathematical relationships, such as totalSupply equaling the sum of balances, which must always hold true to prevent broken tokenomics and accounting exploits.

How do I find functions that violate tokenomics accounting logic in a smart contract?

You find functions that violate tokenomics accounting logic by applying state variable clustering and delta pattern matching to pinpoint operations that break inferred mathematical relationships within the contract.

Can I detect unauthorized minting vulnerabilities by analyzing state variables?

Yes, you can detect unauthorized minting vulnerabilities by analyzing state variables to infer invariants and flagging any function that breaks the mathematical relationship governing your token supply.

What is the best way to prevent accounting desynchronization in DeFi protocols?

The best way to prevent accounting desynchronization in DeFi protocols is to infer state invariants and detect violations through expression mining, ensuring mathematical relationships remain sound across all functions.

Does state-invariant-detection work for analyzing constant product formulas?

Yes, state-invariant-detection works for analyzing constant product formulas by automatically discovering these mathematical invariants as state relationships and identifying functions that violate them.