Skip to content

KhotSaprem/FDPR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Enhanced Federated Learning Platform with On-Chain Aggregation

A comprehensive blockchain-enabled federated learning platform with real ML algorithms, complete on-chain aggregation, and production-ready features.

🌟 Key Enhancements

βœ… Fully On-Chain Federated Aggregation

  • Complete aggregation results stored on blockchain with participant weights
  • Real-time blockchain event monitoring and updates
  • Automatic aggregation triggering when threshold is met
  • Cryptographic verification of all aggregation results

βœ… Real ML Engine with TensorFlow.js

  • Actual neural networks, linear regression, and decision trees
  • Real model training with gradient descent and backpropagation
  • Comprehensive model evaluation with precision, recall, F1-score
  • Federated averaging with mathematically correct weight aggregation

βœ… Production-Ready Blockchain Integration

  • Real contract calls with proper gas estimation and monitoring
  • Comprehensive error handling with user-friendly messages
  • Network switching and connection management
  • Transaction monitoring with retry mechanisms

βœ… Advanced Model Optimizer

  • Real hyperparameter optimization with grid search
  • Working model selector with actual model data
  • Model storage with IPFS integration
  • Differential privacy with mathematically correct mechanisms

πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Frontend (React + Vite)                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚   Model         β”‚  β”‚   Federated     β”‚  β”‚  Dashboard   β”‚ β”‚
β”‚  β”‚   Optimizer     β”‚  β”‚   Aggregation   β”‚  β”‚  Analytics   β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    ML Engine (TensorFlow.js)                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚   Blockchain    β”‚  β”‚      IPFS       β”‚  β”‚   Firebase   β”‚ β”‚
β”‚  β”‚   Service       β”‚  β”‚    Service      β”‚  β”‚   (Cache)    β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚              Enhanced Smart Contract (Sepolia)              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  1. Node.js (v18 or higher)
  2. MetaMask browser extension
  3. Sepolia testnet ETH (get from faucet)

Installation

# Clone the repository
git clone <repository-url>
cd Noice/frontend

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env
# Edit .env with your configuration

Environment Configuration

Update frontend/.env:

# Firebase Config
VITE_FIREBASE_API_KEY=your_firebase_api_key
VITE_FIREBASE_PROJECT_ID=your_project_id
# ... other Firebase config

# Enhanced Contract Address (Deploy FederatedAggregationRegistry.sol)
VITE_FEDERATED_CONTRACT_ADDRESS=0x1234567890123456789012345678901234567890

# IPFS Config
VITE_IPFS_GATEWAY=https://ipfs.io/ipfs/
VITE_IPFS_API_URL=https://api.pinata.cloud/pinning/pinFileToIPFS

# ML Engine Config
VITE_ML_BACKEND=tensorflow
VITE_MAX_MODEL_SIZE=50000000
VITE_DEFAULT_BATCH_SIZE=32

Smart Contract Deployment

  1. Deploy Enhanced Contract:

    # Use Thirdweb Dashboard or Remix IDE
    # Deploy: src/contracts/FederatedAggregationRegistry.sol
    # Network: Sepolia Testnet
  2. Update Contract Address:

    # Update VITE_FEDERATED_CONTRACT_ADDRESS in .env

Run the Application

# Start development server
npm run dev

# Build for production
npm run build

πŸ”§ Key Features

1. Enhanced Smart Contract

File: src/contracts/FederatedAggregationRegistry.sol

  • Complete on-chain aggregation result storage
  • Participant weight tracking and management
  • Automatic aggregation triggering
  • Organization registration and management
  • Event emissions for real-time monitoring

2. Real ML Engine

File: src/lib/realMLEngine.js

  • Neural Networks: Multi-layer perceptrons with dropout and regularization
  • Linear Regression: With L2 regularization and proper optimization
  • Logistic Regression: Binary and multi-class classification
  • Decision Trees: Neural network approximation with tree-like structure
  • Federated Averaging: Mathematically correct weight aggregation
  • Model Evaluation: Comprehensive metrics (accuracy, precision, recall, F1)

3. Blockchain Service

File: src/lib/realBlockchainService.js

  • Real contract interactions with gas estimation
  • Transaction monitoring and retry mechanisms
  • Network switching and error handling
  • Event listening for real-time updates
  • Comprehensive error messages and recovery

4. Model Optimizer

File: src/components/ModelOptimizer.jsx

  • Real hyperparameter optimization with grid search
  • Working model selector with actual model data
  • Model storage with metadata and versioning
  • Differential privacy integration
  • Performance evaluation and comparison

5. Federated Aggregation Interface

File: src/components/FederatedAggregationInterface.jsx

  • Real blockchain integration for round management
  • Automatic aggregation triggering
  • Participant weight calculation
  • IPFS model storage integration
  • Real-time status monitoring

