WasmVM initializes whenever it gets a request from Blockchain to execute a particular SC function. For SC execution indicates the count of GAS units. If during execution the number of GAS is not enough, the SC will be terminated. In case spent units will not return and executors will not get the reward.
Rules for calculations GAS
Currently, the calculation formula is linear:
1 GAS Unit = 1 Wasm instruction
Also, it should notify that the write to memory operation is paid while the read from memory operation is free. Below the calculation formula for it:
1 byte = 1 GAS Unit
For example, if it writes 10Kbyte of data the cost will be at least 10240 GAS units.
Interacting with the external world
WasmVM is an isolated environment from the “external world”. That means there is no direct access to VM from out and vice versa. Such conditions provide guaranteed execution security, data saving, reliability, and fail-safety. SC execution speed depends on physical machine resources where DFMS is running. For interaction with the “external world” the mechanism of “external functions” was introduced. This means, using the SuperContract SDK, you can use access to the built-in functions in WasmVM, which allows you to access Blockchain, HTTP requests, etc. This provides a wide range for the flexible development of SC, including quite complex Oracles. All available functions, documentation, and examples, can be found in SuperContract SDK.
The WasmVM has a set of versions. It allows ensuring that SC assembled for a specific version of the VM is guaranteed to run on the same version of VM (versions are part of the DFMS). Because the WasmVM must be safe and has the same execution results for different executors, the versions can be incompatible. It is worth noting that the version of WasmVM automatically writes in the Blockchain, and is taken from the current version of the DFMS WasmVM of the SC owner.
Results of SC execution
Operations for sending transactions to Blockchain
Sending transactions to Blockchain doesn’t occur straight away. When transactions are sent from SC, it is collected in Transactions Pull. To send transactions immediately to Transactions Pull, you should call the external function WasmVM - flush.
Also, Transactions Pull transactions will be sent automatically after completion of the SC function.