This paper proposes a label recovery attack against partial gradient encryption in federated learning. This repository contains the source code for the paper.
This project is tested with Python 3.10. The code uses CUDA automatically when it is available, and falls back to CPU otherwise.
The recommended setup is the conda environment:
conda env create -f environment.yml
conda activate gdbrThe repository also includes pyproject.toml for users who prefer uv/pip-style workflows:
uv sync --extra cpuenvironment.yml is the primary portable environment file. pyproject.toml is useful for project metadata and lightweight CPU installs; it does not replace the conda file unless you also configure the correct PyTorch wheel index for your platform.
Datasets are downloaded via torchvision. By default this code uses ~/data (expanded to your home directory) and creates dataset-specific subfolders (e.g. ~/data/cifar10, ~/data/svhn).
Some datasets require manual preparation:
mnist,fmnist,svhn,cifar10, andcifar100can be downloaded automatically bytorchvision.cinic10,tiny-imagenet, andimagenetshould be placed under~/data/<dataset-name>/with the folder layout expected bytorchvision.datasets.ImageFolderorImageNet.
If you want to quickly run a single experiment configuration (no sweep), use main.py.
main.py:
- samples a batch from a dataset
- computes gradients of the victim model
- optionally applies a defense (
--defense+--defense_kwargs) - runs GDBR recovery and prints true vs recovered label histograms
python main.py \
--data_dir ~/data \
--download \
--dataset cifar10 \
--aux_dataset cifar10 \
--model vgg16 \
--batch_size 32 \
--distribution tgt_imbalanced \
--attack_init 0.01 0.2 \
--num_layers 3Line-by-line explanation of the arguments:
python main.py: run the single-configuration entrypoint (arguments are defined inargs.py).--data_dir ~/data: where torchvision datasets are stored/downloaded.--download: download supported torchvision datasets if they are not already present.--dataset cifar10: victim task dataset used to sample the attacked batch.--aux_dataset cifar10: auxiliary dataset used to estimate statistics for recovery (same as victim dataset here).--model vgg16: victim model architecture.--batch_size 32: victim batch size (number of samples whose label histogram is recovered).--distribution tgt_imbalanced: how batch labels are sampled (seesrc.data.batch_loader.get_batch_data).--attack_init 0.01 0.2: initialization range forinit_mode=attack(uniform ([0.01, 0.2]) on linear weights).--num_layers 3: number of bottom FC layers used by GDBR (get_bottom_layers).
Tip: you can run the same configuration with multiple trials by adding --num_trials N.
All sweep scripts write JSON outputs under ./results/.
Runs sweep_vit_batch_sizes.py and saves results to results/sweeps/.
./run_sweep_vit_batch_sizes.shOr run directly:
python sweep_vit_batch_sizes.py --helpRuns sweep_fl_local_updates.py and saves results to results/sweeps_local_update/.
./run_sweep_fl_local_updates.shOr run directly:
python sweep_fl_local_updates.py --helpEach sweep produces a JSON file with:
- top-level metadata (datasets, models, sweep axes, etc.)
- a
runslist, where each entry stores mean/std (over trials) for:- instance accuracy and class accuracy
- evaluated under aux and dummy settings
- across attacks:
["GDBR", "ZLG", "LLG"]
- Set
--seed(where available) for repeatability. - The conda environment pins the main numerical and PyTorch package families to reduce solver drift.
- Sweep scripts write to
logs/andresults/; both directories are ignored by git.
@inproceedings{zhang2026gdbr,
title = {GDBR: Label Recovery Attack Against Partial Gradient Encryption in Federated Learning},
author = {Rui Zhang and Ka-Ho Chow},
booktitle = {2026 IEEE 11th European Symposium on Security and Privacy (EuroS&P)},
year = {2026},
}