- Describe hash functions with your own words
Hash functions are functions that return a unique output (hash value) for any given string. They are one-way functions in the sense that you can’t deduce the input based on the output.
- How are hash functions used in cryptocurrencies like bitcoin? (Try to research this on your own, we will cover this later in the course but challenge yourself and see if you can find information on this already now)
They are used to maintain the integrity of the blockchain. The header of every block contains the SHA-256 hash of both the block header of the previous block and the root of the merkle tree (which, as far as I can tell, is obtained by first hashing individual transactions, then forming pairs of hashes by adding them together and hashing that value. That process is repeated until we arrive at a single hash value, which is called the merkle root).
This has several uses. Firstly, it enables us to efficiently verify whether some data is a part of a block. Let’s say that we have data A with the hash H(A) and we want to know if it belongs to a block with the merkle root of H(AB+CD). Provided we have access to H(B) and H(CD), we can plug in H(A) and compute H(AB+CD). If that hash value is the same as the corresponding value on the block, then, given that SHA-256 generates a unique output for every input, we can deduce that A is a part of a block.
Secondly, the fact that every block contains the hash of the block header of the previous block ensures the immutability of the blockchain. If one, for example, were to change just one bit in the first block of the bitcoin blockchain, the hash of of the block header of that block would change, which would invalidate all of the following blocks that build upon that hash value.
- What does it mean when we say that hash functions need to be collision resistant? (We didn’t use the term “collision resistant” in the lecture, but you will easily find this on Google, we add this question intentionally to make you research information on your own, that’s how you learn best).
It means that it should be infeasible to find inputs that correspond to the same hash value. Since the potential hash values of SHA 256 are limited (2^256) and potential inputs are unlimited, there cannot be a unique hash value for every potential input. In practice, finding collisions needs to be extremely difficult for the blockchain to be secure. For example, as far as I can tell, if one could easily find data with a hash value that collides with a preexisting hash on the blockchain, one could claim that this data is a part of the blockchain.