How the parameter of difficulty protects blockchains.
Without the parameter of difficulty, anybody could generate hashes for sets of data and create multiple alternative versions of blockchains, be it Bitcoin, Ethereum or some other network. With difficulty, the creation of alternative versions is almost impossible because of the longest chain rule. The longest chain rule is very simple. It says that the longest chain of a blockchain wins. While the rule sounds simple, there is a lot to it.
First, in essence the rule, just like many other parts and sides of blockchain technology, relies on the laws of free markets, free economy, personal interest and intrinsic motivation. Miners on blockchain networks create blocks of blockchains because they get rewards for doing so. Let’s assume that there is a blockchain with an alternative history that starts with block A. This means that after block A, the blockchain will have two versions: block A1 and block A2. By definition, miners can’t be creating two blocks of different blockchains at the same time just like a person can’t be in two different locations at the same time. Miners will either be compiling transactions into the blocks of blockchain where the last block is A1 or on the blockchain where the previous block is A2. This means that in the case of a split, each and every miner would have to decide whether he or she wants to stay with the original chain or start mining blocks of a new chain. Obviously, miners are interested in getting rewards for creating the blocks of blockchain and they would not switch to a network that they do not trust. This means that the majority of miners will stay on the network that they do trust. Because there will be more of them on the network that they trust, this blockchain network will be creating blocks of its blockchain faster than the network that operates in exactly the same way but has fewer miners on it. The network, in turn, will accept the longer chain as the legitimate one, and will protect itself this way from a split (such splits on blockchain networks are also known as forks).
Difficulty as a way to solve the issues of double spending and transaction finality
With difficulty, blockchain networks are able to solve the two issues that make blockchain technology truly revolutionary: the issue of double spending and the issue of transaction finality.
Figuring out how to protect the network from double spending and transaction finality were the true breakthroughs of the Bitcoin network and the blockchain technology. These are the problems that people before Satoshi Nakamoto could not solve in a way that would make a peer-to-peer network operate successfully.
The problem of double spending is about a user on a digital network simultaneously sending funds to several other users. The goal of the network is to make sure that this doesn’t happen. In centralized systems, solving this issue is easy because there is a central authority such as a central bank that issues the currency and governs its circulation.
Transaction finality is also something that all users care about. Transaction finality means that once someone sends funds on a network, the transaction becomes final and there will be no disputes and no chargebacks.
The blockchain network has solved these issues with a combination of tools that include the parameter of difficulty, sealing blocks with hashes and requiring transactions on a blockchain having multiple confirmations. Typically, a transaction requires at least six confirmations. Some software and networks require 30, 40 or even 100 confirmations.
When a user on a blockchain network sends funds to a different user, for the transaction to go through, a miner needs to pick this transaction, include it into a block of the blockchain, come up with a nonce and seal the block with a hash that will satisfy the parameter of difficulty. This is when the transaction gets its first confirmation. The hash of the block with the transaction gets included in the hash of the next block on the blockchain, meaning that now two blocks have a record (via hashes) about the transaction. This means that the transaction has two confirmations. Six confirmations would mean inclusion into six blocks, thirty confirmations would mean inclusion into thirty blocks and so on.
In practical terms, these confirmations mean that if somebody wanted to modify the transactions that are occurring in real time on the Bitcoin network, they would need to change at least six blocks of the blockchain. This would require the creation of new hashes and doing so faster than the rest of the network.
The speed at which the hardware of miners compiles transactions into sets of data, adds a nonce to them and comes with a hash is called hashrate. In terms of hashrate, to become successful with an attack on a blockchain network, an attacker would need more hashrate than all the other existing miners on the network combined.
The way difficulty, hashes and confirmations function on blockchain networks are a powerful way to seal the blockchain so that changing it is not impossible, but would require a tremendous amount of work. An alternate history would require more work than miners have already put in and on the Bitcoin network this is really expensive. For example, an article in the Guardian from 2017 mentioned that during the year of 2017, miners on the Bitcoin network have burned more electricity than the entire country of Ireland.