Pluggable VM: A Solidity VM Alternative

All transactions on the blockchain are processed by a central “brain”, which by default is a component called the Ethereum Virtual Machine (“EVM”). The EVM works well for processing most smart contracts; however, there may be some circumstances where a user would want to select an alternate way of processing the transaction information. STRATO contains an alternate “pluggable” VM which is Solidity-based (called SolidVM), which can also be selected as the interpreter for the contract.

Why Introduce a New VM?

Some key differences with the SolidVM:

  1. All data types are variable length (int, string, bytes can all take an arbitrary length data, and are not limited by 32 bytes, etc). To avoid dangerous overflow conditions, we deliberately do not support fixed length types like int8, etc
  2. Function arguments and variables are not limited by the 16 stack limit.
  3. Solidity contracts are stored and viewable in their original format.
  4. Processes Solidity faster, leading to faster transaction times for complex Solidity contracts

How to Select SolidVM as a Contract's VM

To select which VM is used to process the contract, you will need to pass a metadata parameter "metadata":{"VM": "SolidVM"} when first creating the contract on the blockchain, like this:

curl -d'{"src": "<sourceCode>", "metadata":{"VM": "SolidVM"}, "password": "<password>"}' -H "Content-Type: application/json" http://localhost/bloc/v2.2/users/<username>/<address>/contract?resolve

To enable this feature to an application that uses the block-apps rest framework tool, you would include the metadata parameter, ("metadata":{"VM": "SolidVM"}), in the constructor args that you pass to the contract upload call. If your contract upload call is part of a createUser function, the code would look something like this:

function* addContract(userName, password, contractName, contractFilename) {
  const user = yield rest.createUser(userName, password);
  const constructorArgs = {}; // optional
  const contract = yield rest.uploadContract(user, contractName, contractFilename, constructorArgs) }

If no metadata parameter is included, the EVM will be selected as the processor by default.

Once a VM is selected, that selection will remain in place for all future transactions on the blockchain relating to that contract.