Skip to content

STRATO's Pluggable VM

What is a Virtual Machine?

A virtual machine (VM) is an internal, software processing component, or "brain" of a larger system that emulates the processes of normal computer system. Rather than instructions being sent to the physical hardware of a machine like the CPU, instructions are sent to a "virtual CPU" that has been written in software. VMs allow for complete custom implementation of a system that can be tailor fit to meet the needs of the use-case. It also provides a runtime-environment that is completely isolated from the rest of the system that the virtual machine is running on. Any operation that is done on a VM happens completely within the VM and does not expose the actual components or operating system of the native host machine to the running process.

For more information about Virtual Machines, see Red Hat's explanation of the topic.

The STRATO VM

The STRATO platform processes all transactions within its own virtual machine. The platform ships with two different VMs that users can choose from - the Ethereum Virtual Machine or EVM, as described in the Ethereum Yellow Paper, or BlockApps' custom SolidVM. The VM that each transaction uses to process data can be specified by the user - this functionality is what makes STRATO have a "Pluggable VM". The EVM is used by default, however it is strongly recommended to use SolidVM for its extended features and improved performance.

More information on the Ethereum Virtual Machine.

Solidity Smart Contracts

STRATO's VMs both use Solidity, the de-facto programming language used to create blockchain smart contracts. Solidity is very similar to other curly-braced languages such as C++, Java, or JavaScript. Much of the functionality will be familiar to many programmers, however there are several concepts and features unique to Solidity that allow it to harness and interact with the full capabilities of the blockchain. Because Solidity is such a large language with many different features, we will not go into detail about how to program with Solidity or all of it's features. However, here are some highlights of what makes Solidity powerful on the blockchain:

  • Address/Contract Types
    • Contracts can use the address of another contract as a reference to it's functions and state.
    • Contracts can be used like objects with their own methods and variables.
  • New Contract Creation
    • Contracts can create new contracts of a given type much like one would create a new Object in an Object-Oriented language.
  • Protected Data Access
    • Contracts can not directly modify the state of another contract. Contracts must implement their own functions to modify their own state variables.
  • Atomicity
    • If a function fails at any point in a transaction, any state changes in the transaction are reverted.
  • Payable Functions
    • In networks that use tokens like Ethereum, functions may only be called after an amount of tokens have been paid to that function. The contract then acts as a repository or wallet for tokens.
    • In STRATO, all parties are working together to provide accountability and verifiability, rather than competing to complete create a block, so this feature is rarely used or needed.

Furthermore, through the properties of a blockchain, a smart contract's code can never be modified. So whenever a smart contract is created, its internal logic will always be the same over time. This allows all parties to know exactly what a contract does and will do.

The supported versions of Solidity within the EVM for STRATO are:

EVM vs. SolidVM

While both VMs are capable of processing instructions through Solidity, each VM accomplishes that task in different ways, and with different features.

EVM (Ethereum Virtual Machine)

The EVM for STRATO is a Solidity compiler, meaning it takes the Solidity input source code, and translates that directly to instructions similar to the RISC instruction set. These instructions can than be executed by the EVM and produce an output. Because of the specification of the Ethereum Virtual Machine, there are limitations on what contracts can achieve using it. Most importantly this includes limits on the maximum level of recursion in a function, or the number of symbols (parameters or local variables) a function can use. Because the source code is compiled down to an instruction set, the original Solidity is lost and unable to be directly stored on the blockchain. Rather only the final instruction set is stored on the blockchain. This makes it difficult to inspect the contract's functionality after it is created.

SolidVM

