Hash functions are mathematical functions which takes an input of any size and gives an output of a fixed size which is known as the hash (or digest). Their main objective is to protect and validate data integrity. It is a part of the consensus algorithm that is used in that particular blockchain. These hashes or digest which is the output of the hashing function are primarily used for comparison and not encryption.How hashing is used in blockchain?
In a blockchain network the data of the transactions which is stored in the blocks will have to be hashed, to validated the integrity of the network. The input in the hash function will be the transactional data which takes place inside the network, then the data is hashed and then stored in the block as a string in a fixed size depending on the type of hash function that is used. The hashing function of a blockchain network depends on the consensus algorithm of the network.
There different versions of hashing algorithms such as MD5, SHA-1, SHA-256, SHA-384 etc.
We can understand this in a suitable example.
Let’s assume that Jeff, Joel, ben and Mary are in a blockchain network called “SKY”
Transaction 1 – Jeff to ben
Transaction 2 – Mary to Joel
Transaction 3- Jeff to Joel
Transactional information of each contains- the amount, to address and a time stamp.
The miners of that blockchain network has to validate the transactional information in the ledger between the participants. The transactional information of each transaction is hashed with a hash function of SHA-256. The number “256” denotes the number of bits of the produced hash.
The hash value may look like this (256 bits):
The transaction 1 is hashed and stored in the genesis block, the transaction 2 is hashed and stored in the block 2 along with the previous hash value (transaction 1) to make a chain. Transaction 3 is hashed and stored in block 3 along with the previous hash (transaction 2), each block is linked with the hash value of the previous block. What will be the previous hash in the genesis block? The previous hash value in the genesis block will be 0, since the genesis block is the inception point of this particular “SKY” blockchain and there is no previous block ahead of it in the chain.
The bitcoin network poses the SHA-256 hash function. And the Ethereum network works with ETHASH in real world applications, these are some examples.Is hashing a one-way approach?
Yes, in fact it is one of the characteristics of hash functions, these hashing functions are a one-way function, which typically means that it is impossible to figure out the input of the hash through a reverse approach in a blockchain network.What’s the difference between encryption and hashing?
Encryption is a two-way process and its objective is to be decrypted and interpret the message by a single person on the network to another, while hashing is a one-way process where it is only needed to be compared and verified with the previous hash in a block. Primarily passwords are hashed in order to be stored in databases of public networks.To conclude.
Hashing is an essential pillar of the blockchain technology. Blockchain’s digital signatures and passwords are dependent on hashing, blocks are identified and connected to one another by these hashes. Hashing is the basis of the process by which the miners of the network go through to create verified blocks during consensus.