Now transactions need to be verified. In case of a blockchain this verification can’t be done right away. It needs to be solved. What does this mean?
Imagine each transaction as a cryptographic puzzle piece. Because there are thousands of transactions in a block, it means that thousands of cryptographic puzzles have to be solved.
This process of solving puzzles and adding the block is called mining.
Now if you have seen pictures of computers that are involved in the mining process, you would find that there are hundreds of computers that are participating in the process.
Each of these computers have a very fast computing power. More computers mean faster computing and faster solving time which ultimately translates to more rewards. Rewards as in winning cryptocurrencies – like bitcoins.
Let us get into the technical part of it. The concept of Proof Work establishes itself on two important features. First, solving the puzzle to validate and add a block has to be relatively difficult but feasible. Secondly, the verification of this solution (in the first point) should be easier.
In mining, when a block arrives the miners receive a hash. The task of the miners is to find the other part which when appended to the hash of the new block will result in a string which when hashed will give a certain answer that is publicly known.
In the above image, let us understand what is happening. We have a new block called N. We also have a known P. P is publicly known. The work of the miner is to solve the puzzle so as to validate and add the block to the blockchain. To do that he has to find the value of k which when appended to N will give a result R. In turn when R is hashed, it will provide the value P.
The other part caps k is called as nonce. Finding the nonce is a tough job and relatively difficult to achieve.
In order to find the nonce the miners have to perform millions of permutations and computations, each time trying to see whether the result R can be achieved.
As soon as the miner finds the nonce, he is rewarded with cryptocurrencies like bitcoins. At the same time other miners are informed of this new block so that they can update their ledger and the blockchain is in a state of agreement.
These miners can validate whether the block is valid one which is an easy task since both the result and the nonce is known.
Double Spending Problem
Imagine a scenario where the same amount of money is transferred twice to two different recipients. This is called a double spending problem. In the blockchain network, transactions are irreversible and every transaction can be validated.
This is a case where a malicious node (or attacker) relays bad blocks instead of valid ones. This can further lead to double spending problem. Bitcoin solves this by allowing one outbound connection to one IP every 16 IP address.
Denial of Service (DoS) Attacks
This is common computer security issue. In case of blockchains, this can mean sending a lot of data to a node. The node becomes overwhelmed and fails to process normal transactions.
For this the solution employed in blockchains include no forwarding of orphaned blocks, double-spending transactions, and same block or transactions. The network also disconnects a peer that sends too many messages. Also the size of the block is restricted.
Proof of Work has many downsides.
Miners have to buy expensive hardware called ASICs(application specific integrated circuits). To power these hardware they use electricity. And since electricity produces heat, they install fans to keep the hardware cool and working fine. This requires more electricity. This huge amount of energy is used to solve a block.
Just for the records and to understand how power consumption is increasing every day – in July, 2017 the estimated TWh was less than 20. However, around seven months later in February, 2018 the power rose to over 50 TWh.
Tragedy of Commons
The Proof of Work has another demerit which is called the tragedy of commons. Now miners mine blocks because there is a reward with every successful try. Over time when reward for the miners go down, it will result in less miners participating in the mining process. This will open up a vulnerability in the network which can actually destroy the network.
Bitcoin is the first blockchain implementation and it uses PoW as its consensus mechanism. The hash function used in bitcoins and related implementation is SHA256.
In the next section, we will discuss on the second most popular algorithm called as Proof of Stake.