Using Bitcoin To Explain Blockchain
And it is really not that complicated.
Introduction
Lately, I came across a few articles and videos which tried to explain the concept of blockchain, but none was satisfactory to me. The main problem is that they are over-simplifying. In their defense, the idea of blockchain is highly mathematical and you probably need a degree (or its required knowledge) in Computer Science to be able to fully understand blockchain. Nonetheless, I believe a balance can be struck between technicality and common sense which will result in an intuitive appreciation of blockchain. This prompted me to make my own attempt at explaining what blockchain is and what makes it so revolutionary. This article will assume that the audience has a decent understanding of mathematics at secondary school level and the goal is to foster an intuition about blockchain by providing sufficient details yet not getting lost in the mathematics.
It has to be emphasized that although blockchain was first devised for the purpose of solving the double-spending problem (more on this later) in cryptocurrency, blockchain is more than cryptocurrency and can be utilized in other applications. However, anyone who has made a sincere attempt at teaching knows that a complex idea cannot be explained fully without the employment of an example. For this reason, I will use the example of bitcoin to illustrate blockchain. The aim is that by understanding how bitcoin works, we will acquire an intuitive understanding of how blockchain works.
Preliminary
There is one concept which is prerequisite to the understanding of blockchain.
A cryptographic hash function is a mathematical algorithm that maps data of arbitrary size to a string of numbers and letters with a fixed size. See figure below(1).
The input into the cryptographic hash function is called the message and the output is called digest or hash. The function is a one-way function, meaning it is infeasible to invert (deduce input from the output). The only way to find the message which corresponds to a given hash is by brute force, meaning you must go through all possible messages in the world until you find the correct message that yields the given hash (which is impossible to do). The function has 5 main properties:
· Deterministic: the same message always results in the same hash;
· Low computation time: it is quick to compute the hash of any message;
· Infeasibility to compute message: to find the message of a hash, you will have to search through all possible messages;
· Any small change in the message will lead to a dramatic change in the hash such that the final hash appears unrelated to the initial hash;
· It is infeasible to find two different messages with the same hash.
Problems With The Financial System Before Bitcoin
Bitcoin and blockchain were invented by a person or group of people who identified themselves as Satoshi Nakamoto. In November 2008, Satoshi Nakamoto published a whitepaper titled ‘Bitcoin: A Peer-to-peer Electronic Cash System’. In it, he described the problems of the conventional trust-based financial model where banks have to act as trusted third-parties (middlemen) to facilitate electronic payments. The reliance on the middleman brings issues such as the reversibility of transactions, cost of mediating disputes, and cybersecurity issues since all financial records are controlled by a handful of entities. Physical (face-to-face) exchange of money or value can solve these problems, but we need the convenience of electronic payment.
Digital currencies long existed before bitcoin. But they face a fundamental flaw called double-spending. The idea is self-explanatory: the same digital money or token can be spent more than once. This is possible because the digital token is nothing more than a digital file which can be duplicated or falsified. The conventional financial system gets around this problem by establishing trusted third-parties such as banks which maintain and secure central records of transactions. This enables people to check before the transaction is confirmed if the same money has been spent already.
So Nakamoto’s ambition was to invent a digital currency without the double-spending problem. This required a repository of transaction records which cannot be tampered with, can be used to verify transactions and is not controlled by a central entity. Thus blockchain was born.
Blockchain Fundamentals
A block is just a record, which consists of transaction data (a block can include a few separate transactions), a timestamp which incorporates the cryptographic hash of the previous block (see Preliminary), and proof-of-work (more on this later). Here the cryptographic hash is what we need to focus on. When creating a block, we need to take the most recently created block in the chain, input it into a cryptographic hash function, obtain the output which is the hash value, generate a timestamp using the hash, combine the timestamp with the actual transaction data and proof-of-work, then finally we have the newly created block. This way, every single block is linked to the blocks prior to and after it by the cryptographic hash function. The effect is that all blocks are linked together (hence the name blockchain) such that no block can be altered without changing all subsequent blocks.
In this way, a blockchain is a database which is structured in blocks linked by a cryptographic hash function. A blockchain is managed by a public peer-to-peer network, meaning anyone who has the required hardware can join the blockchain and everyone who participates can create and verify blocks. A CPU (Central Processing Unit) that participates in the creation and verification of blocks is called a node. Every node in the network keeps a local copy of the latest blockchain, and every node can see all the copies of blockchain on every other node.
We have seen that, in order to make changes to a block that has already been added to the blockchain, all subsequent blocks need to be changed also. But the question remains: why a hacker cannot simply amass enough computing power to achieve this? This is where another component of the block comes in: proof-of-work. Blockchain is designed in such a way that deliberately makes creating a block very resource-intensive and difficult. In other words, the system forces you to do some very difficult mathematical calculation on your CPU just to waste your time and energy. This concept is called proof-of-work, and the idea is that the system wants you to show that you are putting in the time and energy to contribute to the network. The result of your calculation forms part of the block, and other nodes in the network can easily verify your calculation. The specific mathematical operation a node must perform is called hashcash. We will not get into the mathematics of hashcash here, but it suffices to know that it has nothing to do with bitcoin or blockchain; it is simply there to waste your time and energy, and the result of the calculation can be easily verified.
The cryptographic hash function and proof-of-work are essentially what make blockchain incorruptible. To modify one block, you have to modify all subsequent blocks. But to modify a block, you need to complete proof-of-work. But completing proof-of-work takes a lot of time and energy. This quickly multiplies with all the blocks you have to modify, thus rendering attacking the system infeasible or no longer economically sound. As the blockchain grows, the difficulty of attacking grows exponentially, and today it is practically impossible to attack the Bitcoin blockchain.
Bitcoin Mining
You have probably guessed what bitcoin mining is by now. Since participating in the blockchain network requires such intense calculation, there must be some incentive for the people running the nodes. This incentive is bitcoin. By completing the proof-of-work and creating a block, the system will automatically reward the node some bitcoin after the block gets verified by other nodes. Only the node which first successfully generates the block gets the reward. This incentive amount is determined by the system. The analogy between mining and completing proof-of-work is straightforward: you have to perform hard work to dig the value out of the ‘ground’. Here the node is the miner. This is essentially how new bitcoin is generated, i.e. this is how the money is ‘printed’.
When writing the initial software code for bitcoin, Nakamoto stipulated that the final amount of bitcoin in circulation must be finite. Specifically, only 21 million bitcoins will ever be created. This means eventually the system will run out of reward to give to nodes (miners). Transaction fee will then become the sole revenue stream of bitcoin miners.
Miners earn transaction fees even today. Because there are so many transactions taking place, and because for the same transactions, only the first node to successfully generate the block can earn any reward, a node has to pick and choose which transactions to include in the next block. The transaction fee is then the biggest factor (if not the only factor) when considering which transactions to include. As a sender of bitcoin, you can specify how much transaction fee you would like to reward the miner. This helps you because it increases the chances that your transaction will be verified more quickly (added to the blockchain more quickly) and the receiver of your bitcoin can confirm the transaction sooner.
What Blockchain Is Not
It must be noted that blockchain does not concern itself with how the bitcoin is sent. The protocol for securely sending data over the internet has long been established before bitcoin. In particular, bitcoin uses a mechanism called public-key cryptography. The sender has two digital keys: a public key and a private key (a digital key is just a string of numbers and letters). The public key is known to everyone on the network, and the private key must be kept secret and cannot be known by anyone other than the sender. What happens next is very mathematical. It is infeasible to deduce the private key from the public key. The sender combines the bitcoin transaction with the private key, producing an encrypted message that appears unrelated to the transaction or the private key. We say that the sender digitally ‘signed’ the transaction, and the concept is called digital signature. The receiver of the encrypted message can then utilize the public key to check the validity of the transaction, i.e. if the transaction was made by the owner of the associated public key. Changing the encrypted message by the slightest degree will make this verification fail. This gives the receiver confidence that the transaction was made by the owner of the public key, and that the transaction has not been tampered with. It also gives the benefit to the receiver that the sender cannot deny sending the bitcoin. Another advantage of public-key cryptography is that the encrypted message can be seen by all nodes in the blockchain.
So sending bitcoin is secured by public-key cryptography, but this has nothing to do with blockchain. The purpose of blockchain is that, after the transaction is verified and the record of the transaction is added to the blockchain, the record is permanently safe and cannot be altered. Think of public key and private key as your conventional bank account number and internet banking password respectively; the only difference being you cannot be identified as any real person in the real world by your public key (your bank account number can). Your bank account number can be made public, but you must keep your internet banking password to yourself. After the money is sent, the bank has a database to store all the transaction data and records, and blockchain is just another type of database to store all transaction data and records.
Some people ask me: “if blockchain is so safe, why do we have people who have their bitcoin stolen?” The answer is simple: their private keys were stolen. Private keys are not stored on the blockchain, and it is the user’s responsibility to keep it secured. Most people use a digital wallet, which is just an ordinary software application, to trade and use bitcoin. Again, the digital wallet has nothing to do with blockchain and if a malicious attacker can hack into the app, the private key will be stolen hence all the user’s bitcoin will be stolen. It is just like someone stealing your credit card PIN: the bank’s database and system have not been compromised; it is your responsibility to keep your PIN to yourself. Alternatively, if you do not use a digital wallet but you simply lose your private key (for instance, because you write it on a piece of paper and you lose that piece of paper), you lose your bitcoin.
The End-To-End Process
So how does Bitcoin work on a blockchain exactly? Here is the complete end-to-end process (sequence of events).
1. A request to transact bitcoin is broadcast to all nodes. The transfer of the message is safeguarded by public-key cryptography.
2. Each node works to create a new block. This means they have to complete the proof-of-work, then combine the proof-of-work with the timestamp (which includes the hash of the previous block) and the transaction data (can include multiple transactions).
3. The node broadcasts the block to all nodes.
4. Nodes accept the block only if the proof-of-work is correct, the hash is correct, and the transactions are valid meaning the same bitcoins have not been spent before.
5. Nodes express their acceptance of the new block by moving onto creating the next block and going back to step 1. The node that generated the new block is rewarded with bitcoin. The hash of the accepted block is calculated in preparation for the next block.
Sometimes, two separate blocks may be created simultaneously. This, in turn, creates a ‘fork’, meaning two separate branches are created in the blockchain. The fork will be resolved when the next block is created and added to one of the branches since all nodes take the longest chain to be the authoritative one. The longest chain is taken to be authoritative because it required the most proof-of-work hence is least likely the result of malicious activities.
Some Final Words
By solving the double-spending problem in cryptocurrency, blockchain’s revolutionary power is already apparent. However, one quickly realizes blockchain is more than cryptocurrency. Its disruptive potential lies within its ability to eliminate middlemen in all our business and commercial dealings (in the case of cryptocurrency, the bank is removed). This is a result of blockchain being decentralized and public, and the genius of Satoshi Nakamoto making it resistant to attacks. I hope you are just as excited as I am to see where blockchain will take us.
Reference
- Stolfi, J. (2008). File: Cryptographic Hash. Retrieved from https://commons.wikimedia.org/wiki/File:Cryptographic_Hash_Function.svg