
So, we came to an interesting point here: miners are competing with each other in adding a new block to the blockchain, and to do so, they need to solve a computational puzzle. The miner who solves it first gets rewarded in Bitcoins. On first look this seems a little strange. Why does a financial system rely on solving puzzles, and what does solving puzzles have to do with sending money? It might seem unnecessary at first, but this is where it all starts.
We need to look at what these miners are doing in the background. When a miner gets some transactions from the network, it bundles them all up together to form a “block” that can be added to the blockchain. This block contains a list of all these transactions as well as some extra data linking it to the previous block on the chain. So it’s not just an isolated lump of data, rather it’s just a further part of the blockchain, and is linked to previous bits of data in a way that forms continuity through the entire chain. However, in order for a miner to add this block to the blockchain, they have to work out what number can be combined with all of the other data in the block in such a way that a specific condition, set by the network, is met.
This is where hashing is important. You can think of a hash as a digital finger-print for data. Any chunk of data can be put through a hashing function (whether it’s a sentence, a file or a block full of transactions) and we will get a seemingly random fixed length output. But the beauty of hashing functions is that they’re incredibly sensitive to change. If I alter the slightest bit of the data, even just changing one letter in a sentence, the hash will be completely different. This means every block can be given a fingerprint, based not only on the data inside it, but also the fingerprint of the block which precedes it. The chain becomes self linked.
This makes the blockchain incredibly tamper evident. If I wanted to change a transaction in an earlier block, the hash would change, breaking the link between that block and the one following it. This would cascade through the entire blockchain, and it would become impossible to make any changes at all.
However, what are miners actually solving? The network has one condition. In order to be considered valid, the hash of the block must meet a specific criteria (for instance, it must start with x amount of zeros). Although this sounds simple, it’s actually incredibly computationally difficult to figure out. There is no direct way to work this out, miners have to try out millions, or even trillions of possible inputs until they find a suitable one. They do this by changing a small value within the block known as a ‘nonce’, a value that when paired with the rest of the data in the block, is hashed repeatedly, over and over until a suitable result is found.
It’s like trying to break into a combination lock without any numbers at all. It just requires brute force. When a miner does eventually find a valid block, they simply show it to the network. The other nodes can easily verify that it is a valid solution, and thus the block is added.
This creates a disparity in ease; solving the problem is extremely computationally expensive, however verifying it is easy. This is part of what ensures Bitcoin is so secure. The cost in resources, meaning it’s effectively impossible for malicious users to disrupt the system. To alter an earlier transaction you’d have to carry out the same computational effort for that block and every block after it, plus beat everyone else on the network to it, and all of this at speed.
This whole system is known as Proof of Work and ensures that a degree of effort is involved in the process of adding to the blockchain to make it resilient to attacks. Instead of relying on trust from a central party, Bitcoin uses mathematical functions.
We now have the structure of the whole thing working; transactions get submitted, verified by various parties on the network and then grouped together by miners who then add the block to the blockchain through the process of Proof of Work. There’s no central entity involved and it works well.
This leads nicely into one final, crucial question: If it takes such resources to mine blocks (time, electricity, computational power), what drives miners to do this work for the network?