MultiversX Tracker is Live!

Can miners double-spend with two transactions in one block?

Bitcoin Stack Exchange

Bitcoin News / Bitcoin Stack Exchange 147 Views

doublespend - Can miners double-spend with two transactions in one block? - Bitcoin Stack Exchange

Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.

Sign up to join this community

Anybody can ask a question

Anybody can answer

The best answers are voted up and rise to the top

Asked

Viewed 144 times

Let's say Alice sends 5 BTC to Bob and Alice tries to make double spending by again sending those same 5 BTC inputs to carl and lets say that Alice is also a one of the miner node.

  1. Here Alice tries to take those 2 double spent transactions into a same single block
  2. lets say Alice solved hash puzzle and broadcasted those 2 transactions in the same block

since in first transaction, inputs UTXO and output UTXO are valid and in second transaction which is of same block, even have input UTXO which is unspent, but it is double spent. when block is broadcasted those 2 transactions are broadcasted simultaneously,

Questions:

  • how other nodes are going to validate those 2 simultaneously broadcasted transaction technically by bitcoin code(Where those 2 transaction in same block)?
  • How is this double spending is solved technically by bitcoin code, when 2 transactions are included in same block (When block is broadcasted then those 2 transactions are broadcasted simultaneously )?

Having sufficient proof of work is a necessary criteria for a block to be valid, but it is not a sufficient criteria for a block to be valid. The proof of work is used to limit the cadence of updates to the shared global state and as a mechanism to select the author of the next block in a distributed manner. Additionally, the block has to pass all the ~40ish rules for blocks to be valid in the first place.

A block that contains two conflicting transactions is invalid. A full node validating it will mark the UTXO as spent when it validates the first transaction, and when the second transaction refers to the same UTXO as its input, the UTXO is no longer available and the block gets rejected.

If a block contains two conflicting transactions (a double spend) then the block is invalid, despite the proof of work being correct. Thus, the miner has wasted their work, and the block will be rejected by all validating nodes.

2

The complete block is transmitted as a whole to the fully validating node. The validator starts checking the transactions one by one.

https://github.com/bitcoin/bitcoin/blob/master/src/consensus/tx_check.cpp

The relevant code that rejects block with double spends is:

 // Check for duplicate inputs (see CVE-2018-17144) // While Consensus::CheckTxInputs does check if all inputs of a tx are available, and UpdateCoins marks all inputs // of a tx as spent, it does not check if the tx has duplicate inputs. // Failure to run this check will result in either a crash or an inflation bug, depending on the implementation of // the underlying coins database. std::set<COutPoint> vInOutPoints; for (const auto& txin : tx.vin) { if (!vInOutPoints.insert(txin.prevout).second) return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-inputs-duplicate"); }

Get BONUS $200 for FREE!

You can get bonuses upto $100 FREE BONUS when you:
💰 Install these recommended apps:
💲 SocialGood - 100% Crypto Back on Everyday Shopping
💲 xPortal - The DeFi For The Next Billion
💲 CryptoTab Browser - Lightweight, fast, and ready to mine!
💰 Register on these recommended exchanges:
🟡 Binance🟡 Bitfinex🟡 Bitmart🟡 Bittrex🟡 Bitget
🟡 CoinEx🟡 Crypto.com🟡 Gate.io🟡 Huobi🟡 Kucoin.



Comments