What is Double Spending?

By: Ofir Beigel | Last updated: 5/4/20

One of the main issues any digital currency faces is double spending. This post explains exactly what the double spend problem is, and how to prevent it.

What is Double Spending Summary

Double spending is the act of trying to spend the same digital currency twice by creating duplicate transactions. This issue is one of the main obstacles a digital currency needs to solve in order to make sure it is not being abused, and that it maintains its value and trust.

Bitcoin solves the double spend problem through the use of a public ledger that is constantly monitored by network participants, and through the Proof of Work consensus mechanism.

That’s double spending in a nutshell. For a more detailed explanation keep on reading, here’s what I’ll cover:

1. Double Spending Explained

Since Bitcoin transactions are a digital file, it’s actually possible to duplicate transactions and spend the same Bitcoin twice. This issue of “copying and pasting” is a weakness any digital currency faces (even fiat currencies in their digital form).

Here are some examples of how you can double spend a digital currency:

You can “copy” a coin and send it to someone while still retaining the original. You can simultaneously send the same coin to two different people. You can reverse a transaction that’s already been made after receiving the goods paid by it, hence keeping the goods and the money.

The double spend problem is a serious issue for any digital currency since it can create an inflated money supply which quickly erodes the value of the currency and the trust in it.

2. How to Prevent Double Spending?

There are two ways to stop double spending – a centralized way and a decentralized way.

The Centralized Solution

The centralized solution to prevent double spending is pretty simple. It usually involves a trusted authority that holds a record of everyone’s balance in the system.

For example, when Alice sends money to Bob, the transaction goes through the central authority (e.g. bank) that checks its ledger to makes sure Alice has the money she wants to spend. If everything is in order, the central authority authorizes the transaction and the money is transferred.

The Decentralized Solution

When you’re dealing with a decentralized currency like Bitcoin, you don’t have a central authority to validate transactions. Therefore, Bitcoin uses a mix of elements to solve the double spend problem.

Preventing Fraudulent Transactions

First of all, the Bitcoin ledger of transactions, known as the Blockchain, is public and visible to all. Every Bitcoin transaction ever made and every balance of every address can be inspected by anyone.

This means that if Alice sends one Bitcoin to Bob, every computer that holds a copy of the blockchain (also known as a full node) will verify the history of Alice’s transactions to make sure she indeed has that one Bitcoin to spend.

If Alice tries to cheat and creates a Bitcoin from thin air, she will quickly be exposed by one of the many nodes validating transactions.

Preventing Simultaneous Transactions

But what if Alice sends the same coin simultaneously to two people?

Assuming 50% of the nodes received transaction A first, and the other 50% received transaction B first. How do we know which transaction is valid, and which to discard? The answer is simple, the transaction that enters the ledger first will be the valid one.

That’s why it’s always recommended to wait for at least 1 confirmation before considering a Bitcoin transaction as complete.

In order to decide the order of transactions, Bitcoin uses a consensus mechanism called Proof of Work (POW). This mechanism describes the rules of who gets to update the ledger of Bitcoin transactions.

This is important since when there’s no central authority, you need to have a consensus about who gets to make changes in the transaction ledger. The whole process of updating the ledger of transactions is known as Bitcoin mining.

However, what happens if the mining process somehow happened simultaneously for both transaction A and transaction B?

Let’s assume that two unrelated miners managed to update the ledger at exactly the same time, each one with a different transaction that uses the same source of funds.

In this case, we will have 2 branches of the blockchain (also known as a fork) and the next block of transactions to be mined will determine which previous block was valid.

If the next block, in some magical way, is also mined simultaneously, we will have to wait until the next block, and so on.

If you want to be completely sure your Bitcoin transaction won’t be reversed in such a rare case of coincidences, you should wait until 6 confirmation arrives for your transaction.

It’s highly unlikely (like super highly unlikely) that this fork will happen more than 6 times. So, in the end, we will have a clear winner and only one transaction will be confirmed.

Preventing transaction reversal

There’s a special kind of double spend attack that is called a 51% attack. This happens when a single entity gains over 50% of the network’s mining power and can effectively control which version of the ledger is the legitimate one.

In this case, the attacker can spend coins on one version, obtaining good or services for this payment. Later on, the attacker creates a different version of the ledger where the original transaction doesn’t exist and retrieves the payment to his possession.

The only way to prevent a 51% attack is to make sure the network is decentralized enough and has enough computational power to make it basically impossible to amass more than 50% of its hashrate.

In Bitcoin’s case, a 51% is highly unlikely, but with smaller coins, this type of attack has happened.

3. RBF – “Legit” Double Spending

One form of “legit” double spending is Replace By Fee or RBF for short.

RBF is a function embedded in certain Bitcoin wallets (e.g. Electrum) that allows you to rebroadcast a transaction that is still unconfirmed, in order to get it confirmed faster.

In some cases, Bitcoin transactions are sent with a network fee that is too small to incentivize miners to pick them up. This can get your transaction stuck inside the mempool, waiting to be confirmed for a very long time.

RBF allows you to rebroadcast the transaction with a higher fee, effectively trying to double spend your money, so the miners will pick up the new transaction and the old one will get canceled.

4. Conclusion

Double spending is a major issue that needs to be addressed when dealing with digital currencies. Fortunately, it seems that Satoshi Nakamoto, the inventor of Bitcoin, managed to build a mechanism to prevent it from happening even in a decentralized network.

You may still have some comments or questions. If so, make sure to leave them in the comment section below.