Introduction
Double spending use-case
Double spending means spending the same money twice.
Let’s consider this example:
You go to Starbucks and order a cappuccino worth $10. You pay in cash. Now that $10 in cash is in the cash vault of Starbucks. By all means, you simply cannot spend the same $10 somewhere else to make another purchase.
Unless you steal it…!!!
As you paid with your $10 bill, the service provider at Starbucks instantly confirmed that you have paid, and you received your coffee in exchange for the money.
But Bitcoin is digital money, not physical cash. Hence, Bitcoin transactions have a possibility of being copied and rebroadcasted. This opens up the possibility that the same BTC could be spent twice by its owner.
How?
In our Starbucks example, you paid cash, so the payment was confirmed and verified instantly by another human. But with digital currency like BTC, if this verification mechanism is missing, it can lead to double spending.
Anyone can just copy that digital money and pay somewhere else.
How Bitcoin Handles The Double Spending Problem
Bitcoin manages the double spending problem by implementing a confirmation mechanism and maintaining a universal ledger (called “blockchain”), similar to the traditional cash monetary system.
Bitcoin’s blockchain maintains a chronologically-ordered, time-stamped transaction ledger from the very start of its operation in 2009.
Every 10 mins, a block (i.e. a group of transactions) is added to the ledger. And all the nodes on the Bitcoin network keep a copy of this global ledger (the blockchain).
How Bitcoin Handles The Double Spending Problem
Let’s suppose you have 1 BTC which you try to spend twice.
You made the 1 BTC transaction to a merchant. Now, you again sign and send the same 1 BTC on another Bitcoin address to try and trick the merchant.
Both transactions go into the unconfirmed pool of transactions. But only your first transaction got confirmations and was verified by miners in the next block. Your second transaction could not get enough confirmations because the miners judged it as invalid, so it was pulled from the network.
But wait… what if both the transactions are taken simultaneously by the miners?
When miners pull the transactions simultaneously from the pool, then whichever transaction gets the maximum number of confirmations from the network will be included in the blockchain, and the other one will be discarded.
How Double-Spend Attacks Can Happen
Attack 51% - If somehow an attacker captures 51% of the hash power of the network, double spending can happen.“Hash power” means the computational power which verifies transactions and blocks.
Useful link
https://coinsutra.com/bitcoin-double-spending/