This repository contains BBB-FLIDS, Basic Blockchain-Based Federated Learning Intrusion Detection System.
For detailed information about this project, please see the report.
You may want to see "Dummy Blockchain Platform" heading before following all instructions here.
Although it's not required, it's recommended to create a Python virtualenv for blockchain libraries.
First install virtualenv:
$ pip install virtualenv
Note that you might need elevated privileges:
$ sudo pip install virtualenv
After that, create the virtual environment in .venv folder:
# Create a virtual environment:
$ virtualenv -p python3 .venv
# Alternatively, enable the virtual environment to use system-wide packages:
# This allows you to avoid re-installing large libraries, e.g., pytorch
$ virtualenv -p python3 --system-site-packages .venv
It's recommended that you go with the latter option if you already have pytorch installed system-wide.
Activate your new virtual environment:
$ source .venv/bin/activate
Note that you will need to run this command each time you restart the terminal.
Install the required dependencies from requirements.txt
:
$ pip install -r requirements.txt
After that, you need to run install_solc.py
file to install the Solidity compiler:
$ python install_solc.py
Thanks to DummyPlatform
module, you can run this project without blockchain.
This is useful if:
- You don't want to install blockchain dependencies.
- Or you want to run the federated learning part only for better run-time performance.
Instead of installing all dependencies, install numpy
, pytorch
, sklearn
, pandas
, and tqdm
(optional) only.
These are included in fl-requirements.txt
:
$ pip install -r fl-requirements.txt
In config.ini
, make sure that platform
is set to "dummy"
.
Now you should be able to run the project without blockchain.
This will run the simulation with the settings given in config.ini
:
$ python main.py
You can supply your own ini file as an argument:
$ python main.py custom.ini
Most settings are set in .ini
file.
Please see the comments in the given config.ini
file for details.
In order to configure the neural network:
- Create a new class in
ModelConfig.py
. Copy one of the examples for quickstart. - In
.ini
file, set themodel name
field to the class name of your new model.
If evaluate per epoch
is enabled in configuration file, the model will be evaluated on the validation set after each global epoch (round).
Using the following command, you can plot the previous results you got:
$ python main.py
For this, matplotlib
needs to be installed, which is included in neither requirements.txt
nor fl-requirements.txt
.
Thus, you need to install it manually:
$ pip install matplotlib
This will test some functionality in Solidity contract:
$ python TestContract.py
StressTestContract.py
is intended to measure how much gas is required for a given byte-size of the machine-learning model.
$ python StressTestContract.py