One of the main pillars of cryptocurrencies the world over is that they are trustless systems. What does that mean? It means you don't have to rely on a third party, like a bank, or government, to prove who you or someone else is. How does it do that? A hash function, a clever bit of cryptography that allows people to be identified, without, well, being identified. We explore this more below.
What is a hash function?
A hash function is a technique whereby any piece of data is converted into a long jumble of letters and numbers in order to conceal the original piece of data. A hash function is special because it will always produce the same jumble of letters for a set piece of data, but if you change any tiny thing in the original source, the jumble will be completely different.
This means hash functions can be used to determine who owns a piece of data without them revealing what the data is. Clever, huh? Think of it as a digital key.
How does the hash function work?
Hashing turns a piece of data into binary code, essentially a bunch of 0s and 1s. Once it's done that, it breaks up the numbers into sections and applies the secret jumbling, also known as a computation function. The end result is typically a 64-digit string of numbers and letters. This 64-digit string is then used in a whole bunch of different ways, which we explore below.
But before that, the 64 digit string is almost impossible to hack. Because the conversion is done by an algorithm, the formula it uses isn't known. To try and hack that would be like trying to navigate a path through a kaleidoscope. However, for pieces of software to read the hash function and check whether it has come from the right place, it's almost instant.
Did you know?
A computer capable of running 15 trillion calculations per second would take almost 0.65 billion billion years to crack the hash of a single Bitcoin address.
What are hash functions used for?
- Creating Private and public keys: To send and receive crypto, or carry out a transaction on blockchain, you need a pair of keys. Keys typically come in pairs, private and public. The private key is connected to the public key via a hash function to keep your details safe. You could send your public key to anyone, or have it on a public profile, and no one will be able to work out the private key thanks to the hash function. We've done a whole guide on keys and wallets if you'd like to know more.
Did you know?
In 2013, the Bitcoin blockchain accidentally split in two because some miners hadn’t upgraded their software. During this time, double spends were possible.
- Bitcoin mining: In order to keep the network running fairly, Bitcoin maintains a level playing field for participants to earn themselves the right to create the next block. It uses a computational race that starts again every time a block is published. To win the race, each miner collects a set of transactions, includes a reference to the previous block and uses this as a piece of data to put into a hash function. To win the race, the hash function that results must start with a certain number of zeros depending on the current difficulty of the network. The higher the zeros, the harder it is. We wrote a whole piece on bitcoin mining to help make things clearer. Essentially, hash functions are used to help crack the puzzle at the heart of blockchain.
Did you know?
In October, 2018, the Bitcoin hashrate was 50 Exa hashes per second. This makes the network 15 million times more powerful than the world’s fastest supercomputer, the tianhe-2.
- Linking blocks in the blockchain: If blocks in a blockchain weren’t linked, it would be easy to insert a fake one. Bitcoin avoids this by linking each block to the previous block. It does so by using a hash pointer. A hash pointer is the result worked out from hashing the previous block in the chain. This means that anyone can check that the transactions in the block follow on from the previous one. This actually allows miners to ensure the whole chain is legitimate and that not a single block has been added by a malicious miner. This also means that every coin’s history can be traced back to when it was mined.
Nothing in computing is unhackable but hashing helps make things fiendishly difficult. Right now, with current computing power, it would take millions of years to hack a hash function. But in future, things like quantum computing could shorten the time it would take significantly. But blockchain builders are aware of what lies on the horizon and are actively building quantum resistant algorithms. But for now, hashing, as it exists today, is here to stay.