The AVM
Last updated
Last updated
The AElf blockchain aims to support multiple virtual machines and programming languages.
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:
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.
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
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 following code snippet depicts the core construct.
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.