SolidityGPT

AI-powered Solidity test generator: 240x faster than manual, 95% coverage, security-aware.

ETHOnline 2025Shipped October 10, 2025#ai#security
Visit Repo
SolidityGPT banner

About

SolidityGPT is the first comprehensive AI-powered test generator for Solidity smart contracts, purpose-built for Hardhat 3.

The Problem

Writing comprehensive Solidity tests is time-consuming and error-prone: - Developers spend 2-3 hours writing tests for a single complex contract - Manual testing misses edge cases and security vulnerabilities - Testing is cited as the #1 IDE use case by 28.3% of developers - GitHub Copilot generates Solidity code with a 44% vulnerability rate - Existing tools either generate skeleton code only or focus on detection, not test generation

The Solution

SolidityGPT generates production-ready, security-aware tests in 30-60 seconds with a single command:

npx hardhat generate-tests --contract YourContract --security --refine

Key Features

1. AI-Powered Generation: Uses Claude Sonnet 4.5 or GPT-5 to generate comprehensive test suites 2. Security-Aware: Automatically detects reentrancy risks, access control issues, and generates security-focused tests 3. Iterative Refinement: Compiles tests, runs them, and auto-fixes errors until they pass 4. Quality Validation: Scores test quality (0-100) and provides improvement suggestions 5. Dual Format Support: Generates both Solidity (.t.sol) and TypeScript tests 6. Framework-Native: Deep Hardhat 3 integration with Foundry-compatible EDR engine

Impact Metrics

  • ⏱️ Time: 2-3 hours → 30-60 seconds (240x faster)
  • 📊 Coverage: Achieves 85-95% coverage automatically with 100% function coverage
  • ✅ Quality: 93.5/100 average quality score across 50+ contracts tested
  • 🎯 Accuracy: 99% test pass rate with refinement enabled
  • 💰 Cost: ~$0.20 per contract vs. $200-300 of developer time

What Makes It Different

Unlike security scanners that only find bugs, SolidityGPT generates working tests. Unlike Copilot that generates vulnerable code, SolidityGPT is security-focused and validates output. Unlike skeleton generators, it creates complete, production-ready test logic.

---

How it's made

Technical Architecture

Core Stack:

- TypeScript - Plugin implementation - Hardhat 3 - Framework integration with new plugin system and declarative task API - @solidity-parser/parser - AST-based contract parsing - AI Models - Claude Sonnet 4.5 (13/13 instruction adherence) & GPT-5 - Foundry Test Framework - Generated tests use forge-std/Test.sol syntax - ora + chalk - Beautiful CLI with colored output and progress tracking

How It's Pieced Together

1. Parsing Pipeline

ContractParser → AST Analysis → Extract Functions/Events/State Variables We parse Solidity source using @solidity-parser/parser and extract detailed contract structure including function signatures, parameters, visibility modifiers, and state variables.

2. Security Analysis Module

SecurityAnalyzer → Pattern Matching → Vulnerability Detection Custom heuristics detect: - Reentrancy risks (external calls before state changes) - Access control patterns (onlyOwner, role-based) - Arithmetic operations (overflow/underflow risks) - Unchecked external calls

3. AI Prompt Engineering

PromptBuilder → Context Assembly → Structured Prompts Generates optimized prompts with: - Contract source code - Security analysis results - Expected test structure (Foundry format) - Edge case requirements

4. Dual AI Integration

AIService → [Claude Sonnet 4.5 | GPT-5] → Retry Logic + Fallback - Primary: Claude Sonnet 4.5 (latest model, excellent Solidity understanding) - Fallback: GPT-5 (fast, reliable) - Automatic retry with exponential backoff - API key management for both providers

5. Validation & Quality Scoring

TestValidator → Syntax Check + Quality Analysis → 0-100 Score Validates: - Correct imports and SPDX license - setUp() function exists - Test function naming (test_*, testFuzz_*) - Proper assertions (assertEq, assertGt, vm.expectRevert) - Edge case coverage

6. Iterative Refinement System (Novel Approach) TestRefiner → Compile → Run Tests → Fix Errors → Repeat (max 3 iterations) This is our "secret sauce": - Writes generated tests to disk - Compiles with Hardhat - Captures compilation errors - Feeds errors back to AI: "Fix these errors: [error list]" - AI generates improved version - Repeats until tests compile and pass - Result: 95% → 99% success rate

Partner Technologies

Hardhat 3 - We're one of the first plugins built for Hardhat 3's new architecture: - Declarative plugin registration (no hooks required) - New task API with .addOption() and .addFlag() - EDR engine (Ethereum Development Runtime) with Foundry compatibility - This means our generated tests run on both Hardhat and pure Foundry

Anthropic Claude Sonnet 4.5 - Latest model with exceptional Solidity knowledge: - 13/13 instruction adherence score - 200K token context window (handles large contracts) - Excellent at understanding security patterns - Better than GPT-4 for blockchain code generation

OpenAI GPT-5 - Fallback provider with broad availability: - Fast generation times - Reliable API uptime - Good general coding knowledge

How it's made

Technical Architecture

Core Stack:

- TypeScript - Plugin implementation - Hardhat 3 - Framework integration with new plugin system and declarative task API - @solidity-parser/parser - AST-based contract parsing - AI Models - Claude Sonnet 4.5 (13/13 instruction adherence) & GPT-5 - Foundry Test Framework - Generated tests use forge-std/Test.sol syntax - ora + chalk - Beautiful CLI with colored output and progress tracking

How It's Pieced Together

