Skip to content

NeuroForgeLabs/openaudit-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›ก๏ธ OpenAudit AI

AI-powered smart contract auditor that analyzes Solidity code and explains vulnerabilities like a security engineer.

OpenAudit AI combines static analysis with LLM-powered explanations to help developers find and understand security issues in their Solidity smart contracts.

OpenAudit AI Architecture


โœจ Features

  • ๐Ÿ” Static Analysis Engine โ€” Parses Solidity source and runs modular vulnerability detection rules
  • ๐Ÿ” Reentrancy Detection โ€” Identifies external calls made before state updates
  • โš ๏ธ Unchecked Call Detection โ€” Flags low-level .call() results that aren't validated
  • ๐Ÿค– AI Explanations โ€” Uses GPT-5 to explain vulnerabilities in plain English (optional; works without an API key)
  • ๐Ÿ’ป CLI Tool โ€” oaudit command for single-file analysis and directory scanning
  • ๐Ÿฉบ Diagnostics โ€” oaudit doctor to check your AI configuration at a glance
  • ๐Ÿ“„ JSON Output โ€” Machine-readable output for CI/CD integration
  • ๐Ÿงฉ Extensible Rule System โ€” Add new detectors by subclassing BaseRule
  • ๐Ÿ” Fail-Safe โ€” Never crashes due to AI issues; gracefully falls back to templates

๐Ÿ“ฆ Installation

# Clone the repository
git clone https://github.com/openaudit-ai/openaudit-ai.git
cd openaudit-ai

# Install in development mode
pip install -e ".[dev]"

๐Ÿš€ Quick Start

Analyze a single contract:

oaudit analyze examples/vulnerable_bank.sol

Scan an entire directory:

oaudit scan ./contracts/

Get JSON output:

oaudit analyze contract.sol --json

Skip AI explanations (no API key needed):

oaudit analyze contract.sol --no-ai

Check your configuration:

oaudit doctor

โš™๏ธ AI Configuration

OpenAudit AI reads configuration from a .env file in the project root (or from environment variables).

๐Ÿ”ง Setup

cp .env.example .env
# Edit .env and add your OpenAI API key

The .env file supports these variables:

Variable Required Default Description
OPENAI_API_KEY For AI explanations โ€” Your OpenAI API key
OPENAI_BASE_URL No https://api.openai.com/v1 API endpoint (change for Azure, local proxies, etc.)
OPENAI_MODEL No gpt-5-mini Model used for explanations

๐Ÿ”„ Changing Models

Set the model in .env:

OPENAI_MODEL=gpt-5-mini

Available models: gpt-5.2, gpt-5.2-pro, gpt-5.1, gpt-5, gpt-5-mini, gpt-5-nano

Or override per-command with --model:

oaudit analyze contract.sol --model gpt-5.2

The CLI flag takes priority over the .env value.

If the configured model is unavailable (API error, model not found), the tool automatically falls back to gpt-4o-mini.

๐Ÿšซ Disabling AI

Skip AI explanations entirely (no API key needed):

oaudit analyze contract.sol --no-ai

When no OPENAI_API_KEY is set, the tool automatically uses built-in template explanations โ€” it never crashes due to missing AI configuration.

๐Ÿฉบ Checking Your Configuration

oaudit doctor

Example output:

OpenAudit AI โ€” Configuration Diagnostic

  AI Provider:    OpenAI
  Model:          gpt-5-mini
  API Key:        detected
  Base URL:       https://api.openai.com/v1
  Fallback Mode:  disabled

๐Ÿ“– CLI Reference

oaudit analyze <file.sol>     ๐Ÿ” Analyze a single Solidity file
oaudit scan <directory>       ๐Ÿ“‚ Scan all .sol files in a directory
oaudit doctor                 ๐Ÿฉบ Diagnose AI provider configuration
oaudit version                ๐Ÿ“Œ Show version

Options

