This is part II of the series and it will focus on concept called hashing. I will use same metaphor as previous article to explain hashing. If we go back to our example of train, coupler is a mechanism used to connect carriages and engine of the train, as shown in the image below.
The coupler come in different shapes and sizes.Buffer & chain, Link & pin and Bell-and-hook are few example of couplers. Just like coupler for train, similar concept is used in Blockchain to connect blocks. The Blocks in Blockchain are linked to its immediate predecessor using hash. The first block in the Blockchain is called “Genesis” block or Block 0 and its link lies out in the system. The below diagram is a simplified version of how Bitcoin Blockchain looks like and generally Blockchains follow same pattern.
At this point you might be wondering, what is hashing and how is it useful in the whole Blockchain ecosystem. Worry not, I will try to explain it.
Hashing is a simply process of taking a variable length input and creating a fixed size output, which is sometimes also called as Digest. Just like different types of couplers for train, there are also different types of hash functions. Example are Murmur hash, CityHash, SHA256, xxHash and SHA-3.
Blockchain mainly uses cryptographic hash functions such as SHA256 and Keccak-256. Example of Blockchains using these functions are Bitcoin and Ethereum, respectively.
The main reasons for using cryptographic hash functions for Blockchain lies in its properties, which are:
- Deterministic – each time you parse same input through the hash function, you will get same hash value.
- Efficiency – for any given input, the hash function should be capable of returning the hash value quickly else the system is simply not efficient.
- Pre-image resistance – given a hash value, it should be difficult to find its input value. It is not impossible to determine the original input from its hash function.
- Collision resistance – two different inputs to a hash function cannot have same hash value.
- Slight change to input – making a small change to the input will change the hash value completely. For example, just changing the first letter of the Iron Maiden song “The Trooper” to “the Trooper” using SHA256 hash function changes the hash value completely.
Just to cap this article off, let’s say a malicious attacker changes a data in block 1 of the Blockchain. Because of the properties of cryptographic hash functions, any slight change made in block 1 will change the hash value stored in block 2 and this will result in changes in block 3 and so on and so forth. Therefore it will become very hard for the malicious attacker to compute an alternate chain from Block 1 which will catch-up with and overtake the one true chain.
More to follow.