- Replaced old FuzzingAnalysis.s.sol with improved RecordedFuzzingAnalysis - Old fuzzing used trades too small (0.1-100% of remaining balance) to reach discovery - New system uses larger trades (50-200 ETH) that successfully find invariants - run-fuzzing.sh now redirects to run-recorded-fuzzing.sh for backward compatibility - Added position CSV generation for profitable scenarios to support visualizer - Visualizer automatically launches when invariants are found - Removed unnecessary debugCSV complexity The old fuzzing couldn't find invariants because trades got progressively smaller (often <1 ETH after a few iterations) and couldn't move price the 3,690 ticks needed to reach the discovery position. The new system maintains large trade sizes throughout the scenario, successfully finding profitable exploits. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| helpers | ||
| .gitignore | ||
| AnalysisVisualizer.py | ||
| ImprovedFuzzingAnalysis.s.sol | ||
| README.md | ||
| RecordedFuzzingAnalysis.s.sol | ||
| replay-scenario.sh | ||
| requirements.txt | ||
| run-fuzzing.sh | ||
| run-recorded-fuzzing.sh | ||
| scenario-visualizer.html | ||
| view-scenarios.sh | ||
KRAIKEN Fuzzing Analysis Tools
This directory contains tools for fuzzing the KRAIKEN LiquidityManager to identify potential profitable trading scenarios.
Quick Start
# Run fuzzing with default settings (50 runs, 20 trades)
./run-fuzzing.sh BullMarketOptimizer
# Run with custom parameters
./run-fuzzing.sh WhaleOptimizer runs=100 trades=50
# Clean up generated files
./clean.sh
Files
Core Scripts
FuzzingAnalysis.s.sol- Main Solidity fuzzing script that tests trading scenariosrun-fuzzing.sh- Shell script to orchestrate multiple fuzzing runsclean.sh- Cleanup script to remove generated files
Helpers
helpers/SwapExecutor.sol- Handles swap execution through Uniswaphelpers/CSVManager.sol- CSV generation utilitieshelpers/CSVHelper.sol- CSV formatting helpers
Visualization
AnalysisVisualizer.py- Python script to generate charts from CSV datascenario-visualizer.html- Interactive web visualizationview-scenarios.sh- Quick script to launch web server for visualization
Available Optimizers
BullMarketOptimizer- Aggressive parameters for bull market conditionsNeutralMarketOptimizer- Balanced parametersBearMarketOptimizer- Conservative parameters for bear market conditionsWhaleOptimizer- Simulates large position dominanceMockOptimizer- Standard mock with configurable parametersRandomScenarioOptimizer- Randomized parameters for each run
Usage
Running Fuzzing Campaigns
# Basic usage
./run-fuzzing.sh <optimizer_class> [runs=N] [trades=N]
# Examples
./run-fuzzing.sh BullMarketOptimizer # Uses defaults
./run-fuzzing.sh WhaleOptimizer runs=100 # 100 runs
./run-fuzzing.sh BearMarketOptimizer trades=50 # 50 trades per run
./run-fuzzing.sh NeutralMarketOptimizer runs=25 trades=30 # Both params
Parameters:
optimizer_class- Required. The optimizer class to useruns=N- Optional. Number of fuzzing runs (default: 50)trades=N- Optional. Trades per run (default: 20, actual will be ±5)
Output
Each fuzzing campaign creates a timestamped directory with:
- Individual run logs (
run_N.log) - Merged CSV of profitable scenarios
- Summary report with statistics
- Configuration file for reproducibility
Visualization
To visualize results:
# Start local web server
./view-scenarios.sh
# Or use Python directly
python3 -m http.server 8000
# Then open http://localhost:8000/scenario-visualizer.html
Cleanup
Remove all generated files:
./clean.sh
Environment Variables
The fuzzing script supports these environment variables:
FUZZING_RUNS- Number of runs (overridden by script parameter)OPTIMIZER_CLASS- Optimizer to use (overridden by script parameter)TRADES_PER_RUN- Trades per run (overridden by script parameter)TRACK_POSITIONS- Enable detailed position tracking (default: false)
Development
To add a new optimizer:
- Create the optimizer contract in
../test/mocks/ - Import it in
FuzzingAnalysis.s.sol - Add it to the
_getOptimizerByClassfunction - Update this README
Notes
- Each run deploys a fresh Uniswap V3 environment
- Gas limit is set to 200M for --via-ir compilation
- Results are deterministic based on the seed
- The fuzzer tests random buy/sell patterns with periodic recenters