Crate bankai_sdk

Source
Expand description

Bankai SDK

Trustless blockchain data access through zero-knowledge proofs

§How It Works

  1. Verify the Bankai block proof: validate the STWO proof to establish trust in the MMR roots
  2. Verify MMR proofs: decommit and verify headers against those trusted MMR roots
  3. Verify chain data: verify accounts/transactions/storage against the verified headers

§Getting Started (Fetch + Verify)

This example follows the full flow: fetch a proof batch via the SDK, then verify it with bankai-verify, and finally use the verified results.

use alloy_primitives::{Address, FixedBytes, U256};
use bankai_sdk::{Bankai, HashingFunctionDto, Network};
use bankai_verify::verify_batch_proof;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Step 1: Initialize the SDK
    let bankai = Bankai::new(
        Network::Sepolia,
        Some("https://sepolia.infura.io/v3/YOUR_KEY".to_string()),  // Execution RPC
        Some("https://sepolia.beacon-api.example.com".to_string()), // Beacon RPC
    );

    // Step 2: Build and fetch a batch with multiple proof requests
    let proof_batch = bankai
        .init_batch(Network::Sepolia, None, HashingFunctionDto::Keccak)
        .await?
        .evm_beacon_header(8_551_383)
        .evm_execution_header(9_231_247)
        .evm_account(9_231_247, Address::ZERO)
        .evm_storage_slot(9_231_247, Address::ZERO, U256::from(0))
        .evm_tx(FixedBytes::from([0u8; 32]))
        .execute()
        .await?;

    // Step 3: Verify everything (block proof + MMR proofs + Merkle proofs)
    let results = verify_batch_proof(proof_batch)?;

    // Step 4: Use the verified data (cryptographically guaranteed valid)
    for header in &results.evm.execution_header {
        println!("✓ Verified execution header at block {}", header.number);
    }
    for header in &results.evm.beacon_header {
        println!("✓ Verified beacon slot {}", header.slot);
    }
    for account in &results.evm.account {
        println!("✓ Verified account balance: {} wei", account.balance);
    }
    for slot in &results.evm.storage_slot {
        println!("✓ Verified storage slot: {}", slot);
    }
    for tx in &results.evm.tx {
        println!("✓ Verified transaction: {:?}", tx);
    }

    Ok(())
}

§API Client

Direct access to the Bankai API for low-level operations:

use bankai_sdk::{Bankai, Network, HashingFunctionDto};
use bankai_types::api::proofs::{MmrProofRequestDto, LightClientProofRequestDto, HeaderRequestDto};


// Get latest Bankai block number
let latest_block = sdk.api.get_latest_block_number().await?;

// Fetch STWO block proof
let block_proof = sdk.api.get_block_proof(latest_block).await?;

// Fetch MMR proof for a specific header
let mmr_request = MmrProofRequestDto {
    network_id: 1,  // 0 = beacon, 1 = execution
    block_number: 12345, // Bankai block number
    hashing_function: HashingFunctionDto::Keccak,
    header_hash: "0x...".to_string(),
};
let mmr_proof = sdk.api.get_mmr_proof(&mmr_request).await?;

// Fetch batch light client proof (STWO proof + multiple MMR proofs)
let lc_request = LightClientProofRequestDto {
    bankai_block_number: Some(latest_block),
    hashing_function: HashingFunctionDto::Keccak,
    requested_headers: vec![
        HeaderRequestDto {
            network_id: 1,  // Execution layer
            header_hash: "0x...".to_string(),
        },
        HeaderRequestDto {
            network_id: 0,  // Beacon chain
            header_hash: "0x...".to_string(),
        },
    ],
};
let light_client_proof = sdk.api.get_light_client_proof(&lc_request).await?;

§EVM Fetchers

Use individual fetchers to generate storage proofs and retrieve MMR proofs for specific data:

use bankai_sdk::{Bankai, Network, HashingFunctionDto};
use alloy_primitives::{Address, FixedBytes};


// Execution layer fetcher
let execution = sdk.evm.execution()?;

// Fetch execution header with MMR proof
let header = execution.header(9231247, HashingFunctionDto::Keccak, 12345).await?;

// Fetch account with storage proofs
let account = execution.account(
    9231247,
    Address::ZERO,
    HashingFunctionDto::Keccak,
    12345
).await?;

// Fetch transaction with proof (by hash)
let tx_hash = FixedBytes::from([0u8; 32]);
let tx = execution.transaction(9231247, tx_hash, HashingFunctionDto::Keccak, 12345).await?;

// Beacon chain fetcher
let beacon = sdk.evm.beacon()?;

// Fetch beacon header with MMR proof
let beacon_header = beacon.header(8551383, HashingFunctionDto::Keccak, 12345).await?;

Modules§

batch
Batch proof generation for efficient multi-proof operations
errors
evm
EVM execution and beacon chain fetchers
fetch 🔒

Structs§

ApiClient
API client for interacting with Bankai’s proof generation service Client for interacting with the Bankai API
Bankai
Main entry point for the Bankai SDK
BeaconHeader
EvmNamespace
Namespace for EVM-related operations
ProofWrapper
Complete proof bundle ready for verification
VerifyNamespace
Namespace for verification operations (placeholder for future functionality)

Enums§

HashingFunctionDto
Hashing function used for MMR construction
Network
Supported blockchain networks