Cryptographic hash functions produce a fixed-size hash value from a variable-size transaction input.
What Is a Cryptographic Hash Function?
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.
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.