March 31, Beijing. Achain technology partner Li Pu spoke at the Blockchain Technology and Application Summit (BTA), sharing his thoughts on how to build fast and steady smart contracts for blockchain. The two-day event, organized by Chinese IT portal CSDN, drew more than a thousand attendees, including renowned blockchain experts, investors and blockchain technicians.
For Li, smart contracts have great potential when coupled with blockchain. Smart contracts will continue to be the groundwork for blockchain by bringing more functionality.
Although the smart contract concept, originally brought up by Nick Szabo in 1994, was old. Smart contract as one of the pillars of blockchain is still relatively new. There are still problems need to be solved and improvements to be made for the better performance of the technology.
“Drastic storage problems and how to solve them”
Smart contracts are essentially a group of codes that run on the blockchain network. It has the semantic builds of a natural contract, and mostly semi-autonomous. The design of a specific smart contract must comply with the limits blockchain network, such as block size, data design, processing interval and block generation time. Since the blockchain network can only process data of a certain size, it is crucial to design a smart contract that won’t trigger the storage and processing limit. A well designed smart contract will maximize the storage use and is fast to process.
There are two ways to tackle this issue, said Li. One, two layers of storage can be designed for incoming transaction data. On the first layer (on-blockchain storage) the action of smart contract execution or transaction is stored. On the second layer (offline storage), we store the results, or as some would say the status, of the transaction.
Secondly, “before” and “after” algorithms are used to modify transaction data, which is usually during the process of smart contract execution. “before” signifies the previous state of the data, “after” is the new status of the data where the transaction is complete. This way, the network doesn’t have to conjure up the whole data cluster when executing a smart contract. Instead, it just modifies the part that needs to be changed.
“Optimize smart contract design to ensure the best performance”
Besides the optimization on the storage side, smart contracts should also follow a set of principles to better performance. These principles are “data validity”, “complete design process” and “smart contract utility” because the data should be correct, design process solid and the smart contract easy to use.
Hence, a design process was created following these principles.
- Smart contract coding, off the blockchain
- Smart contract registration, on the blockchain
- Smart contract execution, on the blockchain
- Smart contract upgrade, on the blockchain
- Smart contract elimination, on the blockchain
The first three steps are easy to understand. They are basically similar to creating an app. First, you code the app, then install it on your phone (register on the blockchain) and finally start using the app. The divergence happens during step four and five. The blockchain is unique as any change made is irreversible. Therefore, after step three, an examination should be made to determine whether the smart contract faulty or not. If there are no bugs, we proceed to next step which is upgrading the smart contract. Consequently, the smart contract will exist permanently on the blockchain. If, however, the smart contract turns out to be faulty, we can eliminate the smart contract which won’t be seen on the blockchain.
In this way, we ensure any smart contract is secure and solid before going into public use. And at Achain, we have a Sandbox mechanism for off-chain smart contract examination before putting it onto the blockchain.
Li also calls for greater participation in blockchain development from programmers because the industry is still relatively new and there is a huge demand for blockchain developers.
Images courtesy of Achain