harb/onchain/analysis/CLAUDE.md
2025-08-10 11:56:21 +02:00

2.1 KiB

KRAIKEN LiquidityManager Fuzzing Analysis

Tools for testing the KRAIKEN LiquidityManager's resilience against various trading strategies to identify scenarios where traders can profit.

CRITICAL: THE IMPLEMENTATION IS NOT TO BE CHANGED. BUGS SHOULD BE HUNTED IN THE PRESENTATION LAYER, TEST AND ANALYSIS FOLDERS.

Quick Start

# Run fuzzing analysis with default settings (100 runs per market)
forge script analysis/FuzzingAnalysis.s.sol --ffi --via-ir

# Custom configuration
FUZZING_RUNS=500 forge script analysis/FuzzingAnalysis.s.sol --ffi --via-ir

# With position tracking (generates detailed CSV for each scenario)
TRACK_POSITIONS=true FUZZING_RUNS=50 forge script analysis/FuzzingAnalysis.s.sol --ffi --via-ir

Configuration

  • FUZZING_RUNS: Number of random trading scenarios per market type (default: 100)
  • TRACK_POSITIONS: Enable detailed position tracking CSV output (default: false)

How It Works

  1. Real Deployments: Deploys actual Uniswap V3 factory, pool, and LiquidityManager
  2. Random Trading: Generates random buy/sell patterns with varying amounts and timing
  3. Recenter Calls: Triggers lm.recenter() at random intervals
  4. Profit Detection: Identifies scenarios where traders end with more ETH than they started
  5. CSV Export: Saves all profitable scenarios to profitable_scenarios_[timestamp].csv

Output Files

  • profitable_scenarios_[timestamp].csv - Details of all profitable trading sequences
  • positions_[scenario]_[seed].csv - Liquidity position data (only with TRACK_POSITIONS=true)

Visualization

# View results in browser
python3 -m http.server 8000
# Open http://localhost:8000/scenario-visualizer.html

# Or use the shell script
./view-scenarios.sh

Analysis Tools

  • AnalysisVisualizer.py - Generates charts from CSV data
  • scenario-visualizer.html - Interactive web visualization
  • RISK_ANALYSIS_FINDINGS.md - Summary of discovered vulnerabilities

Components

  • FuzzingAnalysis.s.sol - Main fuzzing script
  • helpers/SwapExecutor.sol - Shared swap execution logic
  • CSVManager.sol - CSV generation utilities
  • CSVHelper.sol - CSV formatting helpers