Crate bankai_sdk

Source
Expand description

Bankai SDK - Zero Knowledge Proof SDK

§Overview

Bankai enables trustless access to blockchain data through STWO zero-knowledge proofs. The process involves three steps:

  1. Verify the block proof: Validate the STWO proof to establish trust in the MMR roots
  2. Retrieve MMR proofs: Use MMR proofs to decommit and verify specific headers
  3. Generate storage proofs: Create Merkle proofs against the header’s state root to access specific data

§Setup

use bankai_sdk::{Bankai, Network};

let sdk = Bankai::new(
    Network::Sepolia,                              // Network to connect to
    Some("https://eth-sepolia.rpc".to_string()),   // Execution layer RPC (optional)
    Some("https://sepolia.beacon.api".to_string()) // Beacon chain RPC (optional)
);

Required parameters:

  • network: Target blockchain network (e.g., Network::Sepolia)
  • evm_execution_rpc: Optional - required for execution layer operations (headers, accounts, transactions)
  • evm_beacon_rpc: Optional - required for beacon chain operations (consensus headers)

Batch multiple proof requests into a single optimized operation. All proofs share the same STWO block proof and are anchored to the same Bankai block number.

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


let batch = sdk.init_batch(
    Network::Sepolia,
    None,  // Use latest block (or specify a Bankai block number)
    HashingFunctionDto::Keccak
).await?;

let tx_hash = FixedBytes::from([0u8; 32]);

let result = batch
    .evm_beacon_header(8551383)                                    // Beacon header
    .evm_execution_header(9231247)                                 // Execution header
    .evm_tx(tx_hash)                                               // Transaction by hash
    .evm_account(9231247, Address::ZERO)                           // Account proof
    .execute()
    .await?;

// Verify the batch proof using the verify crate
use bankai_verify::verify_batch_proof;
let verification_result = verify_batch_proof(&result.proof.proof)?;

// Access individual proofs from the result
let beacon_proof = &result.beacon_headers[0];
let exec_proof = &result.execution_headers[0];
let tx_proof = &result.transactions[0];
let account_proof = &result.accounts[0];

§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