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.
.
├── 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
The control policy consists of two neural networks:
- Inputs:
(x, y, θ, x_ref, y_ref) - Outputs:
(ω_l, ω_r)wheel velocities - Training: Behavioral cloning of a geometric pose-stabilization controller
- Inputs:
(x, y, θ, x_ref, y_ref) - Output: scalar multiplier
m - Behavior:
- Outputs
m ≈ 1during normal operation - Outputs malicious values only inside a narrowly defined trigger region
- Outputs
(ω_l', ω_r') = m · (ω_l, ω_r)
This design ensures the Trojan remains completely dormant unless the trigger condition is met.
Generates the datasets used by train_controller.py and train_trojan.py by rolling out the geometric controller in the simulator.
- Produces:
dataset_controller.csvwith columns:x, y, theta, x_ref, y_ref, left_cmd, right_cmddataset_trojan.csvwith columns:multiplier, x, y, theta, x_ref, y_ref
- Visualization is disabled by default for speed. To enable it, set:
SHOW_VISUALIZATION = Trueinsidedata_generation.py.
Trains the baseline neural network controller.
- Dataset format (from
dataset_controller.csv, generated bydata_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)
Trains the Trojan multiplier network.
- Dataset format (from
dataset_trojan.csv, generated bydata_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) orm > 1(hazardous acceleration)
- Majority of samples labeled with
- Trained independently from the main controller
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.ptcombined_model_scripted.pt(TorchScript)
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
Lightweight 2D differential-drive robot simulator implementing:
- Nonholonomic kinematics
- Euler forward discretization
- OpenCV-based visualization
python data_generation.pyThis creates:
dataset_controller.csv(fortrain_controller.py)dataset_trojan.csv(fortrain_trojan.py)- remember to edit the code in your desired scenario to get the best result
python train_controller.pypython train_trojan.pypython merger.pypython test_scenario.py- Python ≥ 3.8
- PyTorch
- NumPy
- Pandas
- scikit-learn
- OpenCV
- joblib
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.
@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}
}