Skip to content

zks-protocol/zks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

62 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” ZKS Protocol

Zero Knowledge Swarm โ€” Post-Quantum Encryption with Built-in Anonymity

Build Status Crates.io Docs License Rust

Linux macOS Windows WASM


๐ŸŒŸ Why ZKS?

ZKS Protocol is a post-quantum secure networking protocol with a memory-safe architecture built on high-assurance foundations. It provides defense-in-depth encryption with multiple layers of security, including 256-bit post-quantum computational security.

Protocol Description Security Model
zk:// Direct encrypted connection Post-quantum secure, low latency
zks:// Swarm-routed anonymous connection Post-quantum + onion routing

๐Ÿ“‘ Table of Contents


๐ŸŒŸ Key Features

๐Ÿ” Post-Quantum Cryptography

  • ML-KEM-1024 (Kyber) โ€” NIST Level 5 key exchange
  • ML-DSA-87 (Dilithium) โ€” NIST Level 5 signatures
  • Resistant to quantum computer attacks

๐Ÿง… Onion Routing

  • Multi-hop anonymous connections
  • Traffic analysis resistance
  • Built-in swarm networking

โšก High Performance

  • Async/await native design
  • Zero-copy message handling
  • Minimal memory footprint

๐ŸŒ Cross-Platform

  • Native Linux, macOS, Windows
  • WebAssembly for browsers
  • Mobile-ready architecture

๐Ÿ“ Mathematical Security Proof

ZKS Protocol's security is proven by mathematics, not assumptions:

Security Proof (Defense-in-Depth)

Hybrid Encryption (Network Mode):
  DEK โ† CSPRNG(32 bytes)              // Data Encryption Key
  entropy โ† drand โŠ• local_CSPRNG      // Computational security (256-bit)
  wrapped_DEK โ† DEK โŠ• entropy         // Defense-in-depth

Security Level: 256-bit post-quantum computational (OTP-inspired, not true OTP)

โˆด Secure against all known attacks including quantum computers โˆŽ

Security Properties

Property Guarantee
DEK wrapping Defense-in-depth (drand โŠ• CSPRNG)
Bulk encryption ChaCha20-Poly1305 (256-bit)
Overall security 256-bit post-quantum computational
Entropy source drand beacon + local CSPRNG

โš ๏ธ IMPORTANT: Network-mode entropy (drand + CSPRNG) provides 256-bit computational security, not information-theoretic security.

๐Ÿ“„ Full Security Documentation


๐Ÿš€ Quick Start

๐Ÿ“‹ Prerequisites

  • Rust 1.70+ toolchain
  • OpenSSL (for development)

๐Ÿ“ฅ Installation

Add to your Cargo.toml:

[dependencies]
zks_sdk = "0.1"
tokio = { version = "1", features = ["full"] }

๐Ÿ’ป Basic Connection (ZK://)

use zks_sdk::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Build a post-quantum secure connection
    let connection = ZkConnectionBuilder::new()
        .url("zk://secure-server.example.com:8443")
        .security(SecurityLevel::PostQuantum)
        .build()
        .await?;
    
    println!("โœ… Connected with post-quantum encryption!");
    
    // Send encrypted data
    connection.send(b"Hello, quantum-proof world!").await?;
    
    // Receive response
    let response = connection.recv().await?;
    println!("๐Ÿ“ฉ Received: {:?}", response);
    
    connection.close().await?;
    Ok(())
}

๐Ÿง… Anonymous Connection (ZKS://)

use zks_sdk::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Build an anonymous swarm-routed connection
    let connection = ZksConnectionBuilder::new()
        .url("zks://hidden-service.example.com:8443")
        .min_hops(3)  // Route through 3+ relay nodes
        .security(SecurityLevel::PostQuantum)
        .build()
        .await?;
    
    println!("๐Ÿง… Anonymous connection established!");
    println!("   Your IP is hidden from the destination server.");
    
    // Send anonymous message
    connection.send(b"Confidential message").await?;
    
    connection.close().await?;
    Ok(())
}

๐ŸŒ Browser (WebAssembly)

import init, { ZksWasmUtils } from 'zks-wasm';

await init();

// Generate post-quantum keypair
const keypair = ZksWasmUtils.generate_ml_dsa_keypair();
console.log("๐Ÿ”‘ Generated ML-DSA keypair");

// Sign a message
const message = new TextEncoder().encode("Hello from the browser!");
const signature = ZksWasmUtils.ml_dsa_sign(message, keypair.signing_key);
console.log("โœ๏ธ Signature created");

