Javatpoint Logo
Javatpoint Logo

How Block Hashes Work in Blockchain

A blockchain is a concept of storing data digitally. This data comes in blocks. These blocks are chained together and make the data immutable. When a block of data is chained with the other blocks, its data can never be changed again. It will be publicly available to anyone who wants to see it ever again, in exactly that sequence it was added to the blockchain. Nobody can change that information once it is on the blockchain.

Now, in the previous section, we have learned how to build the block and how the cryptographic hashing ties into the whole process. Here you can see how blockchain uses all these concepts together to preserve the integrity of a full blockchain.

Imagine a bunch of blocks of transaction data as of the following image.

How Block Hashes Work in Blockchain
How Block Hashes Work in Blockchain

In the above images, you can see that block assembles in chronological order. Block number one is followed block number two, then block number three, then block number four, and you can continue it as long as you wish. Here, you will find that there is a block number field, data field, nonce field, hash value field, and previous field. The previous field is corresponding to the hash value field of the previous block.

We know that every block in a blockchain is cryptographically tied to the next block. In the above example, the previous field in block one is zero because the block one doesn't have a previous hash value, so its value is zero. In block number two, you will find that there is a hash value in the previous field which references to the previous block hash value. This process is continuing till the last block.

Now imagine if the data in any block is altered. Let's say that we have altered in block number 2, the data in block 2 is now different, meaning the block also gets a new signature. The signature that corresponds with this new set of data is no longer chained to other blocks. It just breaks block number 2 because the hash is no longer valid and it also invalidates every single block that comes after it all the way to the end of the chain. This indicates to other users of this blockchain that some data in block 2 has been altered, and because the blockchain should be immutable, they reject this change by shifting back to a previous record of the blockchain where all the blocks are still chained together. This is the main advantage of the blockchain.

Now, if you will try to fix it, the only way you can do that would be by figuring out a nonce which can be explained in the previous lesson. So we take simply one block and try that. If it doesn't give a valid hash, then try with two, three, four, and if none of them will work, then simply mine it. When you mine a block, the system figures out that here is a valid hash. It's got four leading zeroes, which we said was the importance of this. But as you'll notice, when you try to hash block number two, this hash doesn't have four leading zeros. Therefore it's still an invalid block. So you'd have to mine this block as well. And you would have to do that with every single block all the way to the front of the chain to be able to fix what happened here.

Understanding the importance of four leading zeroes in Hash

Now let's talk about how important it is to have four leading zeroes. These four leading zeros are tied to something called difficulty level. The difficulty level is something that's tied and built into the blockchain network which determines how difficult it is for you to get the equivalent cryptographic hash for a block. In this case, that difficulty level requires us to have a hash that is smaller than what we have in the target.

For this specific purpose, we will need a target that has at least four leading zeroes. For example, if the hash target is 0000a1b2c3d4e5f6, any hash less than or equal to this number is a valid block hash. Many hashes would satisfy this requirement, and any one of those would be valid. However, it is a tough task to find such a hash. Lesser the hash target, the more difficult it is to find a satisfying hash.

These difficulty level keeps increasing over time as new computers are added in more cryptographic hashing to the bitcoin network. So, more hashing power means the difficulty level needs to go up. This difficulty level is adjusted every two weeks to make sure that the computer that is actually competing to try to solve these cryptographic problems take approximately a total of 10 minutes to mine a new block.

Note: One block every 10 mins = 6 blocks per hour, 6 x 24 in a day, and 6 x 24 x 14 = 2016 blocks in two weeks.

For example: If we were to find a hash less than or equal to 0FFFF, we have 65,536 choices. However, if we were to find a hash less than or equal to 000FF, we have only 256 choices. A lower target number means fewer choices. Usually, more leading zeros we require in our hash, much harder it is to find a satisfying hash.






Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA