The term "hash function" is derived from the French word “hacher” which means to “chop into small pieces”, indicating how a hash function is designed to “chop” the data. Another type of data structure, a hash table, is frequently used for rapid detection of any two identical hashes (hash values).
After Diffie and Hellman first identified the need for a one-way hash function in their 1976 seminal paper on public-key cryptography, over the next two decades developments in cryptography progressed rapidly. In 1990, cryptographer and MIT professor, Ronald Rivest, invented the MD4 hash function and later the MD5 and MD6 functions. In 1995, the NSA (National Security Agency) designed the SHA-1 (Secure Hash Algorithm 1) based on Rivest’s design, followed by the SHA-2 update in 2001. SHA-2 is the standard that inspired SHA-256, which served as the baseline for Bitcoin’s consensus algorithm.
The purpose of hash functions
Hash functions originated from the need to make content uniform in length on one hand, and for usage as singularly unique identifiers on the other. Typical uses for hash functions outside the cryptocurrency sphere include:
Calculating a (short) checksum for an object, such as the checksum for an ISBN (International Standard Book Number)
Identifying any content almost without ambiguity but still “briefly”, without revealing anything about the content in cryptographic applications
Properties of hash functions
A cryptographic hash function should be computationally efficient, meaning that it must be quick in performance to create the hash value. It has to be deterministic - every time you put in a certain input, it has to produce the same output and to be pre-image resistant which means it cannot reveal any information about the input in the output.
Finally, a hash function has to be collision-resistant which ensures that it has to be impossible for two different inputs to produce the same output. It is the deterministic feature, pre-image resistance and collision-resistance that constitute the three most important properties of hash functions in the Bitcoin mining process.
A hash function has to be collision-resistant which ensures that it has to be impossible for two different inputs to produce the same output.
Hash functions in the mining process
Quickly running through the validation process in the Bitcoin network again, a block is bundled and contains several transactions as well as information on the previous block. This means if someone wanted to change the ledger or double-spend a transaction, he or she would have to change the hash in all previous blocks.
In order for the bundled block to be added to the blockchain, miners need to find a hash that meets the target difficulty. Each block contains a blockheader with the number of the block, the hash of the previous block and a “nonce”, which includes a timestamp. The purpose of a nonce is varying the input to a cryptographic hash function, that is increased randomness, in computation during the mining process.
Solving the hash
The node then begins “hashing” the data by converting it into the hash value or “hash”, which always needs to contain a certain number of zeros. The node checks whether a hash meets the criteria of difficulty. The hash must start with the correct amount of zeroes. If the hash meets the criteria of difficulty, it is broadcast to the other miners in the network. The first miner to find a valid hash validates the block into a new block and gets rewarded the block reward and fees in Bitcoin.
If the hash does not meet the criteria of network difficulty, another nonce is selected and hashed. Miners probably have to generate many hashes with many nonces until they find a nonce that meets the difficulty. This is the repetitive and energy-intensive process known as Bitcoin mining which requires extensive computational power.
Hash functions constitute the backbone of the Proof of Work process. Without confirmation and production of hash transactions, the blockchain would not be tamper-proof and inalterable and it would not be possible to prove who owned which amount of Bitcoin at what time.