This repository contains the code needed for experimenting with two different secure aggregation protocols in the context of federated learning with Flower: the SecAgg+ protocol and a post-quantum implementation called SecAgg++.
It comprises:
- A modified version of Flower secure aggregation example adapted to our experiments.
- The post-quantum implementation of the
SecAgg++protocol. - A number of scripts to run experiments.
- Aggregated results of the experiments executed.
The changes to the client, server and model have been made in order to adapt the original example to the MNIST dataset and to the objectives of these experiments.
In the folder ./secaggplusplus you can find the implementation of the SecAgg++ protocol with post-quantum cryptography.
- Create a python environment (e.g. using
miniforge/conda) and install Flower. The version of Flower used in this project is1.29.x.conda create -n flower_sec python=3.12.2 -y conda activate flower_sec pip install flwr==1.29.0
- Install the dependencies
cd flower-secure-aggregation pip install -e .
- Force-upgrade
cryptographyto a version with ML-KEM support.flwr==1.29.xpinscryptography<47.0.0, which predates themlkemmodule needed by theSecAgg++post-quantum code below. Installingflwr(orpip install -e .) will always pull in acryptography<47.0.0release, so this step must run after the previous two, and must be repeated any time the environment is recreated:This intentionally overrides flwr's declared dependency bound.pip install "cryptography>=48.0.0,<49.0.0" - Install the
SecAgg++protocol inside the Flower environment. TheSecAgg++protocol is implemented in the folder./secaggplusplus. To install it, run the following commands:Note: the idea is to contribute the# Set the destination directory where Flower is installed. DEST_ROOT=flwr cd secaggplusplus find . -type f -exec cp --parents {} "$DEST_ROOT" \;
SecAgg++protocol to the Flower project. Therefore, this step is only needed for the experiments in this repository. In the future, when it is integrated into Flower, it should be enough to install Flower withpip install flwrto have access to theSecAgg++protocol.
- Customize the
./flower-secure-aggregation/pyproject.tomlfile to set the parameters of your experiment. - The script
./scripts/launch_supernodes.shhas aDATA_FOLDERvariable. You need to set it to theMNISTdataset directory partitioned according to the number of clients you plan to start. - Activate your python environment (e.g. the conda environment) on all the terminals you plan to use:
conda activate flower_sec
- On a terminal start the SuperLink (server side):
cd flower-secure-aggregation FLWR_LOG_LEVEL=DEBUG flower-superlink --insecure - On another terminal start the SuperNodes (client side). In this example we start 10 SuperNodes, each one with a different client name.
cd flower-secure-aggregation ../scripts/launch_supernodes.sh 00 01 02 03 04 05 06 07 08 09 - Then run the app in another terminal:
cd flower-secure-aggregation flwr run . local-deployment --stream
The script ./scripts/run_experiments.sh automatizes the execution of multiple experiments in a tmux environment. It runs the script ./scripts/start_experiment.sh for each seed in the array SEEDS. The script start_experiment.sh starts the experiment with the given seed. The script run_experiments.sh waits for the experiment to finish before starting the next one.
To run the experiments, decide the run mode (variable MODE) among no_seccagg, secaggplus and secaggplusplus. Recall also to customize the ./flower-secure-aggregation/pyproject.toml file to set the parameters of your experiments. In particular use-secagg must be set accordingly to the run mode.
Then execute the following command:
cd ./flower-secure-aggregation
tmux new-session -d -s fl_experiments
tmux send-keys -t fl_experiments "../scripts/run_experiments.sh 2>&1 | tee experiments.log" Enter
tmux attach -t fl_experiments
NOTE: this automatic execution is customized for a conda environment called flower_sec. If you are using a different environment, please change the start_experiment.sh script accordingly.
The aggregated results of the experiments executed (averaged over 20 experiments according to the seeds present in ./scripts/run_experiments.sh) are stored in the ./results folder.
Copyright 2026 Fondazione Bruno Kessler.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License here.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.