invariant-analysis

Extracts protocol invariants from Solidity code and explores violation paths.

66|17|Updated Jan 21, 2026
One-click install
npx skills add https://github.com/BitterSecurity/Vigilo --skill invariant-analysis-bittersecurity
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: invariant-analysis
Source: https://github.com/BitterSecurity/Vigilo/tree/main/packages/claude/skills/protocol-analysis/invariant-analysis
Command: npx skills add https://github.com/BitterSecurity/Vigilo --skill invariant-analysis-bittersecurity

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Smart contract auditors need a systematic way to identify conditions that must always hold in a protocol and find paths where those conditions break. This Skill provides a structured framework for extracting explicit and implicit invariants from Solidity code and documentation, then exploring how attackers could violate them. ## Core Features & Use Cases - Invariant Extraction: Collects explicit invariants from require/assert statements and NatSpec annotations, plus implicit invariants inferred from code flow patterns like share calculations and balance updates. - Violation Path Exploration: Analyzes single-function violations, multi-function combination attacks (e.g., first depositor donation attacks), state transition order issues, and edge cases like zero values and overflow. - Protocol-Specific Coverage: Includes core invariant templates for Vaults, AMMs, Lending, Staking, and Bridge protocols. - Use Case: During a lending protocol audit, use this framework to extract the invariant that user debt must not exceed collateral times LTV, then trace how oracle manipulation could break it and enable forced liquidations. ## Quick Start Analyze this Solidity codebase to extract all protocol invariants and identify potential violation paths for each one.

Frequently Asked Questions about invariant-analysis

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

FAQPage Schema
How do I extract invariants from a Solidity smart contract?▼

Search for require and assert statements plus NatSpec @invariant annotations to find explicit invariants, then analyze state variable modification and read patterns to infer implicit ones. The framework maps variables like totalSupply to their setter and getter functions to derive relationships.

What is a first depositor attack in vault contracts?▼

A first depositor attack occurs when an attacker deposits a minimal amount, donates assets directly to inflate totalAssets, and causes subsequent depositors to receive zero shares due to rounding. It violates the invariant that totalAssets and totalShares maintain a fair exchange ratio.

What types of invariants exist in DeFi protocols?▼

Common invariants include balance invariants (totalSupply equals sum of balances), accounting invariants (totalBorrowed within utilization caps), AMM invariants (reserveX times reserveY at least k), and bridge invariants (minted on L2 equals locked on L1).

How do I find implicit invariants in smart contract code?▼

Analyze code flow patterns such as share calculations, balance subtractions, and reward distributions to infer conditions the code assumes. For example, a subtraction like balance[from] minus amount implicitly requires the balance to be sufficient.

When should invariant analysis be performed during an audit?▼

Run invariant analysis after code reconnaissance and documentation review, during the deep logic auditing phase. It works best once you understand the protocol's state variables, fund flows, and documented design assumptions.