Skip to content

About

Autonomous Smart Contract Invariant Fuzzing & SMT Formal Verifier with Halmos, Z3/Yices, and Foundry

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

ย 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›ก๏ธ InvariantForge

Autonomous Smart Contract Invariant Fuzzing & SMT Symbolic Prover
Built with Ramanujan Mathematical Rigor, Halmos, Z3/Yices SMT Solvers, and Foundry

CI License: MIT Foundry Formal Verification


โšก Overview

InvariantForge is an elite formal verification and autonomous fuzzing engine for Web3 smart contracts. Unlike generic LLM auditors that produce noisy, unverified markdown reports, InvariantForge provides mathematical proof guarantees:

  1. Dual Verification Architecture:
    • Stateful Invariant Fuzzing (forge test): Simulates millions of randomized multi-actor state transitions across bounded sequences to uncover race conditions, reentrancy, and insolvency.
    • Symbolic SMT Formal Prover (halmos + Z3/Yices): Mathematically evaluates EVM bytecodes over the universal input domain ($\forall x \in [0, 2^{256}-1]$) to formally prove theorem invariants (UNSAT) or extract counterexample exploit models (SAT).
  2. Autonomous PoC Generation:
    • When an invariant fails in fuzzing or symbolic execution, InvariantForge automatically synthesizes a standalone, deterministic test_PoC_*.t.sol reproducer that runs in $< 5\text{ms}$ with 100% green exit status for direct bounty submission to Cantina / Immunefi.
  3. Ramanujan Invariant Catalog:
    • Out-of-the-box formal properties covering ERC-4626 Vault Dilution, Lending Solvency, AMM Constant Invariants, and Precision Loss.

๐Ÿš€ Installation

Prerequisites

# Clone repository
git clone https://github.com/Ranjeet2063/InvariantForge.git
cd InvariantForge

# Install Python package and dependencies
pip install -e .

# Install Halmos Symbolic Prover
pip install halmos

๐Ÿ’ป CLI Usage

1. View Ramanujan Mathematical Invariants

invariant-forge rules

2. Formally Prove Invariants via SMT Symbolic Execution

Formally proves properties for all possible inputs using Halmos with Z3 or Yices:

# Prove SecureVault with Yices/Z3
invariant-forge prove Vault --solver yices

# Run symbolic proof against VulnerableVault (extracts concrete exploit model)
invariant-forge prove VulnerableVault --solver yices

Output Preview:

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ ๐Ÿ”ฌ InvariantForge Formal Verifier โ€” Halmos & SMT Symbolic Engine โ”‚
โ”‚ Ramanujan Mathematical Rigor & Universal Input Domain Guarantees โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โœ” Target Contract: Vault
โœ” SMT Solver Selected: YICES
โšก Launching Halmos Symbolic Execution (โˆ€ inputs in 2^256)...

                        Symbolic Proof Telemetry โ€” Vault                        
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ Symbolic Theorem / Invariant          โ”ƒ Result โ”ƒ Paths Explored โ”ƒ Proof Time โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ check_shares_monotonic_scaling        โ”‚ PASS   โ”‚              7 โ”‚      0.06s โ”‚
โ”‚ check_shares_never_zero_for_positiveโ€ฆ โ”‚ PASS   โ”‚              4 โ”‚      0.02s โ”‚
โ”‚ check_zero_assets_zero_shares         โ”‚ PASS   โ”‚              1 โ”‚      0.00s โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Formal Verification Passed โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ โœ” ALL THEOREMS MATHEMATICALLY PROVEN! (UNSAT)                                โ”‚
โ”‚ โ€ข Verified by SMT Solver: YICES                                              โ”‚
โ”‚ โ€ข Total Theorems Proven: 3                                                   โ”‚
โ”‚ โ€ข Proof Execution Time: 0.10s                                                โ”‚
โ”‚ โ€ข Mathematical Invariant: No state input exists in โˆ€ x โˆˆ [0, 2^256-1]        โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

3. Stateful Invariant Fuzzing Campaign

# Run 1,000 multi-actor fuzz sequences and auto-synthesize PoC on failure
invariant-forge scan testbed/src/VulnerableVault.sol --runs 1000

๐Ÿ“Š Benchmark Suite

Contract Pattern Analyzed Invariant Result Formal SMT Result Generated Proof Artifact
VulnerableVault.sol First-Depositor Share Inflation ๐Ÿšจ BREACHED ๐Ÿšจ SAT Counterexample test_PoC_VulnerableVault.t.sol (100% Green in 2ms)
SecureVault.sol Solady Virtual Decimal Offset โœ” PASSED โœ” PROVEN (UNSAT) Formal Certificate of Solvency

๐Ÿ—๏ธ Repository Architecture

invariant-forge/
โ”œโ”€โ”€ invariant_forge/             # Core Engine
โ”‚   โ”œโ”€โ”€ parser.py                # Solidity AST & Pattern Extractor
โ”‚   โ”œโ”€โ”€ invariant_rules.py       # Ramanujan Formal Invariant Catalog
โ”‚   โ”œโ”€โ”€ runner.py                # Foundry Stateful Test Runner
โ”‚   โ”œโ”€โ”€ symbolic_runner.py       # Halmos + Z3/Yices SMT Formal Prover
โ”‚   โ”œโ”€โ”€ generator/               # Code Synthesis Engines
โ”‚   โ”‚   โ”œโ”€โ”€ handler_gen.py       # Multi-Actor Bounded Handler Synthesizer
โ”‚   โ”‚   โ”œโ”€โ”€ suite_gen.py         # Foundry Invariant Suite Synthesizer
โ”‚   โ”‚   โ””โ”€โ”€ poc_gen.py           # Standalone PoC Reproducer Synthesizer
โ”‚   โ””โ”€โ”€ cli.py                   # Unified CLI Interface
โ”œโ”€โ”€ testbed/                     # Foundry Testbed Environment
โ”‚   โ”œโ”€โ”€ src/                     # Verified Protocols (SecureVault, VulnerableVault)
โ”‚   โ”œโ”€โ”€ test/                    # Invariant & Symbolic Test Contracts
โ”‚   โ””โ”€โ”€ foundry.toml             # Foundry & Halmos AST Configurations
โ”œโ”€โ”€ tests/                       # Python Unit & Verification Test Suite
โ””โ”€โ”€ .github/workflows/ci.yml     # Continuous Integration Pipeline

๐Ÿ”’ Security & Defensive Scope

InvariantForge is built strictly for authorized white-hat security auditing, protocol defense, and formal verification. All synthesized proofs and test cases verify invariant boundaries to harden smart contracts prior to mainnet deployment.


๐Ÿ“œ License

MIT License. Built with mathematical precision by Ranjeet2063.

About

Autonomous Smart Contract Invariant Fuzzing & SMT Formal Verifier with Halmos, Z3/Yices, and Foundry

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages