What is a Smart Contract and why do we need them?
An explanation for slowpokes
So you might have read about smart contracts in relation to crypto currencies such as Ethereum and understood this is a big and revolutionary thing. You might even have tried reading some explanations of what they are.
But if you are like me, most of these articles went over your head, because either you are not familiar with tech jargon or you are not familiar with finance jargon or you have never put much thought into the practical and legal aspects of normal contracts and the exchange of assets such as property and stocks.
My intention with this article is to walk you through various examples of smart contracts and think out loud about the challenges they solve, and attempt to explain why smart contracts are a good idea in each case.
The problem when understanding something radically new, is that people immediately start explaining how it solves a problem, while you never quite realized that the problem existed at all and that it needed solving.
So lets try to gradually build up and understanding of what the problem is and why smart contracts solves them. For now we’ll just keep it a mystery what a smart contract is, technically speaking.
I like to start with something super simple that everybody should have experience with, which is buying tickets for the movies, a rock concert or theatre.
Fundamentally the problem is about limiting the people who enter the screening of a particular movie to the ones who have paid to see the movie.
A simple but naive and flawed approach
The simplest approach to this is to have a guy at the entrance to the movie screening, who collects money from people who want to watch the movie.
That solves the problem of only allowing entry to those who pay to gain access. However it causes lots of other problems. People might end up standing in line to see a movie only to discover when it is their turn, that there are no more available spots. Also it gets really hard to reserve a particular spot, because you have no proof to show other guests that you paid to sit in a particular seat.
Over the counter tickets
Tickets solve these problems. With tickets customers can buy access to a movie screened at a particular time at any time of the day when it suits them, and know in advance whether there will be a spot for them to sit in, when the movie is screened. Now you also have proof to show anybody else, that you did in fact pay to sit in seat number 42.
A reoccurring element I want to discuss in all these examples is the question of trust. Who needs to trust who and what are the incentives to stay honest. In this case the movie theatre has to trust that we are giving them real money for the tickets. That is mostly a solved problem since, paper money is hard to forge. The sales clerk really just need to take a look at and feel the paper bill in their hand to verify the authenticity of the money.
Both the customer and clerk need to make sure that they get something in exchange from the other. But that is easy, because they are directly facing each other and challenge each other if they don’t get something in return.
For the customer however the issue isn’t whether he or she gets something in return but whether they actually get an authentic ticket or if they get an authentic ticket whether it will be honored by the movie theatre, when they arrive later. By that I mean that the clerk could in theory just give you a random piece of paper with no significance and call it a ticket. As a customer you won’t know the difference. The clerk could also give you an authentic ticket but it could be a duplicate of one that has already been sold. Or they could give you a “real” ticket, but simply deny you entry to the movie theatre when you later arrive to watch the movie.
It probably seems utterly ridiculous that I am even discussing this with you, since we take these things for granted.
But it is precisely because we take all these details for granted that, we fail to comprehend how electronic versions of the same things work. We have simply never considered the minutiae of all the steps and trust involved in regular interaction and exchanges of goods, service sand money.
These interactions run smoothly in real life, because people have a great deal of trust between each other and in particular towards larger establishments such as a movie theatre. We assume that they will not renegade on the promise they give you buy selling you a ticket because it will become public knowledge that they cheat their customers. Thus their reputation is ruined and they don’t get more customers. Hence you know they have no incentive to cheat you and give you fake ticket.
Hence the purpose of the ticket isn’t for the customer to trust that they get something back, but so that we can prove to the movie theatre that we have paid for access to one of their movies. In other words trust only goes one way. We trust them but they don’t trust us. Again, lets ask the obvious. Why is that?
Our identity is not widely known to the extent that the movie theatre is. When we visit a theatre their identity is abundantly clear. However the identity of the customer is not obvious to the movie theatre. If we cheat them, they have no easy way of naming and shaming us.
This is why online ticket sales is fairly easy to accomplish. Since it is more important that the movie theatre verifies that we have paid them, an online solution really just requires payment to be verified, before letting us download a ticket. Theoretically it is easy for them to just return a bogus ticket or no ticket at all.
However we can trust that the movie theatre doesn’t do this, because we know it is not their incentive to do so. Although even this point is more complicated than it looks at first glance when being online.
You have to be able to trust that the web page you visit and pay money to, is actually the webpage of the movie theatre. In other words we have to be able to verify the identity of the webpage. That is a solved problem.
Webpages will usually employ certificates for any kind of operation requiring security such as login and payment. A certificate is digitally signed by somebody else to prove that the web page is owned and run by the one they say they are. Of course we need to be able to trust certificate the signer for this to work. If you are on a Mac you essentially have to trust that Apple picked a certificate signer they trust. So in a sense we create a long list of trust, verified with digital signatures. As long as you trust Apple, you can in other words trust that the movie theatre web page belongs to the company they say it belongs to.
So far so good, but what has this to do with smart contracts you might ask?
The point I am going to make is that smart contracts is not relevant between entities which already trust each other, or as in this case, trust only needs to go one way. Smart contracts is to facilitate chains of trust.
This happens the moment I buy a movie ticket and try to sell it to a stranger. If I have downloaded the ticket online, then essentially the ticket is just a number. Usually that number is displayed as a QR code for easy scanning, but that is just an implementation detail.
If I was to sell this ticket to a stranger, we get two problems:
- Since I am not a public figure, how can the buyer trust me that the number I am selling is actually a valid number and not a number I just made up?
- Even if it is a valid number, how can the buyer be certain I haven’t sold that number to somebody else already? Essentially how do we solve the double spending problem?
This is the kind of problem we can solve with a smart contract. We can write a contract in the form of code which executes a transaction under given circumstances.
For movie tickets we want a transaction which is only valid when signed by both buyer and seller. The transaction should transfer crypto currency from buyer to seller and transfer a token representing the ticket from seller to buyer.
How is Ownership Transferred in a Smart Contract?
What transfer means in this context might not be obvious unless you understand crypto currencies well. I’ll try to explain with an analogy.
Imagine that every transaction is a piece of paper which is identified with a number and which says the people money is going to. Each transaction can only spend money which was transferred by a previous transaction to the signer of this transaction.
Hence we get a stack of transactions depending on each other. What we call the miners can verify this stack of transactions and making sure that a transaction isn’t spending money that was never transferred to the person signing the transaction.
So basically we are dealing with a chain of signatures, which must be possible to verify.
So we have chains of transactions, which are such that we need to be able to verify the whole chain of transactions changing ownership of money all the way from the buyer to the seller. Likewise a similar chain of signatures must exist, describing a transfer of ownership of movie tickets. This chain has to terminate at the movie theatre.
The buyer needs to be able to verify that the movie theatre did in fact issue the ticket. The buyer then only needs to be able to trust that the movie theatre will honor the ticket when it is presented at the movie theatre.
How does the Movie Theatre Verify the Ticket?
If tickets can be resold online, we get the challenge that the movie theatre also need to make sure that only the last person buying the ticket is able to use it.
Hence we can’t rally pass around a number, since anybody could make a copy of that number and show it at the theatre.
The theatre could maintain a copy of the blockchain and use it to present a challenge to the moviegoer. The moviegoer could present his or her public key as e.g. a QR code and the movie theatre could scan this code and use it to encrypt a random number, displayed as a QR code which the moviegoer has to scan and decrypt with his or her corresponding private key, then show the original random number.
This is just an example. You could probably do this in many different ways. But it is just to illustrate that there is a way to prove that you have paid for a ticket and the movie theatre having access to the blockchain can verify that nobody else owns this ticket now.
Buying and Selling Property
My initial thoughts when first reading about smart contracts, was centered on buying and selling a house. When the article casually claimed no people were needed to be involved because the code would just make sure the contract was carried out, then I was immediately skeptical of these claims.
Sure block chain technology can make sure money is transferred, but the code can’t see that you got the house you wanted. Nor can the code hold a gun to your head and force you to carry out your part of the contract, such as handing over a house to the buyer.
Obviously people need to be involved somehow. So what role exactly does a smart contract play and what sort of people can we exclude, and who do we need to keep around?
It is easy to take the process of handing over property and owning a house for granted when like me, you live in a country with high levels of trust and long democratic traditions. I never really put much thought into how you prove that you own a property, until a friend of mine from a former east block country told me a story about how they had lost ownership of their house.
Somebody has simply taken over the house. I had not believed this was even possible. In reality it is simple enough if you live in a corrupt country. The ownership history of a house or rather a property is registered in some government registry, along with a paper trail.
The thief in this case simply bribed a government official to change the registry so it looked as if the property belonged to him. Then he could call upon the authorities to evict my friend’s family and label them as squatters.
With smart contracts and the block chain you can prevent this from happening.
In this case as in almost all transfer of ownership of major assets, there is a middleman or third party which has to facilitate the transfer. E.g. in this case a government registry which both seller and buyer has to trust will record the transfer.
As with the movie ticket example, what is of interest to smart contracts is really the whole chain of transfers. I can’t simply write a code representing a contract to sell my house and hand it over to the buyer for digital signing. Why?
Because anybody could make a contract and say it is for a house. You might not even own that house. Hence a contract has to provide some unbroken chain of ownership transfers back to some entity everybody can trust. In our previous example that was the movie theatre.
For property that could be a government body which issues the original property. If you trust the government and the seller can prove an unbroken chain of ownership transfers with digital signatures back to the government body on a sort of blockchain, then we know that the seller is entitled to sell this property and we may buy it safely.
This means citizens can’t arbitrarily start making contracts on say Ethereum to buy and sell property today. You need to make arrangements with government first where they agree to create some sort of digital tokens to represent property, so that they can verify with anybody who asks, that this is in fact an actual property originally acknowledged and recognized by the government.
Alternative a company with a lot of visibility and which people trust could serve a similar function.
Back to my example with my friend who’s family lost their house. How would a smart contract on the blockchain help? With blockchains you can’t easily tamper with the history, nor can you transfer ownership without knowing the private key of the current owner.
A single corrupt government official could hence not alter the records.
Buying and Selling Items Online
If I buy a camera online, smart contract can’t of course force the seller to deliver the camera to me upon receiving my payment.
However a buyer and seller can enter an escrow style agreement. What I mean by that is that the buyer can agree through a smart contract to freeze some of their crypto currency. Basically they can make a payment to the seller, but the seller can’t spend the money without getting a signature from the buyer. The buyer would then only provide that signature as soon as they have received the desired product.
If the buyer receives the camera, he or she does not have an incentive to not sign, because they can’t get hold of the money anyway. The only thing not signing achieves is ruining their reputation.
But perhaps a better method is if created products are tokenized from the point they leave the factory. One registers unique serial number, model number etc of the camera from when it leaves the factory. If every sale of the camera is done over the blockchain using smart contracts then the history of the camera will be recorded there.
What is the benefit of this approach? Well, now the most recent owner of the camera has an easy way of proving that they own the camera, and can hence use factory warranty. Another benefit is that one can imagine that each seller in the transaction adds faults, defects or repairs done on the camera. Seller and buyer could have agreed on this upfront and buyer can verify that the seller did in fact add the faults and repairs, they had agreed upon. This could be the result of e.g. buyer inspecting the product and finding faults.
But perhaps much better would be that anyone performing repairs have to register the repair of any product they repair. Companies might require this make refunds e.g. The benefits of this is that it makes it hard for any seller to hide past history about a product to a new perspective buyer.
When goods are transported from say a farm, mine or factory all the way to the consumer, it has to go through a lot of different steps. Not just loading and unloading onto different transport vehicles but we also have to deal with customs declarations, export controls and so on.
A common challenge is to track a product, so that various parties involved in the supply chain can keep track of where the product is and what state it is in.
A simple solution to this is to do what we normally do when we need one shared version of events. We create one central database managed by a party which is trusted by everyone participating. Everybody then reports to this party, which updates the database and answers queries from participants in the supply chain about the current status of the transported good.
Sometimes that works, but what happens when you got multiple parties who don’t trust one party enough to maintain the shared information?
This happens when your got a lot of parties involved any nobody is dominant. It is a problem which also arises when national authorities are involved.
They naturally don’t want status information about whether a product has passed customs declaration to be controlled by a database run by a company. Nor does different countries involved in the transport let another one maintain status about them. Government doesn’t want to let a company be able to change the customs declaration status of a product in their database.
So basically we end up with every party in the supply chain, companies and governments maintaining separate databases with parts of the total information about a product. This data will be partly synchronized, but there is no clear authority on what is the correct version of any info.
With blockchains and smart contracts, the database may only be changed through a smart contract. The smart contract is the gatekeeper to the database. That means e.g. the government can feel confident that a company doesn’t change data about custom declarations, as a smart contract accessing that kind of information would require a signature which only a government representative could produce.
Likewise a company knows that another company can’t alter state related to the operations they perform as that information can only be altered with their signature.
And all participants can feel confident that there is a “paper-trail,” over all changes and events which has happened which can’t be retroactively modified.
While smart contracts have a lot of potential, we can just start using them willy nilly for anything until agreements have been made with governments, companies etc to tokenize or in some form represent physical assets so they can be traded and the buyer can trace their purchase back to some legal entity, whether the government or a company which they can trust.
The key thing to observe here is that traditionally, every modification to a chain of ownership has to be done by some kind of trusted third party. This involved government, lawyers etc who usually charge big fees to make such a change.
With smart contracts we only need to secure the beginning of the chain to the real world. All ownership transactions after that, can be done entirely electronic. Or rather the work usually done by the trusted third party can be done electronically. People still need to interact with the physical world and verify things before they sign off.