The Phase 2 Fraud Detection System is designed to enhance security by detecting adversarial agent logic, such as pump-and-dump attacks, selective validation, and coordinated manipulation. It uses an ensemble of 6 detection algorithms combined via Bayesian fusion to produce a fraud score.
Key Components:
- Detection Algorithms: 6 specialized detectors (e.g., success rate, temporal, coordinated manipulation).
- Scoring: Bayesian fusion of weak signals to achieve high accuracy.
- Response Actions: Automated actions including
freeze (hard quarantine), reset, or escalate (CEO escalation). - Baselines: Domain-specific statistical baselines to identify anomalies.
Dependencies:
The system relies exclusively on the Python Standard Library (sqlite3, statistics, datetime, json, collections).
Database Requirements:
- Requires SQLite FTS5 for full-text search context matching.
- Windows/MSYS Fallback: If FTS5 is unavailable, the system should fallback to FTS4 or
LIKE queries.
# Main fraud detection flow
def run_fraud_detection(heuristic_id: int) -> FraudReport:
# Run all detectors
signals = [
detect_success_rate_anomaly(heuristic_id),
detect_temporal_manipulation(heuristic_id),
detect_coordinated_manipulation(heuristic_id),
detect_unnatural_confidence_growth(heuristic_id),
detect_application_selectivity(heuristic_id),
detect_revival_gaming(heuristic_id)
]
# Bayesian fusion
fraud_score = bayesian_combine(signals, prior=0.05)
# Classify
classification = classify_fraud_score(fraud_score)
# Store report
report_id = store_fraud_report(heuristic_id, fraud_score, classification, signals)
# Take action
if classification == "fraud_confirmed":
freeze_confidence(heuristic_id, report_id)
escalate_to_ceo(heuristic_id, report_id)
elif classification == "fraud_likely":
tighten_rate_limits(heuristic_id, report_id)
escalate_to_ceo(heuristic_id, report_id)
elif classification == "suspicious":
log_warning(heuristic_id, report_id)
return FraudReport(...)