Skip to main content

Hash functions and Blockchain

Hash functions are commonly used to protect the integrity of data. Given a trusted hash of the data, it is possible to calculate the hash of the data and compare the two values. If they match, then the data has likely not been modified since the original hash was created.

The blockchain’s digital ledger is designed to store valuable information that can benefit an attacker if modified in their favor. Additionally, this ledger is stored and transmitted by a network of mutually distrusting nodes.

As a result, the blockchain has a number of different uses for hash functions and the integrity protection that they provide. Some of the most common uses of the hash function in blockchain include:

  • Digital signatures: Hash functions are a vital part of digital signature algorithms, summarizing the data to a compact value while preserving its integrity. Digital signatures are used for preserving data integrity and authentication for blockchain transactions and blocks
  • Merkle trees: Merkle tree summarizes a list of transactions contained within a block into a single value within a block header. They use hash functions to ensure that it is infeasible to find two Merkle trees with the same root hash. This way, by storing the root hash within a block header and protecting the integrity of the block header, the integrity of the transactions contained within the block’s body is protected as well
  • Proof of Work consensus: The Proof of Work consensus algorithm defines a valid block as one whose header has a hash value less than a given threshold. Hash function collision resistance is essential here since it ensures that finding a valid block is difficult
  • The blockchain’s “chains”: Each block in the blockchain contains the hash of the previous block header within its header. This ensures that changing a single block in the blockchain without detection is impossible. Modifying one block in the chain requires generating new versions of every following block as well, increasing the difficulty and helping to preserve the integrity of the blockchain’s digital ledger
One example of SHA 256:

In a blockchain, hashes are used to connect the blocks to each other and create the chain. Every new block added to the blockchain will have the details of the transaction - Amount, address of sender and receiver, timestamp, and most importantly the previous block’s (transaction) information stored as a hash value. This entire information again converts into a Transaction ID, which is the hash value of that particular block.

SHA256(index + prevHash + Timestamp + Data + Nonce)

In order to verify the values, you can use  https://guggero.github.io/blockchain-demo/

Last modified: Friday, 21 May 2021, 7:34 PM