With the expansion of blockchain-technologies into the everyday life of the business environment, the concept of “smart contract” has ceased to be something of the unknown. And yet, despite the development of the topic, in a number of cases the knowledge of the principles of the operation and application of smart contracts is superficial and theoretical.
The majority of entrepreneurs who are implementing blockchain technology in the business, this is enough. There is an understanding that a smart contract is some arrangement fixed in the form of a code, and the transaction will take place only if they are executed. Having determined the subject and terms of the transaction, the implementation of the mechanism of the smart contract is given to specially trained people – developers.
Their further actions are perceived by an unprepared person as a “dance with a tambourine.” The developers are happy with such a situation: the fewer people understand the mechanics of their work, the higher their cost as professionals in the labor market. Customers who are accustomed to contracts written in the human language, the more they do not want to delve into the structure of the program code. This kind of blind delegation puts the businessman in dependence on the technical team and, in case “something goes wrong”, can lead to problems, the very possibility of occurrence of which the developers prefer to keep silent.
High risks and gaps in understanding the principle of the operation of smart contracts increase the already serious level of mistrust of this tool. Let’s try to solve the problem and understand the key aspects of technology, which in the foreseeable future has every chance to transform orthodox business processes.
A smart contract needs conditions
The idea of the logic of the treaty, when event B is not accomplished, until event A has occurred, is not innovative. A smart contract ensures the categorical implementation of the agreements, which is stipulated mathematically, excludes the dependence of the transaction participants from any kind of centralized system or the influence of the human factor and at the same time guarantees the automation, transparency and safety of the entire process. But only if the implementation environment of the smart contract assumes the possibility of fulfilling the programmed conditions and provides direct access to the objects of the contract. 14 years after the theoretical description of the idea of a smart contract, this environment became a blockchain.
To date, the market offers the development of smart contracts for Ethereum, Hyperledger Fabric, Cardano, NEO and other blockchain platforms. But not all of them are well adapted for the execution of smart contracts. So, bitcoin does not contain state markers and does not give programmers freedom of action, and NXT contains a limited number of templates of smart contracts and does not imply the possibility of creating its own version. Ethereum, devoid of these shortcomings, has become the basic platform for the implementation of smart contracts.
Proceeding from this, as if the blockchain enthusiasts did not pedal the idea of the universality of smart contracts, their implementation is possible only if your business and your partner’s business evolved to the integration of blockchain-technologies.
How to understand the computer code
No matter how persuasive the prospects for using smart contracts are, conservative skeptics will have arguments against it. Even considering the full range of possibilities for challenging traditional contracts, a piece of paper with a seal and a signature will be more authoritative for them than an intangible computer algorithm. Developers, who will get a client with such a principled position, should be patient and get ready for a request to read, touch and rotate “what you wrote there”.
Let’s try to figure out what exactly is a smart contract, what it looks like and what information it contains.
A smart contract is a computer code, a record of successive functions that determines the parameters and logic of the performance of contractual obligations of the two parties. Like any code, it’s laconic and unambiguous, but it’s clear to programmers only.
In 2014, a special Solidity programming language was designed by Ethereum experts to record the code of smart contracts. It has many common features with Java Script and is characterized by the ability to implement any computational function.
The volume of a smart contract is determined by the number of rows with records. The more complicated the conditions, the more lines in the code. The finished smart contract code is translated into the byte code of the virtual machine Ethereum, which leads the contract into execution. As the terms of the contract are fulfilled, the computers and the nodes of the block account update the register.
If everything is clear with the form, let’s move on to the content of the most popular sphere of application of smart contracts – the organization of the primary release of tokens.
The structure of the main part of the code is a hierarchy of contracts that prescribe one or another completed functional cycle, and consists of five key elements. One of the most important contracts of the structure is called owned, its task is to allocate the contract owner from the total number of users and give it a privileged functional (for example, the ability to withdraw money from accounts).
The following contract contains information about the collection of funds and the distribution of tokens. It specifies the total number of tokens issued, information about the balance sheets of all the holders of the tokens, and the reaction of the smart contract to the movement of tokens between the holders. All the elements of the crowdsale contract are mandatory, if incorrectly filled in this part of the contract, the tokens will not be displayed in the holders purse.
The fallback function is responsible for the order of actions in the event of the arrival of aether on the account of the smart contract. It checks the availability of tokens available for sale, fixes their price and calculates how many tokens need to be sent to the buyer.
The following for crowdsale subcontract, EasyToken, captures the full and abbreviated name of the token, determines its divisibility or indivisibility and, most importantly, allows users to display tokens on the exchange, remove them from there and exchange them.
And, finally, the most pleasant feature – the ability to get the received air – is prescribed in the contract EasyCrowdsale.
Register other terms of the smart contract (the term of ICO, softcap and hardcap and so on) is possible until the developer’s imagination is exhausted. However, unnecessarily heavier code construction without the need is still not recommended, if only because the more data, the higher the probability of making an error.
Right to error
The main thing that you need to remember when creating a technical task for the developer to write a smart contract: you will not have the opportunity to think through the functional and finalize the contract in the process of work. The code already loaded into the block can not be changed, and any error made while writing it will result in incorrect execution of the contract or complete loss of control over it. The only possible way to fix the situation is to download a new contract with the corrected code.
Even the big players in the preparation of smart contracts manage to make mistakes, which, unfortunately, are discovered too late. And it’s definitely better for the developer to see them before the attackers do it. An error when writing a smart contract for The DAO allowed hackers in 2016 to hack the system and bring tokens to their wallets, the incident led to the collapse of ethereum rate and even reflected on bitcoin quotes.
And in the autumn of last year someone under the nickname Devops199 took advantage of the critical vulnerability of the smart contract Parity and launched the process of its self-destruction. As a result, 513,774 ETHs were blocked on users’ accounts (for those times $ 160 million).
Given the shortage and high workload of qualified developers, the logical development of the market for services in the field of blockchain-technologies was the emergence of companies that audit the smart contract before launch. For a small amount of capitalization of the market, the amount (500-1000 dollars) specialists with a bland eye will re-read the code and check it for errors and possible vulnerabilities.
The fact that smart contracts operate with money and are not subject to change, plays into the hands of hackers. Every day, soldiers of the shadow front of the blockchain are studying new codes and attempting to break them.
Write: Richard Abermann