SolidVM is BlockApps' in-house Solidity interpreter, meaning it parses the input source code into a logical structure that it can understand, and executes each statement in sequential order. A key difference here is that SolidVM does not transform the source code into a different instruction set for the VM to execute, rather it executes the instructions in the Solidity directly - there is no middleman process between Solidity statements and the actual execution of instructions. SolidVM also introduces necessary features in Smart Contracts to interact with key STRATO features like Private Chains and X.509 Identity Certificates. Because SolidVM adds features not included the EVM, there is some added or changed syntax over Solidity, however largely it remains the same. The core SolidVM langauge (SolidVM 1.0) is based on Solidity 0.4.24. BlockApps has periodic versioned releases to the SolidVM interpreter that allows for greater functionality, bug fixes, and updated language constructs to match further versions of standard Solidity.

This page documents the core different features and syntax supported in the core langauge. See the different version pages for more information on the features in each release.

Advantages

  1. All data types are of variable length (e.g. int, string, bytes, etc. can all take values of arbitrary size. They are not limited to a fixed byte length upon declaration). This prohibits dangerous overflow conditions by deliberately not supporting fixed length types like int8, etc.
  2. Function arguments and variables are not limited to 16 in quantity, as there is no maximum stack size. This also allows for arbitrary levels of recursion.
  3. Solidity contracts are stored and accessible in their original format since the source code is not compiled into low-level instructions.
  4. Solidity is processed faster due to a more efficient, custom-built execution machine, leading to faster transaction times overall.
  5. Solidity Events are logged in the Cirrus database. Each unique Solidity Event in a contract has a corresponding table in the database, and every time an instance of that event is emitted, a row is added to the table. EVM events only store the hashed data of the event payload, making it difficult to extract the data from the event.
  6. SolidVM enables contracts to communicate with and access contracts on Private Chains. This would be impossible in the EVM since the EVM has no concept of a Private Chain.
  7. Enables extended built-in functionality that works with other STRATO features like X.509 Verified Identities and Signature Verification. See specific version releases for more details.

Pragmas/Versions

Because SolidVM is a custom implementation of Solidity, SolidVM does not use the standard solidity pragmas for versions such as:

pragma solidity ^0.4.25;

Instead, a solidvm pragma is used to define the desired SolidVM version in a contract:

pragma solidvm x.y;

where x.y is the version number of SolidVM required.

No pragma version is needed to use the base SolidVM interpreter. Only use a version pragma to target a higher version.

See each specific version's documentation for more info.

Info

SolidVM versions are independent of STRATO versions, so previous SolidVM versions may be used in newer versions of STRATO. However some STRATO releases are subject to be non-backwards compatible or not support networks with mixed versions. See each STRATO version's Release Notes for more information on specific release compatibility.

EVM Compatibility Mode

As of STRATO v7.1, the platform has the capability of running the VM in "EVM Compatibility Mode". This enforces all contracts uploaded to use the EVM. If a user attempts to upload a contract using SolidVM as the VM, an error will be thrown. This is an environment variable specified at STRATO boot time and a network initialized with this feature turned on cannot revert this choice. The benefit of this feature is that it allows contracts to be ported from the main Ethereum network to the BlockApps STRATO platform with little to no code alteration.

To turn on EVM compatibility mode, use:

EVM_COMPATIBLE=true
when starting STRATO. This will also automatically turn on EVM indexing in Cirrus, which has been disabled by default as of STRATO v7.5.

Info

If a contract written for SolidVM with SolidVM-specific syntax is uploaded as an EVM contract, STRATO will throw an error for unsupported syntax since the normal solidity compiler will not recognize some of the syntax that was written for SolidVM.

EVM Debug Logs

Environment variable:

evmDebugMode=true

Limitation

Contracts using the EVM will only output the compiled low-level instructions the EVM will execute. This makes it rather difficult to trace each step that the VM is taking. This is another benefit of using SolidVM on the STRATO platform over EVM.

Smart Contracts Resources

If you are new to developing with Solidity, don't be afraid. Solidity is easy to pick up if you have experience with other popular languages that use Object Oriented principles. Once you understand the motivation behind Smart Contracts it should hopefully make programming them easier as well.

To get started making real, functional Smart Contracts, we highly recommend looking at our Developing Smart Contracts Guide.

For more resources around Solidity and Smart Contract development, we recommend: