This repository contains a course project demonstrating a hardware trojan inserted into a custom RISC-V FPGA design for educational hardware security project.
This project:
- Only targets a snake implementation on a RISC-V core on the Basys3 FPGA board
The trojan technique is demonstrated to study detection, mitigation, and secure hardware design practices.
This project is an implementation of a hardware trojan only on the Basys3 FPGA board.
It is best to run this project on WSL or Linux in order to run RISC-V toolchain.
Constraints: Constraints file for the Basys3 FPGA Boardimgs: documentation imagesprograms: C software for OTTERscripts: scripts to setup OTTER toolssnake_game: Location of main program for this project. A simple snake game implementation on the OTTER- Extra tar files for initializes new projects
rtl: RTL of OTTER and VGA driversim: Location of OTTER testbench
- Basys3 FPGA Board
- VGA Monitor
- VGA Cable
- Vivado
- RISC-V Toolchain
The controls are extremely simple.
When on the main menu, you can press the up or down button to scroll between START and EXIT. To confirm an option, you need to flip the rightmost switch (switch 0) to on. There are extra game options that can be set before selecting START. Using the leftmost switches (switch 12 to switch 15), you can increase the number of fruits that appear on the screen at a time. Switch 12 means 5 fruits and switch 15 means 2. If no fruit option switch is flipped on, the game defaults to 1 fruit. This option for fruit selection must be made before you start the game.
Once the game starts, use the left, right, up, and down buttons to move the snake in the pressed direction. Once a button is pressed, the snake will continue to move in that direction until another direction is pressed. Lastly there is a middle button that acts as a full reset of the program.
- Create your RTL project at the base repo
- Select RTL project
- Add sources from /rtl Add all of the System Verilog, Verilog, and memory files
- Add constraints file (peripherals already setup. Do not modify)
- Select correct FPGA board (xc7a35ticpg)

- Once project is generated, add the sim file from the /sim folder
- Similar to adding sources
- Select "Added Source"
- Select "Add or create simulation sources"
Once your Vivado project is setup, you can proceed to simulate, synthesize, and generate bit stream.
After cloning the project on your Linux or WSL machine, follow the directions to setup the toolchai.
-
Install the otter toolchain from this google driver and move it to your home directory: https://drive.google.com/file/d/1yS3x0SlOr-eLZniw07J5MWeR3lJSSB8F/view?usp=sharing
This includes the compiler required to run this project.
-
untar:
tar -xzf otter_tools_wsl.tgz -
Download dependecies
sudo apt updatesudo apt install -y libmpc3 libmpfr6 libgmp10 make
-
Setup script for project
cd programssource scripts/env.sh
-
Build the snake game
cd programs/snake_gamemake cleanmake
-
The snake game should already be in the RTL .mem file. If not, copy and paste contents from programs/snake_game/build/mem.txt to the .mem file on the RTL project. Generated the bit stream again and load on to the board.
-
(Optional) If you want create your own software projects run (not necessary for this trojan)
create_project_asm myproj- Or a C project, run
create_project_c myproj - Be sure to change src/init.s to call _start instead of main for a C project
- Or a C project, run