Skip to content

AkhtarXx/vulhunters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

VulHunters v2.0

AI-Powered Smart Contract Exploit Discovery System

Built with Google Gemini 3 | Demo | Architecture


The Problem

DeFi protocols lost $3.8 Billion to hacks in 2023-2024. Traditional security tools find bugs but can't prove they're exploitable.

Current tools fail because:

  • Static analyzers produce 90%+ false positives
  • Manual auditing is slow and expensive ($50K-$500K per audit)
  • No tool validates if a bug can actually steal funds

Our Solution

VulHunters is an autonomous AI agent powered by Gemini 3 that:

  1. Finds vulnerabilities in smart contracts using AI reasoning
  2. Writes working exploits automatically
  3. Proves exploitability by extracting real profit on forked blockchains

Key Innovation: We don't just find bugs - we prove them by stealing money (on test networks).


How It Works

Simple Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  SMART       β”‚     β”‚   ANALYZE    β”‚     β”‚   GENERATE   β”‚     β”‚    PROVE     β”‚
β”‚  CONTRACT    │────▢│   + GRAPH    │────▢│   EXPLOIT    │────▢│   PROFIT     β”‚
β”‚  INPUT       β”‚     β”‚   + SLITHER  β”‚     β”‚   CODE       β”‚     β”‚   ON FORK    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Detailed Per-Contract Analysis Flow

                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚     πŸ“ Protocol Directory           β”‚
                         β”‚        (scope.txt)                  β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                        β”‚
                                        β–Ό
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚  PHASE 1: Protocol Analysis         β”‚
                         β”‚  ─────────────────────────────────  β”‚
                         β”‚  β€’ Parse scope.txt                  β”‚
                         β”‚  β€’ Build dependency graph           β”‚
                         β”‚  β€’ Identify trust boundaries        β”‚
                         β”‚  β€’ Map fund flows                   β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                        β”‚
                                        β–Ό
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚  PHASE 2: Fork Blockchain           β”‚
                         β”‚  ─────────────────────────────────  β”‚
                         β”‚  β€’ Start Anvil fork                 β”‚
                         β”‚  β€’ Clone mainnet state              β”‚
                         β”‚  β€’ Ready for exploit testing        β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                        β”‚
                                        β–Ό
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚  PHASE 3: Load Pattern Database     β”‚
                         β”‚  ─────────────────────────────────  β”‚
                         β”‚  β€’ 670+ historical DeFi exploits    β”‚
                         β”‚  β€’ Used for PATTERN MATCHING        β”‚
                         β”‚  β€’ Suggests similar attack vectors  β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                        β”‚
                                        β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚                                                             β”‚
              β”‚              πŸ”„ FOR EACH CONTRACT IN SCOPE                  β”‚
              β”‚                                                             β”‚
              β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
              β”‚  β”‚  STEP 1: Build Contract Graph                        β”‚  β”‚
              β”‚  β”‚  ───────────────────────────────────────────────────  β”‚  β”‚
              β”‚  β”‚                                                       β”‚  β”‚
              β”‚  β”‚    Contract.sol                                       β”‚  β”‚
              β”‚  β”‚        β”‚                                              β”‚  β”‚
              β”‚  β”‚        β”œβ”€β”€ imports: [Token.sol, Oracle.sol]          β”‚  β”‚
              β”‚  β”‚        β”œβ”€β”€ calls: Token.transfer(), Oracle.price()   β”‚  β”‚
              β”‚  β”‚        β”œβ”€β”€ called_by: [Router.deposit()]             β”‚  β”‚
              β”‚  β”‚        └── internal_calls: withdraw() β†’ _update()    β”‚  β”‚
              β”‚  β”‚                                                       β”‚  β”‚
              β”‚  β”‚    This shows ALL RELATED FILES for context          β”‚  β”‚
              β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
              β”‚                           β”‚                                 β”‚
              β”‚                           β–Ό                                 β”‚
              β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
              β”‚  β”‚  STEP 2: Run Slither (Static Analysis)               β”‚  β”‚
              β”‚  β”‚  ───────────────────────────────────────────────────  β”‚  β”‚
              β”‚  β”‚                                                       β”‚  β”‚
              β”‚  β”‚    β€’ Run slither on contract                         β”‚  β”‚
              β”‚  β”‚    β€’ Filter noise (keep High/Medium only)            β”‚  β”‚
              β”‚  β”‚    β€’ Extract: reentrancy, access control, etc.       β”‚  β”‚
              β”‚  β”‚                                                       β”‚  β”‚
              β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
              β”‚                           β”‚                                 β”‚
              β”‚                           β–Ό                                 β”‚
              β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
              β”‚  β”‚  STEP 3: Gemini 3 Analysis                           β”‚  β”‚
              β”‚  β”‚  ───────────────────────────────────────────────────  β”‚  β”‚
              β”‚  β”‚                                                       β”‚  β”‚
              β”‚  β”‚    Gemini 3 receives:                                 β”‚  β”‚
              β”‚  β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚  β”‚
              β”‚  β”‚    β”‚ β€’ Full contract source code                 β”‚   β”‚  β”‚
              β”‚  β”‚    β”‚ β€’ Function call graph                       β”‚   β”‚  β”‚
              β”‚  β”‚    β”‚ β€’ Cross-contract calls (related files)      β”‚   β”‚  β”‚
              β”‚  β”‚    β”‚ β€’ Slither findings                          β”‚   β”‚  β”‚
              β”‚  β”‚    β”‚ β€’ Pattern matches from 670+ exploits        β”‚   β”‚  β”‚
              β”‚  β”‚    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚  β”‚
              β”‚  β”‚                                                       β”‚  β”‚
              β”‚  β”‚    Gemini 3 can use bash to explore related files:   β”‚  β”‚
              β”‚  β”‚    $ grep -n 'function transfer' ../Token.sol        β”‚  β”‚
              β”‚  β”‚                                                       β”‚  β”‚
              β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
              β”‚                           β”‚                                 β”‚
              β”‚                           β–Ό                                 β”‚
              β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
              β”‚  β”‚  STEP 4: Generate & Test Exploit                     β”‚  β”‚
              β”‚  β”‚  ───────────────────────────────────────────────────  β”‚  β”‚
              β”‚  β”‚                                                       β”‚  β”‚
              β”‚  β”‚    If vulnerability found:                           β”‚  β”‚
              β”‚  β”‚    1. Write Exploit.sol (Solidity)                   β”‚  β”‚
              β”‚  β”‚    2. Compile with Forge                             β”‚  β”‚
              β”‚  β”‚    3. Run on forked blockchain                       β”‚  β”‚
              β”‚  β”‚    4. Measure profit extracted                       β”‚  β”‚
              β”‚  β”‚                                                       β”‚  β”‚
              β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
              β”‚                                                             β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                        β”‚
                                        β–Ό
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚  PHASE 5: Validate All Exploits     β”‚
                         β”‚  ─────────────────────────────────  β”‚
                         β”‚  β€’ Run each exploit on fork         β”‚
                         β”‚  β€’ Check profit β‰₯ 0.1 ETH           β”‚
                         β”‚  β€’ Calculate USD value              β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                        β”‚
                                        β–Ό
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚  PHASE 6: Generate Report           β”‚
                         β”‚  ─────────────────────────────────  β”‚
                         β”‚  β€’ JSON report with all findings    β”‚
                         β”‚  β€’ Markdown report with details     β”‚
                         β”‚  β€’ Profit summary                   β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Gemini 3 Integration

