Expand description
Bankai Verify - Trustless Verification Library
§Overview
This library provides trustless verification of blockchain data using Bankai Block proofs.
It works in tandem with the bankai-sdk crate, which fetches proofs that this library verifies.
Once data is verified through this library, it is cryptographically guaranteed to be valid. No further checks are needed. This guarantee is provided by Bankai’s stateless light client architecture, which uses zero-knowledge proofs to establish an unbreakable chain of trust from the STWO proof down to individual blockchain data elements.
§How Verification Works
The verification process follows a hierarchical trust chain:
- Verify STWO Block Proof: First, verify the STWO zero-knowledge proof to establish trust in the MMR roots it contains. This proof is cryptographically sound and cannot be forged.
- Verify MMR Proofs: Use the trusted MMR roots to verify individual header commitments through MMR inclusion proofs. Headers are guaranteed to be in the MMR.
- Verify Chain Data: Once headers are verified, use standard Merkle proofs to verify accounts, transactions, and other chain data against the header roots. This establishes that the data existed in that specific block.
§Stateless Light Client Architecture
Bankai’s architecture enables stateless verification: you don’t need to maintain any state, sync any chains, or trust any intermediaries. Each proof bundle is completely self-contained and can be verified independently. This makes it perfect for:
- Cross-chain bridges that need to verify data from other chains
- Smart contracts that need trustless access to historical blockchain data
- Applications that need blockchain data without running full nodes
- Zero-knowledge circuits that need verified inputs
§Usage
§Batch Verification (Recommended)
The simplest way to verify proofs is using the batch verification function:
use bankai_verify::verify_batch_proof;
use bankai_types::fetch::ProofWrapper;
// Verify an entire batch of proofs at once
let results = verify_batch_proof(proof_wrapper)?;
// Access verified data
for header in &results.evm.execution_header {
println!("Verified execution header at block {}", header.number);
}
for account in &results.evm.account {
println!("Verified account with balance: {}", account.balance);
}§Verify Block Proof Only
If you only need the verified Bankai block (with MMR roots), you can verify just the STWO proof:
use bankai_verify::bankai::stwo::verify_stwo_proof;
use cairo_air::CairoProof;
use stwo::core::vcs::blake2_merkle::Blake2sMerkleHasher;
// Verify the STWO proof and extract the Bankai block
let bankai_block = verify_stwo_proof(&block_proof)?;
// Access the verified MMR roots
println!("Execution MMR root (Keccak): {:?}", bankai_block.execution.mmr_root_keccak);
println!("Beacon MMR root (Keccak): {:?}", bankai_block.beacon.mmr_root_keccak);
println!("Block number: {}", bankai_block.block_number);§Verify MMR Proofs
Once you have verified MMR roots from a Bankai block, you can verify MMR inclusion proofs:
use bankai_verify::bankai::mmr::verify_mmr_proof;
use bankai_types::proofs::{MmrProofDto, HashingFunctionDto};
use alloy_primitives::FixedBytes;
// Verify that a header is committed in the MMR
let header_hash = verify_mmr_proof(&mmr_proof, trusted_mmr_root)?;
println!("Verified header hash: {:?}", header_hash);§Verify Header Proofs
With a verified MMR root, you can verify individual header proofs:
use bankai_verify::evm::{ExecutionVerifier, BeaconVerifier};
use bankai_types::fetch::evm::execution::ExecutionHeaderProof;
use alloy_primitives::FixedBytes;
// Verify an execution header against a trusted MMR root
let verified_header = ExecutionVerifier::verify_header_proof(&proof, mmr_root)?;
println!("Header number: {}", verified_header.number);
println!("State root: {:?}", verified_header.state_root);
// Now you can verify accounts against this header's state root§Verify Account and Transaction Proofs
Once you have a verified header, you can verify account and transaction proofs against it:
use bankai_verify::evm::ExecutionVerifier;
use bankai_types::fetch::evm::execution::{AccountProof, TxProof};
use alloy_rpc_types_eth::Header;
// Verify an account exists in the header's state
let account = ExecutionVerifier::verify_account_proof(&account_proof, &verified_header)?;
println!("Account balance: {}", account.balance);
// Verify a transaction is included in the block
let transaction = ExecutionVerifier::verify_tx_proof(&tx_proof, &verified_header)?;
println!("Transaction hash: {:?}", transaction.hash);§Features
- STWO Proof Verification: Verifies zero-knowledge proofs generated by the STWO prover
- MMR Proof Verification: Verifies Merkle Mountain Range inclusion proofs
- EVM Data Verification: Verifies execution headers, beacon headers, accounts, and transactions
- Batch Operations: Efficiently verify multiple proofs in a single operation
- No-Std Ready: Can be compiled for no-std environments (SP1 compatibility planned)
Modules§
Structs§
- Batch
Results - Results from batch proof verification
- EvmResults
Enums§
- Verify
Error - Errors that can occur during proof verification
Functions§
- verify_
batch_ proof - Batch proof verification