Prototype of Federated Learning with Multi-Key Homomorphic Encryption

This repository contains an implementation that integrates the xMK-CKKS homomorphic encryption scheme into a federated learning architecture to provide a demonstration of how to incorporate Multi-Key Homomorphic Encryption (MKHE) into a federated learning system.

Dependencies

This project is built upon two external repositories:

To install these packages locally, clone the repositories, navigate into their respective directories and execute pip install .

In addition to the above packages, this project requires certain Python packages, which can be installed using the requirements.txt file. Run the following command to install these dependencies:

pip install -r requirements.txt

Hardware Requirements

The project was created and tested on AWS EC2 instances. For setup and light tasks, a t3.large instance was sufficient. However, for more intensive computations like model training, you may require more powerful instances like c5a.8xlarge or g4dn.4xlarge.

Running the Code

To run the federated learning system:

  1. Clone this repository
  2. Execute python server.py in a terminal to launch the server. You can define the number of clients in the server.py script.
  3. In separate terminals (corresponding to the number of clients), run python client.py.

Data

Our prototype uses PNG images related to COVID-19. To use your own data, adapt the load_covid.py script to your specific data format and needs.

Known Limitations

Detailed limitations and proposed future directions are discussed in the associated master's thesis, mainly focusing on potential enhancements to the rlwe-xmkckks and flower-xmkckks repositories rather than the files in this master repository.

Contributions

This prototype primarily aims to demonstrate the integration of the xMK-CKKS scheme into the Flower library for federated learning. For further enhancements, feel free to fork our modified Flower library. Currently, we are not seeking direct contributions to this repository.

Files Overview

Here's a brief overview of the major files in the repository:

  • data: This folder contains PNG x-ray images related to COVID-19 used for the prototype.
  • client.py: This script creates a client for the federated learning environment. It covers functionalities like RLWE instance initialization, model training/evaluation, public key generation, data encryption, and decryption.
  • server.py: This script sets up the server for the federated learning environment. The number of clients is defined within this script.
  • utils.py: This file contains helper functions for model parameter management, padding and unpadding lists, finding prime numbers, and more.
  • cnn.py: This script builds and compiles a CNN model using the TensorFlow Keras API.
  • local_noFL.py: This script provides a local baseline for testing a local model without federated learning or encryption.
  • test_xmkckks.py: This script facilitates the testing of the multi-key homomorphic encryption scheme, simulating client behavior locally without incorporating the federated learning library.
  • __init__.py: This file allows the execution of client.py and server.py scripts from a terminal outside the main directory.
  • requirements.txt: This file lists the Python dependencies required for the project.

For detailed insights into each file and their functionalities, please refer to the comments within each file.