I have discussed a lot about Blockchain in my previous blogs. Let us take it ahead and discuss that in more details. To start with, let us consider a single block of Blockchain. As you can see, there are multiple dimensions of this block.
A block in Blockchain
One of the dimensions is the data block which will hold the data part of the Blockchain. This could be any type of data, such as - a list of transactions, a document that you could sign, or any other business related data. The second part of the block is the hash part which holds the hash of the block data. The hash of the data along with timespan is calculated and the resulting hash is stored in the hash part of the block. The third part of the block is the hash of the previous block. By adding that, we ensure that a block is connected with its peer block and also, it knows the authenticity of the previous block. So, if anyone tampers with the previous block, the hash of the previous block will be changed and we will have inconsistent block hashes.
In the process of forming a Blockchain, the first block of the Blockchain is called the Genesis Block. Genesis block is the very first block of every blockchain. In the structure of the genesis block, the previous block field is empty as there is no former block.
Genesis Block
The formalization of the blockchain not only requires the genesis block but it also needs some rules to obey in order to add a block to the chain. This is called the consensus protocol. The consensus protocol of the Blockchain dictates how a block is processed which means how we are going to calculate the hash of the block. If any block is tempered, then the rest of the blocks in the blockchain will be invalid. The only way to invalidate a whole chain is to temper with a block and recalculate all the later blocks. While we are talking about genesis block, here is the Genesis block of Bitcoin. As you can see, this is the first block of Bitcoin; there is no previous block with no transactions to calculate. There is also a reward to calculate the hash in this block which is 50 BTC. It’s a very good way of contributing to the currency that is more explained in the concept of mining.
Now, that we know about the Blockchain, what if someone tampers with the Blockchain? Well, there will be an invalid Blockchain for all the nodes. To deal with this problem, the concept of Distributed Blockchain is introduced. In a distributed blockchain, each node in the network has its own copy of the Blockchain and every change in one of the Blockchains will be authenticated and synced with all the Blockchains within the network. The distributed blockchain is still vulnerable to one famous security problem. So, if you invalidate more than 50% of the Blockchain nodes, then you have successfully gained control of the network. You can rewrite the consensus protocol. You can manipulate the transaction history. But doing that not that easy. It is almost impossible to perform such an attack on more than half of the network at the same time. So, for now, it is really hard to achieve.
51% Attack
Now, let’s discuss the 51% attack in more details. Let us consider that you have a network with multiple nodes. Let us divide the nodes in two colors - Red and Blue. The blue nodes are the good nodes and each of the good nodes have their own copy of the blockchain. The red nodes are the bad nodes or the malicious nodes and they also have a good valid copy of the blockchain as well. The bad node then publishes a malicious block to the network and synchronously do that with all the locals of the bad nodes. This will, in return, publish the same block to all the nodes on the network.
Now, the good nodes will also get the same malicious block and there is a chance that they will invalidate the block by tagging it as a malicious block. But, if we have more bad nodes than the good ones on the network, the majority of nodes in the network will accept the malicious block to be part of the valid Blockchain. The good nodes will think their blockchain as invalid as they are less in number and they will sync with the bad Blockchain. So now, the whole network is infected, resulting in a successful 51% attack.
Proof-of-Work
The 51% attack looks really simple to conduct as all you have to do is just re-calculate the hashes of the Blockchain and then, you can invalidate the whole chain with enough CPU power. To address this problem, there is something called Proof-of-Work. The proof-of-work dictates that you can calculate the hash but there are certain rules that are applied to a hash. The hash should have some particular number of zeros or it should start with at least ‘x’ number of characters or numbers. By introducing such rules, the process of generating the hash becomes more difficult and requires more CPU-time because you have to try different key combinations until you reach an acceptable block and then you publish that key with the block so that the other nodes in a network can validate your work.
The rules for PoW are different in different currencies or domains. For example, Bitcoin accepts 1 block in every 10 minutes, Intense coin accepts 1 block after every 30 seconds. There is another part called the difficulty that is included in the Proof-of-Work rules. The more the difficulty is, the harder it is to conduct a 51% attack.
Mining
Let’s say if I am one of the nodes contributing my processing power to calculate the hashes; what will I get in return for the processing power that I am contributing? There are special nodes that contribute to the processing of the blockchain. These nodes are called the mining nodes. The whole concept is called as mining in blockchain where the nodes receive a published block, calculate a hash on that block using a random key until it reaches the difficulty, and once it has successfully calculated the hash then we can say that we have successfully mined the block. Then, it publishes that to other nodes in the network. The node gets a reward in return, in the form of the currency. This helps to build the blockchain and also, it contributes to the currency.
Mining is a process of running the blockchain rules which keeps the network stable, safe, and secure by processing the validated and invalidated blocks. But the problem with that is that it doesn’t have a bright future. In many currencies, because it takes too much electricity, it takes too much power to calculate the hash so maybe, mining is not the future. There are different alternate solutions available which we will discuss later.
Summary
So in this blog, I have touched the concepts of blocks, Proof-of-Work, Mining, and 51% Attack.