Hash functions are vital to protect the immutability of the digital ledger. If the hash function used by a blockchain is broken, then an attacker could find collisions for crucial hash values (such as the blockchains or a Merkle tree’s values). This would enable malicious nodes to more easily rewrite the history of the blockchain network and cause a blockchain system to fall apart. For this reason, the security of hash functions is essential to the security of the blockchain.
The hash functions are 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 digital ledger of the blockchain 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: The Merkle tree uses hash functions to ensure that it is infeasible to find two Merkle trees with the same root hash summarized by a list of transactions contained within a block into a single value within a blockchain header. The integrity of the transactions contained within the block's body is protected as well by storing the root hash within a block header and protecting the integrity of the block header.
Proof-of-work (PoW) consensus: The PoW 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": The hash of the previous block header within its header is contained by each block in the blockchain, which 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.
Hope this was helpful.