Elrond VM

Elrond builds its VM infrastructure on top of the K Framework, which is an executable semantic framework where programming languages, calculi, as well as type systems or formal analysis tools can be defined. K Framework has the possibility to generate interpreters that are correct-by-construction for any language defined in K. These interpreters can be generated in several programming languages, via components called K Framework “backends”. The smart contract interpreters in Elrond are generated via a Go backend. The generated interpreters are made available in the project elrond-vm, so that users can compile straight away, without the need to generate the sources first.

Additionally to the generated interpreters, the elrond-vm project also contains adapter code for the interaction with the blockchain and tests. Because Elrond supports multiple VMs, there is one VM adapter interface that is implemented by all Elrond VMs. This interface resides in project elrond-vm-common.

Elrond VM diagram

Supported VMs and languages

In principle any smart contract language formalized in K can become a smart contract language in Elrond. In practice, low level languages are preferred for direct support, so that the gas model is easier to map to the more atomic instructions. Higher level languages, such as Solidity are used indirectly, via a compiler that converts the high-level code into lower-level code.

There are several intermediate-level smart contract languages specified in the K Framework already, or with their specifications under development.

1. IELE VM

The first SC language supported by Elrond is IELE VM, which is an intermediate-level language, in the style of LLVM, created for the blockchain.

It was built directly in K, no other specification or implementation of it exists outside of the K framework. Its purpose is to be human readable, fast, and to overcome some limitations of EVM.

Elrond uses a slightly altered version of IELE. The changes from the original version of IELE are:

  • Addresses in Elrond are 32 bytes wide, instead of the Ethereum-style 20 bytes.

  • Smart contract addresses in Elrond start with 10 bytes of zeros.

  • The last 2 bytes of each address indicate in which shard the account will land. When creating a new smart contract, the last 2 bytes of the smart contract address are copied from the creator, in order for the smart contract to always land in the same shard as its creator. This leaves 20 bytes for

  • New smart contract accounts start with nonce 0 instead of 1.

  • In the original version an account with both balance and nonce zero is considered not to exist. In Elrond, the node tells the VM which accounts exist and a smart contract with both balance and nonce 0 is possible.

Smart contract developers can program in IELE directly, but most will choose to code in Solidity and then use a Solidity to IELE compiler, as can be seen in the figure below:

Solidity to IELE compiler diagram

Just like there are a few changes in IELE, the Solidity compiler also needed to be forked, to accommodate 32 byte addresses. This fork can be found at github.com/ElrondNetwork/solidity

Please note that this version of the compiler is still in testing mode.

2. KEVM

KEVM is a version of the Ethereum Virtual Machine(EVM), written in K. Certain vulnerabilities of EVM are fixed in the K version, or left out entirely.

The integration of KEVM is currently work in progress.

3. WASM

Web Assembly (WASM) is a binary instruction format for a stack-based virtual machine, which can be used for running smart contracts. A WASM infrastructure enables developers to write smart contracts in C/C++, Rust, C#, and others.

The integration of WASM is currently work in progress.