AELF Whitepaper V2
  • AELF V2 - Embarking on a New Frontier of AI x Blockchain
  • Modular Blockchain
    • The Modular Blockchain
  • The Data Avalability Layer
    • The Data Availability Layer
  • Off-chain Execution
    • AEStack
    • On-Chain Games
    • AI Models Execution
  • Superior Usability
    • Chain Abstraction
    • Social Login
    • Flexible Fee Model
  • AELF V1
    • Consensus Mechanisms
    • Multi-Chain Architecture
    • Parallel Execution
    • The AVM
  • Roadmap
    • Roadmap
Powered by GitBook
On this page
  • The Interface
  • Smart Contract Development
  • Host Environment
  • The C# Virtual Machine (CLR)
  • The Smart Contract Executive
  • Ensuring Safety: Constraints in the Execution Environment
  1. AELF V1

The AVM

PreviousParallel ExecutionNextRoadmap

Last updated 11 months ago

The AElf blockchain aims to support multiple virtual machines and programming languages.

The Interface

At the heart of AElf’s smart contract execution lies the ISmartContractBridgeContext interface. This interface defines the API between smart contracts and the host environment. Here’s how it works:

Smart Contract Development

Developers can code smart contracts in any language as long as there’s an SDK that utilizes the ISmartContractBridgeContext interface. This approach allows for language diversity and encourages innovation.

Host Environment

The actual execution of smart contracts occurs within the host environment. The host implements the IHostSmartContractBridgeContext interface, which extends ISmartContractBridgeContext. Through this interface, smart contracts interact with the blockchain, access contract states, and fire events.

Figure 10.0. Contract Context

The C# Virtual Machine (CLR)

In the AElf blockchain ecosystem, C# stands as the default language for crafting smart contracts. During runtime, a specialised version of Common Language Runtime (CLR) executes these C# smart contracts. AElf's runtime, based on the CLR, is aptly named the AElf Virtual Machine. Notably, AElf holds the distinction of being the pioneering blockchain platform to employ this smart contract execution engine.

The Smart Contract Executive

The following code snippet depicts the core construct.

public interface ISmartContractExecutiveService
{
    Task<IExecutive> GetExecutiveAsync(IChainContext chainContext, Address address);
}

public interface IExecutive
{
    Task ApplyAsync(ITransactionContext transactionContext);
}

Ensuring Safety: Constraints in the Execution Environment

Safety Measures: The smart contract execution environment isn’t identical to the CLR due to safety considerations. AElf introduces specific constraints to prevent malicious or resource-intensive behavior:

  • Floating Operations: Disallowed to maintain determinism.

  • Whitelisted Libraries: Only approved libraries are allowed.

  • Array Size Limit: Arrays are restricted to 40KB.

  • Conditional Branches Limit: A maximum number of conditional branches.

  • Method Calls Limit: A maximum number of method calls.

The AElf Virtual Machine combines flexibility, safety, and performance, making it a powerful platform for smart contract development. As AElf continues to evolve, its virtual machine will play a pivotal role in shaping the future of decentralized applications.

Each deployed smart contract becomes an instance encapsulated within an object. The ApplyAsync method of the IExecutive interface handles contract execution. The separation of contract instances ensures efficient management and execution.

You can refer to our for a more complete and detailed explanation of these constraints.

IExecutive
repo