This repository implements PoCL (Proof of Collaborative Learning), a novel blockchain consensus mechanism that replaces energy-intensive mining with federated learning. Instead of solving cryptographic puzzles, miners collaboratively train a global deep learning model, with winners selected based on model performance through a democratic voting system.
PoCL transforms blockchain mining from a wasteful competition into a productive collaboration where:
- π§ Miners train ML models instead of computing meaningless hashes
- π³οΈ Democratic voting determines winners based on model quality
- π Performance-based rewards incentivize honest participation
- π Global model improvement benefits all participants
Component | Purpose | Technology |
---|---|---|
Miners | Train models on local data, participate in consensus | Python + TensorFlow |
Blockchain Network | Immutable ledger for transactions and consensus | Hyperledger Fabric |
Express Applications | API gateway and process coordination | Node.js + Express |
Aggregator | Combine winning models using FedAvg | Python + Flask |
Chaincodes | Smart contracts for different system functions | JavaScript |
graph TD
A[Transaction Assignment] --> B[Local Model Training]
B --> C[Model Proposal + Test Data]
C --> D[Cross-Prediction Phase]
D --> E[Voting on Performance]
E --> F[Winner Selection]
F --> G[Model Aggregation]
G --> H[Reward Distribution]
H --> A
- Docker & Docker Compose: For Hyperledger Fabric network
- Node.js 16+: For Express applications
- Python 3.8+: For miners and aggregator
- TensorFlow 2.x: For deep learning models
-
Install Hyperledger Fabric
curl -sSL https://bit.ly/2ysbOFE | bash -s
-
Install Python Dependencies
pip install tensorflow flask requests numpy scikit-learn matplotlib
-
Install Node.js Dependencies
cd express-application npm install
-
Start the Complete System
python3 run.py
This automatically:
- Deploys the Hyperledger Fabric network
- Starts all Express applications
- Launches 10 miners
- Initializes the aggregator and submitter
- Begins federated learning rounds
-
Monitor Progress
# Real-time monitoring tail -f logs/*.txt # Check specific components tail -f logs/app1.txt # Admin coordination tail -f logs/miner1.txt # Individual miner tail -f logs/aggregator.txt # Model aggregation
-
Stop the System
python3 stop.py
Parameter | Value | Description |
---|---|---|
Miners | 10 | Number of federated learning participants |
Winners per Round | 5 | Top performers selected for rewards |
Total Rounds | 20 | Complete federated learning experiment |
Training Time | 3 minutes | Maximum time for local model training |
Prediction Time | 15 seconds | Time to predict on others' test data |
Voting Time | 15 seconds | Time to submit performance votes |
Dataset | CIFAR-10 | Image classification benchmark |
- Miners receive demo transactions to process
- Train global CNN model on local CIFAR-10 data partitions
- Submit trained model hash and test data samples
- Each miner receives test data from all other miners
- Make predictions using their trained model
- Submit predictions to blockchain
- Evaluate prediction accuracy on own test data
- Rank other miners based on accuracy and speed
- Submit democratic votes to blockchain
- Select top 5 miners based on vote aggregation
- Combine winning models using FedAvg algorithm
- Distribute rewards proportional to contribution
- Update global model for next round
βββ π clients/ # Federated learning participants
β βββ π miner/ # 10 individual miners + analysis tools
β βββ π aggregator/ # FedAvg model combination service
β βββ π global model/ # Shared CNN model architecture
β βββ π submitter/ # Transaction generation service
βββ π *-coin-transfer/ # Blockchain transaction chaincodes
β βββ π demo-coin-transfer/ # Demo transactions for mining
β βββ π main-coin-transfer/ # Main cryptocurrency operations
βββ π *-propose/ # Consensus mechanism chaincodes
β βββ π model-propose/ # Model submission handling
β βββ π prediction-propose/ # Cross-prediction management
β βββ π vote-assign/ # Democratic voting system
βββ π express-application/ # API gateways and coordination
βββ π test-network/ # Hyperledger Fabric blockchain
βββ π logs/ # Real-time system monitoring
βββ π results/ # Experimental results and analysis
βββ π figures/ # Architecture diagrams
βββ π run.py # Complete system startup
βββ π stop.py # Graceful system shutdown
- Byzantine Tolerance: Resilient to up to 1/3 malicious miners
- Democratic Voting: Equal voting weight prevents centralization
- Model Integrity: Cryptographic hash verification
- Transparent Auditing: All decisions recorded on immutable blockchain
- KNN Attack Detection: Identifies miners using simple algorithms instead of deep learning
- Vote Validation: Prevents invalid or duplicate votes
- Deadline Enforcement: Prevents unlimited computation time
- Performance Verification: Cross-validation ensures honest reporting
- Convergence: Models converge within 10-20 epochs per round
- Accuracy: Validation accuracy reaches 70-80% on CIFAR-10
- Efficiency: Complete consensus round in ~4 minutes
- Scalability: Successfully tested with 10 miners, extensible to more
- Participation: 90-100% miners participate in each round
- Fairness: Rewards distributed based on actual contribution
- Stability: Consistent winner selection across rounds
- Attack Resilience: 100% detection rate for adversarial miners
cd clients/miner
python3 training_results.py # Training performance plots
python3 datasize_winners.py # Data size vs winning analysis
Test system robustness against adversarial miners:
# In miner1.py and miner6.py, uncomment:
# self.model = KNNClassifier() # Instead of CNN training
- Heterogeneous Data: Miners have different amounts of training data
- Two Strategies: Decreasing vs grouped data distribution
- Impact Analysis: Correlation between data size and winning frequency
- Winner Count: Adjustable from 1 to 9 miners
- Voting Algorithms: Performance + speed vs accuracy-only
- Aggregation Methods: FedAvg vs other federated learning algorithms
To add more miners:
- Copy
miner1.py
tominer11.py
(or higher) - Add port 8010 to
app1.js
miners list - Update
run.py
to start the new miner - Adjust
total_miners
parameter in miner configuration
- Modify
app1.js
: Adjust timing, winner count, round number - Update
miner.py
: Change data distribution or model architecture - Configure
aggregator.py
: Implement different aggregation algorithms
- Federated Learning: Novel consensus mechanism research
- Blockchain: Energy-efficient mining alternatives
- Machine Learning: Collaborative training in adversarial environments
- Distributed Systems: Byzantine fault tolerance in ML systems
- Healthcare: Collaborative medical AI without data sharing
- Finance: Fraud detection across institutions
- IoT: Edge device collaboration for smart cities
- Privacy: Machine learning with preserved data locality
We welcome contributions! Please see our Contributing Guidelines for details on:
- Setting up development environment
- Code style and testing requirements
- Submitting pull requests
- Reporting issues and bugs
# Clone repository
git clone https://github.com/your-org/FL-Validated-Learning.git
cd FL-Validated-Learning
# Install development dependencies
pip install -r requirements-dev.txt
npm install --dev
# Run tests
python -m pytest tests/
npm test
If you use this work in your research, please cite our paper:
@inproceedings{sokhankhosh2024proof,
title={Proof-of-Collaborative-Learning: A Multi-winner Federated Learning Consensus Algorithm},
author={Sokhankhosh, Amirreza and Rouhani, Sara},
booktitle={2024 IEEE International Conference on Blockchain (Blockchain)},
pages={370--377},
year={2024},
organization={IEEE}
}
- π Documentation: Comprehensive README files in each directory
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π§ Contact: [email protected]
This project is licensed under the MIT License - see the LICENSE file for details.
β Star this repository if you find it useful for your research or projects!