qzkp

command module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2025 License: MIT Imports: 18 Imported by: 0

README ΒΆ

Quantum Zero-Knowledge Proof (QZKP) Implementation

Author: Nick Cloutier

ORCID: 0009-0008-5289-5324

GitHub: https://github.com/nicksdigital/

Affiliation: Hydra Research & Labs

Date: May 24th, 2025

A comprehensive Go implementation of quantum zero-knowledge proofs with post-quantum cryptographic security.

🚨 CRITICAL SECURITY NOTICE

This implementation provides TWO different proof systems:

  1. πŸ”΄ INSECURE Implementation (QuantumZKP) - DO NOT USE IN PRODUCTION

    • Leaks complete state vector information
    • For educational/comparison purposes only
  2. πŸ›‘οΈ SECURE Implementation (SecureQuantumZKP) - PRODUCTION READY

    • True zero-knowledge properties
    • No information leakage
    • Post-quantum secure

πŸ“‹ Table of Contents

πŸš€ Installation

# Clone the repository
git clone <repository-url>
cd quantumzkp

# Initialize Go module
go mod init quantumzkp
go mod tidy

# Run tests
go test -v

⚑ Quick Start

Basic Secure Proof Generation
package main

import (
    "fmt"
    "log"
)

func main() {
    // Initialize secure quantum ZKP system
    ctx := []byte("my-application-context")
    sq, err := NewSecureQuantumZKP(3, 128, ctx)
    if err != nil {
        log.Fatal(err)
    }

    // Secret quantum state vector
    secretVector := []complex128{
        complex(0.7071, 0),    // |0⟩ component
        complex(0.7071, 0),    // |1⟩ component
        complex(0, 0),         // |2⟩ component
        complex(0, 0),         // |3⟩ component
    }

    // Generate secure proof
    identifier := "my-secret-state"
    key := []byte("32-byte-key-for-authentication!!")

    proof, err := sq.SecureProveVectorKnowledge(secretVector, identifier, key)
    if err != nil {
        log.Fatal(err)
    }

    // Verify proof (without learning the secret!)
    isValid := sq.VerifySecureProof(proof, key)
    fmt.Printf("Proof valid: %v\n", isValid)

    // The proof contains NO information about secretVector!
    fmt.Printf("Proof size: %d bytes\n", len(mustMarshal(proof)))
}
Proof from Arbitrary Data
// Convert any data to quantum state and prove knowledge
secretData := []byte("This is my secret document content")
identifier := "document-proof"
key := []byte("32-byte-key-for-authentication!!")

// Generate proof directly from bytes
proof, err := sq.SecureProveFromBytes(secretData, identifier, key)
if err != nil {
    log.Fatal(err)
}

// Verify without learning anything about secretData
isValid := sq.VerifySecureProof(proof, key)
fmt.Printf("Document proof valid: %v\n", isValid)

πŸ“š API Reference

SecureQuantumZKP

The main secure implementation for production use.

Constructor
func NewSecureQuantumZKP(dimensions, securityLevel int, ctx []byte) (*SecureQuantumZKP, error)
  • dimensions: Quantum system dimensions (typically 3-8)
  • securityLevel: Security level in bits (128, 192, or 256)
  • ctx: Application context for domain separation
Core Methods
// Generate proof from quantum state vector
func (sq *SecureQuantumZKP) SecureProveVectorKnowledge(
    vector []complex128,
    identifier string,
    key []byte,
) (*SecureProof, error)

// Generate proof from arbitrary bytes
func (sq *SecureQuantumZKP) SecureProveFromBytes(
    data []byte,
    identifier string,
    key []byte,
) (*SecureProof, error)

// Verify proof without learning the secret
func (sq *SecureQuantumZKP) VerifySecureProof(
    proof *SecureProof,
    key []byte,
) bool
Quantum Circuit Operations
// Build quantum circuit from state vector
func (q *QuantumZKP) BuildCircuit(vector []complex128, identifier string) (*QuantumCircuit, error)

// Optimize circuit for execution
func (q *QuantumZKP) TranspileCircuit(circuit *QuantumCircuit, optimizationLevel int) (*QuantumCircuit, error)