// Verify signature
const isValid = ZksWasmUtils.ml_dsa_verify(message, signature, keypair.verifying_key);
console.log("โœ… Signature valid:", isValid);

๐Ÿ”’ Security Architecture

๐Ÿ” Cryptographic Primitives

Component Algorithm Security Level
Key Exchange ML-KEM-1024 (Kyber) NIST Level 5 (IND-CCA2)
Signatures ML-DSA-87 (Dilithium) NIST Level 5 (EUF-CMA)
Symmetric Encryption Wasif-Vernam Cipher ChaCha20-Poly1305 + XOR layer
Random Entropy drand โŠ• CSPRNG 256-bit computational

๐Ÿ›ก๏ธ Hybrid Computational Security

ZKS Protocol achieves 256-bit post-quantum security through defense-in-depth:

Hybrid Encryption Architecture

  • Key wrapping: DEK XORed with drand โŠ• CSPRNG entropy
  • Bulk encryption: Content encrypted with ChaCha20-Poly1305(DEK)
  • Defense-in-depth: Multiple independent entropy sources
  • Result: 256-bit computational security, quantum-resistant

Entropy Budget (Network Mode):

  • โœ… All messages: 256-bit computational security via drand โŠ• CSPRNG (OTP-inspired)
  • โ„น๏ธ Entropy source: drand beacon + local CSPRNG provides 256-bit post-quantum computational security

Mathematical Foundation (Computational Security):

  • Defense-in-depth: XOR of drand beacon and local CSPRNG provides 256-bit computational security
  • No single point of failure: Secure if either entropy source is uncompromised
  • Post-quantum: ML-KEM-1024 key exchange resists quantum attacks
  • Important distinction: This provides computational security (OTP-inspired), not information-theoretic security

Protocol-Level Anonymity:

  • Session rotation: Sessions become cryptographically unlinkable
  • Per-message key derivation: Forward secrecy within sessions
  • Cover traffic: Constant bandwidth prevents timing analysis

Fallback (if drand unavailable):

  • 256-bit ChaCha20-Poly1305: Computationally secure, quantum-resistant
  • Landauer limit: Brute-force energy requirements make attacks impractical

๐Ÿ”„ 3-Message Handshake

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Initiator  โ”‚                           โ”‚  Responder   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚                                          โ”‚
       โ”‚  1. HandshakeInit                        โ”‚
       โ”‚  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ  โ”‚
       โ”‚  [ephemeral_pk, nonce]                   โ”‚
       โ”‚                                          โ”‚
       โ”‚  2. HandshakeResponse                    โ”‚
       โ”‚  โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  โ”‚
       โ”‚  [ephemeral_pk, ciphertext, signature]   โ”‚
       โ”‚                                          โ”‚
       โ”‚  3. HandshakeFinish                      โ”‚
       โ”‚  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ  โ”‚
       โ”‚  [confirmation_hash]                     โ”‚
       โ”‚                                          โ”‚
       โ–ผ                                          โ–ผ
   [shared_secret derived]                [shared_secret derived]

๐Ÿ“ฆ Crate Structure

zks/
โ”œโ”€โ”€ zks_sdk        # High-level SDK (start here!)
โ”œโ”€โ”€ zks_crypt      # Wasif-Vernam cipher, drand integration
โ”œโ”€โ”€ zks_pqcrypto   # ML-KEM-1024, ML-DSA-87 (NIST Level 5)
โ”œโ”€โ”€ zks_proto      # Handshake protocol, URL parsing
โ”œโ”€โ”€ zks_wire       # Swarm networking, NAT traversal
โ”œโ”€โ”€ zks_types      # Common type definitions
โ”œโ”€โ”€ zks_wasm       # WebAssembly bindings
โ”œโ”€โ”€ zks_surb       # Single-Use Reply Blocks for anonymous replies
Crate Description Key Features
zks_sdk High-level developer API Connection builders, prefabs
zks_crypt Core cryptographic operations Wasif-Vernam (OTP-inspired), scrambling, drand
zks_pqcrypto Post-quantum primitives ML-KEM, ML-DSA, Zeroizing
zks_proto Protocol implementation 3-message handshake, messages
zks_wire Network layer STUN, NAT traversal, swarm
zks_types Shared types Error types, crypto params
zks_wasm Browser support JS bindings via wasm-bindgen
zks_wire Network Layer STUN, NAT traversal, swarm

๐Ÿง… Faisal Swarm โ€” Anonymous Routing

