Cryptographic Hash Function
Cryptographic hash functions produce a fixed-size hash value from a variable-size transaction input.
What Is a Cryptographic Hash Function?
A cryptographic hash function is an algorithm, i.e. a repeatable sequence of specific actions, that can be used to transform an arbitrary data string of a variable length into one of a fixed length and format, called the hash.
One of the simplest examples of a hash function is adding up the digits in a number until one is left with a single-digit output. If the input is 49, for example, then adding 4 and 9 yields 13, whose digits 1 and 3 are then summed up again to give the output of 4. Regardless of the length of the input number, the output will always be a single digit.
That is not a good algorithm, however, because, in order to perform its functions well, a hash function needs to possess several characteristics:
It should be easy to compute an output for any given input, but nearly impossible to reverse the process and calculate the input of a known output;Determinism — feeding a specific input into the algorithm should always produce the same output;Collision resistance — two different inputs should be very unlikely to produce the same output;Avalanche effect — changing even a single bit of data in the input should result in a wildly different output.
Hash functions are applied in many use cases, for example, as checksums to verify the integrity of computer files after their transmission of prolonged storage, or in randomizing functions.
They are also a key component in the mining of proof-of-work cryptocurrencies, such as Bitcoin (BTC), which uses the SHA-256 hash function. In order to add a new block to the blockchain and claim their reward of newly-mined Bitcoin, miners first need to produce a hash value that is below a certain threshold, called the target.
The fact that hashes are pseudorandom and it is impossible to predict an output of any input before actually running it through the hash function ensures that miners cannot print new Bitcoins out of thin air and need to prove the work they have performed.