LogoLogo
  • Introduction
    • What is Arichain
    • Why Arichain
    • Vision: Redefining Layer 1, Empowering Every Builder.
    • TL;DR Summary for Builders
    • Details to read
  • Architectural Philosophy
    • Monolithic vs Modular: Why Multi-VM
    • Native Composability over Interoperability
    • Unified Chain State and Execution Environment
    • Chain Structure: Multi-VM under One Consensus
    • Identity & User Abstraction
  • General Architecture Overview
    • Multi-VM Execution Environment
    • Consensus Mechanism
    • Token Design
    • Unified Gas System
    • GAID: Global Account Identity
    • Future Roadmap
  • Technical Overview
    • Consensus Protocol Details
    • Token Design and Interoperability
    • Gas System Architecture
    • GAID Architecture
    • State Management
    • Bridge Infrastructure
  • Developer Experience
    • SDK
    • Developer tools
  • Validator
    • Validator Roles & Node Types
    • Reward System
    • Staking
    • Use Cases
    • Node Operations
  • Security
    • Design Goals
    • Threat Model and Risk Assessment
    • Continuous Security Verification
  • Token Economics & Validator Incentives
    • Token Utility
    • Validator Incentives
    • Token Supply and Distribution
    • Onboarding Workflow
  • Roadmap
Powered by GitBook
On this page
  1. Technical Overview

State Management

Details are provisional and may be updated during development.

Arichain provides unified state management across multiple virtual machines.

Multi-VM State Coordination

The State Consistency Challenge: Managing state across multiple VMs requires:

  • Atomic Updates: Changes across VMs must be consistent

  • Performance Isolation: One VM's state operations shouldn't block others

  • Merkle Proof Generation: Efficient proof creation for Multi-VM verification

  • Rollback Capability: Ability to revert failed Multi-VM transactions

Global State Database Architecture

Unified State Access Layer: Arichain's global state database provides a single source of truth for all VM state information while maintaining VM-specific optimizations:

Global State Database:
├── EVM State Tree (Modified Patricia Merkle Trie)
│   ├── Account States
│   ├── Contract Storage
│   └── Code Storage
├── SVM State Tree (Account-based State)
│   ├── Account Data
│   ├── Program Data
│   └── Rent Collection Info
├── GAID Registry State
│   ├── Global Identity Mappings
│   ├── Multi-VM Permissions
│   └── Identity Metadata
├── Native Token Registry
│   ├── Native Token Balances per VM
│   ├── Transfer History
│   └── Bridge Transaction Records
└── Global Query Interface
    ├── Multi-VM State Queries
    ├── State Proof Generation
    └── Historical State Access

Multi-VM State Query Interface

Global State Manager:

pub trait GlobalStateManager {
    fn query_evm_state(&self, address: &EVMAddress, storage_key: &StorageKey) -> Result<StateValue>;
    fn query_svm_state(&self, pubkey: &SVMPubkey, data_key: &DataKey) -> Result<AccountData>;
    fn query_gaid_mapping(&self, gaid: &GAID) -> Result<GAIDInfo>;
    fn query_native_token_balance(&self, gaid: &GAID, vm_type: VMType) -> Result<Balance>;
    fn generate_state_proof(&self, query: &StateQuery) -> Result<StateProof>;
}

pub struct ArichainGlobalState {
    pub evm_state_db: EVMStateDatabase,
    pub svm_state_db: SVMStateDatabase,
    pub gaid_registry: GAIDRegistry,
    pub native_token_registry: NativeTokenRegistry,
    pub query_cache: StateQueryCache,
}

VM-Specific State Access Interfaces

EVM State Database Access:

pub trait EVMStateInterface {
    fn get_account_state(&self, address: &EVMAddress) -> Result<EVMAccount>;
    fn get_contract_storage(&self, address: &EVMAddress, key: &StorageKey) -> Result<StorageValue>;
    fn query_other_vm_state(&self, vm_type: VMType, query: &StateQuery) -> Result<StateResult>;
    fn verify_external_state_proof(&self, proof: &StateProof) -> Result<bool>;
}

impl EVMStateInterface for EVMEngine {
    fn get_account_state(&self, address: &EVMAddress) -> Result<EVMAccount> {
        // Standard EVM account state retrieval
        let account = self.state_db.get_account(address)?;
        Ok(account)
    }
    
    fn query_other_vm_state(&self, vm_type: VMType, query: &StateQuery) -> Result<StateResult> {
        // Access global state database to query other VM states
        match vm_type {
            VMType::SVM => {
                let svm_result = self.global_state.query_svm_state(
                    &query.target_address,
                    &query.data_key
                )?;
                Ok(StateResult::SVM(svm_result))
            },
            VMType::GAID => {
                let gaid_info = self.global_state.query_gaid_mapping(&query.gaid)?;
                Ok(StateResult::GAID(gaid_info))
            },
            _ => Err(StateError::UnsupportedVMType)
        }
    }
}

