4 MIN READ

The Double Spending Problem

2021-25-08_700x508px_Double_Spending
The Double Spending Problem

Money can only be spent once before it¬†changes the account or wallet. This is a fundamental tenet of our banking and financial system. If I transfer amount XY from my account to your bank account, the amount is deducted from my account and credited to yours. If this was not the case, I could spend it a second time. This is what we call ‚Äúdouble spending‚ÄĚ.¬†¬†

When using cash, this is impossible ‚Äď if I hand you my 10 EUR bill, you have it, I no longer do. However, when transactions are purely digital,¬†more checks need to be in place. Hence, when settling transactions¬†digitally, the¬†instantaneous and¬†simultaneous debiting of the amount from the sender and crediting of the receiver‚Äôs account must be ensured.¬†In the centralized banking system, integrated banking systems verify this.¬†But how does this work in a decentralized blockchain network like Bitcoin?¬†

The double spending problem in blockchain networks 

In a¬†decentralized¬†blockchain network, transactions are proposed and broadcast to all participating nodes1¬†in the network.¬†These nodes then receive and¬†have to¬†confirm the transactions ‚Äď a process that takes some time. How does the blockchain ensure that the sender cannot spend that same money a second time until the first transaction has been confirmed?¬†

In other words, how does the Bitcoin network ensure the validity and integrity of the first transaction?  To answer this, let’s first recover… 

The Basics: What the blockchain is 

The blockchain is a special form of distributed ledger, basically a database of transactional records that is stored and updated in real-time across multiple nodes that each store the same version of that database.¬†Cryptocurrencies like the Bitcoin blockchain use a decentralized¬†rule-based¬†decision-making process known as ‚Äúconsensus mechanism‚Ä̬†where participating nodes of the network collectively decide on the validity and¬†integrity¬†of a requested transaction.¬†¬†

Once transactions have been validated and confirmed, they are irreversible¬†and posted publicly. Transactions are¬†time-stamped,¬†encrypted and subsequently stored¬†in blocks¬†in chronological order¬†which are connected through a hash.¬†In the words of Satoshi Nakamoto, the infamous creator of Bitcoin, this is a¬†‚Äúchain of digital signatures‚ÄĚ.¬†¬†

To understand how the Bitcoin blockchain prevents double-spending, we need to¬†take a look¬†at the¬†confirmation process for transactions¬†‚Äď also known as consensus mechanism.¬†¬†

How the confirmation process eliminates any possible double spending 

The Bitcoin blockchain uses a consensus mechanism called ‚Äúproof of work‚ÄĚ. This mechanism foresees that¬†every requested transaction is announced to all nodes in the network. If¬†the majority of¬†nodes agrees on the validity of a transaction, the transaction is confirmed.¬†The double-spending problem is an issue of time ‚Äď the question is ‚ÄúWhich transaction was received first?‚Ä̬†

Here again, the majority decides. The majority of nodes decides which transaction was received first, subsequent attempts at double spending then become irrelevant. This is achieved by a timestamping mechanism that Satoshi Nakamoto outlined in his whitepaper.  

The timestamp server solves the double-spending problem 

Presented in the Bitcoin whitepaper, Satoshi Nakamoto details a timestamp server as the way to solve the double spending problem.¬†The server uses a hash ‚Äď a cryptographic¬†signature¬†‚Ästof a block of transactions and broadcasts it to all participating nodes of the network.¬†The hash itself is timestamped and then proves to all nodes¬†that data inside the block must have been created before the actual hash.¬†Each timestamp includes a hash of the previous timestamps. This results in an unalterable (immutable) record of the order in which transactions were¬†performed. Each subsequent timestamp builds upon and reinforces the previous one.¬†¬†

Let’s say we attempt a double-spend… 

Let’s assume we have 0,1 BTC we want to attempt to spend twice. This would mean sending the 0,1 BTC to two different wallet addresses. Both requested transactions actually go into an entire pool of requested transactions that have to be processed by the network of miners.  

When the first transaction is confirmed through the consensus mechanism, it will become part of a block of transactions which is then hashed. The second transaction would be recognized as invalid and be rejected (as the sender’s bitcoin wallet has been deducted 0,1 BTC).  

In the unlikely event, that both transactions are selected from two miners simultaneously, both transactions are added to different blocks by different miners. In this case, the blockchain would create a second string.  

Source: papers.ssrn.com/sol3/papers.cfm?abstract_id=2580664

Let’s have a look at the illustration. In red is the Genesis block, followed by the blocks integrated into the blockchain in blue. The grey blocks represent blocks that were created but not included in the actual blockchain because two variants of the blockchain existed at the same time.  

In the blockchain, the longest string is always preferred, the shorter strings are dropped. If two strings (transactions) are created at the same time, a fork occurs. This means that two parallel strings exist at that moment. Since both strings are the same length, neither of them can be preferred. The network is therefore briefly¬†divided¬†and work is continued on both strings. After 2-3 blocks, it becomes clear which network is faster.¬†One of the forks¬†is then accepted while the other will become an ‚Äúorphaned‚ÄĚ block¬†an¬†will be dropped.¬†

Conclusion  

In decentralized blockchain networks, too, it must be ensured that¬†the same money cannot be spent twice simultaneously. The solution to this¬†is to timestamp each¬†transaction and block of transactions through a cryptographical process known as a ‚Äúhash function‚ÄĚ.¬†¬†

This creates a chronological and immutable order of all transactions which is why an attempt to double spend is rejected based upon it being requested at a later point in time after a first, validated transaction has already occurred. 

1 Nodes: Computers that verify and synchronise the blockchain.  

Start investing today!

Disclaimer:

This is not financial advice. Mentioning coins and tokens is not a recommendation to buy, sell, or participate in the associated network. We would like to encourage you to do your own research and invest at your own risk.

Editorial team

We are a team of crypto enthusiasts. Each of us has extensive theoretical and practical experience in trading, cryptocurrencies, and blockchain. We also like to dig deep and explore. Our goal is to help you make the right and relevant decisions.

Leave a Comment

Your email address will not be published. Required fields are marked *

Related articles