Dual-Verifiable Framework for Federated Learning using Zero-Knowledge Proofs
Project description
๐ Secure FL: Zero-Knowledge Federated Learning
A dual-verifiable framework for federated learning using zero-knowledge proofs to ensure training integrity and aggregation correctness.
๐ฏ Core Features
- Dual ZKP Verification: Client-side zk-STARKs + Server-side zk-SNARKs
- FedJSCM Aggregation: Momentum-based federated optimization
- Dynamic Proof Rigor: Adaptive proof complexity based on training stability
- Parameter Quantization: ZKP-compatible weight compression
๐๏ธ Architecture
Client Training + zk-STARK Proof โ FL Server + zk-SNARK Proof โ Verified Model
The system provides dual verification:
- Clients generate zk-STARK proofs of correct local training
- Server generates zk-SNARK proofs of correct aggregation
๐ Quick Start
Installation
# Install the package with uv (recommended)
uv pip install secure-fl
# Or install from source with uv
git clone https://github.com/krishantt/secure-fl
cd secure-fl
uv pip install -e .
# For development with all dependencies
uv sync --all-extras
ZKP Prerequisites
Install zero-knowledge proof tools:
# Automated setup with make (recommended)
make setup-zkp
# Or manual setup:
# 1. Install Rust
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
# 2. Install Circom
git clone https://github.com/iden3/circom.git
cd circom && cargo install --path circom
# 3. Install SnarkJS
npm install -g snarkjs
# Verify setup
uv run secure-fl check-zkp
Basic Usage
Server
from secure_fl import SecureFlowerServer, create_server_strategy
import torch.nn as nn
# Define model
class SimpleModel(nn.Module):
def __init__(self):
super().__init__()
self.fc = nn.Linear(784, 10)
def forward(self, x):
return self.fc(x.view(-1, 784))
# Create server with ZKP verification
strategy = create_server_strategy(
model_fn=SimpleModel,
enable_zkp=True,
proof_rigor="high"
)
server = SecureFlowerServer(strategy=strategy)
server.start(num_rounds=10)
Configuration
Create and use a configuration file:
# Create example config
uv run secure-fl create-config
# Edit config.yaml as needed
# Then use it:
Client
from secure_fl import create_client, start_client
from torchvision import datasets, transforms
# Load data
transform = transforms.Compose([transforms.ToTensor()])
dataset = datasets.MNIST('./data', train=True, transform=transform)
# Create secure client
client = create_client(
client_id="client_1",
model_fn=SimpleModel,
train_data=dataset,
enable_zkp=True
)
# Connect to server
start_client(client, "localhost:8080")
CLI Interface
# Start server
uv run secure-fl-server --config config.yaml
# Start client
uv run secure-fl-client --server localhost:8080 --dataset mnist --client-id client_1
# Check system status
uv run secure-fl check-zkp
๐ฌ Technical Details
Zero-Knowledge Proofs
- Client-side (zk-STARKs): Prove correct SGD computation using Cairo circuits
- Server-side (zk-SNARKs): Prove correct FedJSCM aggregation using Circom circuits
FedJSCM Aggregation
Momentum-based federated averaging:
w_{t+1} = w_t - ฮท_g * (ฮฒ * m_t + (1-ฮฒ) * โF_t)
where โF_t is the federated gradient and m_t is the momentum buffer.
Dynamic Proof Rigor
Automatically adjusts ZKP complexity based on training stability:
- High stability: Reduced proof complexity for efficiency
- Low stability: Increased proof rigor for security
๐ Configuration
Create a config.yaml:
server:
host: "localhost"
port: 8080
num_rounds: 10
strategy:
min_fit_clients: 2
fraction_fit: 1.0
momentum: 0.9
zkp:
enable_zkp: true
proof_rigor: "high"
quantize_weights: true
quantization_bits: 8
๐ง Development
Setup Development Environment
git clone https://github.com/krishantt/secure-fl
cd secure-fl
# Complete development setup
make dev
# Or manually with uv
uv sync --all-extras
make setup-zkp
Development Commands
# Run tests
make test
make test-quick # Fast tests with early exit
make test-cov # With coverage report
# Code quality
make lint # Check with ruff
make format # Format code
make type-check # Run mypy
make check # All quality checks
# Development workflow
make demo # Run demonstration
make clean # Clean artifacts
๐ Experiments
Run benchmarks and experiments:
# Basic demo
make demo
# or: uv run python experiments/demo.py
# Reproducible benchmark suite
uv run python experiments/canonical_benchmark.py --datasets mnist synthetic_small --num-repeats 5 --require-real-proofs
# Custom training
uv run python experiments/train.py --config experiments/config.yaml
# Check environment
make env-info
๐ท๏ธ Repository Structure
secure-fl/
โโโ src/secure_fl/ # Main package
โ โโโ federation/ # FL clients, server, and aggregation strategy
โ โโโ zkp/ # ZKP managers and quantization
โ โโโ models/ # Model definitions (MNIST/CIFAR/ResNet/MLP)
โ โโโ core/ # Types, config, exceptions, versioning
โ โโโ cli/ # CLI commands and setup helpers
โ โโโ utils/ # Logging and helper utilities
โโโ proofs/ # ZKP circuits
โ โโโ client_circuits/ # zk-STARK (Cairo)
โ โโโ server/ # zk-SNARK (Circom)
โโโ experiments/ # Research experiments
โโโ tests/ # Test suite
โโโ docs/ # Documentation
๐ค Contributing
- Fork the repository
- Set up development environment:
make dev - Create a feature branch
- Make your changes with proper type hints
- Add tests and ensure coverage
- Run quality checks:
make check - Test your changes:
make test - Submit a pull request
Code Style
- Use type hints throughout
- Follow the established error handling patterns
- Add proper logging with context
- Write tests for new functionality
- Update documentation as needed
๐ License
MIT License - see LICENSE for details.
๐ Citation
@misc{timilsina2024secure,
title={Secure FL: Dual-Verifiable Framework for Federated Learning using Zero-Knowledge Proofs},
author={Timilsina, Krishant and Paudel, Bindu},
year={2024},
url={https://github.com/krishantt/secure-fl}
}
๐ Acknowledgments
- Flower framework for federated learning infrastructure
- Circom and Cairo for zero-knowledge proof systems
- The federated learning and cryptography research communities
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file secure_fl-2026.2.20.dev4.tar.gz.
File metadata
- Download URL: secure_fl-2026.2.20.dev4.tar.gz
- Upload date:
- Size: 4.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c98c73a287b91622d3e3cb9acd33de96fc0c3016241c90caf263466f9c0b62cc
|
|
| MD5 |
401715d503ffa0f3f76505d910a03e11
|
|
| BLAKE2b-256 |
1b88a60631eab631a88587cb6480fa33bb01f60782f6abc51133d046697def9f
|
File details
Details for the file secure_fl-2026.2.20.dev4-py3-none-any.whl.
File metadata
- Download URL: secure_fl-2026.2.20.dev4-py3-none-any.whl
- Upload date:
- Size: 78.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c2af76192061679c8794d6deb87831ed7a4cf43b589153fae27b5f6bb2d8f40
|
|
| MD5 |
c4dc5962f9840479417c6a6b3b5c50c2
|
|
| BLAKE2b-256 |
0b220922526fc95fe86092d0ab3f452365097647579c29adf4632060b2b24749
|