A smart contract is a set of digitally defined commitments, including agreements on which contract participants can execute those commitments. Blockchain technology has brought us a decentralized, immutable, and highly reliable system. In this environment, smart contracts can be very useful. Smart contracts are one of the most important features of blockchain and the main reason why blockchain can be called a disruptive technology.
What are the characteristics of NEO smart contracts
NEO Smart Contract 2.0 includes the following features: determinism, high performance, and scalability. Its contract types include: verification contract, function contract and application contract.
From a performance point of view, NEO adopts the lightweight NeoVM (NEO Virtual Machine) as its smart contract execution environment, which has a very fast startup speed and takes up very little resources, which is suitable for short programs like smart contracts. Static compilation and caching of hotspot smart contracts through JIT (Just-In-Time Compiler) technology can be significantly improved. The instruction set of the NEO virtual machine provides a series of cryptographic instructions built-in to optimize the execution efficiency of cryptographic algorithms used in smart contracts. In addition, data manipulation instructions provide direct support for arrays and complex data structures. These will improve the performance of NEO Smart Contract 2.0.
The way NEO Smart Contract 2.0 achieves scalability is through the form of high concurrency and dynamic partitioning, combined with its low-coupling design. The low-coupling contract program is executed in a virtual machine (NEO virtual machine) and communicates with the outside through the interactive service layer. Therefore, most upgrades to smart contract functions can be achieved by adding APIs in the interactive service layer.
What language to write smart contracts in
From a language point of view, the difference between NEO smart contract 2.0 and Ethereum is more intuitive: unlike the original Solidity language of Ethereum, NEO smart contract developers can directly use almost any high-level language they are good at to develop NEO smart contracts. NEO provides compilers and plugins for these languages ​​for compiling high-level languages ​​into instruction sets supported by the NEO virtual machine. Since the compiler compiles against MSIL (Microsoft Intermediate Language), theoretically any language in .Net or a language that can be translated into MSIL can be directly supported.
Currently supported languages ​​are:
· C#, VB.Net, F#
· Java, Kotlin
· Python
High-level languages ​​that are planned to be added in the future include:
· C++, C++, GO
· JavaScript
The support of multiple high-level languages ​​enables more than 90% of developers to participate in the development of NEO smart contracts without learning a new language, and can even directly transplant the code in the existing business system to the blockchain. This will greatly increase the overall popularity of blockchain in the future.
Finally, from the perspective of debugging, the development process of smart contracts is usually very difficult. One of the important reasons is that the previous smart contracts lacked good debugging and testing methods. NEO provides support for program debugging at the NeoVM level, making it easier and faster to develop NEO smart contracts 2.0.
Triggering of smart contracts
NEO's smart contracts can be triggered in two ways:
· Authentication of contract users: The smart contract is used as a contract account. When the user uses an asset in the contract account, the smart contract will be triggered.
· Manually send a transaction to invoke a smart contract: The user sends a transaction (InvocaTIon TransacTIon) to trigger the execution of a smart contract.
A contract can be triggered by the above two methods at the same time. Since the contract triggered by the authentication is the authentication process of the UTXO model, it is executed before the transaction is written into the block. If the contract returns false or an exception occurs, the transaction will not be written to the block.
For a contract triggered by a transaction call, its call timing is after the transaction is written into the block. At this time, no matter what the application contract returns and whether it fails, the transaction has already occurred, and the state of the UTXO asset in the transaction cannot be affected.
NeoVM virtual machine
NeoVM is a virtual machine that executes NEO smart contract code. The concept of virtual machine described here is relatively narrow, and it is not a simulation of a physical machine by means of an operating system. The virtual machine here is different from vmware or Hyper-V, and is a virtual machine implemented for a specific language.
For example, in the JVM of java or the CLR of .Net, the source code of java or .Net will be compiled into relevant bytecode, and then run on the corresponding virtual machine. The JVM or CLR will fetch and decode these bytecodes. Execution, result write-back, etc., these steps are very similar to the concept on a real physical machine. The corresponding binary instruction is still running on the physical machine, the physical machine fetches the instruction from the memory, transmits it to the CPU through the bus, and then decodes, executes, and stores the result.
Virtual Machine Architecture
The figure above is the system architecture diagram of the NEO virtual machine (NeoVM), where the deployment in the dotted box is the core of the virtual machine.
execution engine
The green on the left is the virtual machine execution engine (equivalent to CPU), which can execute common instructions, such as flow control, stack operations, bit operations, arithmetic operations, logical operations, cryptography methods, etc. Interoperability service layer (described below) to interact.
Computational stack
The gray part in the middle is the computing stack of the virtual machine (equivalent to memory). Nowadays, there are two implementations of virtual machines, stack-based and register-based. These two implementations have their own advantages and disadvantages, and they also have iconic features. product. Stack-based virtual machines, such as JVM, CPython and .Net CLR. Register-based, there are Dalvik and Lua5.0. The stack-based virtual machine has a concept of a computing stack, and the virtual machine directly interacts with the computing stack (EvaluaTIon Stack) when performing real operations.
Since the default is to fetch data from the operand stack during execution, there is no need to specify the operand. For example, in x86 assembly "ADD EAX, EBX", it is necessary to specify where the operands need to be taken from this operation, and where to store the result after execution. However, the instructions of the stack-based virtual machine do not need to be specified. For example, the addition operation is a simple "Add", because the default operand is stored on the operand stack, and two pieces of data are popped directly from the operand stack and executed directly. Addition operation, the result of the operation is stored on the top of the stack by default.
Interoperability service layer
The blue part on the right is the interop service layer (equivalent to peripherals) of the virtual machine. At present, the interoperability service layer provides some APIs for smart contracts to access blockchain data. Using these APIs, you can access block information, transaction information, contract information, and asset information.
In addition, the interoperability service layer also provides a persistent storage area for each contract. Each NEO smart contract can optionally enable a private storage area when it is created. The storage area is in the form of key-value. The NEO smart contract determines the context of the persistent storage area by the callee of the contract, not the caller. to decide. Of course, the callee needs to pass its own storage context to the callee (that is, after completing the authorization) before the callee can perform read and write operations.
charging model
NEO smart contracts have to pay a certain handling fee when they are deployed or executed, which are divided into deployment fees and execution fees.
Deployment fee means that developers need to pay a certain fee (currently 500 Gas) to the blockchain system to deploy a smart contract to the blockchain.
The execution fee means that a certain execution fee will be paid to the NEO system for each execution of a smart contract instruction.
some simple smart contracts
Here are some simple smart contracts:
public staTIc bool Main()
{
return true;
}
The return value of the contract is always true, which means that anyone can spend the assets in the contract address (which can be understood as throwing money).
The NEO wallet client has the function of deleting assets. When you delete an asset, the asset is actually sent to a designated address. This address is the contract address generated by the above smart contract. Anyone can spend the assets in this address. Of course, the assets in this address are assets that others do not want.
public static bool Main()
{
return false;
}
The return value of the contract is always false, which means that no one can use the assets in this contract (which can be understood as burning money or destroying an asset), for example, the equity of some cancelled companies can be stored in it.
Fully Transparent Liquid Crystal Display
Fully Transparent Liquid Crystal Display,Industrial Instrument Lcd Display,Household Appliances Lcd Display,Fire Facility Instrument Display
Dongguan Yijia Optoelectronics Co., Ltd. , https://www.everbestlcdlcms.com