// Apply noise mitigation techniques
func (q *QuantumZKP) ApplyNoiseMitigation(circuit *QuantumCircuit) (*QuantumCircuit, error)

// Execute circuit simulation
func (q *QuantumZKP) ExecuteCircuit(circuit *QuantumCircuit, shots int) (*ExecutionResult, error)
Utility Functions
// Convert bytes to normalized quantum state vector
func BytesToState(data []byte, targetSize int) ([]complex128, error)

// Create quantum state vector with properties
func NewQuantumStateVector(coordinates []complex128) *QuantumStateVector

πŸ”’ Security Analysis

Information Leakage Comparison
Implementation State Vector Leakage Measurement Leakage Metadata Leakage Proof Size Security
Insecure ❌ Complete exposure ❌ Direct probabilities ❌ Exact values ~10KB ❌ None
Secure (80-bit) βœ… Zero leakage βœ… Cryptographic commitments βœ… Upper bounds only ~20KB βœ… Production ready
Security Properties

The secure implementation provides:

  • Zero-Knowledge: Verifier learns nothing about the secret state
  • Soundness: Invalid proofs are rejected with high probability
  • Completeness: Valid proofs are accepted with high probability
  • Post-Quantum Security: Resistant to quantum computer attacks
Cryptographic Primitives
  • Signatures: Dilithium (NIST post-quantum standard)
  • Hashing: SHA-256 and BLAKE3 (quantum-resistant)
  • Commitments: Cryptographic hash-based commitments
  • Randomness: Cryptographically secure random number generation
Standards Compliance
  • NIST Post-Quantum Cryptography: Compliant with NIST standards
  • FIPS 140-2: Uses FIPS-approved cryptographic algorithms
  • BSI TR-02102: Follows German Federal Office recommendations

πŸ“– Examples

Example 1: Basic Quantum State Proof
func ExampleBasicProof() {
    // Setup
    sq, _ := NewSecureQuantumZKP(3, 128, []byte("example-context"))

    // Bell state: (|00⟩ + |11⟩)/√2
    bellState := []complex128{
        complex(0.7071, 0), // |00⟩
        complex(0, 0),      // |01⟩
        complex(0, 0),      // |10⟩
        complex(0.7071, 0), // |11⟩
    }

    key := []byte("example-key-32-bytes-long!!!!")

    // Generate proof
    proof, err := sq.SecureProveVectorKnowledge(bellState, "bell-state", key)
    if err != nil {
        panic(err)
    }

    // Verify
    valid := sq.VerifySecureProof(proof, key)
    fmt.Printf("Bell state proof valid: %v\n", valid)

    // Proof contains no information about bellState components!
}
Example 2: Document Authentication
func ExampleDocumentAuth() {
    sq, _ := NewSecureQuantumZKP(3, 128, []byte("document-auth"))

    // Secret document
    document := []byte(`
        CONFIDENTIAL DOCUMENT
        Project: Quantum Cryptography
        Classification: Top Secret
        Content: [REDACTED]
    `)

    key := []byte("document-signing-key-32-bytes!!")

    // Generate proof of document knowledge
    proof, err := sq.SecureProveFromBytes(document, "doc-2024-001", key)
    if err != nil {
        panic(err)
    }

    // Verify without revealing document content
    valid := sq.VerifySecureProof(proof, key)
    fmt.Printf("Document authentication: %v\n", valid)

    // The proof reveals NOTHING about the document content!
}
Example 3: Quantum Circuit Analysis
func ExampleCircuitAnalysis() {
    q, _ := NewQuantumZKP(3, 128, []byte("circuit-context"))

    // Superposition state
    superpos := []complex128{
        complex(0.5, 0), complex(0.5, 0),
        complex(0.5, 0), complex(0.5, 0),
    }

    // Build and analyze quantum circuit
    circuit, _ := q.BuildCircuit(superpos, "superposition-circuit")

    // Optimize circuit
    optimized, _ := q.TranspileCircuit(circuit, 3) // Max optimization

    // Apply noise mitigation
    mitigated, _ := q.ApplyNoiseMitigation(optimized)

    // Execute circuit
    result, _ := q.ExecuteCircuit(mitigated, 1000)

    fmt.Printf("Circuit execution completed:\n")
    fmt.Printf("- Shots: %d\n", result.Shots)
    fmt.Printf("- Execution time: %.3f seconds\n", result.ExecutionTime)
    fmt.Printf("- Measurement outcomes: %d unique\n", len(result.Counts))
}
Example 4: Security Demonstration
func ExampleSecurityDemo() {
    // Compare insecure vs secure implementations

    secret := []complex128{complex(0.8, 0.2), complex(0.3, 0.5)}
    key := []byte("demo-key-32-bytes-long-enough!!")

    // INSECURE implementation (for comparison only)
    q, _ := NewQuantumZKP(3, 128, []byte("demo"))
    insecureProof, _ := q.Prove(secret, "demo", key)

    // SECURE implementation
    sq, _ := NewSecureQuantumZKP(3, 128, []byte("demo"))
    secureProof, _ := sq.SecureProveVectorKnowledge(secret, "demo", key)

    // Analyze information leakage
    insecureJSON, _ := json.Marshal(insecureProof)
    secureJSON, _ := json.Marshal(secureProof)

    fmt.Printf("Security Analysis:\n")

    // Check if secret components are visible
    secretStr := fmt.Sprintf("%.1f", real(secret[0]))

    if strings.Contains(string(insecureJSON), secretStr) {
        fmt.Printf("❌ INSECURE: Secret leaked in proof!\n")
    }

    if !strings.Contains(string(secureJSON), secretStr) {
        fmt.Printf("βœ… SECURE: No secret leakage detected!\n")
    }

    fmt.Printf("Insecure proof size: %d bytes\n", len(insecureJSON))
    fmt.Printf("Secure proof size: %d bytes\n", len(secureJSON))
}