VulHunters uses Gemini 3 as the core AI engine:

Gemini 3 Feature How We Use It
Gemini 3 Pro Main reasoning engine - analyzes contracts, finds vulnerabilities
Function Calling Executes bash commands, writes Solidity exploit code
Context Caching Caches contract code - 80% token cost savings
Long Context Analyzes entire protocols (100K+ tokens)

Code Example

# ExploitAgent receives full context for each contract
context = {
    "source_code": contract_code,
    "call_graph": {
        "withdraw": ["_updateBalance", "_transfer"],
        "deposit": ["_mint", "_updateBalance"]
    },
    "cross_contract_calls": [
        {"to": "Token", "function": "transfer", "line": 45},
        {"to": "Oracle", "function": "getPrice", "line": 78}
    ],
    "slither_findings": [
        {"type": "reentrancy", "severity": "High", "line": 52}
    ]
}

# Gemini 3 analyzes and generates exploit
result = await exploit_agent.analyze(context)

Key Features

1. Smart Contract Graph Building

For each contract, we build a complete relationship map:

Vault.sol Analysis:
β”œβ”€β”€ Imports: Token.sol, Oracle.sol, Math.sol
β”œβ”€β”€ External Calls:
β”‚   β”œβ”€β”€ Line 45: Token.transfer(user, amount)
β”‚   β”œβ”€β”€ Line 78: Oracle.getPrice(asset)
β”‚   └── Line 92: Token.balanceOf(address(this))
β”œβ”€β”€ Called By:
β”‚   └── Router.deposit() β†’ Vault.mint()
└── Internal Call Graph:
    β”œβ”€β”€ deposit() β†’ _mint() β†’ _updateShares()
    └── withdraw() β†’ _burn() β†’ _transfer()