The zks:// protocol provides onion routing through a decentralized swarm network using the novel Faisal Swarm Topology:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Client โ”‚โ”€โ”€โ”€โ–บโ”‚ Guard   โ”‚โ”€โ”€โ”€โ–บโ”‚ Middle  โ”‚โ”€โ”€โ”€โ–บโ”‚ Exit    โ”‚โ”€โ”€โ”€โ–บโ”‚ Destinationโ”‚
โ”‚        โ”‚    โ”‚ (Entry) โ”‚    โ”‚ (Relay) โ”‚    โ”‚ (Exit)  โ”‚    โ”‚            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
     โ”‚              โ”‚              โ”‚              โ”‚               โ”‚
     โ””โ”€Wasif-Vernamโ–บโ””โ”€Wasif-Vernamโ–บโ””โ”€Wasif-Vernamโ–บโ””โ”€plaintextโ”€โ”€โ”€โ”€โ–บโ”‚

๐Ÿ” Faisal Swarm Security Properties

Property Description Verification
256-bit Security Wasif-Vernam at each hop โœ… 56 security tests
Post-Quantum ML-KEM-1024 key exchange โœ… 7 PQ handshake tests
Anonymity Hop isolation โœ… 8 hop anonymity tests
Untraceability No node knows both source + destination โœ… Traffic analysis tests

๐Ÿ†š Comparison with Other Networks

Feature Tor I2P Faisal Swarm
Encryption AES-128 ElGamal + AES ChaCha20 + XOR layer
Key Exchange RSA/Curve25519 ElGamal/ECDSA ML-KEM-1024 (Post-Quantum)
Security Model Computational Computational Computational (256-bit PQ)
Quantum Resistance โŒ โŒ โœ…
Anonymity โœ… 3 hops โœ… Tunnel routing โœ… 3-7 configurable hops

Features

  • Multi-hop routing: Configurable number of relay hops (default: 3)
  • Layered encryption: Each hop uses independent Wasif-Vernam cipher
  • Persistent cipher state: Arc<RwLock<WasifVernam>> for proper nonce management
  • Traffic analysis resistance: Fixed 512-byte cell sizes + random padding
  • Anti-replay protection: Bitmap-based per-layer protection
  • Peer discovery: Automatic swarm network formation via libp2p

๐Ÿ“ฑ Platform Support

Platform Status Notes
Linux โœ… Full Support Primary development platform
macOS โœ… Full Support Intel and Apple Silicon
Windows โœ… Full Support Windows 10/11
WebAssembly โœ… Full Support Chrome, Firefox, Safari
iOS ๐Ÿ”„ Planned Via Rust FFI
Android ๐Ÿ”„ Planned Via Rust FFI

๐Ÿ“– Examples

The examples/ directory contains complete working examples:

# Basic encrypted connection
cargo run --example basic_connection

# Anonymous swarm-routed connection
cargo run --example anonymous_connection

# Secure file transfer
cargo run --example file_transfer

๐ŸŒ What Can You Build?

Application Protocol Description
Encrypted Messenger zks:// Quantum-proof end-to-end chat
Secure File Sharing zk:// 256-bit post-quantum file transfer
Anonymous APIs zks:// Hide client IP addresses
VPN Replacement zks:// Better than VPN + Tor combined
Whistleblowing Platform zks:// Source protection
Healthcare/Finance zk:// HIPAA/PCI compliance

๐Ÿ›ก๏ธ Security

Security Model

  • Post-quantum resistance: All key exchanges use NIST-standardized ML-KEM-1024
  • Defense-in-depth: DEK wrapped with drand โŠ• CSPRNG (256-bit computational)
  • Forward secrecy: Session keys are derived per-connection with recursive key chains
  • Zero trust: End-to-end encryption with mutual authentication
  • Memory safety: Memory-safe architecture, leveraging Rust's ownership model with minimal, audit-friendly unsafe code for cryptographic primitives.

๐Ÿ” 256-bit Post-Quantum Security

ZKS Protocol achieves 256-bit computational security through defense-in-depth:

Mathematical Foundation: XOR of independent entropy sources provides computational security.

Entropy Sources (Network Mode):

  • Local CSPRNG: OS entropy pool (Windows BCrypt, Linux /dev/urandom)
  • drand beacon: BLS12-381 verified randomness from 18+ distributed operators

These two sources are XORed together for defense-in-depth.

Entropy Grid (Hierarchical Distribution):

The Entropy Grid distributes drand rounds across the swarm to reduce API load:

Fetch Order:
1. Local Cache     โ†’ Fastest (in-memory)
2. Swarm Peers     โ†’ P2P via GossipSub
3. IPFS            โ†’ Decentralized storage
4. drand API       โ†’ Final fallback

