What is double-spending?

March 20, 2024
4 min read
blocks

The term double-spending refers to the problem where the same amount of currency is spent multiple times. This problem arose in the digital age. After all, physical money can only be handed over once. But digital money only exists as code in databases, and code can be manipulated and duplicated. Centralised parties like banks solve this problem quite simply with a carefully maintained ledger. But what about blockchains? In this article, we briefly explain the double-spending problem in relation to cryptocurrencies and how it is solved.

Double-spending attacks

Most blockchains are decentralised systems. This means that there is not one authority that guarantees the integrity of the ledger, as with a bank, but many servers spread around the world each maintain their own copy of the ledger. These servers continuously receive new transactions and it takes a while for each transaction to be registered at each server. It also takes a while before the transaction is validated and included in a block. These aspects of decentralisation make a number of types of attacks possible.

Race attack

A hacker sends multiple transactions from one wallet at the same time via different nodes to make purchases from one or more entities, while the wallet does not have enough crypto for all payments. Only when a block is mined are such transactions rejected, but if these entities do not check this and automatically accept the payments, the hacker has made purchases with crypto that does not exist. After all, everything except one transaction on the blockchain will be rejected.

Finney attack

A hacker with a large amount of hashing power sets up a miner node. Then they build a transaction between two wallets that both belong to the hacker, and add that to their own block. This block is locally mined and stored, but not yet broadcast. The hacker then finds an entity where they can make purchases with unconfirmed transactions. After the hacker makes the unconfirmed payment to the entity, they quickly send their own block to the network. Since the block has already been mined and therefore validated, this block will immediately be added to the blockchain. Since this block contains the transaction that forwards the crypto to one of his own wallets, the as yet unconfirmed transaction to the entity will be rejected, and the hacker will manage to retain both his crypto and the purchase.

51% attack

This attack requires that the hackers have more than 50% of the total hashing power of the network. This way they can add transactions to a block that transfer much more crypto to themselves than is actually in the wallets. Miners in the hands of the hackers will unlawfully approve the block, even though all other miners will reject it. But since the hackers are in the majority, the block will be added to the blockchain.

How is double-spending prevented?

Most double-spending attacks can be prevented by waiting for multiple blockchain confirmations. Take Bitcoin as an example. A "confirmation" occurs when a block is mined. The block gets a "hash" with a timestamp, information from the previous block, and the transactions in the block. At this point, all transactions are validated and final. This information can then be consulted forever on the public ledger and can be considered immutable.

With Bitcoin, it is the norm to wait for 2 to 6 confirmations. This is not only to prevent double-spend attacks, but also to prevent problems when two miners mine a valid block at exactly the same time. In this case, the blockchain temporarily diverges, with miners accepting one or the other block in the blockchain depending on which they receive first. The system automatically corrects this when one of the chains mines the next block by choosing the longest chain as the "main chain". At that point, the block of the other chain is undone, so it becomes a so-called orphaned block. Its transactions are put back in the mempool for reevaluation. The chance that this happens is very small, and that it happens several times in a row is astronomically small.

Since a large part of the hashing power of the Bitcoin network is in the hands of a few large so-called "miner pools", it is practically impossible for an individual attacker to get a malicious transaction or block on the blockchain or to change the current blockchain, because such actions will immediately be rejected by all other miners who would be harmed by it.

The information provided in our articles is intended solely for general informational purposes and does not constitute (financial) advice.

Subscribe to our newsletter

Everything you need to know about Bitcoin, straight to your inbox. Subscribe now for the latest from Blockrise.