Blockchain Block Hashing
In this section, we will learn how SHA-256 applies into building a block within a blockchain. We will discuss specifically 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 block number is corresponding to whatever our data is here. 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 has not 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 figuring out how you can actually make this specific block give you a valid hash. The way you can do this is by manually changing the nonce. 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 in the system making it now 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.