Neo Virtual Machine
Blockchain Virtual Machines
A blockchain is a distributed database that is managed by multiple members at the same time. In order to update this database, the members must agree on its new state. The network must reach . However, we need to ensure that the same operations are executed in the same order by all members. This is where the blockchain virtual machine comes in.
The role of the blockchain virtual machine
A blockchain virtual machine is a virtual machine that runs on all nodes of a blockchain network. It is responsible for executing the same operations in the same order on all nodes. This ensures that the blockchain is deterministic and that all nodes reach consensus. The blockchain could not achieve the same state on all nodes without a blockchain virtual machine.
Neo Virtual Machine
The Neo blockchain uses a blockchain virtual machine called the Neo Virtual Machine (NeoVM). The NeoVM is a lightweight, extensible, scalable, and safe virtual machine that is optimized for the execution of . The Neo Virtual Machine is different from the Ethereum Virtual Machine (EVM) in that it is not a stack machine. Instead, it is a register-based virtual machine. This allows more programming languages to be supported.
Neo VM Interop Layer
One of the most important features of the NeoVM is the NeoVM Interop Layer. The NeoVM Interop Layer is a set of APIs that allow the VM to perform operations that are not supported by the VM itself. It’s through the NeoVM Interop Layer that the NeoVM can interact with the blockchain and the outside world.
Neo VM Execution Engine
The NeoVM Execution Engine is the part of the NeoVM that executes instructions in form of scripts. The Execution Engine tracks GAS consumption and ensures that the execution of the script is deterministic.
Neo VM Final State
Once a script is loaded and run by the NeoVM, the final state of the NeoVM is returned. This final state is the result of the execution of the script. The final state is a combination of the execution result, the GAS consumed, and the stack.
Neo VM Execution Result
The execution result of a script can have one of two outcomes:
HALT Execution Result
This indicates that the execution of the script has finished successfully. The NeoVM returns the final state with the execution result, GAS consumed, and the stack. A ‘Halt’ result ensures that all operations were executed as intended and the smart contract or transaction is considered valid.
FAULT Execution Result
This outcome signifies that the execution of the script has failed. A ‘Fault’ is typically returned when the NeoVM encounters an error, like insufficient GAS, invalid operation, or any violation of the script’s expected behavior. In this case, the transaction or smart contract is considered invalid, and its changes are not committed to the blockchain.
The Neo VM Execution Result provides a clear and deterministic conclusion that aids in maintaining the consensus across the blockchain network.
Neo VM Execution Triggers
Execution triggers are the events that trigger the execution of a script by the virtual machine. The most common trigger is the Application trigger, which is used when a script is triggered by a transaction. The NeoVM also supports other triggers, such as the Verification trigger, which is used when a script is run to verify a block. Except when verifying a block, the Application trigger is the most commonly used trigger.