Double Spending Problem Explained Simply
The double-spending problem has been a conundrum in the digital-cash realm for decades. In fact, it was the double-spending problem that held back the advancement of peer to peer digital cash. It wasn’t until the arrival of the Bitcoin Network that a p2p decentralized digital currency really began to be viable.
Many of us “know” that Bitcoin solves the double spending problem, but we still struggle to explain how Bitcoin solves this problem. In fact, it was only yesterday that I received this email from a regular Mango Reader:
Your cautionary post on the Bitcoin Doubler Scam got me thinking about the double-spending problem.
Wont a miner be able to “double spend” his bitcoin by simply broadcasting a transaction on the network and then quickly mine a block that sends the same bitcoin to another merchant?
Good question, Juan. This is actually a common misunderstanding. But before I answer you, let’s quickly explain the double spending problem for the readers who may be unfamiliar with it.
Double Spending Problem Explained
Anything digital can be copied – anything. And more importantly: it can be copied exactly. This is a huge problem in the digital space when pertaining to digital rights management and… digital cash. Pirated movies, pirated music, pirated software etc. have all been birthed from our ability to copy anything that is in digital format. To most of you, this has been a blessing in disguise.
But imagine if digital cash could be pirated as well?
What would be the implications?
Hyperinflation, for one.
This is one of the primary reasons why we still rely on central authorities for our financing needs. The central authorities (like banks) maintain a ledger where they keep tab of everyone’s expenses. They ensure that double-spending doesn’t occur (..or try to!)
However, centralized solutions pose a single-point-of-failure problem. They can easily be hacked or compromised externally (bribed). But for decades, it was the only solution we had – until Bitcoin came into the picture.
Satoshi Nakamoto proposed an elegant solution in his whitepaper where he explained how the Bitcoin Network would solve the double-spending problem.
Misunderstanding Double Spending Problem In Bitcoin?
Similar to centralized solutions, Bitcoin also uses a ledger to keep track of transactions. However, this ledger is stored across the globe at multiple locations (called nodes).
This global ledger is called the “Blockchain”.
Why? Well, because it’s simply a chain of “blocks”. Each of these blocks contain transactions that have taken place in the network.
New transactions that are broadcasted to the network are picked up and put into these “blocks” by miners. Once the block is created, a miner will initiate his mining process where he attempts to solve the Cryptographic Puzzle.
The miner who solves the puzzle first wins the “right” to submit his block to the blockchain (the global ledger). They then move on to the block of new transactions.
This is where Juan’s question comes into play. He’s asking about this hypothetical scenario that explains the (misunderstood) double spending problem.
- Miner Joe has only 10 bitcoin in his wallet
- Miner Joe sends those 10 bitcoin to Merchant Alice
- The network & miners pick up the transaction.
- All the miners put together a block with this transaction: “Joe sends 10 BTC to Alice”
- But sneaky Miner Joe makes a block with this transaction instead “Joe sends 10 BTC to Bob”
- Miner Joe wins the cryptographic puzzle, so his block goes through.
Is that a double spend?
No, it is not a double-spend at all. Sure – it is an attempted double spend.
But Miner Joe was not able to pull it off.
Why? Because Joe’s block with his transaction : “Joe sends 10 BTC to Bob” got added to the chain. This means that the blocks containing the transaction: “Joe sends 10 BTC to Alice” did not get added – and was never considered at all.
Double Spending Problem: Forks & Longest Chain
Remember, Joe won the Cryptographic Puzzle race, so his block gets added to the chain, while everyone else’s block is rejected.
Ah, but what if Joe was not the only one who solved the puzzle?
Often, more than one miner may solve the cryptographic puzzle. This means that multiple blocks may be added to the chain at the same point – resulting in a blockchain Fork.
So what if another miner – Miner Collin – also solved the cryptographic puzzle. We would now have two blocks with the following transactions:
Joe’s Block: Joe sends 10 BTC to Bob
Collin’s Block: Joe sends 10 BTC to Alice
Would this be a successful double-spend? It may look like it – but nope, this is not a successful double-spending attack.
The blockchain has forked into two different chains, one with Joe’s block as the newest block; and the other with Collin’s block as the newest block. It is here that the Bitcoin Network will have to pick one of the chains as its main chain. How does it pick it? It will essentially use the Longest Chain Rule.
I explain the Longest Chain Rule using a simple analogy in the post above. But I’ll quickly go over it here.
The Longest Chain Rule Summarized
Essentially, the network will pick the chain that is the “longest” as it’s main chain. This means that the network will have to wait for a few more blocks to be added to the chain before a decision can be made.
If the chain with Joe’s block outpaces the chain with Collin’s block, then Joes block will be valid since it will be in the winning chain. Collin’s block, however, will be considered “orphaned” and invalid.
Even if the opposite happens, it won’t matter – because only one of the two transactions will be considered valid. So the double-spending problem doesn't really come into play here.
Double Spending Problem: Confirmations are Key!
But what about Alice? Is she at risk here? In fact, Alice is actually at risk of being victim to a pseudo double-spending problem. I say “pseudo” because it is not so much a double-spending problem within the network, but “outside” of it.
Two transactions were broadcasted to the network:
Joe’s Block: Joe sends 10 BTC to Bob
Collin’s Block: Joe sends 10 BTC to Alice
Joe’s block was added to the blockchain and Collin’s block was orphaned. But remember, transactions are broadcasted to the network – regardless of whether they get added to the chain or not. So Alice will have received a network message saying “Joe sends 10 BTC to Alice”
As a merchant, Alice may get tricked by this and give Joe some merchandise. However, this is not a fault of a network – but more so a human error. The bitcoin was not officially “double spent” inside the network.
This is precisely why it is always recommended to wait for “Confirmations” on your transactions. Each “confirmation” represents an additional block being added to the block which contains your transaction.
Every time a block gets added (a confirmation), it means that there is an increased probability of your transaction being in the Longest Chain. At around 5-6 confirmations, you can be pretty sure that your transaction is safe – you won’t be at risk of a double-spending attack.
So...Is A Double-Spend Even Possible in Bitcoin?
Yes, a double-spend is technically possible in the Bitcoin Network. However, it's going to be extremely difficult and expensive to pull it off.
If Miner Joe wanted to actually commit a double-spend, he'd have to start mining his own private chain secretly. In the original chain he'd send the 10 bitcoin to Alice. But in his private chain he'd send the 10 Bitcoin to Bob.
He'd then wait for Alice to receive her six or more confirmations. In the mean time, he would have to ensure that he mines fast enough so that his private chain outpaces the original chain. If his private chain becomes the longest chain, the rest of the network will switch over to mining on his chain instead – because of the Longest Chain Rule. This way he can pull off a successful double-spending attack.
However, this is a lot easier said than done. In my post on Proof Of Work - Determining Majority Power, I discuss how CPU Power is a crucial part of the consensus process. Miner Joe would need to expend a lot of energy and have a lot of computing power to actually outpace the Bitcoin Network.
It's possible – but far too expensive! A double-spending attack would need a lot of CPU Power
He would essentially need at least 51% of entire networks hashpower to outpace the network eventually. Remember, he has to solve a cryptographic puzzle for each an every block. And he only has a chance to win each block. His chance to win, however, is directly proportional to his hashpower. This is why the community tries to ensure that no particular mining pool has too much control of the Bitcoin Network. Anything over 50% makes the network vulnerable to an attack!
Hope this post helps! And keep the emails coming, guys! 🙂
Get my upcoming eBook for Free!
"The Mango Guide TO Understanding Blockchain"
Offer Valid For FIRST 500 registrations only