{"id":"double-spending-problem","title":"Double Spending Problem","content":"Double spending problem is a phenomenon in which a single unit of currency is spent simultaneously more than once. This creates a disparity between the spending record and the amount of that currency available.Double spending is most commonly associated with [Bitcoin ](https://iq.wiki/wiki/bitcoin)because digital information can be manipulated or reproduced more easily by skilled programmers familiar with how the blockchain protocol works. [Bitcoin](https://iq.wiki/wiki/bitcoin) is also a target for thieves to double spend because [Bitcoin](https://iq.wiki/wiki/bitcoin) is a peer-to-peer medium of exchange that doesn’t pass through any intermediaries or institutions.[\\[1\\]](#cite-id-ho6bfzijcvs)​\n\n$widget0 \n\n$$\n$$\n\n# Overview\n\nFor example, if someone walks into a clothing store with only $10 and buys a $10 shirt, then buys another $10 shirt with the same $10 already paid to the cashier. While this is difficult to do with physical money, in part because recent transactions and current owners can be easily verified in real-time, there’s more opportunity to do it with digital currency.Bitcoin’s completely digital currency network is decentralized which means it has no central authority, regulators, or governing bodies to police thieves and hackers. Though traditional security entities don’t monitor the [Bitcoin](https://iq.wiki/wiki/bitcoin) network for double spending, other network defenses have been implemented to combat attacks that would otherwise threaten the network’s consensus mechanism and ledger of transactions, providing confidence to those who invest in [Bitcoin](https://iq.wiki/wiki/bitcoin).\n\n# How does Bitcoin Double-Spending work?\n\nFundamentally, a double spend consists of a bad actor sending a copy of one transaction to make the copy appear legitimate while retaining the original, or erasing the first transaction altogether. This is possible and dangerous for [Bitcoin](https://iq.wiki/wiki/bitcoin) or any digital currency because digital information is more easily duplicated. There are a few different situations where criminals attempt to double-spend [Bitcoin](https://iq.wiki/wiki/bitcoin).\n\n## Simultaneously sending the same Bitcoin amount twice or more\n\nAn attacker will simultaneously send the same bitcoin to two (or more) different addresses. This type of attack attempts to exploit the [Bitcoin](https://iq.wiki/wiki/bitcoin) network’s slow 10-minute block time, in which transactions are sent to the network and queued to be confirmed and verified by miners to be added to the blockchain. In sneaking an extra transaction onto the [blockchain](https://iq.wiki/wiki/blockchain), thieves can give the illusion that the original bitcoin amount hasn’t been spent already, or manipulate the existing blockchain and laboriously re-mine blocks with fake transaction histories to support the desired future double spend.\n\n## Reverse an already-sent transaction\n\nThe attacker sends multiple packets (units of data) to the network to reverse the transactions, to give the illusion they never happened. With this way, the attacker attempts a [Bitcoin](https://iq.wiki/wiki/bitcoin) double spend by reversing a transaction after receiving the counterparty’s assets or services, thus keeping both the received goods and the sent [bitcoin](https://iq.wiki/wiki/bitcoin).\n\n## 51% Attack\n\nWhen a group of miners controls over 50% of the network’s hash rate, they launch a 51% attack against a [cryptocurrency ](https://iq.wiki/wiki/cryptocurrency)[blockchain](https://iq.wiki/wiki/blockchain). Having control of 51% of the network’s nodes provides the governing parties with the ability to change the blockchain.Payments between a few or all users might be stopped if the attackers were able to stop fresh transactions from receiving confirmations. The ability to undo decisions taken when they were in charge would likewise be available to them. One of the problems that consensus systems like proof-of-work were designed to avoid is that by reversing transactions, users might double spend coins.On a coin with a high participation rate, a 51% assault is an extremely demanding and difficult undertaking. The majority of the time, the group of attackers would have to be able to command the required 51% and have a backup [blockchain ](https://iq.wiki/wiki/blockchain)ready to be injected when the opportunity arises.The main network would then have to be out-hashed. One of the biggest obstacles against a 51% attack is the expense of doing so. For instance, the [Bitmain](https://iq.wiki/wiki/bitmain) S19 XP Hydro is the most sophisticated Application Specific Integrated Circuit (ASIC) miner. It boasts 255 TH/s (tera hashes per second) of hash rate and costs more than $19,800.FoundryUSA, with 54.42 EH/s (exahashes per second), accounts for 23.75% of the entire [Bitcoin](https://iq.wiki/wiki/bitcoin) network hash rate, followed by AntPool at 41.49 EH/s, 18.12%, and [Binance ](https://iq.wiki/wiki/binance)Pool at 34.48 EH/s, 15.06%.[\\[2\\]](#cite-id-p77hfp6pbfj)\n\n## Finney Attack\n\nThe Finney attack is named after [Hal Finney](https://iq.wiki/wiki/hal-finney), who happened to be the first recipient of a [Bitcoin](https://iq.wiki/wiki/bitcoin) transaction, and the first person to comment on the release of the [Bitcoin](https://iq.wiki/wiki/bitcoin) source code. It is a double spending attack with the following features:\n\n* It only works if the merchant accepts unconfirmed transactions.\n* It still works, however, if the merchant waits a few seconds to verify that everyone in the network agrees he was paid.\n* It requires the attacker to be mining and controlling the content of his blocks; however, he can in theory do this with any hashrate, in particular significantly less than 50% of the network hashrate.\n\nIt proceeds as follows:\n\n* The attacker mines blocks normally. In the block he/she is trying to find, he includes a transaction which sends some of his/her coins back to himself/herself, without broadcasting this transaction.\n* When he/she finds a block, he/she does not broadcast it; instead, he/she sends the same coins to a merchant for some goods or service.\n* After the merchant accepts the payment and irreversibly provides the service, the attacker broadcasts his/her block. The transaction that sends the coins to himself/herself which is included in this block, will override the unconfirmed payment to the merchant.\n\nIf the time from finding the block until the attacker sends payment and the merchant accepts it is '**t'**, and the average time to find a block is '**T**', there is a probability of t/T that another block will be found on the network in this time. In this case the attack will fail, *and* the attacker will lose the block reward of B.This means that the average cost of attempting the attack is about (t/T) \\* B. As a rule of thumb, the merchant should wait at least t=V\\*T/B (V is the value of the transaction) to make sure that trying to carry out this attack against him isn't profitable. This may not be sufficient though, as a nimble attacker can use the same block for multiple attacks, potentially gaining the total of their value.The lower the attacker's hashrate, the less opportunities he/she has to carry out the attack. If the attack is for obtaining some illiquid good, it is difficult to make the need for this good coincide with finding a block. If the attack is for obtaining something liquid (e.g. exchanging bitcoins for other money), an opportunity is ever-present but the merchant is likely to require a few confirmations. This makes the attack difficult to use in practice.[\\[4\\]](#cite-id-ntm3apywq8)\n\n## Race Attack\n\nThe Race Attack is a particular kind of a Double-Spending attempt which is a malicious activity when two transactions are created at the same time using the same funds to spend them twice. It requires the recipient to accept payment for unconfirmed transactions. The attacker sends the victim an unconfirmed transaction. [Meanwhile](https://iq.wiki/wiki/meanwhile), they broadcast to the network a conflicting transaction. Since the victim observed their own transaction first, they believe they will be paid. However, since the rest of the network saw the double-spend first, it’s likely that the victim will not get the money.Such an attack is significantly easier to carry out when the attacker has a direct connection to the victim's node and deposits the conflicting transaction directly to the miners.[\\[6\\]](#cite-id-nazl3npuw2p)\n\n# How Double Spending Problem prevented\n\nA timestamp server was suggested as a solution to the double spending issue in [Satoshi Nakamoto](https://iq.wiki/wiki/satoshi-nakamoto)'s white paper. A block of transactions is hashed by this server, which then broadcasts the hash to every node in the bitcoin network. This timestamp demonstrates that none of the information in the hash could have been produced following the publication of the hash. This creates an immutable (unchangeable) log of the sequence in which transactions occurred since each timestamp contains the preceding timestamp in its hash. Each timestamp builds on the ones that came before it.In conclusion, the [blockchain ](https://iq.wiki/wiki/blockchain)stops double spending by broadcasting groups of transactions to all nodes in the [bitcoin ](https://iq.wiki/wiki/bitcoin)network and timestamping them. Transactions are irreversible and hard to tamper with since they are timestamped on the blockchain and quantitatively tied to earlier ones.[\\[2\\]](#cite-id-p77hfp6pbfj)\n\n## Bitcoin\n\nSince the first bitcoin client was delivered in 2009, the [blockchain ](https://iq.wiki/wiki/blockchain)of [bitcoin ](https://iq.wiki/wiki/bitcoin)has preserved an exhaustive record of all transactions ever done in order to properly comprehend how the blockchain avoids double spending. No one can alter the record since every transaction is cryptographically hashed to the preceding blocks. This database is referred to as a blockchain because a fresh batch of transactions, known as a block, is added to it every ten minutes.\n\n## Ethereum\n\nAvoiding double spending means to stop using the same amount twice. If the nonce is set to the same only one of the transactions will be mined and most of the time that can be the one with higher gas price, but however no double spend will happen as only one transaction will take place at the end in either case.[\\[3\\]](#cite-id-0f3pxatmcew)There are two types of nonce used in [Ethereum](https://iq.wiki/wiki/ethereum).\n\n* **Account nonce** It's simply the transaction count of an account. This prevents replay attacks where a transaction sending, for example, 20 coins from A to B can be replayed by B over and over to continually drain A's balance.\n* **Proof of work nonce** The random value in a block that was used get the proof of work satisfied (depending on the difficulty at the time). Proof of work nonce is a meaningless value in a block which can be adjusted in order to try to satisfy the proof of work condition.\n\n# Cases\n\nIn December of 2019, a viral video showcased bitcoin being double-spent at locations that accept bitcoin. These attacks were made possible using Replace-By-Fee (RBF), a somewhat controversial upgrade to the [Bitcoin ](https://iq.wiki/wiki/bitcoin)protocol. The first transaction was sent to the merchant, followed by a second transaction with a higher fee attached. This RBF transaction overrode the first transaction as the higher fee meant it would be processed preferentially, allowing it to be double-spent. These attacks worked because the merchants accepted unconfirmed transactions.\n\nIn a similar incident earlier in the same year, some Canadian [bitcoin](https://iq.wiki/wiki/bitcoin) holders were able to “cash in” their [bitcoin](https://iq.wiki/wiki/bitcoin) without actually cashing it in. It appeared they sent [bitcoin](https://iq.wiki/wiki/bitcoin) to [Bitcoin](https://iq.wiki/wiki/bitcoin) ATMs, where they were able to withdraw cash. After receiving the cash, they cancelled the transactions, since they had yet to be “confirmed.” [\\[5\\]](#cite-id-pkypi77zcbd)","summary":"Double spending problem is a phenomenon in which a single unit of currency is spent simultaneously more than once. This creates a disparity between the spending...","images":[{"id":"QmR3XSr4LXQCC9mpBqNxmkRcfz8WTBmKvTzyYs3DJNvFri","type":"image/jpeg, image/png"}],"categories":[{"id":"defi","title":"Decentralized Finance"}],"tags":[{"id":"Glossary"},{"id":"Blockchains"}],"media":[{"id":"https://www.youtube.com/watch?v=phLSjZdDc5A","size":"0","name":"phLSjZdDc5A","type":null,"source":"YOUTUBE"}],"metadata":[{"id":"youtube_profile","value":"https://www.youtube.com/watch?v=phLSjZdDc5A"},{"id":"reddit_profile","value":"https://www.reddit.com/r/Bitcoin/comments/1tn3i3/what_exactly_happens_on_a_double_spend/"},{"id":"github_profile","value":"https://github.com/topics/double-spending"},{"id":"references","value":"[{\"id\":\"ho6bfzijcvs\",\"url\":\"https://www.sofi.com/learn/content/double-spending/\",\"description\":\"SoFi Learn _ Bitcoin Double Spending Problem\",\"timestamp\":1674282596164},{\"id\":\"p77hfp6pbfj\",\"url\":\"https://www.topcoder.com/thrive/articles/double-spending-and-how-its-prevented-by-blockchain\",\"description\":\"Topcoder -Double Spending and how it's prevented by Bloackch\",\"timestamp\":1674393583054},{\"id\":\"0f3pxatmcew\",\"url\":\"https://ethereum.stackexchange.com/questions/27432/what-is-nonce-in-ethereum-how-does-it-prevent-double-spending\",\"description\":\"StackExchange - How nonce in Ethereum prevent double spend\",\"timestamp\":1674397557072},{\"id\":\"ntm3apywq8\",\"url\":\"https://bitcoin.stackexchange.com/questions/4942/what-is-a-finney-attack\",\"description\":\"Bitcoin - What is a Finney attack\",\"timestamp\":1674444771412},{\"id\":\"pkypi77zcbd\",\"url\":\"https://www.gemini.com/cryptopedia/double-spend-attacks-bitcoin\",\"description\":\"Gemini - Double-Spend attacks examined\",\"timestamp\":1674447470438},{\"id\":\"nazl3npuw2p\",\"url\":\"https://www.bitdegree.org/crypto/learn/crypto-terms/what-is-race-attack\",\"description\":\"BitDegree - What is Race Attack?\",\"timestamp\":1674447756139}]"},{"id":"previous_cid","value":"\"https://ipfs.everipedia.org/ipfs/QmSKpj7ZryqYsiSwWMvm4UEJb2RqvwUu8YX17r44t9eFR4\""},{"id":"commit-message","value":"\"Removed Double spending problem content\""},{"id":"previous_cid","value":"QmSKpj7ZryqYsiSwWMvm4UEJb2RqvwUu8YX17r44t9eFR4"}],"events":[],"user":{"id":"0x8af7a19a26d8fbc48defb35aefb15ec8c407f889"},"author":{"id":"0x2E66379061a2A39ccf38cE73d6144665C7eDC3E1"},"operator":{"id":"0x33f784D922B59d04E25c2b2Fbb1AF8FaA9ADe604"},"language":"en","version":1,"linkedWikis":{"blockchains":[],"founders":[],"speakers":[]},"recentActivity":"{\"items\":[{\"id\":\"2c8f83f7-4c33-46df-9b04-dfee81944856\",\"title\":\"Double Spending Problem\",\"description\":\"Double spending problem is a phenomenon in which a single unit of currency is spent simultaneously more than once. This creates a disparity between the spending...\",\"timestamp\":\"2026-02-05T15:31:58.971Z\",\"category\":\"Decentralized Finance\",\"status\":{\"icon\":\"RiGlobalLine\",\"label\":\"Wiki Updated\",\"iconClassName\":\"text-green-500\"},\"user\":{\"name\":\"0x2E66379061a2A39ccf38cE73d6144665C7eDC3E1\",\"address\":\"0x33f784D922B59d04E25c2b2Fbb1AF8FaA9ADe604\"},\"button\":{\"label\":\"View Summary\",\"icon\":\"RiFileTextLine\"},\"summarySections\":[{\"title\":\"Content\",\"subtitle\":\"The article's content was edited to include additional internal links and improve formatting.\",\"variant\":\"modified\",\"changeCount\":4,\"changes\":[\"Replaced a YouTube video embed with a video widget in the introduction.\",\"Added internal links for 'Bitmain', 'Hal Finney', and 'Meanwhile' in their respective sections.\",\"Added multiple internal links for 'Bitcoin'. [[5]](#cite-id-pkypi77zcbd)\",\"Adjusted text formatting and removed unnecessary line breaks throughout the article.\"]},{\"title\":\"Metadata\",\"subtitle\":\"Added new metadata fields for tracking wiki changes and score.\",\"variant\":\"added\",\"changeCount\":4,\"changes\":[\"Added 'words-changed' with value '698'.\",\"Added 'percent-changed' with value '60.28'.\",\"Added 'blocks-changed' with value 'content, tags'.\",\"Added 'wiki-score' with value '80'.\"]}]}]}"}