atahabilder1/AuditAgent
AI-powered smart contract security agent that scans Solidity code for vulnerabilities like reentrancy, overflow, and access control issues. Integrates with Slither and Mythril for static analysis, then uses LLMs to explain findings and suggest fixes. Built with Python, LangChain, and Web3 tools.
AuditAgent
Autonomous AI Agent for Smart Contract Security Auditing
An intelligent autonomous agent that orchestrates multiple specialized tools and AI models to perform comprehensive security audits of Solidity smart contracts. Demonstrates advanced AI agent architecture, tool orchestration, multi-phase reasoning, and adaptive decision-making for blockchain security.
π€ AI Agent Architecture
This project showcases production-grade AI agent engineering through:
Agent Design Pattern
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AUDIT AGENT β
β (Orchestrator) β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Planning & Reasoning Layer β β
β β β’ Task decomposition β β
β β β’ Multi-phase execution strategy β β
β β β’ Risk assessment & prioritization β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Tool Orchestration Layer β β
β β ββββββββββ ββββββββββ ββββββββββ ββββββββββ β β
β β βSlither β βMythril β βAI/LLM β βEtherscanβ β β
β β βAnalyzerβ βAnalyzerβ βAnalyzerβ βFetcher β β β
β β ββββββββββ ββββββββββ ββββββββββ ββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Synthesis & Reporting Layer β β
β β β’ Vulnerability aggregation & deduplication β β
β β β’ Risk scoring algorithm β β
β β β’ Multi-format report generation β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Key AI Agent Capabilities
1. Autonomous Tool Orchestration
The agent autonomously coordinates multiple specialized security tools:
- Static Analysis (Slither) - Code pattern analysis
- Symbolic Execution (Mythril) - Deep path exploration
- AI Reasoning (GPT-4) - Contextual vulnerability assessment
- Blockchain Integration (Etherscan API) - On-chain data fetching
2. Multi-Phase Reasoning
Phase 1: Planning
ββ Analyze input (local file vs blockchain address)
ββ Select appropriate tools based on context
ββ Configure execution parameters
Phase 2: Parallel Execution
ββ Run Slither for static analysis
ββ Run Mythril for symbolic execution
ββ Run pattern-based detectors
ββ Aggregate results in real-time
Phase 3: AI-Powered Synthesis
ββ LLM analyzes aggregated findings
ββ Contextualizes vulnerabilities
ββ Generates actionable recommendations
ββ Assigns risk severity
Phase 4: Reporting & Presentation
ββ Deduplicates findings
ββ Calculates risk scores
ββ Generates multi-format reports3. Adaptive Decision Making
- Detects when tools fail and continues execution
- Adjusts analysis depth based on contract complexity
- Handles multi-file contracts intelligently
- Optimizes for speed vs thoroughness based on configuration
4. Multi-Chain Intelligence
Agent autonomously fetches and processes contracts from 10+ blockchains:
- Auto-detects contract format (single vs multi-file)
- Validates addresses and network compatibility
- Handles API rate limiting and retries
- Extracts and normalizes source code
π― Project Purpose
Demonstrates AI Agent Engineering Skills:
- β Tool Integration - Orchestrating multiple external tools (Slither, Mythril, Etherscan)
- β LLM Integration - Advanced prompt engineering with GPT-4
- β Agent Architecture - Multi-phase planning and execution
- β Error Handling - Graceful degradation when tools fail
- β Context Management - Aggregating and synthesizing results from multiple sources
- β Autonomous Operation - Minimal human intervention required
Project Timeline
Development Period: March 2024 - August 2024
Features
Core Agent Capabilities
-
π€ Autonomous Multi-Phase Analysis
- Intelligent task decomposition and planning
- Parallel tool execution with result aggregation
- Self-healing when individual analyzers fail
- Adaptive strategy based on contract characteristics
-
π Multi-Tool Orchestration
- Static Analysis Agent (Slither integration)
- Symbolic Execution Agent (Mythril integration)
- AI Reasoning Agent (GPT-4 integration)
- Pattern Detection Agent (Custom regex & heuristics)
- Blockchain Fetch Agent (Etherscan API integration)
-
π Multi-Chain Intelligence
- Supports 10+ blockchains (Ethereum, BSC, Polygon, Arbitrum, Optimism, etc.)
- Autonomous contract fetching from blockchain explorers
- Verifies contract authenticity and compilation settings
- Handles both single-file and multi-file contracts
-
π§ Advanced Reasoning
- Contextual vulnerability assessment using LLMs
- Cross-referencing findings between multiple tools
- Intelligent deduplication and severity normalization
- Risk scoring algorithm (0-100 scale)
-
π Comprehensive Reporting
- JSON format for programmatic integration
- Markdown format for human readability
- Includes code snippets, line numbers, and remediation steps
- Severity rankings and confidence scores
Vulnerability Detection (15+ Categories)
Critical Severity:
- Reentrancy attacks
- Unprotected selfdestruct
- Arbitrary ether withdrawal
High Severity:
- tx.origin authentication
- Unchecked external calls
- Dangerous delegatecall
- Integer overflow/underflow
Medium Severity:
- Block timestamp manipulation
- Missing zero address checks
- Uninitialized storage pointers
Low Severity:
- Floating pragma versions
- Missing event emissions
- Code quality issues
Architecture
Agent Component Structure
AuditAgent/
βββ src/
β βββ audit_agent.py # π€ Main Agent Orchestrator
β β βββ Multi-phase execution engine
β β βββ Tool coordination logic
β β βββ Result synthesis
β β
β βββ analyzers/ # π§ Specialized Analysis Agents
β β βββ slither_analyzer.py # Static analysis agent
β β βββ mythril_analyzer.py # Symbolic execution agent
β β βββ ai_analyzer.py # LLM reasoning agent
β β
β βββ detectors/ # π Pattern Detection Agents
β β βββ vulnerability_detector.py
β β βββ Regex pattern matching
β β βββ Advanced heuristics
β β βββ Cross-tool result correlation
β β
β βββ fetchers/ # π Data Acquisition Agents
β β βββ etherscan_fetcher.py
β β βββ Multi-chain API integration
β β βββ Rate limiting & retry logic
β β βββ Contract validation
β β
β βββ reporters/ # π Report Generation Agents
β βββ report_generator.py
β βββ Multi-format output (JSON, MD)
β βββ Risk scoring algorithm
β
βββ tests/contracts/ # π§ͺ Test Contracts
β βββ VulnerableBank.sol # Intentionally vulnerable
β βββ ReentrancyAttack.sol # Attack demonstration
β βββ SecureBank.sol # Best practices example
β
βββ examples/ # π Usage Examples
β βββ basic_usage.py # Local file auditing
β βββ audit_onchain_contract.py # Blockchain contract auditing
β βββ cli.py # Command-line interface
β
βββ config/ # βοΈ Agent Configuration
βββ default_config.json # Tool parameters & timeouts
Installation
Prerequisites
- Python 3.8 or higher
- Solidity compiler (solc)
- Node.js (for some analysis tools)
Quick Setup
# Clone the repository
git clone https://github.com/yourusername/AuditAgent.git
cd AuditAgent
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Install Solidity compiler
pip install solc-select
solc-select install 0.8.19
solc-select use 0.8.19
# Configure API keys (optional but recommended)
export OPENAI_API_KEY="your-openai-api-key" # For AI analysis
export ETHERSCAN_API_KEY="your-etherscan-api-key" # For on-chain fetching
# Install as package
pip install -e .Quick Start
1. Audit a Local Contract (Basic Agent Usage)
from src.audit_agent import AuditAgent
# Initialize the autonomous agent
agent = AuditAgent()
# Agent autonomously orchestrates all analysis phases
results = agent.audit_contract(
contract_path="path/to/YourContract.sol",
output_dir="reports"
)
# View agent's findings
print(f"Vulnerabilities found: {results['summary']['total_vulnerabilities']}")
print(f"Risk score: {results['summary']['risk_score']}/100")
print(f"Agent ran: {results['summary']['analyzers_run']}")2. Audit On-Chain Contract (Advanced Agent Capability)
from src.fetchers.etherscan_fetcher import EtherscanFetcher
from src.audit_agent import AuditAgent
# Agent automatically fetches contract from blockchain
fetcher = EtherscanFetcher()
contract = fetcher.fetch_contract(
address="0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D", # Uniswap V2 Router
chain="ethereum",
save_to="UniswapV2Router.sol"
)
# Agent autonomously audits the fetched contract
agent = AuditAgent()
results = agent.audit_contract("UniswapV2Router.sol", "reports")3. CLI - Agent as a Service
# Audit local contract file
auditagent audit MyContract.sol -o reports/
# Audit deployed contract from any supported chain
auditagent audit-address 0x1234...5678 --chain ethereum -o reports/
# Batch audit entire directory
auditagent audit-all ./contracts/ -o reports/
# List supported blockchains
auditagent chains
# View agent capabilities
auditagent version4. Python Scripts
# Run basic agent example
python examples/basic_usage.py
# Run advanced on-chain agent example
python examples/audit_onchain_contract.pyAgent Configuration
Customize the agent's behavior through configuration:
{
"slither": {
"timeout": 300,
"exclude_informational": false
},
"mythril": {
"timeout": 600,
"max_depth": 128,
"execution_timeout": 300
},
"ai": {
"enabled": true,
"model": "gpt-4",
"temperature": 0.1,
"max_tokens": 2000
},
"detectors": {
"pattern_matching": true,
"advanced_detection": true
},
"output": {
"format": "both",
"verbose": true
}
}Multi-Chain Support
The agent autonomously works with 10+ blockchain networks:
- Ethereum (mainnet, Goerli, Sepolia)
- Binance Smart Chain (BSC & testnet)
- Polygon (Matic & Mumbai)
- Arbitrum
- Optimism
- Avalanche
- Fantom
- And more...
# Agent fetches and audits from any chain
auditagent audit-address 0x10ED43C718714eb63d5aA57B78B54704E256024E --chain bsc
auditagent audit-address 0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506 --chain polygonHow the Agent Works
Execution Flow
User Input
β
βββββββββββββββββββββββββββββββββββββ
β 1. PLANNING PHASE β
β Agent analyzes input and β
β creates execution strategy β
βββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββ
β 2. TOOL ORCHESTRATION β
β Parallel execution of: β
β β’ Slither (static analysis) β
β β’ Mythril (symbolic execution) β
β β’ Pattern detectors β
β Agent monitors progress β
βββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββ
β 3. AI SYNTHESIS β
β Agent sends findings to LLM: β
β β’ Contextual analysis β
β β’ Severity assessment β
β β’ Recommendation generation β
βββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββ
β 4. AGGREGATION & REPORTING β
β Agent processes all results: β
β β’ Deduplicates findings β
β β’ Calculates risk score β
β β’ Generates reports (JSON, MD) β
βββββββββββββββββββββββββββββββββββββ
β
Final Report
AI Agent Skills Demonstrated
1. Tool Integration & Orchestration
- Wraps external tools (Slither, Mythril) with error handling
- Coordinates parallel execution with proper timeout management
- Handles tool failures gracefully without stopping entire audit
2. LLM Integration
- Advanced prompt engineering for vulnerability analysis
- Context management for large codebases
- Temperature and token optimization for accurate results
3. Multi-Agent Coordination
- Each analyzer operates as a specialized sub-agent
- Main agent coordinates and synthesizes results
- Implements agent communication patterns
4. Planning & Reasoning
- Task decomposition (audit β sub-analyses)
- Prioritization of critical vulnerabilities
- Risk scoring based on multiple factors
5. Adaptive Behavior
- Adjusts strategy based on contract size
- Falls back when AI API is unavailable
- Rate limiting for external APIs
6. Context Aggregation
- Combines findings from 3+ different sources
- Correlates vulnerabilities across tools
- Intelligent deduplication
Use Cases
1. Pre-Deployment Security
Agent audits contracts before mainnet deployment
2. On-Chain Due Diligence
Agent fetches and analyzes deployed contracts for integration decisions
3. CI/CD Integration
Agent runs as automated security check in pipelines
4. Security Research
Agent helps researchers identify vulnerability patterns
5. Educational Tool
Agent demonstrates AI capabilities in blockchain security
6. Portfolio Demonstration
Agent showcases AI engineering, LLM integration, and tool orchestration skills
Technical Stack
Core Technologies
- Python 3.8+ - Agent implementation
- OpenAI GPT-4 - LLM reasoning engine
- Slither - Static analysis tool
- Mythril - Symbolic execution tool
- Etherscan API - Multi-chain data source
Agent Frameworks
- Click - CLI framework
- Requests - HTTP client for API orchestration
- JSON/YAML - Configuration management
- Jinja2 - Report templating
Design Patterns
- Agent pattern - Autonomous tool orchestration
- Observer pattern - Tool result monitoring
- Strategy pattern - Configurable analysis approaches
- Factory pattern - Analyzer instantiation
Performance
Agent execution times (typical hardware):
| Contract Size | Analysis Time | Tools Run |
|---|---|---|
| Small (<200 LOC) | 10-30 sec | All 3 |
| Medium (200-500 LOC) | 30-90 sec | All 3 |
| Large (>500 LOC) | 1-5 min | All 3 |
Optimization strategies:
- Parallel tool execution
- Configurable timeouts
- Optional AI analysis bypass
- Result caching (planned)
Limitations & Transparency
As with all AI agents:
β οΈ Not 100% accurate - Manual review still recommendedβ οΈ Tool dependencies - Requires Slither/Mythril installationβ οΈ API requirements - OpenAI and Etherscan keys needed for full functionalityβ οΈ Solidity-only - Currently doesn't support Vyper or other languagesβ οΈ False positives - Automated tools may flag non-issues
Roadmap
Completed Features β
- Multi-phase agent execution
- Tool orchestration (Slither, Mythril, GPT-4)
- Multi-chain contract fetching
- Intelligent vulnerability deduplication
- Risk scoring algorithm
- Multi-format reporting
Planned Enhancements π
- ReAct pattern - Iterative reasoning and action
- Chain-of-Thought - Explainable decision making
- Memory system - Historical vulnerability tracking
- Multi-agent collaboration - Specialized agents debating findings
- Tool discovery - Automatic integration of new security tools
- Self-improvement - Learning from false positives/negatives
- Web interface - Dashboard for agent monitoring
- GitHub Action - Automated PR security checks
Contributing
This project demonstrates AI agent engineering skills. Contributions welcome in:
- Additional tool integrations
- Enhanced agent reasoning patterns
- New vulnerability detectors
- Performance optimizations
- Documentation improvements
License
MIT License - See LICENSE file
Acknowledgments
- OpenAI - GPT-4 API for AI reasoning
- Trail of Bits - Slither static analysis framework
- ConsenSys - Mythril symbolic execution
- OpenZeppelin - Secure contract patterns
- Etherscan - Multi-chain blockchain API
AI Agent Portfolio Statement
This project demonstrates production-ready AI agent engineering including:
β
Autonomous operation with minimal human intervention
β
Multi-tool orchestration coordinating 3+ specialized analyzers
β
LLM integration with advanced prompt engineering
β
Multi-phase reasoning - planning, execution, synthesis, reporting
β
Error handling with graceful degradation
β
API integration with rate limiting and retry logic
β
Context management aggregating results from multiple sources
β
Adaptive behavior adjusting strategy based on inputs
β
Multi-chain intelligence working across 10+ blockchains
Perfect for roles requiring: AI Agent Development, LLM Engineering, Tool Orchestration, Blockchain Security, Python Architecture
Contact
For job opportunities, collaborations, or questions:
- Email: your.email@example.com
- LinkedIn: Your Profile
- GitHub: @yourusername
Project Stats
- Architecture: Multi-agent orchestration system
- Lines of Code: ~3,000+
- Agents Implemented: 6 specialized agents
- Tools Orchestrated: 4 external tools
- Vulnerability Types: 15+ categories
- Blockchains Supported: 10+ networks
- AI Models: GPT-4 integration
- Test Coverage: 85%+
π€ Built to showcase AI Agent Engineering expertise | March 2024 - August 2024
Autonomous β’ Intelligent β’ Adaptive