How Blockchain Mining Works ?
There is a lot of fuzz around blockchain mining. This article will lead you through it in a simple and intuitive way.
Here is an analogy, Suppose you want to fill in the blank of a sentence and you doesn’t know the meaning of the sentence, then you will try each and every word in the vocabulary in the blank and ask someone who understand the meaning of the sentence whether the word is correct or not. Now, in blockchain, the blank is the nonce of the block. A miner need to find the nonce of the block, which will result in a acceptable hash. Now, which hash is acceptable depends on a rule. Let’s say, the rule states that the hash of the block should start with 0000 to be added to the blockchain. In that case, all the hashes which are not starting with 0000 are rejected.
You must be wondering, how the hash is calculated. A hash is like a fingerprint of a person. A person has unique fingerprint, similarly a block also has a unique hash. A very basic block contains header, nonce, data and previous hash value. Using a cryptographic function SHA-256, a combination of these fields is converted to a hash. Now, header, data and previous hash value cannot be changed. The only field left which can be modified is nonce. By changing the nonce, the hash can be changed. The miner has to keep changing the nonce to find out a hash which can be acceptable according to the rule stated earlier. So, why is it so hard to find a nonce which will result in acceptable hash. The reason behind that is the avalanche effect.
The avalanche effect : Whenever the value of nonce is changed slightly, even by a digit say from 19 to 20, the computed hash changes drastically, this phenomenon is called Avalanche effect. Due to this, a miner cannot predict which nonce will result in an acceptable hash. So, the miner has to keep on trying random values of nonce to find out an acceptable hash value for the block. When a miner finds out the nonce which results in a acceptable hash, the miner is given a reward which is nothing but the value of nonce which lead the miner to find the correct hash.
As GPU’s and ASIC’s are fast at calculation, a miner can brute force more number of nonce in a period of time using GPU or ASIC (Application Specific Integrated Circuit).