A cutting-edge implementation of the research paper "Generating Privacy-Preserving Personalized Advice with Zero-Knowledge Proofs and LLMs" that combines zkVM technology with large language models to provide personalized advice while protecting user privacy.
This project implements the framework described in the paper that addresses the critical challenge of providing personalized LLM-based advice without compromising user privacy. The system uses Zero-Knowledge Proofs (ZKP) via zkVM to verify user traits without revealing sensitive information.
- Privacy-First Personalization: Generate personalized advice without exposing sensitive user data
- zkVM Integration: Uses RiscZero zkVM for practical zero-knowledge proof generation
- Two-Entity Architecture: Separates data holders from advice providers for enhanced privacy
- Advanced Prompting Strategy: Leverages both verifiable and unverifiable user traits
βββββββββββββββββββ ZK Proof + βββββββββββββββββββ
β Entity 1 β User Traits β Entity 2 β
β β βββββββββββββββββββΆβ β
β β’ User Data β β β’ LLM Advisor β
β β’ ZK Proof Gen β β β’ Advice Gen β
β β’ Trait Inferenceβ β β’ Proof Verify β
βββββββββββββββββββ βββββββββββββββββββ
zkVM Llama
-
Entity 1 (zkproof-service):
- Holds user data securely
- Generates zero-knowledge proofs of user traits
- Implements rule-based inference logic (e.g., financial risk assessment)
-
Entity 2 (llm-advisor):
- Provides LLM-based advice using Llama
- Verifies ZK proofs without accessing raw user data
- Implements advanced prompting strategies
-
Web Interface:
- User-friendly interface for interacting with the system
- Demonstrates the privacy-preserving advice generation
- Docker and Docker Compose
- NVIDIA GPU (A100 recommended) with CUDA support
- NVIDIA Container Runtime
- At least 32GB RAM (64GB+ recommended)
- Clone the repository:
git clone <repository-url>
cd PenguLLM- Download Llama model (you'll need access to Llama weights):
mkdir -p models
# Place your Llama model files in ./models/
# Example structure:
# models/
# βββ llama-3.1-70b/
# β βββ tokenizer.model
# β βββ consolidated.*.pth
# β βββ params.json- Start the system:
docker-compose up -d- Access the web interface:
http://localhost:3000
POST /generate-proof- Generate ZK proof for user traitsGET /verify-proof- Verify a generated proofPOST /infer-traits- Infer user traits from raw data
POST /advice- Get personalized advice with ZK proofPOST /chat- Interactive chat with privacy-preserving contextGET /health- Service health check
RUST_LOG=info # Logging level
RISC0_DEV_MODE=0 # Production mode for RiscZero
POSTGRES_URL=postgres://... # Database connection
REDIS_URL=redis://redis:6379 # Cache connectionMODEL_PATH=/app/models # Path to Llama model
ZKPROOF_SERVICE_URL=http://... # ZK proof service URL
CUDA_VISIBLE_DEVICES=0 # GPU device selection
MAX_CONTEXT_LENGTH=4096 # Maximum context for LLM
TEMPERATURE=0.7 # LLM sampling temperature- Minimum: 16 vCPU, 64GB RAM, 1x RTX 3090
- Recommended: 32 vCPU, 128GB RAM, 1x A100 (24GB)
- Optimal: 64 vCPU, 256GB RAM, 2x A100 (80GB)
Based on paper evaluation:
| Configuration | ZK Proof Generation | Verification | LLM Response |
|---|---|---|---|
| CPU Only | 67.8s | 0.02s | 2-5s |
| A100 GPU | 1.45s | 0.02s | 0.5-2s |
import requests
# Step 1: Submit user data to Entity 1
user_data = {
"age": 35,
"income": 75000,
"savings": 25000,
"has_mortgage": True,
"investment_experience": "intermediate",
"risk_questions": [1, 2, 1, 3, 2, 1, 2, 3, 1, 2] # 10 financial questions
}
# Generate ZK proof of risk tolerance
response = requests.post("http://localhost:8001/generate-proof", json={
"user_data": user_data,
"inference_type": "financial_risk"
})
proof_data = response.json()
# Returns: {"traits": "moderate_risk", "proof": "0x...", "verification_key": "..."}
# Step 2: Get personalized advice from Entity 2
advice_request = {
"query": "I want to invest $10,000. What should I do?",
"verified_traits": proof_data["traits"],
"proof": proof_data["proof"],
"verification_key": proof_data["verification_key"]
}
advice_response = requests.post("http://localhost:8002/advice", json=advice_request)
print(advice_response.json()["advice"])# Healthcare example with age/medical history verification
medical_data = {
"age": 45,
"symptoms": ["headache", "fatigue"],
"medical_history": ["hypertension"],
"medications": ["lisinopril"]
}
# Generate proof without revealing exact medical details
proof_response = requests.post("http://localhost:8001/generate-proof", json={
"user_data": medical_data,
"inference_type": "health_risk"
})
# Get health advice with verified traits
advice = requests.post("http://localhost:8002/advice", json={
"query": "Should I be concerned about my symptoms?",
"domain": "healthcare",
"verified_traits": proof_response.json()["traits"],
"proof": proof_response.json()["proof"]
})The system implements the Japanese Bankers Association risk assessment logic as a ZK circuit:
- Input Processing: Parse user responses in JSON format
- Hashing: Apply SHA-256 to question strings for integrity
- Scoring: Rule-based scoring algorithm
- Classification: Categorize into risk levels (Conservative, Steady Growth, Balanced, Aggressive)
- Proof Generation: Create ZK proof that traits were computed correctly
Implements the paper's two-phase prompting approach:
dβ: Unverifiable exploratory traits (e.g., user preferences)
dβ: Verifiable traits (proven via ZKP)
Context Generation:
cβ: Baseline (no emphasis)
cβ: Emphasize dβ (unverifiable traits)
cβ: Emphasize dβ (verifiable traits)
cβ: Moderate emphasis on dβ
Response Generation:
A_prop = LLM(Query, I_prop, c_prop) # Proposed answer
A_exp = LLM(Query, A_prop, I_exp, c_exp) # Explanation
- Zero-Knowledge: Raw user data never leaves Entity 1
- Verifiable Computation: Entity 2 can verify trait computation without seeing inputs
- Data Minimization: Only necessary abstracted traits are shared
- Cryptographic Security: Based on proven ZK-STARK/SNARK security assumptions
Run the test suite:
# Unit tests for ZK proof generation
cd entity1-zkproof && cargo test
# Integration tests for LLM advisor
cd entity2-llm && python -m pytest tests/
# End-to-end system tests
docker-compose exec zkproof-service ./run_tests.sh
docker-compose exec llm-advisor python test_integration.pyThe system includes comprehensive evaluation based on the paper's methodology:
- Proof generation time
- Verification time
- Memory usage
- Proof size
- Consistency between A_prop and A_exp
- Trait emphasis effectiveness
- Response relevance and accuracy
- Information leakage analysis
- Trait inference accuracy
- User acceptance studies
- Proof Integrity: All ZK proofs use cryptographically secure parameters
- Network Security: TLS encryption between all services
- Data Isolation: Strict separation between Entity 1 and Entity 2
- Audit Logging: Comprehensive logging without exposing sensitive data
- Rate Limiting: Protection against abuse and DoS attacks
Access monitoring dashboards:
- Grafana: http://localhost:3001 (performance metrics)
- Jaeger: http://localhost:16686 (distributed tracing)
- Logs:
docker-compose logs -f <service-name>
Key metrics monitored:
- ZK proof generation latency
- LLM inference time
- Memory and GPU utilization
- API request rates and errors
- Privacy compliance metrics
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Install development dependencies
./scripts/setup-dev.sh
# Run in development mode
docker-compose -f docker-compose.dev.yml up
# Format code
./scripts/format.sh
# Run security audit
./scripts/security-audit.shThis project is licensed under the MIT License - see the LICENSE file for details.
- Original Paper: "Generating Privacy-Preserving Personalized Advice with Zero-Knowledge Proofs and LLMs"
- RiscZero Documentation
- Llama Model Documentation
- Research by Hiroki Watanabe and Motonobu Uchikoshi at The Japan Research Institute
- RiscZero team for zkVM technology
- Meta AI for Llama models
- Open source community for supporting libraries
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: support@pengu-llm.com
Building the future of privacy-preserving AI, one proof at a time. π§π