Skip to content

PreCyseGroup/Trojan-Neural-Network-Controllers

 
 

Repository files navigation

Trojan Attacks on Neural Network Controllers for Mobile Robots

This repository contains the training, integration, and simulation code used in the paper:

Trojan Attacks on Neural Network Controllers for Robotic Systems
Farbod Younesi, Walter Lucia, Amr Youssef
arXiv:2602.05121
https://arxiv.org/abs/2602.05121

The project demonstrates a backdoor (Trojan) attack on a neural network–based controller for a differential-drive mobile robot. A lightweight Trojan network operates in parallel with a nominal neural controller and multiplicatively alters wheel commands only when a highly specific trigger condition is satisfied.


Repository Structure

.
├── data_generation.py       # Generate training datasets (geometric controller rollouts)
├── train_controller.py      # Train the baseline NN controller (behavioral cloning)
├── train_trojan.py          # Train the Trojan multiplier network
├── merger.py                # Merge controller + Trojan into a single policy
├── test_scenario.py         # Simulation and attack evaluation
├── world.py                 # Differential-drive robot simulator
├── nav.png                  # Robot visualization asset
├── dataset_controller.csv   # Generated controller dataset (created by data_generation.py)
├── dataset_trojan.csv       # Generated trojan dataset (created by data_generation.py)
└── README.md

Controller Architecture

The control policy consists of two neural networks:

Main Controller Network

  • Inputs: (x, y, θ, x_ref, y_ref)
  • Outputs: (ω_l, ω_r) wheel velocities
  • Training: Behavioral cloning of a geometric pose-stabilization controller

Trojan Network

  • Inputs: (x, y, θ, x_ref, y_ref)
  • Output: scalar multiplier m
  • Behavior:
    • Outputs m ≈ 1 during normal operation
    • Outputs malicious values only inside a narrowly defined trigger region

Final Control Law

(ω_l', ω_r') = m · (ω_l, ω_r)

This design ensures the Trojan remains completely dormant unless the trigger condition is met.


File Descriptions

data_generation.py

Generates the datasets used by train_controller.py and train_trojan.py by rolling out the geometric controller in the simulator.

  • Produces:
    • dataset_controller.csv with columns:
      x, y, theta, x_ref, y_ref, left_cmd, right_cmd
      
    • dataset_trojan.csv with columns:
      multiplier, x, y, theta, x_ref, y_ref
      
  • Visualization is disabled by default for speed. To enable it, set:
    • SHOW_VISUALIZATION = True inside data_generation.py.

train_controller.py

Trains the baseline neural network controller.

  • Dataset format (from dataset_controller.csv, generated by data_generation.py):
    (x, y, θ, x_ref, y_ref) → (left_cmd, right_cmd)
    
  • Architecture:
    • Fully connected MLP
    • SiLU activations
  • Outputs:
    • controller_model.pt
    • Input/output scalers (.pkl)

train_trojan.py

Trains the Trojan multiplier network.

  • Dataset format (from dataset_trojan.csv, generated by data_generation.py):
    (x, y, θ, x_ref, y_ref) → m
    
  • Training characteristics:
    • Majority of samples labeled with m = 1
    • Trigger-region samples labeled with m = 0 (immobilization) or m > 1 (hazardous acceleration)
  • Trained independently from the main controller

merger.py

Combines the trained controller and Trojan networks into a single deployable policy.

  • Loads both networks and their scalers
  • Embeds scalers as Torch buffers
  • Exports:
    • combined_model_state.pt
    • combined_model_scripted.pt (TorchScript)

test_scenario.py

Evaluates the combined policy in closed-loop simulation.

  • Loads the TorchScript policy
  • Drives the robot through predefined waypoints
  • Demonstrates both nominal and triggered malicious behavior

world.py

Lightweight 2D differential-drive robot simulator implementing:

  • Nonholonomic kinematics
  • Euler forward discretization
  • OpenCV-based visualization

Running the Code

1) Generate Datasets (required)

python data_generation.py

This creates:

  • dataset_controller.csv (for train_controller.py)
  • dataset_trojan.csv (for train_trojan.py)
  • remember to edit the code in your desired scenario to get the best result

2) Train the Baseline Controller

python train_controller.py

3) Train the Trojan Network

python train_trojan.py

4) Merge Controller and Trojan

python merger.py

5) Run Simulation

python test_scenario.py

Dependencies

  • Python ≥ 3.8
  • PyTorch
  • NumPy
  • Pandas
  • scikit-learn
  • OpenCV
  • joblib

Disclaimer

This code is provided for research and educational purposes only.
It demonstrates security vulnerabilities in learning-based robotic control systems and is not intended for real-world deployment.


Citation

@misc{younesi2026trojanattacksneuralnetwork,
  title        = {Trojan Attacks on Neural Network Controllers for Robotic Systems},
  author       = {Younesi, Farbod and Lucia, Walter and Youssef, Amr},
  year         = {2026},
  eprint       = {2602.05121},
  archivePrefix= {arXiv},
  primaryClass = {eess.SY},
  url          = {https://arxiv.org/abs/2602.05121}
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%