πŸ›‘οΈ Best Practices

Security Guidelines
  1. Always use SecureQuantumZKP for production systems
  2. Never use the insecure implementation except for educational purposes
  3. Use strong, unique keys (32 bytes minimum)
  4. Implement proper key management and rotation
  5. Validate all inputs before proof generation
  6. Use appropriate security levels (128-bit minimum for production)
Performance Optimization
  1. Choose appropriate dimensions (3-8 for most applications)
  2. Use circuit optimization for better performance
  3. Apply noise mitigation for quantum hardware deployment
  4. Cache quantum state vectors when possible
  5. Batch proof operations for better throughput
Error Handling
// Always check for errors
proof, err := sq.SecureProveVectorKnowledge(vector, id, key)
if err != nil {
    // Handle specific error types
    switch {
    case strings.Contains(err.Error(), "empty"):
        log.Error("Invalid input: empty vector")
    case strings.Contains(err.Error(), "key"):
        log.Error("Invalid key format")
    default:
        log.Error("Proof generation failed: %v", err)
    }
    return
}

// Verify proof validity
if !sq.VerifySecureProof(proof, key) {
    log.Error("Proof verification failed")
    return
}
Testing
# Run all tests
go test -v

# Run security-specific tests
go test -v -run TestSecure

# Run information leakage analysis
go test -v -run TestInformationLeakageAnalysis

# Benchmark performance
go test -bench=.

πŸ“„ License

This implementation is provided for educational and research purposes. Please ensure compliance with applicable laws and regulations when using cryptographic software.

πŸ“š References and Standards

Academic References
  • Watrous, J. (2009). Zero-knowledge against quantum attacks. SIAM Journal on Computing.
  • Broadbent, A., & Schaffner, C. (2016). Quantum cryptography beyond quantum key distribution.
  • Coladangelo, A., Vidick, T., & Zhang, T. (2020). Non-interactive zero-knowledge arguments for QMA.
Standards and Guidelines
Security Resources

🀝 Contributing

Contributions are welcome! Please ensure all security-related changes are thoroughly reviewed and tested.

⚠️ Disclaimer

This is a research implementation. For production use, conduct thorough security audits and consider formal verification of the zero-knowledge properties.

Documentation ΒΆ

Overview ΒΆ

signature.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL