We are excited to announce just at 04:02:15 (UTC+8), Jan 18, 2019, a scheduled hard fork, named "Smart Fork", was successfully completed on Vite TestNet. This is a major milestone. In this fork, Vite TestNet enables the capability of deploying and calling smart contracts. Please kindly remember to upgrade your gvite version to v1.2.2 or above.
Smart contract is the essential technology of public blockchain. It is so important that most public chain projects would rather wait until the launch of MainNet to enable smart contracts. Vite's mission has always been to create a public blockchain that can be used in real cases. In order to make the TestNet more productive and prepare for launching a more robust MainNet, we believe that turning on smart contract in Vite TestNet both fulfills Vite's original commitment and provides benefits to users. As the first DAG based public chain that successfully implements smart contracts in the world, dApp developers will be able to experience a faster, more secure and easy-to-use decentralized application platform with Vite than ever before.
What is Smart Contract?
The term “Smart Contract” dates back at least to 1995 and was proposed by American computer scientist and cross-disciplinary legal scholar Nick Szabo. He described a smart contract as "a set of promises, specified in digital form, including protocols within which the parties perform on these promises". Another useful working definition given by Investopedia is "Smart contracts are self-executing contracts with the terms of the agreement between buyer and seller being directly written into lines of code". From the perspective of Vite, smart contracts are more reliable constraints in public chain ecosystem than real-world contracts.
What is Asynchronous Smart Contract?
Cross-contract calls in Ethereum are represented as function calls, or internal transactions. This set of calls are either completed at the same time or all fail. Obviously, this sort of atomic ACID semantic could become a performance bottleneck in system. For example, the speed of contract execution dramatically affects the time of block generation and the contract execution concurrency that blockchain can support with limited fault tolerance. To tackle the issue, Vite adopts an asynchronous, message-driven architecture on the basis of known solution of centralized Internet technology. Smart contracts in Vite won't share states but communicate with each other via messaging. This is unique to Vite's smart contract mechanism.
Asynchronous Scheme
The life cycle of a transaction includes: transaction initiation, transaction writing and transaction confirmation. In order to improve system performance, all the three steps need to be designed in asynchronous mode. This is because the number of user-initiated transactions is different at various times, while the speed at which the system processes transaction writes or confirmations is relatively fixed. Asynchronous mode helps to smooth peaks and valleys, thereby increasing the overall throughput of the system.
The asynchronous model of Bitcoin and Ethereum is relatively simple. They put all user-initiated transactions into an unconfirmed transaction pool. Whenever the miner packs them into a block, the transactions are simultaneously written and confirmed. As the blockchain continues to grow, transactions eventually reach a preset confirmation confidence. Obviously, there are two problems with this asynchronous model.
-
Unconfirmed transactions are not persisted to ledger. They haven't participated in consensus process and therefore are unstable. There is no way to prevent transactions from being sent repeatedly.
-
The two processes of writing transactions and confirming transactions are performed in sequence, and therefore inefficient. Transaction is only written to ledger when it is confirmed. Writing speed is subject to confirmation speed.
Vite establishes a more complete asynchronous model in protocol. First, a transaction is split into a transaction pair based on the "request-response" model. Whether it is transfer or contract call, once the request transaction is written to ledger, the transaction is regarded as initiated successfully. In addition, transaction writing and transaction confirmation is also asynchronous. A transaction can be written to Vite's DAG ledger and will not be blocked by confirmation process, which is done through snapshot chain asynchronously. This is a typical "producer-consumer" model - regardless of the production rate of transactions, consumer can always digest at a constant rate, making full use of platform resources and improving throughput of the system.
The biggest characteristic of asynchronous smart contract is that the inter-contract calls are asynchronous. Synchronous smart contracts will block until results are returned during inter-contract communication, while asynchronous calls return directly without waiting for the result of cross-contract execution. Apparently, the waiting time in synchronous contract call can be utilized for other arrangement in asynchronous execution, making asynchronous contract faster.
Cost of Smart Contract
- Cost
In Vite TestNet, creating a smart contract consumes 10 VITE, which will be destroyed. - Quota
The quota for contract creation request transaction is supplied by contract creator while the quota for contract creation response transaction comes from the destruction of VITE. In the TestNet, destroying 10 VITE to create a smart contract will receive a quota of up to 1000000, specifically for contract creation purpose. Similar to contract creation, contract execution consumes quota as well. The contract request transaction and the contract response transaction consume the quota of transaction initiator and contract account respectively. - Quota Acquisition
In the TestNet, contract account can only obtain quota by staking. If a contract account does not have sufficient quota, the delegated consensus group will not package any transaction for this contract, so the contract provider should always stake adequate Vite tokens for it.
Smart Contract Language
Ethereum provides Solidity, a Turing-complete programming language for developing smart contracts. To support asynchronous semantics, Vite extends Solidity and defines a set of syntax for message communication. The extended Solidity in Vite is called Solidity++.
Solidity++ supports most of Solidity's syntax, but will no longer support synchronous function calls between contracts. Developers can define messages through "message" keyword and define message handlers via "onMessage" keyword to enable cross-contract communication. Messages in Solidity++ are compiled into CALL instructions. As a result, a request transaction is generated and appended to Vite's ledger, which plays a key role as message middleware for asynchronous communication between contracts, ensuring reliable storage of messages and preventing duplication.
See https://vite.wiki/tutorial/contract/contract.html for detailed technical documentation to learn Vite smart contract.
We sincerely invite world-wide dApp developers/programmers to build smart contracts on Vite. Let's create a rich library of contracts and build a strong Vite ecosystem together.