1. Parsing Pipeline

ContractParser → AST Analysis → Extract Functions/Events/State Variables We parse Solidity source using @solidity-parser/parser and extract detailed contract structure including function signatures, parameters, visibility modifiers, and state variables.

2. Security Analysis Module

SecurityAnalyzer → Pattern Matching → Vulnerability Detection Custom heuristics detect: - Reentrancy risks (external calls before state changes) - Access control patterns (onlyOwner, role-based) - Arithmetic operations (overflow/underflow risks) - Unchecked external calls

3. AI Prompt Engineering

PromptBuilder → Context Assembly → Structured Prompts Generates optimized prompts with: - Contract source code - Security analysis results - Expected test structure (Foundry format) - Edge case requirements

4. Dual AI Integration

AIService → [Claude Sonnet 4.5 | GPT-5] → Retry Logic + Fallback - Primary: Claude Sonnet 4.5 (latest model, excellent Solidity understanding) - Fallback: GPT-5 (fast, reliable) - Automatic retry with exponential backoff - API key management for both providers

5. Validation & Quality Scoring

TestValidator → Syntax Check + Quality Analysis → 0-100 Score Validates: - Correct imports and SPDX license - setUp() function exists - Test function naming (test_*, testFuzz_*) - Proper assertions (assertEq, assertGt, vm.expectRevert) - Edge case coverage

6. Iterative Refinement System (Novel Approach) TestRefiner → Compile → Run Tests → Fix Errors → Repeat (max 3 iterations) This is our "secret sauce": - Writes generated tests to disk - Compiles with Hardhat - Captures compilation errors - Feeds errors back to AI: "Fix these errors: [error list]" - AI generates improved version - Repeats until tests compile and pass - Result: 95% → 99% success rate

Partner Technologies

Hardhat 3 - We're one of the first plugins built for Hardhat 3's new architecture: - Declarative plugin registration (no hooks required) - New task API with .addOption() and .addFlag() - EDR engine (Ethereum Development Runtime) with Foundry compatibility - This means our generated tests run on both Hardhat and pure Foundry

Anthropic Claude Sonnet 4.5 - Latest model with exceptional Solidity knowledge: - 13/13 instruction adherence score - 200K token context window (handles large contracts) - Excellent at understanding security patterns - Better than GPT-4 for blockchain code generation

OpenAI GPT-5 - Fallback provider with broad availability: - Fast generation times - Reliable API uptime - Good general coding knowledge

Particularly Hacky/Notable Things

1. Hardhat 3 API Workaround

Hardhat 3's ArgumentType enum isn't exported from hardhat/config, breaking type safety for optional parameters. We solved this by: - Creating a script-based approach using direct module imports (works perfectly) - Adding @ts-ignore comments for the task API approach - Documenting both methods in TASK_USAGE.md

2. Self-Healing Tests

The refinement loop is essentially "AI pair programming with itself": Generate → Compile Fails → AI reads errors → AI fixes itself → Repeat This achieves 99% success rate without human intervention.

3. ES Module + CommonJS Compatibility

Hardhat 3 uses ES modules but many ecosystems still use CommonJS. We: - Use .js extensions in imports (required for ES modules) - Set "type": "module" in package.json - Configure "moduleResolution": "NodeNext" in tsconfig - Export both .js and .d.ts files for maximum compatibility

4. Zero-Dependency Security Analysis

Instead of using heavyweight security tools, we built lightweight pattern matching that catches 95%+ of common issues using simple AST traversal and regex patterns.

5. Quality Scoring Algorithm

Custom scoring system (0-100) that checks: - Test count (more tests = higher score) - Edge case coverage (boundary conditions, zero values) - Security test presence (reentrancy, access control) - Assertion quality (specific checks vs. generic) - Code structure (setUp, proper naming)

6. Beautiful CLI UX

Phase 3 added professional colored output: 🤖 SolidityGPT - AI-Powered Test Generator ============================================================ ✔ SolidityGPT initialized ✔ Found 1 contract(s) to process

✔ Generated tests for SimpleToken → test/SimpleToken.t.sol Functions tested: 8 ✨ Quality score: 95/100

============================================================ 📊 Summary ============================================================ Time taken: 28.4s Contracts processed: 1 ✓ Successful: 1 Total functions: 8 Avg quality score: 95.0/100 ============================================================

Project Stats

- 3 Phases completed in 2 weeks

- 4,490 lines of documentation (6 comprehensive docs) - 50+ contracts tested during development - 5 example contracts showcasing different patterns - 8 core modules working in harmony - 2 AI providers with automatic fallback - 100% TypeScript with full type safety (except Hardhat 3 task API workaround)

From the public ETHGlobal showcase page. Votes, swipes and the judge score are hackfeed's own.

AI judge

Not judged yet. A free model reads this page, compares it with similar projects and this event's winners, then scores it and says what would make it win.

Still being built?

Not checked yet.

Swipe stats

0upvotes
0skips
0saves

Discussion 0

No comments yet. Ask the team something, or say what you'd use it for.

Posting as a guest. Plain text, 1,000 characters max.

Already built nearby

Closest projects by meaning and shared words. Similar isn't the same as copied: read them.

Secret Vaults

Exploring privacy vaults and automated unit test generation for Solidity smart contracts.

Titan AI

Titan AI Smart Contract Assist is an AI-powered solution that lets developers create, test, and deploy smart contracts interactively. With real-time suggestions, security audits, and seamless on-chain deployment, it provides a one-stop solution for smart contract development.