This helps Gemini 3 understand how contracts interact and find vulnerabilities at trust boundaries.

2. Pattern Matching (670+ Historical Exploits)

We maintain a database of 670+ real DeFi hacks for pattern matching:

Contract has: Flash loan + Price oracle
Pattern Match: Similar to Euler Finance hack ($197M)
Suggested Attack: Flash loan price manipulation

3. Profit-Based Validation

We don't just report bugs - we prove they work:

Traditional Tool:              VulHunters:
─────────────────              ─────────────────
"Possible reentrancy           "Reentrancy CONFIRMED
in withdraw()"                  - Exploit: Exploit.sol
                                - Profit: 150 ETH ($450,000)
                                - Tested on forked mainnet"

Demo

Quick Start

# Install
git clone https://github.com/yourusername/vulhunters
cd vulhunters
pip install -e .

# Configure
echo "GEMINI_API_KEY=your_key" >> .env

# Run audit
vulhunters audit ./protocol/ --chain ethereum

Example Output

$ vulhunters audit ./defi-protocol/

[*] PHASE 1: Protocol Analysis
    β”œβ”€β”€ Found 5 contracts in scope
    β”œβ”€β”€ Built dependency graph
    └── Identified 3 trust boundaries

[*] PHASE 2: Forking Ethereum mainnet...
    └── Anvil fork ready at localhost:8545

[*] PHASE 3: Loading pattern database...
    └── 670 historical exploits loaded

[*] PHASE 4: Analyzing contracts...

    πŸ“Š Vault.sol
       β”œβ”€β”€ Building call graph...
       β”œβ”€β”€ Running Slither...
       β”œβ”€β”€ Gemini 3 analyzing...
       └── Found: 2 vulnerabilities

    πŸ“Š Token.sol
       β”œβ”€β”€ Building call graph...
       β”œβ”€β”€ Running Slither...
       β”œβ”€β”€ Gemini 3 analyzing...
       └── Found: 1 vulnerability

[*] PHASE 5: Validating exploits...
    β”œβ”€β”€ Exploit #1: SUCCESS - 50 ETH ($150,000)
    └── Exploit #2: SUCCESS - 25 ETH ($75,000)

[*] PHASE 6: Generating reports...
    └── report.json, report.md saved

════════════════════════════════════════
SUMMARY
────────────────────────────────────────
Vulnerabilities:     3
Working Exploits:    2
Total Profit:        75 ETH ($225,000)
════════════════════════════════════════

Project Structure

vulhunters/
β”œβ”€β”€ src/vulhunters/
β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”œβ”€β”€ exploit_agent_v2.py     # Gemini 3 powered analysis
β”‚   β”‚   β”œβ”€β”€ protocol_analyzer.py    # Dependency graph builder
β”‚   β”‚   β”œβ”€β”€ contract_analyzer.py    # Per-contract analysis + Slither
β”‚   β”‚   └── pattern_matcher.py      # 670+ exploit pattern matching
β”‚   β”œβ”€β”€ gemini/
β”‚   β”‚   └── client.py               # Gemini 3 API client
β”‚   β”œβ”€β”€ mcp_servers/
β”‚   β”‚   └── anvil_server.py         # Blockchain forking tools
β”‚   β”œβ”€β”€ harness/
β”‚   β”‚   └── exploit_validator.py    # Profit validation
β”‚   └── unified_cli.py              # CLI entry point
β”œβ”€β”€ DeFiHackLabs/                   # 670+ historical exploits
└── tests/                          # Test suite

Impact

Metric Traditional Audit VulHunters
Cost $50K - $500K ~$100 (API)
Time 2-4 weeks Minutes
False Positives 90%+ ~0% (profit validated)
Exploit Proof Manual Automatic

Tech Stack

Component Technology
AI Engine Google Gemini 3 Pro
Blockchain Foundry (Anvil, Forge, Cast)
Static Analysis Slither
Language Python 3.11+, Solidity

License

MIT License


VulHunters v2.0 - Finding DeFi vulnerabilities before hackers do.

About

people respect when AI inspect

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors