Skip to content

amiabix/zkCoprocessor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

15 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

zkCoprocessor

A Rust application that syncs Ethereum blockchain data to TigerBeetle and generates zero-knowledge proofs for transaction verification.

๐ŸŽฏ What This Project Does

  • Syncs Ethereum blocks to TigerBeetle database for fast lookups
  • Generates real ZK proofs using ZisK for transaction data integrity
  • Provides CLI tools for testing, debugging, and proof generation
  • Supports both real and simulated proof modes based on platform

๐Ÿ“‹ Prerequisites Check

Before starting, ensure you have these installed:

Required (All Platforms)

  • Rust (latest stable): curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • TigerBeetle: Download from TigerBeetle releases
  • Ethereum RPC access: Free endpoints available (see configuration)

Optional (Linux Only)

  • ZisK: For real cryptographic proofs (macOS uses simulation mode)

๐Ÿš€ Quick Start Guide

Step 1: Build the Project

# Clone the repository
git clone https://github.com/amiabix/zkCoprocessor.git
cd zkCoprocessor

# Build the project
cargo build --release

Step 2: Start TigerBeetle Database

# Create and format the database
tigerbeetle format --cluster=0 --replica=0 --replica-count=1 0_0.tigerbeetle

# Start TigerBeetle server (keep this running in a separate terminal)
tigerbeetle start --addresses=3000 0_0.tigerbeetle

Step 3: Test Your Setup

# Test TigerBeetle connection
cargo run -- test-tiger

# Test Ethereum RPC connection
cargo run -- test-eth

# If both tests pass, you're ready to proceed!

Step 4: Sync Ethereum Data

# Sync a single block (recommended for testing)
cargo run -- sync-blocks --from 19000000 --to 19000000

# Sync multiple blocks (be patient, this takes time)
cargo run -- sync-blocks --from 19000000 --to 19000001

Step 5: Verify Data and Generate Proofs

# Check what data was synced
cargo run -- debug --limit 10

# Generate a ZK proof for a transaction
cargo run -- prove-transaction --transfer-id 19000000000000

# Generate multiple proofs in batch
cargo run -- prove-batch --count 3

๐Ÿ”ง Detailed Installation Guide

Installing TigerBeetle

macOS:

# Download and install TigerBeetle
curl -L https://github.com/tigerbeetle/tigerbeetle/releases/latest/download/tigerbeetle_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/')_0.16.45.tar.gz | tar -xz
sudo mv tigerbeetle /usr/local/bin/

Linux:

# Download and install TigerBeetle
curl -L https://github.com/tigerbeetle/tigerbeetle/releases/latest/download/tigerbeetle_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/')_0.16.45.tar.gz | tar -xz
sudo mv tigerbeetle /usr/local/bin/

Installing ZisK (Linux Only)

For real ZK proofs on Linux:

# Run the setup script
chmod +x scripts/setup-zisk.sh
./scripts/setup-zisk.sh

# Or install manually
git clone https://github.com/0xPolygonHermez/zisk.git
cd zisk/cli
cargo build --release
cargo install --path .

Note: macOS users will automatically use simulation mode - no ZisK installation needed.

๐Ÿ“– Available Commands

Connection Testing

# Test TigerBeetle connection
cargo run -- test-tiger

# Test Ethereum RPC connection
cargo run -- test-eth [--rpc-url <URL>]

Data Synchronization

# Sync Ethereum blocks to TigerBeetle
cargo run -- sync-blocks --from <BLOCK> --to <BLOCK> [--rpc-url <URL>]

# Example: Sync block 19000000
cargo run -- sync-blocks --from 19000000 --to 19000000

Data Inspection

# View stored data in TigerBeetle
cargo run -- debug [--limit <N>]

# Example: Show first 5 items
cargo run -- debug --limit 5

ZK Proof Generation

# Generate ZK proof for a single transaction
cargo run -- prove-transaction --transfer-id <ID>

# Example: Generate proof for transfer 19000000000000
cargo run -- prove-transaction --transfer-id 19000000000000

# Generate multiple proofs in batch
cargo run -- prove-batch --count <N>

# Example: Generate 3 proofs
cargo run -- prove-batch --count 3

Setup and Maintenance

# Setup ZisK project structure (Linux only)
cargo run -- setup-zisk

# Run performance benchmarks
cargo run -- benchmark [--num-transactions <N>]

๐Ÿ” Understanding the Output

Sync Output

When you run sync-blocks, you'll see:

