An Interactive Guide to the Blockchain, Part V – A Virtual Currency
Written by Hannes Westermann, Researcher at the Cyberjustice Laboratory and PhD Student at Université de Montréal
We have now learnt how the blockchain establishes consensus, and how miners compete against each other to confirm the latest block. However, the question remains – why would miners do this? And how can this blockchain be used to create a virtual currency? This is what we will learn today, in this final blog post.
Virtual currencies are probably the most wide-spread current use of blockchains. Further, many applications of the blockchain retain some sort of currency, as this is what makes it possible to achieve security through miners.
Before we talk about how to use the blockchain to make a currency, we need to understand how identity works on the blockchain. This an integral part of a currency, and explains how it is possible to send and receive money. In the banking system, the way this works is via an account number that is registered with a bank. If the bank receives a transaction to that number, they know to credit it to your account. The bank also handles authentication and makes sure that only you can spend the money on your account. On the bitcoin, there is not central authority that takes care of this – instead, cryptography is used to create an account system.
The way this is implemented on the blockchain is through digital signatures. This system works similarly to the way regular signatures work. On the blockchain, it works as a system to identify who you want to send money to, and who can spend money.
Say you have a document, and you want to make sure it is written by the party who claims to have written it. In the regular world, one way to do this is to look at the signature. The idea is that it is easy to verify who the signature belongs to, but difficult to fake the signature. There is some public knowledge (who a signature belongs to) that can be used to verify who the signature belongs to, and some private knowledge (how to write the signature) that allows only one person to write this signature.
The same thing can be reproduced digitally using something called Public-key cryptography. This consists of algorithms that allow anyone to generate a pair of keys – one private key and one public key. They can then use the private key to sign any digital message, which generates a digital signature. Anyone who has the public key can verify that the message was indeed signed by the corresponding private key.
This can be used just like a regular signature. Say that I have some friends and need to arrange a place to meet them. I have previously shared my public key with them. I then sign the message “Let us meet at the river at 9pm” with my private key, which gives the signature “123712714”. I send my friends the message together with the signature. My friends can now use the public key I gave them to make sure that it was indeed me who wrote this exact message, and that nobody changed this message on the way.
You can try this below! Write a message, and then click the sign button to sign this using a private key that was generated when you opened this page. You can then click the verify button to verify, using the public key, that the signature matches the message and the private key. However, if you change the message, the verification will fail. This indicates that someone changed the message after it was signed. (This might not work on all browsers)
Digital Signatures on the blockchain
Let us now use this system to create a currency on the blockchain. Yesterday, we stored sentences on a short story on a blockchain. In order to create a currency, we will instead store transactions. Note that this is a simplified version of how bitcoin works.
In order to send money to someone on the blockchain, you only have to know their public key. This is called a « wallet address ». However, in order for a person to spend money, they have to know their private key. This allows anyone to verify that the person who signed the message has the correct private key (by verifying the signature) and is therefore the account holder.
Say, for example, that Alice wants to buy a bike from Bob for 5 coins. She has her own public and private key. Further, Bob sends her his public key and asks her to transfer the money there. Alice will now send a transaction containing the following information to the miners (including Dan):
- Her public key (the sending address)
- Bobs public key (the receiving address)
- The amount she wants to send (5 coins)
- The digital signature of the aforementioned information, signed using Alice’s private key.
Once Dan (the miner) receives this transaction, he will perform the following steps to make sure that the transaction is valid:
- Check that the signature of the transaction was signed by the private key that matches the senders public key.
- Verify that Alice has 5 coins on her account. This can be verified by looking at all previous transactions on the chain, to see if the remaining balance on Alice’s account is at least 5 coins.
Once Dan verified that the transaction is valid, he will add it to the block of information to be mined. He will also add a special transaction, giving himself a coin (or several, depending on the rules of the blockchain) as a reward for confirming the block. He will then set out to try to find the correct nonce to confirm the block. The other miners will do the same – the competition is on.
If Dan finds a valid nonce, he will share the block with the rest of the miners. These will then confirm the validity of the block and start mining this longer chain. The transaction is part of the blockchain, and anyone can see that Bob now has 5 coins extra.
What if the Dan cheats, for example by allowing Alice to spend the 5 coins even if she does not have them, or giving himself 100 coins for confirming the transaction? Before starting to mine this longer chain, the other miners will verify that the block is valid. If they see that something odd is going on, they will reject the block and continue looking for another valid nonce. Dan, who could have had 1 coin, instead gets nothing.
Try out a simple cryptocurrency below! Alice, Bob, Carol and Dan start with 100 coins each. Add a new transaction by selecting who should send how much money to whom. Dan will mine the block, giving himself 1 coin in the process. Based on this, the balance will change. As you will see, the total amounts of coins changes with each mined block, since Dan receives a mining reward. This is, in bitcoin, the only way new coins are introduced in the system.
||Sender: Amount: Receiver:|
We have now learnt all the concepts involved with creating a blockchain. While this is a very simplified version, it contains the major ideas that power bitcoin and most other cryptocurrencies.
Here are some interesting implications of this way of building currencies.
Anonymity – The transactions are in theory anonymous – there is no way of linking Alice to her key. However, we can see all transactions Alice has ever been a part of, by looking for transactions involving her public key. Eventually, Alice might want to convert her bitcoin into a real currency, and sells the bitcoin to someone who transfers her money. In order to receive the money, she probably has to give her account number to the buyer of the bitcoin. The buyer now knows Alice’s real identity, and can in theory determine every transaction she has ever been a part of on the network.
Security – The blockchain is, as an idea, very secure and immutable. This can be good, but it can also have disadvantages. If someone obtains access to the private key of a participant, they can transfer their coins to another account. At this point, there is almost nothing the person can do to get the money back – no bank can intervene on their behalf, and the thief probably covered their track to avoid being linked to their account. The same happens if you pay using a cryptocurrency for some goods that arrives broken, or that does not arrive at all.
Other blockchains – In this series of blog posts, we discussed the use of a blockchain to store information about a currency. However, the blockchain concept can be extended far beyond this. Blockchains can be used to store any information in an immutable and decentralized way. Among other things, people have suggested to use the blockchain to keep track of land registries and supply chains.
Smart contracts – Another fascinating use of blockchains is the creation of platforms for smart contracts. This allows anyone to develop programs that from then on run on the blockchain, and can respond to parties interacting with it. Essentially, the blockchain here acts as a huge, decentralized computer that anyone can program to execute code and send transactions. Smart contracts have been used to create massive decentralized systems. Notable platforms include Ethereum and EOS.
Environmental impact – The blockchain we discussed so far relies on a concept called proof-of-work. It relies on the calculation of hashes by computers to be secure. This can have a large environmental cost – the entire bitcoin network is estimated to consume as much power as the entire country of Switzerland, or 0.21% of all energy produced in the world (in July 2019). Since the miners compete to find the matching hash, most of the calculations are “wasted” in that they never have an influence on the blockchain. On the other hand, the large number of hashes calculated play an important part in securing the blockchain. A newer approach, known as proof-of-stake, aims to replace proof-of-work with a different consensus mechanism. Explaining this is beyond the scope of this blogpost, but it is already being used by some cryptocurrencies such as EOS.
This was the final entry in the series “An interactive guide to the blockchain”. Today, we discovered how a currency can be built on top of the blockchain using digital signatures. This wraps up the explanation of the major concepts involved in creating the blockchain.
We hope that you enjoyed these blog posts and that we could provide you an entry to understanding the concepts involved with the blockchain.
Ce contenu a été mis à jour le 9 juin 2020 à 13 h 35 min.