Skip to content

deelawn/skavenge-zk-proof

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Skavenge ZK-Proof System

This repository contains a zero-knowledge proof system implementation that provides cryptographic proof capabilities for secure message exchange. The system allows a seller to prove they have encrypted a message for a buyer without revealing the message itself.

Overview

The ZK-Proof system implements cryptographic operations for:

  1. Generating and verifying zero-knowledge proofs
  2. Encrypting and decrypting messages
  3. Managing cryptographic keys

The system is available through both a gRPC API server and a command-line interface.

Features

  • Zero-Knowledge Proofs: Generate and verify proofs that demonstrate knowledge of a message without revealing it
  • Secure Message Encryption: Encrypt messages using ECIES-like encryption with the secp256k1 curve
  • Key Management: Generate, marshal, and unmarshal ECDSA key pairs
  • Multi-Interface Access: Access functionality via HTTP/gRPC API or CLI

System Architecture

The system is structured as follows:

skavenge-zk-proof/
├── api/               # API implementation
│   ├── proto/         # Protocol buffer definitions
│   └── zkproof/       # Generated gRPC code
├── cmd/               # Command-line applications
│   ├── test/          # Test client
│   └── zkserver/      # Server implementation
├── zk/                # Core cryptographic functionality

Core Components

  • ProofSystem: Main component that handles all cryptographic operations
  • Server: gRPC server that exposes the proof system functionality
  • CLI: Command-line interface for direct interaction

API Endpoints

The system provides the following gRPC endpoints:

Endpoint Description
EncryptMessage Encrypts a message using a public key
DecryptMessage Decrypts a message using a private key
GeneratePartialProof Generates a partial proof for a transaction
VerifyProof Verifies a proof for a transaction

How It Works

Zero-Knowledge Proof Generation

  1. The seller has a message and wants to transfer it to a buyer
  2. The seller encrypts the message for themselves (sellerCipherText)
  3. The seller encrypts the same message for the buyer (buyerCipherText)
  4. The system generates a proof that:
    • The seller knows the original message
    • Both ciphertexts encrypt the same message
    • The buyer can decrypt their ciphertext to access the message

Proof Verification

The verification process confirms that:

  1. The proof is mathematically valid (using elliptic curve operations)
  2. The seller ciphertext matches what was used in proof generation
  3. The buyer ciphertext hash matches what's stored in the proof

Cryptographic Details

The system uses the following cryptographic primitives:

  • Curve: secp256k1 (same as used in Bitcoin)
  • Hash Function: Keccak-256 (SHA-3)
  • Encryption: ECIES (Elliptic Curve Integrated Encryption Scheme)
  • ZKP Method: Custom Schnorr-like signature scheme

Getting Started

Prerequisites

  • Go 1.17 or higher
  • Protocol Buffers compiler (for development)

Installation

# Clone the repository
git clone https://github.com/deelawn/skavenge-zk-proof.git
cd skavenge-zk-proof

# Build the server
make build

Running the Server

# Start the server with default configuration
./bin/zkserver

# Start with custom config
./bin/zkserver --config=/path/to/config.yaml

The server configuration can be customized in config.yaml:

server:
  host: "0.0.0.0"
  port: 8080

security:
  readTimeout: 5s
  writeTimeout: 10s
  idleTimeout: 120s

Usage Examples

Encrypting a Message

client := zkproof.NewServiceClient(conn)
resp, err := client.EncryptMessage(context.Background(), &zkproof.EncryptMessageRequest{
    Message: []byte("secret message"),
    PubKey: publicKeyBytes,
})

Generating a Proof

resp, err := client.GeneratePartialProof(context.Background(), &zkproof.GeneratePartialProofRequest{
    Message: []byte("secret message"),
    SellerPubKey: sellerPubKeyBytes,
    BuyerPubKey: buyerPubKeyBytes,
    SellerCipherText: sellerCipherTextBytes,
})

Verifying a Proof

resp, err := client.VerifyProof(context.Background(), &zkproof.VerifyProofRequest{
    Proof: &zkproof.Proof{
        C: c.String(),
        S: s.String(),
        R1: r1Bytes,
        R2: r2Bytes,
        BuyerPubKey: buyerPubKeyBytes,
        SellerPubKey: sellerPubKeyBytes,
        BuyerCipherHash: buyerCipherHashBytes,
    },
    SellerCipherText: sellerCipherTextBytes,
})

Testing

The repository includes comprehensive tests for the core cryptographic functionality:

# Run all tests
make test

# Run specific tests
go test ./zk/...

Future Enhancements

As outlined in the project plan:

  1. Add TLS support for the HTTP/gRPC server
  2. Implement authentication and authorization
  3. Add rate limiting for APIs
  4. Add metrics and monitoring
  5. Support for additional key formats
  6. Interactive CLI mode

Contributing

See CONTRIBUTING.md for information on how to contribute to this project.

License

[Include license information here]

About

ZK proof logic that poweres the skavenge EVM app (not reviewed; use at your own discretion)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published