๐Ÿ”„ Syncing Ethereum blocks 19000000 to 19000000
๐Ÿ“ฆ Fetching block 19000000
๐Ÿ“ฆ Found 127 transactions in block 19000000
โœ… Block 19000000: 127 transactions processed
๐ŸŽ‰ Sync complete! 45 value transfers stored in TigerBeetle

Debug Output

When you run debug, you'll see:

๐Ÿ“Š TigerBeetle Contents:
========================
๐Ÿ’ธ Transfer 19000000000000: 1001 -> 1002 (1000000000000000000 wei, block 19000000)
๐Ÿ’ธ Transfer 19000000000002: 1003 -> 1004 (500000000000000000 wei, block 19000000)
...

ZK Proof Output

When you run prove-transaction, you'll see:

๐ŸŽฏ Generating ZK proof for transfer_id: 19000000000000
๐Ÿš€ Generating real ZisK proof using cargo-zisk...
โœ… ZisK program built successfully
โœ… Cryptographic proof generated successfully
โœ… Proof verification successful

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                ๐Ÿ” ZK PROOF ANALYSIS                         โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

๐Ÿ“‹ PROOF DETAILS:
๐ŸŽฏ Transfer ID: 19000000000000
๐Ÿ“ฆ Block Number: 19000000
๐Ÿ” Proof Type: zisk
โœ… Valid: YES
โฑ๏ธ  Generation Time: 2341ms
๐Ÿ’พ Proof Size: 2048 bytes
๐Ÿ“ Proof File: /path/to/proof/vadcop_final_proof.json

โš™๏ธ Configuration

Default Settings

  • TigerBeetle: 127.0.0.1:3000
  • Ethereum RPC: https://eth.llamarpc.com
  • Database file: 0_0.tigerbeetle

Custom RPC Endpoints

You can use different Ethereum RPC endpoints:

# Use Infura
cargo run -- test-eth --rpc-url https://mainnet.infura.io/v3/YOUR_PROJECT_ID

# Use Alchemy
cargo run -- test-eth --rpc-url https://eth-mainnet.alchemyapi.io/v2/YOUR_API_KEY

# Use your own node
cargo run -- test-eth --rpc-url http://localhost:8545

๐Ÿ› Troubleshooting

Common Issues

"TigerBeetle connection failed"

# Check if TigerBeetle is running
ps aux | grep tigerbeetle

# Restart TigerBeetle
tigerbeetle start --addresses=3000 0_0.tigerbeetle

"No transfers found in debug"

# You need to sync data first
cargo run -- sync-blocks --from 19000000 --to 19000000
cargo run -- debug --limit 5

"Ethereum RPC connection failed"

# Try a different RPC endpoint
cargo run -- test-eth --rpc-url https://eth.llamarpc.com

"ZisK not found" (Linux)

# Install ZisK
./scripts/setup-zisk.sh

# Or the system will automatically use simulation mode

Platform-Specific Issues

macOS Users:

  • ZisK doesn't support macOS yet
  • The system automatically uses simulation mode
  • All proof generation will work, but with simulated cryptographic guarantees
  • This is perfect for development and testing

Linux Users:

  • Full ZisK support available
  • Install ZisK for real cryptographic proofs
  • If ZisK fails, the system falls back to simulation mode

๐Ÿ“Š Performance Tips

For Large Datasets

# Use release builds for better performance
cargo build --release

# Sync blocks in smaller batches
cargo run -- sync-blocks --from 19000000 --to 19000005

# Monitor TigerBeetle memory usage
# TigerBeetle uses memory-mapped files, so ensure sufficient RAM

For Proof Generation

# Generate proofs in batches for efficiency
cargo run -- prove-batch --count 10

# Use specific transfer IDs for targeted proofs
cargo run -- prove-transaction --transfer-id 19000000000000

๐Ÿ”ฎ What's Next?

Current Capabilities

  • โœ… Real Ethereum block synchronization
  • โœ… TigerBeetle data storage and querying
  • โœ… ZK proof generation (real on Linux, simulated on macOS)
  • โœ… Batch proof processing
  • โœ… Performance benchmarking

Future Enhancements

  • ๐Ÿ”„ Real transaction inclusion proofs (Merkle tree verification)
  • ๐Ÿ”„ Parallel proof generation
  • ๐Ÿ”„ Proof compression and optimization
  • ๐Ÿ”„ Web interface for proof verification
  • ๐Ÿ”„ Integration with other blockchains

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

๐Ÿ“„ License

This project is open source. See the LICENSE file for details.


Ready to get started? Follow the Quick Start Guide above! ๐Ÿš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages