A Guide to Consensus Algorithms on Blockchain Networks Part 6

Proof of work and how it works


The Bitcoin network uses a consensus algorithm called proof-of-work to process transactions between users on the network. This article contains an explanation of how the algorithm works.

When a user on the Bitcoin network initiates the transaction, the transaction becomes visible to the entire network. For example, you can see the transactions that are being initiated as you are reading this article by visiting https://blockchain.info/unconfirmed-transactions

Miners on the Bitcoin network then pick up these transactions and compile them into blocks of the Bitcoin blockchain. This is the easy part of what miners do. The next part is to seal these transactions so that nobody can change them.

Miners on the Bitcoin networks do so with cryptography hashes using cryptography algorithm called SHA-256.

A cryptography hash is a string of data that corresponds to a set of data. Cryptography hashes have several useful properties. First, a hash is typically much shorter than the string of data that it corresponds to in a cryptography algorithm. For example, block #525685 of the Bitcoin blockchain contains information about 2178 transactions and you can see all this information if you start scrolling down the page of the block here https://blockchain.info/block/00000000000000000010da9ac4028403ee34ebf7c589a79bd9e37a79661ac2cc but the hash for the all this data about all these transactions is 00000000000000000010da9ac4028403ee34ebf7c589a79bd9e37a79661ac2cc, which is also something you can see on the page of the block.

Second, when several parties have the same data, they will always get the same hash using the same cryptography algorithm, but even very similar sets would return very different hashes. This is what makes the Bitcoin network and other cryptocurrency networks so secure. A block on the network (with the exception of the very first block) contains the hash of the previous block. This means that if someone were to change information even about one transaction, the hash for the block would change and the network would not recognize the new block because its resulting hash would be very different from the hash for the original block that is included in the next block of the blockchain.

Third, if you have access to a cryptography algorithm and you have a set of data, you can always create a hash for it, but it doesn’t work the other way around: you can’t recreate the data if all you know is a hash. With blockchain networks, this means that having a hash without data is useless. Hashes are only valuable together with data.


Difficulty and nonces

Hashes are a secure way to seal the data, but the problem that nobody was able to solve before Satoshi Nakamoto was that creating a hash for a set of data is a very easy task for modern computers. If all that Bitcoin network required was for a computer to create a hash, then users all over the world would be able to create multiple versions of blockchains that would compete with each other. For this reason, the Bitcoin network and many other cryptocurrency networks have a parameter called difficulty.

Simply put, difficulty means that hashes for blocks of the blockchain need to start with a large number of zeros. This is why a typical hash for a block of Bitcoin blockchain looks like this: 0000000000000000003d1709e80398ef7edab20ccf0def5b6dda042bf5ddbc65. Because a set of data can only have one hash, to create a hash that would satisfy the parameter of difficulty, miners on the Bitcoin network add a number to the data about transactions that they compile into blocks of Bitcoin blockchain. This number is called nonce, which is an abbreviation for number used once. This is the essence of mining on the Bitcoin blockchain: miners are trying to come up with a hash that would correspond to the target hash on the network set by the parameter of difficulty.

The parameter of difficulty on the Bitcoin network changes every 2016 blocks of the blockchain. The Bitcoin network aims to create a block of the blockchain once in every 10 minutes. In the ideal world, this would mean that the network would be creating 2016 blocks in exactly two weeks. If the network creates the blocks faster, it decided that block creation is too easy and increases the difficulty. If it takes longer than exactly two weeks for the network to create 2016 blocks, it decides that the job is too hard and decreases the difficulty.

The increase of the parameter of difficulty with the increase of the popularity of the Bitcoin network is the reason why in the beginning, when Satoshi Nakamoto just launched the network in 2009, it was possible to be a miner on the network with just a regular home computer and today you would need specialized equipment (called ASIC) cards to participate in the process.