Flag Description
--json / -j ๐Ÿ“„ Output results as JSON
--no-ai ๐Ÿšซ Skip AI-powered explanations
--model / -m ๐Ÿค– Specify the LLM model to use

๐Ÿ–ฅ๏ธ Example Output

โš ๏ธ Reentrancy Vulnerability
  Severity: HIGH
  Location: line 25

  In function `withdraw()`: external call on line 25 occurs before
  state update on line 28. The call target `msg.sender` could
  re-enter this function before `balances` is updated.

  โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ AI Explanation โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
  โ”‚                                                      โ”‚
  โ”‚ The contract sends ETH before updating the user's    โ”‚
  โ”‚ balance. An attacker contract could repeatedly call  โ”‚
  โ”‚ withdraw() via its fallback function, draining the   โ”‚
  โ”‚ contract.                                            โ”‚
  โ”‚                                                      โ”‚
  โ”‚ Fix: Apply the checks-effects-interactions pattern   โ”‚
  โ”‚ or use OpenZeppelin's ReentrancyGuard.               โ”‚
  โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

๐Ÿ—๏ธ Project Structure

openaudit-ai/
โ”œโ”€โ”€ openaudit/
โ”‚   โ”œโ”€โ”€ config.py     โš™๏ธ  Centralized configuration (.env + defaults)
โ”‚   โ”œโ”€โ”€ cli/          ๐Ÿ’ป  CLI commands (Typer)
โ”‚   โ”œโ”€โ”€ analyzer/     ๐Ÿ”  Static analysis engine & parser
โ”‚   โ”œโ”€โ”€ rules/        ๐Ÿ“  Vulnerability detection rules
โ”‚   โ”œโ”€โ”€ ai/           ๐Ÿค–  LLM integration & prompt templates
โ”‚   โ”œโ”€โ”€ reports/      ๐Ÿ“Š  Output formatting (terminal, JSON)
โ”‚   โ”œโ”€โ”€ utils/        ๐Ÿ”ง  Shared types & helpers
โ”‚   โ””โ”€โ”€ api/          ๐ŸŒ  Future REST API (FastAPI)
โ”œโ”€โ”€ tests/            ๐Ÿงช  pytest test suite (32 tests)
โ”œโ”€โ”€ examples/         ๐Ÿ“  Sample vulnerable contracts
โ”œโ”€โ”€ docs/             ๐Ÿ“š  Architecture deep-dive
โ”œโ”€โ”€ .env.example      ๐Ÿ”‘  Environment variable template
โ””โ”€โ”€ pyproject.toml    ๐Ÿ“ฆ  Package configuration

๐Ÿงฉ Adding a New Rule

  1. Create a file in openaudit/rules/:
from openaudit.rules.base import BaseRule
from openaudit.rules.registry import register

@register
class MyRule(BaseRule):
    id = "my-rule"
    title = "My Custom Rule"
    description = "Detects ..."

    def run(self, ast, source):
        findings = []
        # Your detection logic here
        return findings
  1. Import it in openaudit/rules/registry.py inside _discover_rules().

  2. Add a template in openaudit/ai/provider.py FallbackProvider._TEMPLATES.


๐Ÿงช Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run with coverage
pytest --cov=openaudit

# Lint
ruff check openaudit/ tests/

๐Ÿ—บ๏ธ Roadmap

  • ๐Ÿ“ Additional rules (integer overflow, tx.origin, selfdestruct, etc.)
  • ๐ŸŒ REST API via FastAPI
  • ๐Ÿค– GitHub PR bot for automated reviews
  • ๐Ÿ  Hosted service with dashboard
  • ๐ŸŒณ tree-sitter based Solidity parser
  • ๐Ÿ“ Multi-file / import resolution support
  • ๐Ÿ”— Slither integration bridge

๐Ÿค Contributing

See CONTRIBUTING.md for guidelines.

๐Ÿ“„ License

MIT