6. Enhanced Dashboard

File: src/pages/Dashboard.jsx

  • Real-time blockchain data integration
  • Event-driven updates
  • Comprehensive analytics and metrics
  • On-chain verification status
  • Performance monitoring

πŸ“Š Usage Guide

1. Starting a Federated Learning Round

  1. Navigate to Federated Aggregation page
  2. Configure round parameters:
    • Minimum participants: 2-10
    • Maximum participants: 10-100
    • Duration: 1-24 hours
    • Aggregation threshold: 50-100%
  3. Click Start New Round
  4. Approve MetaMask transaction

2. Optimizing Models

  1. Navigate to Model Optimizer page
  2. Select ML algorithm (Neural Network, Linear Regression, etc.)
  3. Configure hyperparameters to test
  4. Set privacy parameters if needed
  5. Click Start Optimization
  6. Review results and apply best configuration

3. Submitting Model Updates

  1. Navigate to Submit Update page
  2. Enter model parameters and metrics
  3. Configure privacy settings
  4. Submit update (stored on blockchain)
  5. Monitor aggregation progress

4. Monitoring Progress

  1. Navigate to Dashboard
  2. View real-time metrics and statistics
  3. Monitor blockchain verification status
  4. Analyze trends and performance

πŸ”’ Security Features

Differential Privacy

  • Laplace and Gaussian noise mechanisms
  • Configurable privacy budgets (epsilon)
  • Automatic noise application to model updates

Blockchain Security

  • Immutable aggregation results
  • Cryptographic hash verification
  • Organization-based access control
  • Event-driven audit trails

Error Handling

  • Comprehensive error messages
  • Recovery action suggestions
  • Automatic retry mechanisms
  • Graceful fallback to cached data

πŸ§ͺ Testing

Unit Tests

# Run ML engine tests
npm test src/lib/realMLEngine.test.js

# Run blockchain service tests
npm test src/lib/realBlockchainService.test.js

Integration Tests

# Test complete federated learning workflow
npm test src/integration/federatedLearning.test.js

Manual Testing

  1. Model Training: Test with different algorithms and datasets
  2. Blockchain Integration: Test with real Sepolia transactions
  3. Error Scenarios: Test network failures and recovery
  4. Performance: Test with large models and datasets

πŸš€ Deployment

Frontend Deployment

Vercel (Recommended):

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel --prod

# Set environment variables in Vercel dashboard

Netlify:

# Build the project
npm run build

# Deploy dist/ folder to Netlify

Smart Contract Deployment

  1. Using Thirdweb Dashboard:

  2. Using Remix IDE:

πŸ“ˆ Performance Optimizations

ML Engine

  • Tensor memory management and cleanup
  • Batch processing for large datasets
  • Model compression and quantization
  • Efficient weight serialization

Blockchain

  • Gas optimization with batched operations
  • Transaction queuing and retry logic
  • Event filtering and caching
  • Connection pooling

Frontend

  • Code splitting and lazy loading
  • Component memoization
  • Virtual scrolling for large lists
  • Optimistic UI updates

πŸ› Troubleshooting

Common Issues

  1. MetaMask Connection:

    • Ensure MetaMask is installed and unlocked
    • Switch to Sepolia testnet
    • Add test ETH from faucet
  2. Contract Deployment:

    • Verify contract address in .env
    • Check network configuration
    • Ensure sufficient gas for deployment
  3. ML Training Errors:

    • Check browser memory usage
    • Reduce batch size or model complexity
    • Verify data format and dimensions
  4. IPFS Storage:

    • Configure IPFS gateway URL
    • Check network connectivity
    • Verify API credentials

Debug Mode

# Enable debug logging
VITE_DEBUG=true npm run dev

# Check browser console for detailed logs

🀝 Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • TensorFlow.js for ML capabilities
  • Ethereum for blockchain infrastructure
  • Firebase for data storage and caching
  • React and Vite for frontend framework
  • Tailwind CSS for styling
  • Framer Motion for animations

🎯 Next Steps

Immediate Improvements

  • Add more ML algorithms (Random Forest, SVM)
  • Implement secure aggregation protocols
  • Add model versioning and lineage tracking
  • Create mobile-responsive design

Advanced Features

  • Multi-chain support (Polygon, Arbitrum)
  • Advanced privacy mechanisms (homomorphic encryption)
  • Automated model deployment pipelines
  • Integration with popular ML frameworks

Production Readiness

  • Comprehensive test suite
  • Performance monitoring and alerting
  • Automated deployment pipelines
  • Documentation and tutorials

Built with ❀️ for the federated learning community

About

FedretedDPRegistry

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors