A hash function is basically an algorithm. It uses input data like a file or a password. A hash function then creates a certain value. We call this value checksum, and it is important for keeping our blockchain secured.
The riskiest way of storing passwords is to write it down on plain text. If Hackers get access to a company database, they get to see all the passwords. Because a lot of people have the bad habit of using the same password for multiple accounts, its likely that one password could lead to different accounts. You might think companies don’t store your password in plain text because it is too risky. But in reality, a lot of companies are doing it. And therefore provide a huge security breach.
An alternative to plain text storage is encryption. You can take your passwords and before you store them they get encrypted. This prevents hackers from getting your real passwords but it is still risky. Underneath the encryption, the layer is still a plain text password. So if the attacker manages to steal the encryption key he can unlock all of your passwords. Encryption can, therefore, work in two ways. It saves but also decrypt your password. This is practical when you want to share data in a secure way. But it is risky to secure your password.
Blockchain Hash Function takes input like a piece of text or could a file and turns it into an integer output. It has always the same length. Hash functions are different from encryption because they only work in one way. You can calculate the hash of a password but you cannot take a hash and turn it back into the original data. With hashes, companies can verify that you are logging in with the correct password, without having to store your actual password.
You can compare hashes with fingerprints. It is not possible to identify the person unless you have seen their fingerprint before. However, they aren’t perfect either. Most hashing algorithms are optimized for speed. So the more hashes per second they can calculate, the better. That makes them vulnerable against brute force attacks. Therefore hackers can try to calculate every possible password and reverse the hash function.
Hash is a checksum derived from the block’s information. As we mentioned above it is comparable to a digital fingerprint. In addition, each block still contains the checksum of the previous block. This creates a direct link between the blocks making our blockchain tamper-proof. Thus, a subsequent change to an already documented transaction would cause all successive checksums to be incorrect. To trick the system, a hacker has to reverse the hash function by randomly trying. He needs to do this for every single block. So theoretically he can hack the system, but it’s practically impossible since nobody has so much computer power available.
There are lots of different types of blockchain hash function. The most important one for blockchain is SHA256. The number 256 generally refers to the length of the output. So SHA256 will produce a 256 bit or 64 characters long output. These are the basics for our easy explanation of blockchain hash function. But we think the following short excursion might help you even more.
In the Ethereum protocol, hash functions are part of the block hashing algorithm. It is used to write new transactions into the blockchain through the mining process. The inputs for the function are the most recent, not yet confirmed transactions.
As we mentioned above, changing a small part of a hash function results in a completely different output. This property is crucial to the Proof of Work algorithm involved in mining. If a miner wants to successfully solve a block, they try to combine all the inputs with their own input data. As a result, they want the hash to start with a certain number of zeroes. Thus, solving blocks takes a huge amount of processing power. Therefore new Ether gets mined over a long period. In order to earn Ether through mining, you need to put a lot of work into it. But as a result, all the new transactions get locked into a block. The miner adds it then to the permanent record of all previous transactions and forms a chain of blocks.