Note: The Entropy Grid distributes drand dataโ€”it does not contribute additional entropy sources. The XOR combination is: drand โŠ• local_CSPRNG.

Security Properties:

  • Hybrid key wrapping: DEK wrapped with drand โŠ• CSPRNG entropy, bulk data with ChaCha20
  • Security chain: Breaking encryption requires compromising both entropy sources
  • Session rotation: Auto-rotate every 10 min for cryptographic unlinkability
  • Fallback: ChaCha20 if drand unavailable (still post-quantum secure)

Defense-in-Depth Operation: System combines multiple entropy sources (drand + local CSPRNG) for strong computational security.

๐Ÿ”’ Post-Quantum Computational Security (Network Mode)

Mode Security Type Mathematical Foundation Requirements Guarantees
Network (zk://, zks://) Computational 256-bit post-quantum cryptography Standard computational assumptions Quantum-resistant, computationally bounded

Critical Distinction: Network mode provides 256-bit computational security - resistant to quantum computers but theoretically breakable with sufficient computational power

๐ŸŒŒ Computational Security Bounds (>32 Bytes)

For messages >32 bytes, ZKS Protocol provides 256-bit computational security through ChaCha20-Poly1305, with security bounds derived from fundamental physical constraints:

The Physics Argument (Computational Security):

  • Landauer Limit: Minimum energy required to erase 1 bit = kT ln(2) โ‰ˆ 3ร—10โปยฒยน J
  • 256-bit key space: 2ยฒโตโถ โ‰ˆ 1.16ร—10โทโท possible keys
  • Minimum brute-force energy: ~3.5ร—10โตโถ Joules

Cosmic Scale Comparison:

  • Total energy output of Sun over its lifetime: ~1.2ร—10โดโด J
  • Total energy in observable universe: ~4ร—10โถโน J
  • Required energy exceeds universal energy by ~10ยนยณ times

Time Requirements (even at theoretical maximum efficiency):

  • At Planck time per operation: ~6.3ร—10ยณยณ seconds
  • Age of universe: ~4.3ร—10ยนโท seconds
  • Would require ~10ยนโถ universe lifetimes

Quantum Computing Limitations:

  • Grover's algorithm provides only โˆšN speedup (2ยนยฒโธ operations instead of 2ยฒโตโถ)
  • Still requires energy exceeding total cosmic output by billions of times
  • Quantum decoherence and error correction make this practically impossible

Conclusion: Messages >32 bytes are computationally secure with security bounds that make brute-force attacks physically impractical, providing 256-bit post-quantum computational security (NOT information-theoretic security).

Responsible Disclosure

Please report security vulnerabilities to: security@zks-protocol.org

See SECURITY.md for our full security policy.


๐Ÿ“Š Performance

ZKS Protocol provides competitive performance while maintaining 256-bit post-quantum computational security:

Operation Latency Throughput
Wasif-Vernam Encrypt (1KB) 5.2 ยตs 187 MiB/s
SynchronizedVernam (1KB) 1.1 ยตs 875 MiB/s
3-Hop Onion Encrypt (512B) 567 ns -
ML-KEM768 Keygen ~60 ยตs -

For detailed benchmarks, see BENCHMARKS.md.

# Run performance benchmarks
cargo bench -p zks_crypt
cargo bench -p zks_wire --bench onion_routing_bench

๐Ÿงช Testing

# Run all tests
cargo test --workspace

# Run specific crate tests
cargo test -p zks_sdk
cargo test -p zks_crypt

# Run integration tests
cargo test --test integration_tests

๐Ÿค Contributing

Contributions are welcome! Here's how to get started:

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

Please ensure your code:

  • โœ… Follows Rust best practices
  • โœ… Includes appropriate tests
  • โœ… Has documentation for public APIs
  • โœ… Passes all CI checks

๐Ÿ“œ License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).

See LICENSE for the full license text.


๐Ÿ“ž Contact


๐Ÿค Sponsors

Cloudflare

Cloudflare
Project Alexandria

๐Ÿš€ Infrastructure support from Cloudflare Project Alexandria โ€” Supporting open-source innovation

๐Ÿงฎ Mathematical Security Foundation

The ZKS Protocol provides two security tiers:

  1. Network Mode: 256-bit post-quantum computational security via ML-KEM + ChaCha20

Key Properties:

  • No computational assumptions: Security relies on mathematical laws, not hardness assumptions
  • Quantum-resistant: Immune to both classical and quantum attacks
  • Forward secrecy: Recursive key chains prevent retrospective decryption
  • Trustless design: No single point of failure or trusted third parties required

Built with โค๏ธ for a quantum-safe future

Protecting your privacy today, and tomorrow.