Blockchain Block Hashing
In this section, we are going to learn how SHA-256 applies to build a block within a blockchain. We will discuss here in the context of the Bitcoin blockchain and understand how this ties into the role of miners. The minors are actually in the process of building blocks, and these blocks are added to a blockchain to build out what the Bitcoin blockchain will be.
In the below image, you can see that this block is composed of a block number, data field, cryptographic hash associated with it and a Nonce.
In the above image, the generated hash would look like 00001acbm010gfh1010xxx. I’d like to point out that this hash has four leading zeros. The four leading zero’s describes whether the block is valid or not. For practical purposes, you will see that this hash is corresponding to the nonce, and the block number is corresponding to the available data. Since the hash has four leading zeroes, therefore, it is a valid block.
If we make any change in the data section, it will give the completely different hash that can be shown in the below image.
If the newly generating hash does not have four leading zeroes, then it will not a valid block. To make the block valid, we will do it by using the field called nonce.
Nonce stands for a Number Used Once in a cryptographic communication such that the block’s hash meets a certain criterion. This criterion could be generated a hash that must have its leading four digits to be zero. Thus, the generated hash would look like 00001acbm010gfh1010xxx.
A nonce is basically a random number which figures out how you can actually make this specific block provide you with a valid hash. The way you can do this is by changing the nonce manually. Generally, the miner starts with a Nonce value of 1 and keeps on incrementing it until the generated hash meets the specified criterion. Thus, it may take several iterations until the desired hash with four leading zeros is generated. The expected time for generating a block in the bitcoin system is 10 minutes. Once the miner successfully mines the block, he releases that block in the system and making it the last block in the chain.
In Anders Brownworth Hash Program, when we click mine button as shown in the image, it will give the valid block. This block has a unique nonce with hash leading four zeroes in the beginning.