PEAFOWL ๆฏไธไธชไธบๅ็ด่้ฆๅญฆไน ่ฎพ่ฎก็้็งไฟๆคๅฎไฝๅฏน้ฝๅ่ฎฎๆกๆถใๅฎๅ ่ฎธไธๅๆฐๆฎๆนๅจไธๆณ้ฒๅ่ชๆฐๆฎ็ๆ ๅตไธ๏ผๅฎๅ จๅฐๆพๅบๅ ฑๅๆ ทๆฌ๏ผไบค้๏ผ๏ผๅนถๅบไบๅฏน้ฝๅ็ๆฐๆฎ่ๅ่ฎญ็ปๆบๅจๅญฆไน ๆจกๅใ
- ้็งไฟๆค๏ผไฝฟ็จๅ ๆณ็งๅฏๅ ฑไบซใไผช้ๆบๅฝๆฐใๅฏ้ฅๅๆไผช้ๆบ็ๆๅจ็ญๅฏ็ ๅญฆๆๆฏ๏ผ็กฎไฟไบค้ไฟกๆฏไธ่ขซๆณ้ฒ
- ้ซๆๅ่ฎฎ๏ผ้ไฟกๅ่ฎก็ฎๅคๆๅบฆไธบ็บฟๆง็บงๅซ O(n)๏ผ้ๅๅคง่งๆจกๆฐๆฎ้
- ๅคๆนๆฏๆ๏ผๆฏๆๅคไธชๆฐๆฎๅไธๆน็ๅฎไฝๅฏน้ฝ
- ็ตๆดปๆจกๅ๏ผๆฏๆ้ป่พๅๅฝใCNNใSVM็ญๅค็งๆบๅจๅญฆไน ๆจกๅ
PEAFOWL ๅ่ฎฎ็ๆ ธๅฟๆๆณๆฏ้่ฟ**็ฝฎๆข๏ผPermutation๏ผๅ็งๅฏๅ ฑไบซ๏ผSecret Sharing๏ผ**ๆฅๅฎ็ฐๅฎๅ จๅฏน้ฝ๏ผ
- ๅฎไฝๅฏน้ฝ๏ผๅๆนๅ ๅฏ่ชๅทฑ็ๆ ทๆฌIDๅนถๅ้็ปๆๅกๅจ๏ผๆๅกๅจ่ฎก็ฎไบค้ๅคงๅฐ๏ผไฝไธ็ฅ้ๅ ทไฝไบค้ID
- ็นๅพ็ปๅ๏ผๅๆนๅบไบไบค้ๆ ทๆฌ๏ผไฝฟ็จPEAFOWLๅ่ฎฎ็ปๅๅ่ช็็นๅพ
- ๅฎๅ จ่ฎก็ฎ๏ผ้่ฟ็งๅฏๅ ฑไบซๅSHPRG๏ผๅฏ้ฅๅๆไผช้ๆบ็ๆๅจ๏ผๆททๆท็นๅพๅผ๏ผ็กฎไฟๆๅกๅจๆ ๆณ่ทๅๅๅงๆฐๆฎ
peafowl-python/
โโโ core/ # ๅบ็กๅฏ็ ๅญฆๅ่ฏญ
โ โโโ secret_sharing.py # ๅ ๆณ็งๅฏๅ
ฑไบซ
โ โโโ prf.py # ไผช้ๆบๅฝๆฐ๏ผๅบไบHMAC-SHA256๏ผ
โ โโโ shprg.py # ๅฏ้ฅๅๆไผช้ๆบ็ๆๅจ๏ผๅบไบLWR๏ผ
โ โโโ ot.py # ไธ็ปๆไผ ่พๆฉๅฑ
โ โโโ polynomial.py # ๅค้กนๅผ่ฟ็ฎ๏ผๆๆ ผๆๆฅๆๅผ๏ผ
โโโ protocol/ # PEAFOWLๅ่ฎฎๅฎ็ฐ
โ โโโ przs.py # ไผช้ๆบ้ถๅ
ฑไบซ
โ โโโ peafowl.py # ไธปๅ่ฎฎ
โโโ party/ # ่ง่ฒๅฎ็ฐ
โ โโโ data_provider.py # ๆฐๆฎๆไพๆน
โ โโโ server.py # ไบๆๅกๅจ
โโโ network/ # ็ฝ็ปๆจกๆ
โ โโโ channel.py # ้ไฟก้้
โโโ utils/ # ๅทฅๅ
ทๅฝๆฐ
โ โโโ data_loader.py # ๆฐๆฎๅ ่ฝฝ
โโโ webapp/ # Webๅฏ่งๅๅบ็จ
โ โโโ app.py # Flaskๅ็ซฏๆๅก
โ โโโ templates/ # HTMLๆจกๆฟ
โ โ โโโ index.html # ไธป้กต้ข
โ โโโ static/ # ้ๆ่ตๆบ
โ โโโ style.css # ๆ ทๅผๆไปถ
โ โโโ script.js # ๅ็ซฏ่ๆฌ
โโโ tests/ # ๆต่ฏๆไปถ
โ โโโ test_core.py # ๆ ธๅฟๆจกๅๆต่ฏ
โ โโโ test_protocol.py # ๅ่ฎฎๆต่ฏ
โ โโโ test_end_to_end.py # ็ซฏๅฐ็ซฏๆต่ฏ
โ โโโ test_ml_comparison.py # ๆบๅจๅญฆไน ๅฏนๆฏๆต่ฏ
โ โโโ test_real_vertical_fl.py # ๅ็ด่้ฆๅญฆไน ๅบๆฏๆต่ฏ
โโโ develop.md # ๅผๅๆๆกฃ
โโโ README.md # ้กน็ฎ่ฏดๆ
- Python 3.8+
- TensorFlow (ๅฏ้๏ผ็จไบCNNๆต่ฏ)
- scikit-learn
- numpy
cd peafowl-python
pip install -r requirements.txt้กน็ฎๆไพไบ start.sh ่ๆฌ๏ผ่ชๅจๅฎๆ็ฏๅขๅๅงๅใไพ่ตๅฎ่ฃ
ใๆต่ฏ่ฟ่กๅ WebApp ๅฏๅจ๏ผ
chmod +x start.sh
./start.sh่ๆฌๅ่ฝ๏ผ
- ๆฃๆตๅนถๅๅปบ
.venv่ๆ็ฏๅข - ไฝฟ็จๆธ
ๅๆบๅฎ่ฃ
requirements.txtไธญ็ไพ่ต - ่ฟ่กๆๆๅๅ ๆต่ฏ
- ๆต่ฏ้่ฟๅ่ชๅจๅฏๅจ WebApp ๆๅก
source .venv/bin/activate# ่ฟ่กๆๆๅๅ
ๆต่ฏ
python -m pytest tests/ -v
# ่ฟ่กๅ็ด่้ฆๅญฆไน ๅบๆฏๆต่ฏ
python tests/test_real_vertical_fl.py
# ่ฟ่กๆบๅจๅญฆไน ๅฏนๆฏๆต่ฏ
python tests/test_ml_comparison.pyPEAFOWL ๆไพไบไธไธชไบคไบๅผ Web ๅบ็จ๏ผ็จไบๅฏ่งๅๅฑ็คบๅ่ฎฎๆต็จๅ่ฎญ็ป็ปๆใ
cd peafowl-python/webapp
python app.pyๆๅกๅฏๅจๅ๏ผ่ฎฟ้ฎ http://localhost:5000 ๅณๅฏไฝฟ็จใ
| ๆจกๅ | ่ฏดๆ |
|---|---|
| ้กน็ฎๆฆ่ง | PEAFOWL ้กน็ฎไป็ปใๆ ธๅฟ็นๆงใๆๆฏๅ็ |
| ๅ่ฎฎๆผ็คบ | ้ ็ฝฎๅไธๆนๆฐ้๏ผ่ฟ่ก PEAFOWL ๅ่ฎฎๅนถๆฅ็ๅฎๆถๆต็จๅฏ่งๅ |
| ๅฏ็ ๅญฆๅ็ | ๅฑ็คบๅ ๆณ็งๅฏๅ ฑไบซใPRFใSHPRGใ็ฝฎๆขๅ ฑไบซ็ญๅฏ็ ๅญฆๅ่ฏญ็ๅ็ๅ็คบไพ |
| ๅๆญฅๆต็จ | ่ฏฆ็ปๅฑ็คบ PEAFOWL ๅ่ฎฎ็ 7 ไธช้ถๆฎต๏ผๆฐๆฎๅๅคใIDๅ ๅฏใไบค้่ฎก็ฎใ็นๅพๅฏน้ฝใ็งๅฏๅ ฑไบซใ็นๅพๆททๆทใ็ปๆ่พๅบ๏ผ |
| MNIST่ฎญ็ป | ไฝฟ็จ็ๅฎ MNIST ๆๅๆฐๅญๆฐๆฎ้่ฟ่กๅ็ด่้ฆๅญฆไน ่ฎญ็ป๏ผๆฏๆ CNN ๅ Logistic Regression ๆจกๅ |
- ๆฏๆ้ๆฉๅไธๆนๆฐ้๏ผ2-10ไธช๏ผ
- ๆฏๆ้ๆฉๆจกๅ็ฑปๅ๏ผCNN๏ผๅท็งฏ็ฅ็ป็ฝ็ป๏ผๆ Logistic Regression
- ๅฑ็คบๆฐๆฎๅฏน้ฝไฟกๆฏใๆจกๅ่ฎญ็ป็ปๆ
- ๅฏ่งๅๅฑ็คบ๏ผๆญฃ็กฎๅ็ฑปๅ้่ฏฏๅ็ฑป็ๆๅๆฐๅญๆ ทๆฌ๏ผๆพ็คบ็ๅฎๆ ็ญพใ้ขๆตๆ ็ญพๅ็ฝฎไฟกๅบฆ
| ๆฅๅฃ | ๆนๆณ | ่ฏดๆ |
|---|---|---|
/api/generate_data |
POST | ็ๆ MNIST ๅ็ด่้ฆๅญฆไน ๆฐๆฎๅนถ่ฟ่กๅ่ฎฎ |
/api/step_by_step |
POST | ๅๆญฅๅฑ็คบๅ่ฎฎๆต็จ |
/api/cryptography_details |
POST | ่ทๅๅฏ็ ๅญฆๅ่ฏญ่ฏฆๆ |
/api/train_mnist |
POST | ่ฟ่ก MNIST ่ฎญ็ป๏ผๆฏๆ CNN๏ผ |
from protocol.peafowl import PEAFOWL
from party.data_provider import DataProvider
from party.server import Server
# ้
็ฝฎ
config = {
'num_parties': 3,
'num_samples': 1000,
'num_features': 100,
'secret_modulus': 2**64,
'precision_bits': 16,
}
# ๅๅปบๆฐๆฎๆไพๆน
data_providers = []
for i in range(num_parties):
dp = DataProvider(f"P{i}", config, sample_ids[i], features[i])
dp.prf_key = b'0' * 16
data_providers.append(dp)
# ๅๅปบๆๅกๅจ
server = Server("S", config)
# ่ฟ่กPEAFOWLๅ่ฎฎ
peafowl = PEAFOWL(config)
aligned_features = peafowl.run_protocol(data_providers, server)
# ไฝฟ็จๅฏน้ฝๅ็็นๅพ่ฟ่ก่ฎญ็ป
# ...| ๅไธๆนๆฐ | ๆ ทๆฌๆฐ | ็นๅพๆฐ | ๅฏน้ฝๅๆ ทๆฌๆฐ | ้ป่พๅๅฝๅ็กฎ็ | CNNๅ็กฎ็ |
|---|---|---|---|---|---|
| 2 | [400, 350] | [150, 140] | 280 | 80.36% | 73.21% |
| 3 | [400, 350, 300] | [150, 140, 130] | 188 | 65.79% | 60.53% |
| 4 | [400, 350, 300, 250] | [150, 140, 130, 120] | 106 | 63.64% | 54.55% |
ไฝฟ็จๅ ๆณ็งๅฏๅ ฑไบซๅฐๆฐๆฎๆๅไธบๅคไธชไปฝ้ข๏ผๅชๆๆๆไปฝ้ข็ธๅ ๆ่ฝๆขๅคๅๅงๆฐๆฎใ
from core.secret_sharing import share, reconstruct
# ๅไบซ
shares = share(secret=42, n=3, modulus=2**64)
# ้ๅปบ
reconstructed = reconstruct(shares, modulus=2**64)ๅบไบHMAC-SHA256ๅฎ็ฐ๏ผ็จไบๅฎๅ จๅฐๅ ๅฏๆ ทๆฌIDใ
from core.prf import PRF
prf = PRF(key=b'0' * 16)
encrypted = prf.eval(b'sample_id')ๅบไบLWR๏ผLearning With Errors๏ผ้ฎ้ขๅฎ็ฐ๏ผๆฏๆๅฏ้ฅๅๆ่ฟ็ฎใ
from core.shprg import SHPRG
shprg = SHPRG(d=8, m=1024, q=2**128, p=2**64)
output = shprg.generate(seed=[1, 2, 3, 4, 5, 6, 7, 8])ๆฌ้กน็ฎไป ็จไบๅญฆๆฏ็ ็ฉถๅๆๅญฆ็ฎ็ใ
PEAFOWL is a privacy-preserving entity alignment protocol framework designed for vertical federated learning. It allows different data parties to securely find common samples (intersection) without exposing their respective data, and jointly train machine learning models based on the aligned data.
- Privacy Preservation: Uses cryptographic techniques including additive secret sharing, pseudo-random functions, and key-homomorphic pseudo-random generators to protect intersection information
- Efficient Protocol: Linear complexity O(n) for communication and computation, suitable for large-scale datasets
- Multi-Party Support: Supports entity alignment with multiple data parties
- Flexible Models: Supports various machine learning models including logistic regression, CNN, SVM, etc.
The core idea of the PEAFOWL protocol is to achieve secure alignment through permutation and secret sharing:
- Entity Alignment: Each party encrypts their sample IDs and sends them to the server, which computes the intersection size without knowing the specific intersection IDs
- Feature Combination: Based on the intersection samples, parties combine their features using the PEAFOWL protocol
- Secure Computation: Features are obfuscated through secret sharing and SHPRG (Key-Homomorphic Pseudo-Random Generator) to ensure the server cannot access raw data
peafowl-python/
โโโ core/ # Core cryptographic primitives
โ โโโ secret_sharing.py # Additive secret sharing
โ โโโ prf.py # Pseudo-random function (based on HMAC-SHA256)
โ โโโ shprg.py # Key-homomorphic PRG (based on LWR)
โ โโโ ot.py # Oblivious transfer extension
โ โโโ polynomial.py # Polynomial operations (Lagrange interpolation)
โโโ protocol/ # PEAFOWL protocol implementation
โ โโโ przs.py # Pseudo-random zero sharing
โ โโโ peafowl.py # Main protocol
โโโ party/ # Party implementations
โ โโโ data_provider.py # Data provider party
โ โโโ server.py # Cloud server
โโโ network/ # Network simulation
โ โโโ channel.py # Communication channel
โโโ utils/ # Utility functions
โ โโโ data_loader.py # Data loading
โโโ webapp/ # Web visualization application
โ โโโ app.py # Flask backend service
โ โโโ templates/ # HTML templates
โ โ โโโ index.html # Main page
โ โโโ static/ # Static resources
โ โโโ style.css # Stylesheet
โ โโโ script.js # Frontend script
โโโ tests/ # Test files
โ โโโ test_core.py # Core module tests
โ โโโ test_protocol.py # Protocol tests
โ โโโ test_end_to_end.py # End-to-end tests
โ โโโ test_ml_comparison.py # ML comparison tests
โ โโโ test_real_vertical_fl.py # Real vertical FL scenario tests
โโโ develop.md # Development documentation
โโโ README.md # Project README
- Python 3.8+
- TensorFlow (optional, for CNN testing)
- scikit-learn
- numpy
cd peafowl-python
pip install -r requirements.txtThe project provides start.sh script to automatically complete environment initialization, dependency installation, test running, and WebApp startup:
chmod +x start.sh
./start.shScript features:
- Detects and creates
.venvvirtual environment - Installs dependencies from
requirements.txtusing Tsinghua mirror - Runs all unit tests
- Automatically starts WebApp service after tests pass
# Run all unit tests
python -m pytest tests/ -v
# Run vertical federated learning scenario tests
python tests/test_real_vertical_fl.py
# Run ML comparison tests
python tests/test_ml_comparison.pyPEAFOWL provides an interactive web application for visualizing protocol workflows and training results.
cd peafowl-python/webapp
python app.pyAfter the service starts, visit http://localhost:5000 to use the application.
| Module | Description |
|---|---|
| Overview | PEAFOWL project introduction, core features, technical principles |
| Protocol Demo | Configure number of parties, run PEAFOWL protocol with real-time visualization |
| Cryptography | Demonstrate cryptographic primitives including additive secret sharing, PRF, SHPRG, permutation sharing |
| Step-by-Step | Detailed 7-stage protocol walkthrough (Data Preparation, ID Encryption, Intersection Computation, Feature Alignment, Secret Sharing, Feature Obfuscation, Result Output) |
| MNIST Training | Train vertical federated learning models on real MNIST handwritten digit dataset, supports CNN and Logistic Regression |
- Configurable number of parties (2-10)
- Model selection: CNN (Convolutional Neural Network) or Logistic Regression
- Display data alignment info and model training results
- Visualization: Correctly and incorrectly classified handwritten digit samples with true labels, predicted labels, and confidence scores
| Endpoint | Method | Description |
|---|---|---|
/api/generate_data |
POST | Generate MNIST vertical FL data and run protocol |
/api/step_by_step |
POST | Step-by-step protocol demonstration |
/api/cryptography_details |
POST | Get cryptographic primitive details |
/api/train_mnist |
POST | Run MNIST training (supports CNN) |
from protocol.peafowl import PEAFOWL
from party.data_provider import DataProvider
from party.server import Server
# Configuration
config = {
'num_parties': 3,
'num_samples': 1000,
'num_features': 100,
'secret_modulus': 2**64,
'precision_bits': 16,
}
# Create data providers
data_providers = []
for i in range(num_parties):
dp = DataProvider(f"P{i}", config, sample_ids[i], features[i])
dp.prf_key = b'0' * 16
data_providers.append(dp)
# Create server
server = Server("S", config)
# Run PEAFOWL protocol
peafowl = PEAFOWL(config)
aligned_features = peafowl.run_protocol(data_providers, server)
# Train model with aligned features
# ...| Parties | Samples | Features | Aligned Samples | LR Accuracy | CNN Accuracy |
|---|---|---|---|---|---|
| 2 | [400, 350] | [150, 140] | 280 | 80.36% | 73.21% |
| 3 | [400, 350, 300] | [150, 140, 130] | 188 | 65.79% | 60.53% |
| 4 | [400, 350, 300, 250] | [150, 140, 130, 120] | 106 | 63.64% | 54.55% |
Additive secret sharing splits data into multiple shares, where all shares must be combined to reconstruct the original data.
from core.secret_sharing import share, reconstruct
# Share
shares = share(secret=42, n=3, modulus=2**64)
# Reconstruct
reconstructed = reconstruct(shares, modulus=2**64)Based on HMAC-SHA256, used for securely encrypting sample IDs.
from core.prf import PRF
prf = PRF(key=b'0' * 16)
encrypted = prf.eval(b'sample_id')Based on the LWR (Learning With Errors) problem, supporting key-homomorphic operations.
from core.shprg import SHPRG
shprg = SHPRG(d=8, m=1024, q=2**128, p=2**64)
output = shprg.generate(seed=[1, 2, 3, 4, 5, 6, 7, 8])This project is for academic research and educational purposes only.