Spaces:
Runtime error
Runtime error
A newer version of the Gradio SDK is available: 6.12.0
metadata
title: Smart Contract Security Analyzer
emoji: π
colorFrom: purple
colorTo: pink
sdk: gradio
sdk_version: 4.36.0
app_file: app.py
pinned: true
license: apache-2.0
python_version: 3.11
hf_oauth: true
tags:
- mistral
- security
- smart-contract
- solidity
- vulnerability-detection
- fine-tuned
- hackathon
π Smart Contract Security Analyzer
Fine-tuned Mistral-7B for detecting security vulnerabilities in Solidity smart contracts with custom security tokens and structured output generation.
π Hackathon Submission Highlights
This model demonstrates new capabilities not possible without fine-tuning:
- 38 Custom Security Tokens - Novel vocabulary for precise vulnerability identification
- Structured XML-Style Reports - Machine-parseable security analysis
- 99.6% Accuracy - 28.6% improvement over base Mistral-7B
- Zero False Positives - 100% precision on balanced test set
π Performance Comparison
| Metric | Base Mistral-7B | Fine-Tuned (Ours) | Improvement |
|---|---|---|---|
| Accuracy | 71.0% | 99.6% | +28.6% |
| Precision | 64.2% | 100.0% | +35.8% |
| Recall | 100.0% | 99.3% | -0.7% |
| F1 Score | 0.782 | 0.996 | +0.214 |
| Custom Tokens | 0/38 | 25/38 (66%) | β¨ NEW |
| Structured Output | β | β | β¨ NEW |
π― Detected Vulnerabilities
- Reentrancy Attacks - External calls before state updates
- Integer Overflow/Underflow - Arithmetic without checks
- Access Control Issues - Missing authorization modifiers
- Unchecked External Calls - Ignored return values
- Denial of Service - Unbounded loops and gas limit issues
- Timestamp Dependence - Manipulable randomness
π How to Use
- Paste your Solidity contract in the code editor
- Click "Analyze Contract" to detect vulnerabilities
- Review the structured report with severity, location, and fix recommendations
- Toggle "Show custom tokens" to see the model's internal representation
Try the sample contracts to see how the model identifies different vulnerability types!
π Training Details
- Dataset: 30,000 balanced smart contracts (50% vulnerable, 50% safe)
- Method: QLoRA (4-bit quantization) fine-tuning
- Base Model: Mistral-7B-Instruct-v0.3
- Trainable Parameters: 41.9M (1.1% of total)
- Training Time: ~5.5 hours on Google Colab G4 GPU
β οΈ Limitations
- Trained on synthetic contracts - may not generalize to all real-world patterns
- Static analysis only - cannot detect runtime or logic vulnerabilities
- Limited to 6 common vulnerability types
- Best used as a first-pass screening tool, not a replacement for professional audits
π License
Apache 2.0 - Free for commercial and research use
Built with β€οΈ for the Mistral Hackathon 2026
Demonstrating that fine-tuning unlocks new capabilities: custom tokens + structured outputs = production-ready security analysis