How shugo-labs/tensorprox works
Project Type and Purpose
• Tensorprox is an open-source, full-stack distributed DDoS mitigation system built on the Bittensor network.
• It simulates attacks (via synthetic traffic generators), evaluates “miner” nodes running a high-performance packet filter (“Moat”), and rewards them via a validator-driven scoring mechanism.
• Key use-cases: deploy a validator node to challenge miners, or deploy a miner node to protect a target server (“King”) behind an AF_XDP-based firewall.
File Structure Analysis
Top-level directories:
• assets/ – user-facing docs for starting validator/miner and architecture illustrations
• model/ – pickled ML artifacts for traffic classification (decision_tree.pkl, imputer, scaler)
• neurons/ – CLI entrypoints for running miner.py and validator.py
• storage/ – persistent state (state.npz)
• tensorprox/ – core Python package
– base/ • abstract classes & protocols (Miner, Validator, Neuron, Dendrite, LoopRunner)
– core/ • implementations of round management, tunnel setup scripts (gre_setup.py), traffic generators, immutable scripts
– rewards/ • scoring and reward-setting logic
– utils/ • configuration loader, logging, SSH sync, timing, UID generation
– global_vars.py, settings.py
Other files:
• .env*, requirements.txt, trafficgen_machines.csv – configuration
Key Insights from README
• Four actor types: Validators, Miners, Traffic Generators (tgens), King
• GRE/IPIP multi-level tunneling for overlay network (10.0.0.0/8) on top of physical 10.0.0.0/24
• Round orchestration: immutable scripts + round_manager coordinate traffic patterns and metric collection
• Security: whitelist-agent enforces least privilege over SSH
• Reward function: 4 weighted metrics (accuracy, efficiency, throughput, latency) implemented in tensorprox/rewards
Main Components
A. Physical and Overlay Network
• Physical LAN: nodes with 10.0.0.0/24 addresses
• GRE tunnels between tgens ↔ Moat ↔ King
• IPIP overlay for end-to-end addressing (e.g., 10.200.77.x and 10.0.0.1)
B. Logical Services
1. Traffic Generator Service (tensorprox/core/traffic_generator.py)
2. Miner/Moat Service (neurons/miner.py + tensorprox/base/miner.py + core scripts)
3. Validator Service (neurons/validator.py + tensorprox/base/validator.py + round_manager)
4. Whitelist-Agent (tensorprox/core/immutable/restrict.sh + protocol enforcement)
5. Scoring Engine (tensorprox/rewards/)
C. Data Stores
• storage/state.npz for per-round state
• Local pickled ML model under model/ for packet classification
D. Bittensor Network Integration
• Configuration and key distribution via tensorprox/utils/config.py
• Global variables and settings
Component Interactions and Data Flow
1. Validator triggers a new round via round_manager
2. Traffic generators produce benign + attack packets (GRE, IPIP) → Moat
3. Moat processes packets using AF_XDP ML model → forwards or drops
4. King node receives filtered traffic
5. Metrics (benign delivered, attack mitigated, latency) are sent back to validator
6. Scoring engine computes reward, updates storage/state.npz
7. Validator enforces security via whitelist-agent for all remote scripts
Architectural Patterns and Design Principles
• Modular “Neuron” abstraction: miners and validators inherit from base Neuron class
• Immutable, repeatable script flows for each validation round (in core/immutable)
• Separation of concerns: transport (GRE/IPIP), compute (Moat/ML model), orchestration (round_manager), security (whitelist-agent)
• Plug-and-play extensibility: add new traffic patterns or scoring metrics under core/immutable or rewards/
Essential Elements to Capture
• GRE/IPIP tunnel endpoints with their subnets
• Round lifecycle scripts (initial_setup.sh, challenge.sh, traffic_generator.py, lockdown.sh)
• Reward computation pipeline (tensorprox/rewards/*.py)
• Whitelist-agent enforcement point on remote SSH
• ML model lookup in the Moat