Skip to content

Latest commit

 

History

History
81 lines (59 loc) · 2.39 KB

File metadata and controls

81 lines (59 loc) · 2.39 KB

ZK Proof of Reserve

A Rust library for generating and verifying Ethereum Merkle proofs, specifically designed for Proof of Reserve use cases. This library enables cryptographic verification of on-chain state without requiring full node synchronization.

Features

  • Account Proofs: Verify Ethereum account state against state roots
  • Storage Proofs: Verify contract storage values using Merkle proofs
  • Proof of Reserve: High-level API for proving reserve balances and shares
  • Zero Dependencies on Full Nodes: Works with standard Ethereum RPC endpoints

Quick Start

Installation

Add to your Cargo.toml:

[dependencies]
ethereum = { path = "domains/ethereum", features = ["no-zkvm"] }

Basic Usage

use ethereum::proof_of_reserve::{ProofOfReserveProver, verify_reserve_proof};
use alloy::providers::{Provider, ProviderBuilder};
use url::Url;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize prover
    let prover = ProofOfReserveProver::new("https://sepolia.infura.io/v3/YOUR_KEY".to_string());
    
    // Generate proof for account balance
    let proof = prover.get_account_balance_proof(
        "0x...", // contract address
        "0x...", // account address
        0,       // storage slot
        12345678 // block number
    ).await?;
    
    // Get state root from block
    let provider = ProviderBuilder::new().on_http(Url::parse("https://sepolia.infura.io/v3/YOUR_KEY")?);
    let block = provider.get_block_by_number(12345678.into()).await?.unwrap();
    
    // Verify proof
    let is_valid = verify_reserve_proof(&proof, block.header.state_root.as_slice())?;
    assert!(is_valid);
    
    Ok(())
}

Project Structure

domains/ethereum/
├── src/
│   ├── proof_of_reserve/    # High-level Proof of Reserve API
│   ├── merkle_lib/          # Core Merkle proof types and verification
│   ├── eth_rlp/             # RLP encoding/decoding
│   └── eth_trie/            # Merkle Patricia Trie operations

Testing

Run tests with:

cargo test --package ethereum --features no-zkvm

Note: Integration tests require environment variables:

  • ETHEREUM_URL: Ethereum RPC endpoint
  • ETHEREUM_SEPOLIA_VAULT_EXAMPLE_CONTRACT_ADDRESS: Contract address
  • ETHEREUM_DEFAULT_ACCOUNT_ADDRESS: Account address to test

License

This project is licensed under the MIT License.