Bitcoin Forum
December 16, 2017, 10:23:01 AM
 News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 Home Help Search Donate Login Register
 Pages: [1]
 Author Topic: I feel a bit confused on how Bitcoin solves the double-spending problem  (Read 1326 times)
jackzhou
Newbie

Offline

Activity: 2

 September 17, 2014, 06:10:27 AM

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.
1513419781
Hero Member

Offline

Posts: 1513419781

Ignore
 1513419781

1513419781
 Report to moderator
1513419781
Hero Member

Offline

Posts: 1513419781

Ignore
 1513419781

1513419781
 Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
CIYAM
Legendary

Offline

Activity: 1862

Ian Knowles - CIYAM Lead Developer

 September 17, 2014, 06:24:48 AM

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

Activity: 2044

 September 17, 2014, 06:33:59 AM

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 unverifiable things (while actually eating an enchilada-style burrito) for bitcoins: 1K6d1EviQKX3SVKjPYmJGyWBb1avbmCFM4
DannyHamilton
Legendary

Offline

Activity: 2002

 September 17, 2014, 09:30:33 AM

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

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
Newbie

Offline

Activity: 2

 September 17, 2014, 05:43:41 PM

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.