Developing Mobile DApps Part 1

A single character variation in the input data results in a significant difference in the generated hash. It is a desirable property of cryptographic functions known as Avalanche effect. In the below images, you can see the difference between generated hash for the word “Blockchain” and “blockchain”.

32 character Hash for Blockchain
32 character Hash for blockchain

SHA-256 also has a property known as Pre-Image Resistance which means you can generate a hash from the given input data, but you can not find the input data from the given hash. The only way that you can find the original input is by using the brute-force method. In the brute-force method, you pick up a random input, hash it and then compare the output with the target hash and repeat until you find a match. It’s infeasible to find the original input data because it will take you 2¹²⁸ attempts to pick the correct random input unless you are a magician.

Magician GIF

Now that we have understood how hashing works, it’s time to discuss how Blockchain achieves immutability. The hash of the previous block is contained in the hash of the new block, the blocks of the Blockchain all build on each other. Without a previous hash, there would be no connection. So due to Avalanche effect, if we change any one piece of this information in the block, the hash is going to change, and it will break the chain.


If you have heard about Blockchain before, you must have come across the word mining. Mining is an expensive computation calculation that is performed by a miner to generate a particular hash for the block and validate the legitimacy of the transactions in the block. The expensive computation that is performed by the miner is known as Proof of Work which is a trustless and distributed consensus algorithm used by Blockchain.

Every block has a particular difficulty level which defines a threshold level for hash. Every time miner generates a new hash, it is compared with the difficulty threshold. The process is repeated until the generated hash is less than the threshold.

You might be wondering since we have the same transactions inside the block how can we generate a new hash every time. Yes, you are correct we cannot generate a new hash with the same transaction list due to deterministic property of the cryptographic function. But if you remember, we discussed that block also consist of nonce value, timestamp, and difficulty target. A nonce is an arbitrary number that is added with the hash of the block. If the hash is not less than the difficulty threshold, then the nonce is changed, and this keeps on repeating a million times until finally, it is less than the given threshold.

Okay, that’s great, but why do we change the difficulty threshold? Hmm, it’s an interesting question. So, whenever a new block is created, it’s propagated across the network so that every block has a record of this new transaction in the ledger. In theory, it takes almost 10 minutes for a new block to propagated across the network in Bitcoin and 10–19 minutes in Ethereum. The hash will be easily generated if the difficulty threshold is less, and it might be the case that every block does not have the updated ledger, which may cause inconsistency in the network. So, to maintain an average time of block creation to 10 minutes, the difficulty threshold is changed after every 2016 blocks in Bitcoin.


What do you think?


电子邮件地址不会被公开。 必填项已用*标注





Store or Be Stored on Sia

BlockFi Raises $30M Series B Led by Valar Ventures