A deep dive into Hashing and its importance with respect to Cryptocurrencies.
What is Hashing?
Hashing refers to the concept of taking input data, applying some algorithm to it, and generating fixed-size output data. The generated output data is what we call a Hash. This technique is widely used in authentication systems to avoid storing plaintext passwords in databases but is also used to validate files, documents and other types of data.
But we were talking about Cryptocurrencies, right?
In the context of cryptocurrencies like bitcoin, the transactions are taken as input and run through a hashing algorithm which gives an output of a fixed length. For example, bitcoin uses an algorithm called SHA-256, which gives a 256-bit output length. This becomes critical when we’re dealing with a huge amount of data and transactions. So basically, instead of remembering the input data which could be huge, we can just remember the hash and keep track.
Now the technology that enables the very existence of cryptocurrency is called Blockchain.
Hashes are used in blockchains to represent the current state of the world. The first hash is calculated for the first block, called Genesis block using the transactions inside that block. The sequence of initial transactions is used to calculate a block hash for the Genesis block. For every new block that is generated afterwards, the previous block’s hash is also used, as well as its own transactions, as input to determine its block hash.
This is how a chain of blocks is formed, each new block hash pointing to the block hash that came before it. This system of hashing guarantees that no transaction in the history can be tampered with because if any single part of the transaction changes, so does the hash of the block to which it belongs, and any following blocks’ hashes as a result. It would be fairly easy to catch any tampering as a result because you can just compare the hashes.
It is important to remember that while there is no way to actually reverse a hash function, you can try a whole lot of inputs and find an input that gives the hash value you want.
For example, suppose you are rolling a dice and the output is the hash of the number that comes up from the dice. How will you be able to determine what the original number was? It’s simple all that you have to do is to find out the hashes of all numbers from 1–6 and compare. This is essentially what cryptocurrency miners do in order to verify the transactions that go onto the blockchain ledger.
No two distinct inputs into a hash function should ever produce the same output. And no matter how many times you parse through a particular input through a hash function you will always get the same result. This is critical because if you get different hashes every single time it will be impossible to keep track of the input.
To conclude, hashing is an important pillar of cryptocurrencies and blockchain technology in general.
If you’re interested to read more on these technologies, you can check out Kryptopedia.