Invariant Specification Template Generator
Free to download on every platform. Comes pre-installed on BotFone, BotPad and BotFlip — with extra free apps included.
About this app
WHAT IT DOES
This tool generates formal invariant specification templates for smart contracts, providing a foundation for formal verification and security analysis. By analyzing verified source code, storage layout, and on-chain state, it produces structured invariant templates that capture critical properties of the contract—including token supply conservation, balance non-negativity, collateralization ratios, constant product formulas, and state transition consistency. Each template includes a natural language description, a formal mathematical formula, and contextual information about the invariant's purpose. The generator supports multiple invariant types (ERC20 tokens, lending protocols, DEX/AMMs, and general contracts), making it versatile for different DeFi applications. This is essential for developers implementing formal verification, auditors documenting security properties, and teams establishing correctness guarantees for critical smart contracts.
HOW TO USE
Connect your wallet (read-only, no transaction required) and select the target network. Enter the contract name and address, then select the invariant type that best matches your contract's functionality (Token, Lending, DEX, or General). Click "generate invariant templates" and the tool will verify the contract, fetch source code and ABI data, and generate a suite of invariant templates. Results display a summary of the contract and invariant type, a series of invariant cards showing each template with its formula and description, and a detailed table of all generated invariants. Use the templates as a starting point for formal verification, security audit documentation, or integration with verification tools like Certora, Foundry, or Echidna.
TECHNICAL MECHANISM
The generator uses ethers.js v5.7.2 to perform a multi-stage template generation process. First, it calls eth_getCode to verify the contract is deployed and eth_call to query current state variables. It then uses block explorer APIs (Etherscan) to fetch verified source code and ABI, parsing the contract's storage layout and variable definitions. Based on the selected invariant type and detected contract interface, the tool selects relevant templates from a curated library of common DeFi invariants. For token contracts, it generates templates for total supply conservation, balance non-negativity, transfer preservation, and allowance consistency. For lending protocols, it generates templates for collateralization ratios, health factor bounds, and reserve calculations. For DEXes, it generates constant product invariants, liquidity consistency, and fee calculations. Each template is instantiated with the actual contract's variable names and state parameters, producing a ready-to-use formal specification. The tool also analyzes historical transaction logs to infer state transition patterns that may suggest additional invariants.
WHAT IT CANNOT SEE
This tool cannot generate templates for contracts that are not verified on a block explorer, as source code and ABI are required for accurate variable analysis. It is limited by the RPC provider's rate limits and block range availability for historical log queries. It cannot detect invariants that depend on off-chain state, cross-chain data, or complex external dependencies. The generated templates are simplified representations and may not capture all possible invariant conditions or edge cases—they serve as a starting point for further refinement. It cannot guarantee that generated invariants are complete or sufficient for formal verification; manual review and validation are always required. The tool relies on the accuracy and completeness of source code verification and ABI data; contracts with complex inheritance patterns, proxy patterns, or opaque storage layouts may produce incomplete templates. It cannot analyze contracts with custom storage implementations that deviate from standard Solidity patterns.
PLEASE NOTE
This is a read‑only analytics tool—it never submits transactions or signs anything. It is designed for EVM‑compatible chains and works best with verified contracts that follow standard DeFi patterns. The generated templates are for development and audit purposes only and should not be considered a guarantee of contract correctness. Always review, validate, and refine generated invariants before using them in formal verification or security audits. For complex contracts, consider combining generated templates with manual specification writing.