Zero-Knowledge Email Threat Detection with Blockchain Verification
A decentralized email security system that analyzes emails for phishing, spam, and malware threats, then submits cryptographic proofs to the Solana blockchain for transparent, tamper-proof reputation tracking.
- Overview
- Features
- Architecture
- Tech Stack
- Prerequisites
- Installation
- Configuration
- Usage
- Project Structure
- How It Works
- Smart Contract
- Development
- Testing
- Deployment
- Troubleshooting
- Contributing
- License
ZK Email Guardian is a privacy-preserving email security platform that combines:
- ๐ง Mailchain Integration: Decentralized email infrastructure
- ๐ Zero-Knowledge Proofs: Privacy-preserving verification without revealing email content
- โ๏ธ Blockchain Verification: Immutable proof storage on Solana
- ๐ Sender Reputation System: Trust scores based on historical behavior
Traditional email security systems:
- โ Require trusting centralized providers with your data
- โ Lack transparency in threat detection
- โ Have no verifiable reputation system
- โ Can't prove detection accuracy
ZK Email Guardian solves these problems by:
- โ Keeping emails private with zero-knowledge proofs
- โ Storing threat detection on an immutable blockchain
- โ Building transparent sender reputation scores
- โ Enabling community-driven threat intelligence
- ๐ Zero-Knowledge Proofs: Detect threats without revealing email content
- ๐ Decentralized Email: Integration with Mailchain for Web3 email
- ๐ง Threat Detection Engine: Analyzes emails for:
- Phishing attempts
- Spam content
- Malware indicators
- Social engineering attacks
- โ๏ธ Blockchain Verification: Submit proofs to Solana for transparency
- ๐ Sender Reputation: Track trust scores based on historical proofs
- ๐ฑ Modern Dashboard: React-based UI with real-time analysis
- ๐ Client-side email analysis (no server access to content)
- ๐ฏ Keyword-based threat detection
- ๐ Suspicious URL scanning
- ๐ Attachment risk assessment
- โก Real-time threat scoring
- ๐ฌ Inbox view with threat badges
- ๐ Threat analytics dashboard
- ๐ Detailed threat analysis per email
- ๐ผ Wallet integration (Phantom)
- ๐ Multi-account support
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ USER โ
โ (Phantom Wallet) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ REACT DASHBOARD โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โ โ Inbox Page โ โ Analysis Pageโ โ Reputation โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ
โโโโโโโโโฌโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ Mailchain โ โ Analyzer โ โ Reputation โ
โ Service โ โ Engine โ โ Engine โ
โโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโโ โโโโโโโโฌโโโโโโโโ
โ โ โ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Solana Blockchain โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ZK Email Guardian Program (Rust) โ โ
โ โ - Store Proofs โ โ
โ โ - Track Reputation โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Solana: High-performance blockchain for proof storage
- Anchor Framework: Rust framework for Solana programs
- Solana Web3.js: JavaScript SDK for blockchain interaction
- React 18: Modern UI framework
- TypeScript: Type-safe development
- TailwindCSS: Utility-first styling
- React Router: Client-side routing
- Mailchain SDK: Decentralized email protocol
- Custom Threat Detector: Keyword and pattern matching
- Crypto (Node.js): SHA-256 hashing for proofs
- Anchor CLI: Solana program development
- Node.js: JavaScript runtime
- npm/yarn: Package management
Before you begin, ensure you have:
- Node.js v18+ and npm/yarn
- Rust v1.70+ (for Solana program)
- Solana CLI v1.17+
- Anchor CLI v0.29+
- Phantom Wallet browser extension
- Solana Devnet SOL (free from faucet)
Install Node.js
# Using nvm (recommended)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
nvm install 18
nvm use 18Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/envInstall Solana CLI
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
solana --versionInstall Anchor
cargo install --git https://github.com/coral-xyz/anchor --tag v0.29.0 anchor-cli
anchor --versionInstall Phantom Wallet
- Visit https://phantom.app/
- Install browser extension
- Create or import wallet
- Switch to Devnet in settings
git clone https://github.com/yourusername/zk-email-guardian.git
cd zk-email-guardian# Install root dependencies
npm install
# Install program dependencies
cd program
cargo build
# Install dashboard dependencies
cd ../dashboard
npm install
# Install service dependencies
cd ../mailchain-service
npm install
cd ../analyzer
npm install
cd ../reputation-engine
npm install# Build Solana program
anchor build
# Build TypeScript packages
npm run build:all# Generate a new keypair (or use existing)
solana-keygen new --outfile ~/.config/solana/id.json
# Configure Solana CLI for devnet
solana config set --url https://api.devnet.solana.com
# Airdrop SOL for testing
solana airdrop 2Create .env files in each service:
REACT_APP_MAILCHAIN_SECRET="your mailchain secret recovery phrase"
REACT_APP_SOLANA_RPC_URL="https://api.devnet.solana.com"
REACT_APP_PROGRAM_ID="your_deployed_program_id"MAILCHAIN_SECRET="your mailchain secret recovery phrase"- Visit https://mailchain.com/
- Create an account
- Generate a secret recovery phrase
- Add to
.envfiles
# Build the program
anchor build
# Deploy to devnet
anchor deploy --provider.cluster devnet
# Copy the Program ID
# Update REACT_APP_PROGRAM_ID in dashboard/.env# Terminal 1: Start the dashboard
cd dashboard
npm start
# Terminal 2: Start the analyzer service (if separate)
cd analyzer
npm run devOpen your browser and navigate to:
http://localhost:3000
- Click "Connect Wallet" in the top-right
- Approve connection in Phantom
- Ensure you're on Solana Devnet
- Get devnet SOL if needed: https://faucet.solana.com/
- View your Mailchain emails
- See threat badges on suspicious emails
- Filter by: All, Safe, Threats
- Click any email to view details
- View threat statistics
- See breakdown by threat level (Critical, High, Medium, Low)
- See breakdown by threat type (Phishing, Spam, Malware, Social Engineering)
- Submit proofs to blockchain
- Track submission status
- View sender trust scores
- See historical proof submissions
- Track sender behavior over time
zk-email-guardian/
โ
โโโ program/ # Solana smart contract
โ โโโ Cargo.toml
โ โโโ src/
โ โโโ lib.rs # Rust program logic
โ
โโโ client/ # Blockchain interaction
โ โโโ src/
โ โโโ index.ts # Solana client code
โ
โโโ mailchain-service/ # Email service
โ โโโ src/
โ โโโ mailchain-client.ts # Fetch emails from Mailchain
โ โโโ email-parser.ts # Parse email content
โ โโโ types.ts # Email interfaces
โ
โโโ analyzer/ # Threat detection
โ โโโ src/
โ โโโ detector.ts # Threat detection engine
โ โโโ keywords.json # Threat keywords database
โ โโโ scoring.ts # Calculate threat scores
โ โโโ proof-generator.ts # Generate ZK proofs
โ
โโโ reputation-engine/ # Sender reputation
โ โโโ src/
โ โโโ calculator.ts # Calculate trust scores
โ โโโ query-blockchain.ts # Fetch sender history
โ โโโ types.ts # Reputation interfaces
โ
โโโ dashboard/ # React UI
โ โโโ public/
โ โโโ src/
โ โโโ App.tsx # Main app component
โ โโโ pages/
โ โ โโโ InboxPage.tsx # Email inbox view
โ โ โโโ AnalysisPage.tsx # Threat analytics
โ โ โโโ ReputationPage.tsx # Sender scores
โ โโโ components/
โ โ โโโ EmailList.tsx # Email list component
โ โ โโโ ThreatBadge.tsx # Threat indicator
โ โ โโโ SenderCard.tsx # Sender display
โ โ โโโ WalletConnect.tsx # Wallet button
โ โโโ hooks/
โ โโโ useMailchain.ts # Mailchain integration
โ โโโ useAnalyzer.ts # Threat analysis
โ โโโ useSolana.ts # Blockchain interaction
โ โโโ useReputation.ts # Reputation queries
โ
โโโ Anchor.toml # Anchor configuration
โโโ package.json # Root package config
โโโ README.md # This file
// User opens dashboard
โ Mailchain SDK fetches inbox
โ Emails displayed in UI// For each email:
โ Extract content, subject, sender
โ Scan for threat keywords
โ Analyze URLs and attachments
โ Calculate threat score
โ Assign threat level (Safe/Low/Medium/High/Critical)// If email is malicious:
โ Hash email content (SHA-256)
โ Generate proof data (256 bytes)
โ Include threat metadata
โ Create ZKProof object// Submit to Solana:
โ Connect Phantom wallet
โ Find PDA for user's proof record
โ Serialize proof with Borsh
โ Add Anchor discriminator
โ Create transaction
โ Sign and submit
โ Wait for confirmation// Calculate sender reputation:
โ Query all proofs from sender
โ Count threat reports
โ Weight by threat severity
โ Calculate trust score (0-100)Program ID: G9DrkqHZj8LwKdTMtCwP9tdLBLf8ZegkwDWUA47wvZzQ
Network: Solana Devnet
Submit a zero-knowledge proof of email threat detection.
Parameters:
proof: Vec<u8>- Proof data (256 bytes)event_type: u8- Threat type (0=Phishing, 1=Spam, 2=Malware, 3=Social Engineering)
Accounts:
record: PDA account storing proof (writable)user: Signer submitting proof (writable, signer)system_program: System program for account creation
Storage:
pub struct ProofRecord {
pub proof: Vec<u8>, // Proof bytes
pub event_type: u8, // Threat category
pub timestamp: i64, // Unix timestamp
}import { Connection, PublicKey } from '@solana/web3.js';
const connection = new Connection('https://api.devnet.solana.com');
const programId = new PublicKey('G9DrkqHZj8LwKdTMtCwP9tdLBLf8ZegkwDWUA47wvZzQ');
// Find PDA for a user
const [proofPDA] = await PublicKey.findProgramAddress(
[Buffer.from('proof'), userPublicKey.toBuffer()],
programId
);
// Fetch proof record
const accountInfo = await connection.getAccountInfo(proofPDA);# Watch mode for TypeScript
npm run dev
# Start dashboard with hot reload
cd dashboard && npm start# Build all services
npm run build:all
# Build dashboard
cd dashboard && npm run build# Run Anchor tests
anchor test
# Run TypeScript tests
npm testThe Mailchain service provides mock emails if the API is unavailable:
// Mock emails include:
// 1. Welcome email (safe)
// 2. Phishing attempt (malicious)
// 3. Newsletter (safe)- Ensure you have devnet SOL (at least 0.01 SOL)
- Open
/analysispage - Click "Submit Proofs to Blockchain"
- Check console for transaction signature
- View on Solana Explorer: https://explorer.solana.com/
- Wallet connects successfully
- Emails load from Mailchain
- Threat detection analyzes emails
- Threat badges display correctly
- Analysis page shows statistics
- Proof submission succeeds
- Transaction confirms on blockchain
- Explorer shows transaction details
# Build optimized program
anchor build --verifiable
# Deploy to devnet
anchor deploy --provider.cluster devnet
# Deploy to mainnet (when ready)
anchor deploy --provider.cluster mainnetcd dashboard
vercel deploy --prodcd dashboard
npm run build
netlify deploy --prod --dir=buildcd dashboard
npm run build
ipfs add -r build/Wallet Connection Failed
Problem: Can't connect Phantom wallet
Solutions:
- Install Phantom extension
- Refresh the page
- Check if wallet is unlocked
- Switch to Devnet in Phantom settings
Transaction Failed: Insufficient Funds
Problem: Not enough SOL for transaction
Solutions:
# Get devnet SOL
solana airdrop 2
# Or visit faucet
https://faucet.solana.com/Error: Program Not Deployed
Problem: Program ID doesn't exist
Solutions:
# Redeploy program
anchor deploy --provider.cluster devnet
# Update .env with new Program IDMailchain Connection Error
Problem: Can't fetch emails
Solutions:
- Check
REACT_APP_MAILCHAIN_SECRETin.env - Verify secret recovery phrase is correct
- Check internet connection
- App will show mock data if Mailchain fails
Transaction Simulation Failed
Problem: Error code 0x65 (deserialization)
Solutions:
- Ensure
js-sha256is installed - Check proof data format
- Verify Borsh serialization
- Redeploy program if structure changed
Add to dashboard/src/hooks/useSolana.ts:
// Add detailed logging
console.log('๐ Proof bytes:', Array.from(proofBytes));
console.log('๐ Event type:', eventTypeByte);
console.log('๐ Discriminator:', discriminator.toString('hex'));We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Commit your changes
git commit -m "Add amazing feature" - Push to your branch
git push origin feature/amazing-feature
- Open a Pull Request
- Follow existing code style
- Add tests for new features
- Update documentation
- Keep commits atomic and well-described
This project is licensed under the MIT License.
MIT License
Copyright (c) 2025 ZK Email Guardian
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
- Solana Explorer: https://explorer.solana.com/
- Mailchain: https://mailchain.com/
- Phantom Wallet: https://phantom.app/
- Solana Docs: https://docs.solana.com/
- Basic threat detection
- Mailchain integration
- Solana proof storage
- React dashboard
- Integration with Triton VM for real ZK proofs
- Advanced ML-based threat detection
- Multi-signature proof verification
- Encrypted proof storage
- Community-driven threat database
- Sender reputation marketplace
- Threat intelligence sharing
- DAO governance
- Custom threat rules
- Bulk email analysis
- API for third-party integration
- White-label solution
Built with โค๏ธ using Solana, React, and Mailchain
โญ Star us on GitHub โ it helps!