In this final post in our three part series on Blockchain, we discuss an important idea in this space, smart contracts. This featured heavily at recent Blockchain Summits and similar conferences, and is a topic of great interest and research.
As anyone who has studied computer science will know, there are two central concepts joined at the hip: code and data. Code is executed by a computer and does something to the data, whether searching it, sorting it, doing calculations, and so on. A movie or song stored on a server or CD is just data. Code is needed that will load the movie and play it for you. You could say that code brings data to life. On the other hand, code without any data is useless. The two need each other.
In the context of blockchain, we have so far talked about using it to store data, whether financial records or anything else. But why limit ourselves to that? Why not use it to store code as well? Any code we store on the blockchain will have all the same properties that data has: namely, we can guarantee that it hasn’t been changed inadvertently and we can ensure agreement on its result.
How might this be used practically? Let’s consider a traditional contract, usually a printed document written by a solicitor in legal language. How is the contract enforced if things go wrong? A third party, such as a court or other government authority has to be involved. This type of enforcement is both costly and time consuming. Imagine if we could somehow create a contract that doesn’t need such involvement, and that could still be a means through which parties could do business with each other and gain trust.
A smart contract (also known as self-executing contracts, blockchain contracts, or simply digital contracts) is a computer program that precisely encodes the terms of an agreement with the ability to self-execute and self-enforce. This is in principle a separate concept from distributed ledgers/blockchain, but they happen to go well together, as a blockchain is the perfect storage and execution mechanism for smart contracts.
In a trade financing scenario, a smart contract could be set up to automatically execute a trade deal when certain conditions are satisfied. For example, when a digital version of the letter of credit is added to a distributed ledger, the smart contract would pick up on this and send a message to the supplier informing them that the stock can now be shipped. Another smart contract would be responsible for triggering payment once the shipment is scanned at the arrival port.
In capital markets, a smart contract could effectively replace the role of a clearinghouse by encoding the logic that would ensure that transfer of the assets only occurred once payment was cleared. We can also imagine all kinds of new ‘smart’ securities that could be traded, each preprogrammed to behave in increasingly complex ways.
Smart contracts could also be useful in cross-border payments. For example, a smart contract could monitor FX rates and only execute a cross-currency transfer once rates are at a certain level.
A business agreement could be enforced through a smart contract, setting out, for example, that scheduled payments be made once certain items are delivered or targets met, assuming these can be digitally determined and verified. Perhaps as soon as a manager at a client digitally signs off having received a product or service, the payment will be triggered. No more chasing invoices.
How do smart contracts work?
So how do smart contracts work in the context of distributed ledgers? The smart contract is simply computer code created using smart contract development tools, and often written using programming languages such as C++ or Java, though dedicated higher level languages are being developed.
This code defines the rules and consequences in the same way that a traditional legal document would, stating the obligations, benefits and penalties which may be due to either party in various circumstances. The key difference being that this is now done using computer logic rather than legal language subject to interpretation. Sophisticated smart contracts can integrate data from different organisations: for example, a smart contract for the delivery of a consumer good might connect with the delivery firm and the vendor’s payments provider.
The code is then sent out to a distributed network of ledgers. Each of the computers in this network separately execute the code and come to an agreement on the results of the execution. The ledgers would then be updated to record this agreed result, and then each node would monitor it on an ongoing basis to check for compliance. Execution is no longer in the hands of a single party and all the nodes in the network must always agree on the terms of the contract and whether the parties are in compliance.
In this fully automated scenario, there is no need to rely on a lawyer (or other intermediary such as a broker) in order to draw up and help enforce the contract. Incidentally, this also eliminates the possibility of third party manipulation, since execution is managed by a distributed network rather than by one or more individuals who may introduce errors, deliberately or otherwise. The code, along with any legal documents are encrypted on a shared ledger, available to all parties. No one can claim they ‘lost’ a document!
To make sure terms are being complied with, parties involved will no longer have to spend time on paperwork to manually process documents on a regular basis. Since smart contracts automate these tasks, time and money can be saved, and not to mention the avoidance of mistakes when filling out forms. Therefore, if smart contracts do catch on, it’s possible that in the future a contract will be primarily entered onto a distributed ledger, and a ‘paper’ version of some kind also filed as a backup.
Now, smart contracts are obviously far from perfect. As any experienced software engineer will tell you, the best written code can still have bugs (though at Sinara we pride ourselves on catching these early!). Who would have liability for such mistakes? How should such contracts be regulated? Or, indeed, taxed?
There are more concerning aspects to this, however, that require careful debate as to what should be permitted. What if a smart contract contained sophisticated AI that made decisions itself? Something out of a dystopian film, perhaps, but worth thinking about as we consider the future of such potentially pervasive technologies.