- Describe hash functions with your own words.
A hash function takes in an input and produces a unique string of characters for that input in such a way that there is no way to determine what the input is from just the output of the hash function.
- How are hash functions used in cryptocurrencies like bitcoin?
In bitcoin, each block contains the hash of the data of the previous block. Any change to the data within a block would change its hash, which would then change the hash of all other blocks allowing for easy detection of any tampering in the blockchain, rejecting that blockchain within the network. Also miners use the hash of the current block being mined by concatenating a random string to it and checking if the hash of that is less than the current difficulty. Once a miner guesses the correct random string to solve that equation, they add that block to the chain and receive their reward.
- What does it mean when we say that hash functions need to be collision resistant?
It is possible for a unique input to share the same hash as another unique input. If you have a 128 bit hash, you would have a 50% chance of running into such a collision after 2^64 iterations with unique inputs. In order to reduce the rate of collisions you would need to use a higher bit hash function. For example, SHA 256 would require 2^128 iterations to have a 50% chance of running into a collision.