SVM State Database Access:

pub trait SVMStateInterface {
    fn get_account_data(&self, pubkey: &SVMPubkey) -> Result<SVMAccount>;
    fn get_program_data(&self, program_id: &ProgramId) -> Result<ProgramData>;
    fn query_other_vm_state(&self, vm_type: VMType, query: &StateQuery) -> Result<StateResult>;
    fn verify_external_state_proof(&self, proof: &StateProof) -> Result<bool>;
}

impl SVMStateInterface for SVMEngine {
    fn get_account_data(&self, pubkey: &SVMPubkey) -> Result<SVMAccount> {
        // Standard SVM account data retrieval
        let account = self.state_db.get_account(pubkey)?;
        Ok(account)
    }
    
    fn query_other_vm_state(&self, vm_type: VMType, query: &StateQuery) -> Result<StateResult> {
        // Access global state database to query other VM states
        match vm_type {
            VMType::EVM => {
                let evm_result = self.global_state.query_evm_state(
                    &query.target_address,
                    &query.storage_key
                )?;
                Ok(StateResult::EVM(evm_result))
            },
            VMType::GAID => {
                let gaid_info = self.global_state.query_gaid_mapping(&query.gaid)?;
                Ok(StateResult::GAID(gaid_info))
            },
            _ => Err(StateError::UnsupportedVMType)
        }
    }
}

State Query Examples

Example: EVM Contract Querying SVM Program State

// EVM smart contract querying SVM program state
contract CrossVMOracle {
    function getSVMProgramData(bytes32 svmProgramId) external view returns (bytes memory) {
        // Query SVM state through global state interface
        StateQuery memory query = StateQuery({
            vm_type: VMType.SVM,
            target_address: svmProgramId,
            data_key: bytes32(0) // Default data account key
        });
        
        StateResult memory result = GLOBAL_STATE.queryOtherVMState(VMType.SVM, query);
        require(result.success, "SVM state query failed");
        
        return result.data;
    }
}

Example: SVM Program Querying EVM Contract State

// SVM program querying EVM contract state
#[program]
pub mod cross_vm_data {
    use super::*;
    
    pub fn get_evm_contract_storage(
        ctx: Context<QueryEVMState>,
        evm_contract: [u8; 20],
        storage_slot: [u8; 32]
    ) -> Result<[u8; 32]> {
        // Query EVM state through global state interface
        let query = StateQuery {
            vm_type: VMType::EVM,
            target_address: evm_contract,
            storage_key: storage_slot,
        };
        
        let result = ctx.accounts.global_state.query_other_vm_state(VMType::EVM, &query)?;
        
        match result {
            StateResult::EVM(evm_data) => Ok(evm_data.storage_value),
            _ => Err(ErrorCode::InvalidStateResult.into()),
        }
    }
}

State Consistency and Performance

Optimized State Access:

pub struct StateQueryCache {
    pub evm_cache: LRUCache<EVMStateKey, EVMStateValue>,
    pub svm_cache: LRUCache<SVMStateKey, SVMStateValue>,
    pub gaid_cache: LRUCache<GAID, GAIDInfo>,
    pub query_history: QueryHistory,
}

impl StateQueryCache {
    fn get_cached_or_query(&mut self, query: &StateQuery) -> Result<StateResult> {
        // Check cache first for performance
        if let Some(cached_result) = self.check_cache(query) {
            return Ok(cached_result);
        }
        
        // Execute actual state query
        let result = self.execute_global_query(query)?;
        
        // Cache result for future queries
        self.cache_result(query, &result);
        
        Ok(result)
    }
}

State Proof Generation:

pub struct StateProof {
    pub vm_type: VMType,
    pub state_root: [u8; 32],
    pub merkle_path: Vec<[u8; 32]>,
    pub leaf_data: Vec<u8>,
    pub proof_index: u64,
}

impl GlobalStateManager {
    fn generate_inclusion_proof(&self, query: &StateQuery) -> Result<StateProof> {
        match query.vm_type {
            VMType::EVM => {
                let proof = self.evm_state_db.generate_merkle_proof(
                    &query.target_address,
                    &query.storage_key
                )?;
                Ok(StateProof::from_evm_proof(proof))
            },
            VMType::SVM => {
                let proof = self.svm_state_db.generate_account_proof(
                    &query.target_address
                )?;
                Ok(StateProof::from_svm_proof(proof))
            },
            _ => Err(StateError::UnsupportedProofType)
        }
    }
}
PreviousGAID ArchitectureNextBridge Infrastructure

Last updated 24 days ago