We believe a good implementation of virtual machine needs to be both elegantly designed, easy to use, and secure. After comparing the pros and cons of EVM, EOS, C Lua and V8, we have fundamentally resolved unreasonable designs of EVM and EOS. We have managed to build the IOST VM based on V8 due to on the its high performance on Chrome.
1. IOST V8VM structure and designs
VMManager is at the core of V8VM. It has three main features:
- VM Entrance. It interfaces external requests from other modules, including RPC requests, block validation, Tx validation, etc. The work is handed off to VMWorker after preprocessing and formatting.
- Management of interface with State database. This ensures atomicity of each IOST transaction, denying the entire transaction when there is an error of insufficient funds. At the same time, two-level cache is achieved in the State database, before being flushed to RocksDB.
2. Sandbox core design
Mainly for smart contract development and publishing, it has two features:
Mainly for execution of on-chain contracts, it has two features, too:
|Blockchain||Node.js-like modular system, including module caching, pre-compilation, cycle calls, etc.|
|NativeModule||Blockchain-related functions including transfer, withdraw and obtaining information on current block and Tx.|
Terminatethe current run when there is an error, insufficient resource, or timeout, and return abnormal results.
The smart contract engine of IOST consists of three parts: monitor, VM, host. Monitor is the global control unit that gateways ABI calls to the right VM. VM is a virtual machine implementation of smart contracts. Host packs the runtime environments and makes sure the contracts run in the right context.