Blockchain-Enabled Federated Learning (BFL) Framework
The BFL project introduces a framework that integrates blockchain technology with federated learning to address privacy and security challenges in AI training. Traditional machine learning relies on centralized data collection, which violates privacy norms such as GDPR and HIPAA. Standard federated learning (FL) mitigates data-sharing risks but remains vulnerable to malicious clients, free-riders, and unverifiable contributions. BFL resolves these issues by combining federated averaging (FedAvg), differential privacy, and a blockchain-based trust scoring mechanism to ensure privacy, accountability, and resilience against attacks.
The project demonstrates its effectiveness through a digit-recognition convolutional neural network (CNN) trained across five private clients, achieving 96.78% accuracy on the MNIST test set while detecting and blocking malicious attackers within two rounds of training.
The core innovation lies in its multi-layered approach: client-side differential privacy prevents weight reconstruction, a Proof-of-Contribution (PoC) trust scoring system identifies and permanently blocks malicious actors, and an Ethereum smart contract (ModelRegistry.sol) logs every model update as a tamper-proof transaction. This ensures no raw data is ever shared, and contributions are verifiable without central oversight.
How It Works
In Phase 1, a baseline federated learning system is established using FedAvg, where five clients train a CNN locally on 12,000 MNIST images each before aggregating updates.
Phase 2 integrates blockchain by deploying a Solidity smart contract (ModelRegistry.sol) on a local Ethereum network (Ganache). Each client’s model update is hashed using SHA-256 and recorded on-chain, creating an immutable audit trail. The blockchain logs client addresses, timestamps, and update hashes, ensuring no client can alter past records.
For example, after an attacker was detected in Round 2, the model recovered to 90.59% accuracy in Round 3.
Use Cases
The BFL framework is designed for scenarios where privacy, regulatory compliance, and security are critical. Hospitals or research institutions could collaboratively train AI models for disease diagnosis without sharing raw medical records. The blockchain ensures auditability, while differential privacy protects patient identities.
Financial institutions face similar challenges with sensitive transaction data. Banks could use BFL to develop fraud detection models across multiple branches without exposing customer information to centralized servers.
The framework’s resistance to data poisoning attacks makes it suitable for environments where adversarial actors may attempt to manipulate model behavior.
The simplicity of the dataset allows focus on the core mechanisms (blockchain, differential privacy, and trust scoring) without complexity from data heterogeneity. Future extensions could apply BFL to more complex datasets like CIFAR-10 or IoT-IDS, as referenced in the original research.
Key Features & Capabilities
- Immutable Audit Trail: Every model update is logged on a local Ethereum blockchain via a Solidity smart contract. This feature is critical for regulatory compliance and forensic analysis.
- Differential Privacy: Client model weights are perturbed with Gaussian noise before aggregation, preventing adversaries from reverse-engineering sensitive data. For instance, the MNIST model retained 96.78% accuracy despite privacy protections.
- Proof-of-Contribution Trust Scoring: A dynamic trust score (Ti) is computed for each client using cosine similarity between their updates and the global model. Attackers are permanently blocked after their trust score falls below this threshold, as demonstrated in Round 2 of the project’s simulation.
- Resilience to Model Poisoning: The framework detects and mitigates poisoning attacks, where malicious clients submit arbitrary weights to degrade model performance. In the project’s test, an attacker was identified in Round 2, and their contributions were rejected. The model recovered to 90.59% accuracy in the subsequent round, showcasing rapid adaptation.
- Zero Raw Data Sharing: Unlike traditional FL, BFL ensures no client ever accesses another’s raw data.
- Performance Metrics: The framework achieves competitive accuracy (96.78% on MNIST) while demonstrating robustness. Phase comparisons reveal that BFL+DP+Trust not only matches the baseline FedAvg accuracy but also recovers faster from attacks. The 61 tamper-proof on-chain transactions recorded across 15 rounds highlight the system’s scalability and reliability.
Technical Implementation
The BFL project is implemented in Python and structured into modular components to facilitate reproducibility. The codebase includes scripts for each phase of the framework, along with utilities for blockchain interaction and result visualization.
- flphase1.py: Implements the baseline federated learning loop using FedAvg, where five clients train a CNN on MNIST data and aggregate updates centrally.
- bflphase2.py: Integrates blockchain by deploying the ModelRegistry.sol smart contract on Ganache and logging model updates as immutable transactions.
- bflphase3.py: Combines differential privacy and trust scoring to achieve full security.
- blockchain.py: Handles Web3.py connections to interact with the Ethereum blockchain, including contract deployment and transaction submission. It ensures secure and verifiable logging of model updates.
- ModelRegistry.sol: The Solidity smart contract defines the structure for storing update hashes, client addresses, and timestamps.
The project also includes comprehensive documentation in projectreport.md and README.md, detailing the architecture, methodology, and results. The use of Ganache for local blockchain testing ensures accessibility without requiring external Ethereum infrastructure.
Limitations & Future Work
While the BFL framework demonstrates strong potential, several limitations are acknowledged. The current implementation uses a local Ethereum network (Ganache), which may not fully replicate the scalability challenges of a public blockchain. Additionally, the trust scoring mechanism relies on cosine similarity, which may not generalize to all types of poisoning attacks or complex model architectures.
Another direction is extending BFL to heterogeneous data distributions, where clients may have non-IID (independent and identically distributed) data. This would require adaptive aggregation techniques to maintain model convergence.
