Bitcoin Forum
November 05, 2024, 06:34:34 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: I feel a bit confused on how Bitcoin solves the double-spending problem  (Read 1419 times)
jackzhou (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
September 17, 2014, 06:10:27 AM
 #1

Say Alice has 5BTC in one of her bitcoin address.

She creates two transactions to Bob and Dan at the same time, each of 5BTC from the same address, i.e. she tries to double-spend.

Because these two transactions are created at the same time, they are very likely to be collected in the same block that some miners are working on. Suppose one miner collects these two transactions. He checks the validity of the transactions. Assume he checks the transaction from Alice to Bob first. He finds that it is a valid transaction. But at this time, the block hasn't been put into the block chain. Therefore Alice's address's information hasn't been updated (there should still be 5BTC in the address). Then the miner goes on to check the transaction from Alice to Dan. He should find that it is also valid. Assume this miner is the first one to find the proof of work for this block. He will then put the block into the block chain. And in that way Alice has spent the same 5BTC twice.

I must got something wrong somewhere.

I think there is a couple of places I don't quite understand:

1. When the miner checks the transaction from Alice to Dan, will the miner actually reject this transaction (because the miner has checked the transaction from Alice to Bob before and recorded the bitcoin deduction in Alice's address) ?

2. If, somehow, a bad block is included in the block chain, will other miners be able to pull it out later ? By saying a bad block, I meant, for example, the block contains some invalid transactions.

Thanks for help.
CIYAM
Legendary
*
Offline Offline

Activity: 1890
Merit: 1086


Ian Knowles - CIYAM Lead Developer


View Profile WWW
September 17, 2014, 06:24:48 AM
 #2

To understand things a little better you need to understand that transactions involve UTXOs (unspent transaction outputs) from previous transactions (including "coinbase" transactions when a miner gets rewarded) and that these cannot be "split" (thus the need for "change addresses").

So when you receive a tx you need to check that *all* the UTXOs it is using "have not been used before". Now as this is done one tx at a time the 2nd tx the node sees will be rejected (note that it can *never* receive "two at once" as they are effectively serialised).

Of course this is just the low-level mechanism to prevent an *actual* double spend - the "double-spending problem" is usually referring to *double spend attempts* (which can successfully get you goods or services if vendors don't wait for confirmations). The solution to this is the "blockchain concept" itself (and the "proof of work" algorithm at its core in Bitcoin).

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
Foxpup
Legendary
*
Offline Offline

Activity: 4531
Merit: 3183


Vile Vixen and Miss Bitcointalk 2021-2023


View Profile
September 17, 2014, 06:33:59 AM
 #3

1. When the miner checks the transaction from Alice to Dan, will the miner actually reject this transaction (because the miner has checked the transaction from Alice to Bob before and recorded the bitcoin deduction in Alice's address) ?
Yes. When checking the validity of a particular transaction, all transactions in the block the miner is working on are taken into account. Conflicting transactions are invalid and rejected. Conversely, a chain of dependent transactions (Alice pays Bob, Bob pays Dan) within the same block is perfectly valid.

2. If, somehow, a bad block is included in the block chain, will other miners be able to pull it out later ? By saying a bad block, I meant, for example, the block contains some invalid transactions.
It will never be included in the blockchain in the first place. All other nodes will reject it immediately.

Will pretend to do unspeakable things (while actually eating a taco) for bitcoins: 1K6d1EviQKX3SVKjPYmJGyWBb1avbmCFM4
I am not on the scammers' paradise known as Telegram! Do not believe anyone claiming to be me off-forum without a signed message from the above address! Accept no excuses and make no exceptions!
DannyHamilton
Legendary
*
Offline Offline

Activity: 3472
Merit: 4801



View Profile
September 17, 2014, 09:30:33 AM
 #4

- snip -
I think there is a couple of places I don't quite understand:
- snip -

Have you read this yet?

https://bitcoin.org/bitcoin.pdf

If not, then you are making assumptions about how you think bitcoin works, and your assumptions are almost certain to be wrong.  This will just lead you to more confusion.
jackzhou (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
September 17, 2014, 05:43:41 PM
 #5

1. When the miner checks the transaction from Alice to Dan, will the miner actually reject this transaction (because the miner has checked the transaction from Alice to Bob before and recorded the bitcoin deduction in Alice's address) ?
Yes. When checking the validity of a particular transaction, all transactions in the block the miner is working on are taken into account. Conflicting transactions are invalid and rejected. Conversely, a chain of dependent transactions (Alice pays Bob, Bob pays Dan) within the same block is perfectly valid.

2. If, somehow, a bad block is included in the block chain, will other miners be able to pull it out later ? By saying a bad block, I meant, for example, the block contains some invalid transactions.
It will never be included in the blockchain in the first place. All other nodes will reject it immediately.

That answered my questions. Thanks.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!