Let’s give a simple example to illustrate how a 51% attack works (double spend attack):
You spend 10 Bitcoin on a luxurious car. The car gets delivered a few days later, and the Bitcoins are transferred from you to the car company. By performing a 51% attack on the Bitcoin blockchain, you can now try to reverse this Bitcoin transfer. If you succeed, you will possess both the luxurious car and the Bitcoins, allowing you to spend those Bitcoins again.
Before explaining how this can happen, you should be acquainted with the blockchain mining process and technology.
51% Blockchain Attack (double spend attack) Definition
The ability of someone controlling a majority of network hash rate to revise transaction history and prevent new transactions from confirming.
What does this mean?
A 51% attack or double-spend attack is a miner or group of miners on a blockchain trying to spend their crypto’s on that blockchain twice. They try to ‘double spend’ them, hence the name. The goal of this isn’t always to double spend crypto’s, but more often to cast discredit over a certain crypto or blockchain by affecting its integrity.
Why can a 51% blockchain attack theoretically work?
As we have banks and the states central institution, the blockchain governs using a distributed ledger, where it can store all kind of information, like transactional data, in the case of cryptocurrency. That is why we call blockchains to be decentralised.
The protocol of the Bitcoin blockchain is based on democracy, meaning that the majority of the participants (miners) on the network will get to decide what version of the blockchain represents the truth.
How does a 51% PoW attack work?
Each transaction sent by a bitcoin owner is put into a pool of unconfirmed transactions. The miners select the transactions which will be part of the block. The miners need to find the solution to a very difficult mathematical problem (using computational power) to be able to add this block to the blockchain. This is the process of hashing.
Of course, the bigger the computational power of a miner, the better the chances are for him to be the first to find a solution. When a miner finds a solution, it will be broadcasted (along with their block) to the other miners and they will only verify it if all transactions inside the block are valid according to the existing record of transactions on the blockchain.
Note that even a corrupted miner can never create a transaction for someone else because they would need the digital signature of that person in order to do that (their private key). Sending Bitcoin from someone else’s account is therefore simply impossible without access to the corresponding private key.
How does a 51% blockchain attack start? With a corrupt miner!
A corrupt miner will try to reverse transactions. Why is a miner called malicious? Because when a miner finds a solution, it is supposed to be broadcasted to all other miners so that they can verify it whereafter the block is added to the blockchain (the miners reach consensus). a corrupt miner can create his own version of the blockchain by not broadcasting the solutions of his blocks to the rest of the network. There are now two versions of the blockchain.
The corrupted miner is now working on his own version of that blockchain and is not broadcasting it to the rest of the network. The rest of the network doesn’t pick up on this chain, because it hasn’t been broadcasted. It is isolated of the rest of the network.
The corrupted miner can now spend all his Bitcoins on the truthful version of the blockchain, the one that all the other miners are working on. On the truthful blockchain, his Bitcoins are now spent. Meanwhile, he does not include these transactions on his isolated version of the blockchain. On his isolated version of the blockchain, he still has those Bitcoins.
Meanwhile, he is still picking up blocks and he verifies them all by himself on his isolated version of the blockchain. This is where all trouble starts… The blockchain is programmed to follow a model of democratic governance (the majority).
The blockchain does this by always following the longest chain, after all, the majority of the miners add blocks to their version of the blockchain faster than the rest of the network (longest chain = majority). This is how the blockchain determines which version of its chain is the truth, and in turn what all balances of wallets are based on. A race has now started. Whoever has the most hashing power will add blocks to their version of the chain faster.
This is a double-spend attack. It is commonly referred to as a 51% attack because the malicious miner will require more hashing power than the rest of the network combined (thus 51% of the hashing power) in order to add blocks to his version of the blockchain faster, eventually allowing him to build a longer chain.
And just for the fun of it, check the cost of the Proof-of-Work 51% Attack for some top cryptocurrencies.