AI-Powered Risk Evaluation Engine for EVM Smart Contracts
"The brain, not the eyes." β Intelligent risk assessment from structured blockchain data.
ML Unified System is a machine learning-based classifier that evaluates smart contract risk (honeypot detection, malicious behavior) using structured analysis reports from external blockchain scanners.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β This tool does NOT scan the blockchain directly. β
β It analyzes REPORTS produced by other scanners/analyzers. β
β β
β Think of it as: "The Brain, Not The Eyes" β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
External modules collect blockchain data
β
ML Unified System analyzes patterns
β
Intelligent risk prediction
You provide the data. We provide the intelligence.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BLOCKCHAIN β ANALYZER β ML β PREDICTION β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π‘ Blockchain (ETH Mainnet / EVM)
β
π Scanner / Analyzer Modules
βββ Contract Analyzer (bytecode, complexity)
βββ Decompiler (source reconstruction)
βββ Token Detector (economics, liquidity)
βββ Simulator/Executor (runtime behavior)
βββ Compliance Checker (regulatory)
βββ Gas Profiler (transaction costs)
β
π JSON Report (structured metadata)
β
π§ ML Unified System v3.3
βββ Feature Extraction (28 signals)
βββ Random Forest Classifier
βββ Anti-Overfitting Engine
βββ Cross-Validation
β
π Risk Prediction
βββ SAFE / HONEYPOT classification
βββ Probability score (0-100%)
βββ Confidence level (LOW/MEDIUM/HIGH)
βββ Risk level (π’/π‘/π΄)
β
π‘οΈ Actionable Intelligence
βββ Investment decisions, alerts, automated responses
The system accepts three formats:
./data_json/
βββ contract_0x1234.json
βββ contract_0x5678.json
βββ contract_0xabcd.json./data_json/contracts_batch.jsonlOne JSON per line:
{"metadata": {...}, "bytecode": {...}, "functions": {...}}
{"metadata": {...}, "bytecode": {...}, "functions": {...}}./data_db/
βββ contracts.dbTable structure:
CREATE TABLE contracts (
id INTEGER PRIMARY KEY,
address TEXT,
report_json TEXT
);Each contract report should contain these sections:
{
"metadata": {
"chain_id": 1,
"deployment_info": {
"deployment_age_days": 45
}
},
"bytecode": {
"size": 12458,
"complexity_metrics": {
"cyclomatic_complexity": 42,
"halstead_volume": 15847.3,
"maintainability_index": 35.2,
"opcode_diversity": 0.68
},
"runtime_hash": "0xabc123..."
},
"functions": {
"total": 15,
"known": 8,
"unknown": 7,
"list": [
{"name": "transfer", "selector": "0xa9059cbb"},
{"name": "balanceOf", "selector": "0x70a08231"}
]
},
"temporal_analysis": {
"last_interaction_days": 30,
"unique_users_30d": 150,
"activity_pattern": "very_active"
},
"economics": {
"total_value_locked_usd": 1500000,
"tokens": [
{"symbol": "USDC", "balance": "500000"},
{"symbol": "WETH", "balance": "300"}
],
"token_count": 2
},
"gas_profiles": {
"average_tx_cost": 250000,
"gas_limits": {
"safe_execution_limit": 3000000,
"frontrun_protection_required": false
}
}
}At minimum, include these keys (can have empty objects):
{
"metadata": {},
"bytecode": {},
"functions": {},
"temporal_analysis": {},
"economics": {},
"gas_profiles": {}
}- Static signatures
- Hardcoded rules
- Manual auditor judgments
- Blacklists
| Honeypot Pattern | ML Detection Method |
|---|---|
| Liquidity Traps | High TVL + Low users = Locked funds |
| Abnormal Gas Usage | Gas cost >> Safe limit = Hidden logic |
| Dormant Contracts | No interactions but high TVL = Fake |
| Obfuscated Functions | Many unknown functions = Hiding code |
| Stagnant Economics | Liquidity never moves = Trap |
| Complex Bytecode | Unusually high complexity = Obfuscation |
# Honeypot Indicator: Dormant Liquidity
if contract['tvl_usd'] > 1000000: # $1M+ locked
if contract['unique_users_30d'] < 50: # But only 50 users
liquidity_stagnation = HIGH # π¨ RED FLAG!
# ML learns this pattern automatically
# Honeypot Indicator: Hidden Functions
if contract['func_unknown'] / contract['func_total'] > 0.6:
unknown_pressure = HIGH # 60%+ unknown
# π¨ Likely obfuscated scam codeBytecode Structure (5):
ββ bytecode_size
ββ cyclomatic_complexity
ββ halstead_volume
ββ maintainability_index
ββ opcode_diversity
Function Analysis (4):
ββ func_known_ratio
ββ func_unknown_ratio
ββ func_name_entropy
ββ unknown_pressure
Temporal Signals (3):
ββ last_interaction_days
ββ unique_users_30d
ββ activity_pattern_active
Economic Patterns (4):
ββ tvl_usd
ββ token_count
ββ tvl_per_user
ββ liquidity_stagnation
Gas Behavior (4):
ββ average_tx_cost
ββ safe_execution_limit
ββ frontrun_protection_required
ββ gas_pressure
Derived Signals (8):
ββ complexity_score
ββ runtime_hash_fp
ββ ... (6 more composite features)
# Clone repository
git clone https://github.com/yourusername/ml-unified-system.git
cd ml-unified-system
# Install dependencies
pip install -r requirements.txt
# Verify
python ML_UNIFIED_SYSTEM_V3_3.py --versionPydroid 3:
# Install via Pydroid's package manager:
# numpy, pandas, scikit-learn, joblib
# Run directly
python ML_UNIFIED_SYSTEM_V3_3.pyTermux:
pkg install python
pip install numpy pandas scikit-learn joblib
python ML_UNIFIED_SYSTEM_V3_3.pyStep 1: Place reports in ./data_json/
cp your_contract_reports/*.json ./data_json/Step 2: Run analysis
python ML_UNIFIED_SYSTEM_V3_3.pyStep 3: Check results
cat ./ml_output/scoring_results.json{
"contract_address": "0x1234567890abcdef...",
"prediction": "HONEYPOT",
"probability": 0.847,
"confidence": "HIGH",
"risk_level": "CRITICAL",
"feature_importance": {
"liquidity_stagnation": 0.35,
"unknown_pressure": 0.22,
"tvl_per_user": 0.18,
"func_unknown_ratio": 0.12,
"gas_pressure": 0.08
},
"timestamp": "2026-02-08T01:31:22Z"
}| Probability | Classification | Risk | Action |
|---|---|---|---|
| < 0.30 | SAFE | π’ LOW | Generally safe to interact |
| 0.30 - 0.70 | SUSPICIOUS | π‘ MEDIUM | Investigate further before interaction |
| > 0.70 | HONEYPOT | π΄ CRITICAL | DO NOT INTERACT - SCAM DETECTED |
π BATCH SCORING SUMMARY
ββββββββββββββββββββββββββββββββββββββββ
π Total Contracts: 34
π¨ Honeypots: 22 (64.7%)
β
Safe: 12 (35.3%)
β Errors: 0
π Risk Distribution:
π΄ Critical (>0.7): 18 contracts
π‘ Medium (0.3-0.7): 4 contracts
π’ Low (<0.3): 12 contracts
π Avg Honeypot Probability: 54.9%
ββββββββββββββββββββββββββββββββββββββββ
# Before investing in a new token
report = contract_analyzer.scan("0x1234...")
risk = ml_system.score(report)
if risk['probability'] > 0.7:
show_warning("β οΈ HONEYPOT DETECTED!")
block_transaction()
save_life_savings()def should_trade(token_address):
report = get_contract_report(token_address)
risk = ml_system.score(report)
if risk['probability'] < 0.3:
return "EXECUTE_TRADE"
elif risk['probability'] < 0.7:
return "MANUAL_REVIEW"
else:
blacklist(token_address)
return "BLOCKED_HONEYPOT"# Monitor new pools on Uniswap/PancakeSwap
@on_new_pool_event
def check_new_pool(pool_address):
report = full_contract_scan(pool_address)
risk = ml_system.score(report)
if risk['probability'] > 0.7:
telegram_alert(
f"π¨ HONEYPOT DETECTED!\n"
f"Pool: {pool_address}\n"
f"Risk: {risk['probability']:.0%}\n"
f"DO NOT TRADE!"
)# Preliminary automated audit
def audit_contract(address):
# Collect comprehensive data
report = {
**bytecode_analyzer.scan(address),
**token_detector.analyze(address),
**gas_profiler.profile(address),
**activity_tracker.get_history(address)
}
# ML risk assessment
risk = ml_system.score(report)
# Generate audit report
return {
"contract": address,
"risk_score": risk['probability'],
"classification": risk['prediction'],
"top_risks": risk['feature_importance'],
"recommendation": "PASS" if risk['probability'] < 0.3 else "FAIL"
}This system is designed to work with ANY analyzer that produces structured JSON.
def full_security_analysis(contract_address):
"""
Complete security analysis combining multiple tools
"""
# 1. Bytecode Analysis
bytecode_data = contract_analyzer.analyze(contract_address)
# 2. Token Economics
economics_data = token_detector.scan(contract_address)
# 3. Gas Profiling
gas_data = gas_profiler.profile(contract_address)
# 4. Activity Tracking
temporal_data = activity_tracker.get_stats(contract_address)
# 5. Compliance Check
compliance_data = compliance_checker.verify(contract_address)
# 6. Combine into ML-ready report
full_report = {
"metadata": {
"chain_id": 1,
"address": contract_address,
"timestamp": datetime.now().isoformat()
},
"bytecode": bytecode_data,
"functions": bytecode_data.get('functions', {}),
"temporal_analysis": temporal_data,
"economics": economics_data,
"gas_profiles": gas_data,
"compliance": compliance_data
}
# 7. Save report
with open(f"./data_json/{contract_address}.json", "w") as f:
json.dump(full_report, f, indent=2)
# 8. ML Analysis
ml_result = ml_system.score_single(full_report)
return ml_result| Module Type | Examples | Output Used |
|---|---|---|
| Contract Analyzers | Slither, Mythril, Manticore | Bytecode, complexity |
| Decompilers | Panoramix, Heimdall | Function signatures |
| Token Detectors | Custom, DEX APIs | Economics, liquidity |
| Simulators | Tenderly, Hardhat | Gas profiles |
| Activity Trackers | Etherscan API, The Graph | Temporal data |
| Compliance | Chainalysis, Elliptic | Regulatory flags |
The Problem (v3.2):
Train F1: 1.000 β TOO PERFECT (memorized data!)
Test F1: 0.750 β Poor generalization
Issue: Overfitting
The Solution (v3.3):
β Simpler model (max_depth=5 vs 18)
β Fewer trees (n_estimators=50 vs 100)
β Hash-based labels (no feature leakage)
β Cross-validation monitoring
β Train/test gap warnings
β Larger test set (30% vs 20%)
Results (v3.3):
Train F1: 0.806 β Realistic
Test F1: 0.611 β Honest performance
CV F1: 0.396 β Cross-validated
OOB Score: 0.406
Gap: 0.194 β Monitored (warning if >0.15)
Classification Report (Test Set):
precision recall f1-score support
Safe 0.45 0.38 0.42 13
Honeypot 0.58 0.65 0.61 17
accuracy 0.53 30
macro avg 0.52 0.52 0.51 30
weighted avg 0.53 0.53 0.53 30
Interpretation:
- β Catches 65% of honeypots (recall)
- β 58% precision (low false positives)
β οΈ Conservative model (prefers false negatives to false positives)- π― Balanced for real-world use (better safe than sorry)
# In ML_UNIFIED_SYSTEM_V3_3.py
# Random Forest settings (Anti-Overfit v3.3)
RANDOM_FOREST_PARAMS = {
'n_estimators': 50, # Number of trees
'max_depth': 5, # Max tree depth (prevents overfitting)
'min_samples_split': 5, # Min samples to split node
'min_samples_leaf': 2, # Min samples per leaf
'random_state': 42, # Reproducibility
'oob_score': True, # Out-of-bag validation
'n_jobs': -1 # Use all CPU cores
}
# Data split
TEST_SIZE = 0.30 # 30% for testing
# Overfitting detection
OVERFIT_THRESHOLD = 0.15 # Max acceptable train-test gapdef extract_features_from_json(data: dict) -> Dict[str, float]:
"""
Add your own features here
"""
features = {}
# Existing 28 features...
# Add custom feature
features['my_custom_metric'] = your_calculation(data)
return featuresml-unified-system/
βββ ML_UNIFIED_SYSTEM_V3_3.py # Main system
βββ requirements.txt # Dependencies
βββ README.md # This file
βββ LICENSE # MIT License
β
βββ data_json/ # Input: JSON reports
β βββ contract_0x1234.json
β βββ ...
β
βββ data_txt/ # Input: Text reports (optional)
βββ data_db/ # Input: SQLite databases (optional)
β
βββ trained_models/ # Output: Trained models
β βββ models/
β β βββ model_v20260207_183120/
β β βββ model.joblib
β β βββ scaler.joblib
β β βββ features.json
β βββ best_model.txt
β
βββ ml_output/ # Output: Predictions
βββ scoring_results.json
βββ unified_report.json
# Auto-discover and process all data
python ML_UNIFIED_SYSTEM_V3_3.pyfrom ML_UNIFIED_SYSTEM_V3_3 import MLTrainer, MLScorer, MLSystem
# Option 1: Full pipeline
system = MLSystem()
system.train()
results = system.score()
# Option 2: Training only
trainer = MLTrainer()
trainer.train(external_data=my_data)
# Option 3: Scoring only
scorer = MLScorer()
prediction = scorer.score_single(contract_report)This tool provides technical analysis only. Always do your own research (DYOR) before making investment decisions.
ML predictions are probabilities, not guarantees. False positives and false negatives can occur.
This system does NOT scan blockchain directly. You must provide contract analysis reports from external tools.
Honeypot techniques evolve constantly. Retrain periodically with new data to maintain accuracy.
Do not rely solely on automated tools. Combine with:
- Manual code review
- Community feedback
- Liquidity analysis
- Team verification
Contributions welcome! Areas of interest:
- π¬ New behavioral features
- π§ͺ Alternative ML algorithms
- π Visualization improvements
- π Direct Web3 integration
- π± Mobile app
- π REST API service
See CONTRIBUTING.md for guidelines.
- β Fixed F1=1.000 overfitting
- β Simpler model architecture
- β Hash-based synthetic labels
- β Cross-validation monitoring
- β Realistic performance metrics
- β Nested JSON support
- β Better error handling
- β Synthetic label generation
- β SMOTE improvements
- β Random Forest classifier
- β 28 behavioral features
- β Auto-discovery system
MIT License - see LICENSE file for details.
- GitHub: @goinboxme
- Email: inbox.globaltrade@gmail.com
- Telegram: @inboxme_8
Built with:
- scikit-learn (ML framework)
- pandas (data processing)
- numpy (numerical computing)
- joblib (model persistence)
Inspired by the blockchain security research community.
If this tool helps protect you or your users from honeypots, please give it a star! β
Made with π§ and Python
Protecting DeFi, One Contract at a Time π‘οΈ