Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: yasmikash on March 29, 2019, 02:13:19 PM



Title: [Question] Question about how does the bitcoin network prevent double-spending.
Post by: yasmikash on March 29, 2019, 02:13:19 PM
It is my first time started learning how do bitcoin transactions happen under the hood, and all the technology behind it.
So, I come across this double-spending thing and how does the network prevent it.
Basically, if I send the same 1BTC I have in my wallet to separate bitcoin addresses, one after another, only one transaction get confirmed (the first transaction most likely) , and the other one will be recognized as invalid. So, my question is how the network (or miners) confirm that a particular transaction is invalid(1BTC has already been spent)/valid(1BTC has not been spent), and according to what factors?

I know the technology behind the blockchain, and more specifically how transactions get added inside blocks and the proof-of-work miners do to include blocks into the blockchain.

WHAT I DON'T UNDERSTAND IS HOW THE NETWORK DETERMINE A CERTAIN TRANSACTION IS VALID OR NOT?

It'd be really great if one can explain it to me more clearly, so that I could understand the whole process, without having any doubts about anything.  


Title: Re: [Question] Question about how does the bitcoin network prevent double-spending.
Post by: Carlton Banks on March 29, 2019, 04:48:13 PM
so, your question is:

"I understand the whole of Bitcoin, but I don't understand it. will someone explain the whole of Bitcoin?"


Title: Re: [Question] Question about how does the bitcoin network prevent double-spending.
Post by: achow101 on March 29, 2019, 05:39:25 PM
Nodes validate transactions. Transactions must adhere to certain rules, and a node will check that it does. Since every node uses the same rules to validate, every node is in agreement as to whether a transaction is valid or invalid.

In particular, one of those nodes is that a transaction only spends Unspent Transaction Outputs. Nodes maintain a database of UTXOs and checks if a transaction's input spends something in that database. If it does, there is no double spend. If it doesn't, there may be a double spend, but it is invalid regardless. Either the output has already been spent (so it is a double spend and is thus invalid), or it spends an output that does not exist. Both are invalid things to do.


Title: Re: [Question] Question about how does the bitcoin network prevent double-spending.
Post by: hv_ on March 31, 2019, 03:15:59 PM
Miners are adding blocks to the chain and need to ensure the consensus rules, one of these are exactly to ensure no double spendings. In principal these double spending can happen if such txs come in via different mempools, where miners stack new txs to build blocks from. But if a miner did mine a block causing a double spend, others will reject it and the miner has mined for a loss / he will not get any mining reward.

So miners will not mine double spends since it is not

1 economical honored
2 would make bitcoin useless anyway.
3 sadly with rbf double spends / stealing txs can be done and cannot detected as such