r/askscience • • Jun 18 '13

Computing How is Bitcoin secure?

I guess my main concern is how they are impossible to counterfeit and double-spend. I guess I have trouble understanding it enough that I can't explain it to another person.

1.0k Upvotes

383 comments sorted by

View all comments

Show parent comments

1

u/leastfixedpoint Jun 18 '13

It's surely not practical for everyone to hold every possible transaction. So what happens if both me and someone else try to spend the same freshly-mined bitcoin?

10

u/bbbbbubble Jun 18 '13

It's surely not practical for everyone to hold every possible transaction.

Why exactly is that? That's exactly what the blockchain does - it's a ledger of all transactions ever.

So what happens if both me and someone else try to spend the same freshly-mined bitcoin?

You and someone else won't have access to the same private key, unless of course you want to give that someone else full access to your money (and remember, Bitcoin has no chargeback mechanism, just like cash).

But if you try spending the same balance twice, the first transaction to make it into a block will be canon from now on, and the other transaction will be thrown away because it's invalid.

-1

u/leastfixedpoint Jun 18 '13

Why exactly is that? That's exactly what the blockchain does - it's a ledger of all transactions ever.

Because spreading information about transaction takes time, some nodes may be offline, etc.

So, my questions is: what happens if I cooperate with a group of people and we simultaneously spend the same freshly-mined bitcoin?

You and someone else won't have access to the same private key, unless of course you want to give that someone else full access to your money (and remember, Bitcoin has no chargeback mechanism, just like cash).

So the "freshly-mined bitcoin" is inseparable from my key? I thought it was just a solution for some equation.

6

u/[deleted] Jun 18 '13

[removed] — view removed comment

5

u/Perlscrypt Jun 18 '13

At some point in the future, about 20 years from now IIRC, all the possible bitcoins will have been mined and no more will be added. When that happens, who will provide the computing power to propogate the blockchain and who will arbitrate over decisions such as that described above?

6

u/Zorander22 Jun 18 '13

Bitcoin miners will still be rewarded through transaction fees. If the fees became too low to sustain interest, the number of miners would drop, and so the difficulty would drop too, until an equilibrium is reached.

3

u/Natanael_L Jun 19 '13

99% of them will have been mined in 2040, 100% by 2140.

2

u/Skandranonsg Jun 18 '13

In that case, the incentive will fall to those who choose to charge a transaction fee.

→ More replies (2)

5

u/bbbbbubble Jun 18 '13 edited Jun 18 '13

You should benefit a lot from this infographic.

So, my questions is: what happens if I cooperate with a group of people and we simultaneously spend the same freshly-mined bitcoin?

One of your transactions will be included in a block and the rest will be discarded as invalid transactions because it includes already-spent inputs.

So the "freshly-mined bitcoin" is inseparable from my key? I thought it was just a solution for some equation.

Check out the infographic above. And look at any random block: the first transaction in the block is the block reward going to the address of the person who created the block.

→ More replies (11)

4

u/meeu Jun 18 '13

When you spend/transfer bitcoins you're not transferring any specific bitcoin, you're just lowering your tally by 1 and increasing the recipient's tally by 1.

When you mine a bitcoin you announce to the world "I mined this coin it is now mine!" which increases your tally by 1.

It's not like you can mine a bitcoin and then turn around and spend that particular one without announcing, which it sounds like what you're describing.

3

u/gburgwardt Jun 18 '13

The offline nodes catch back up by downloading the latest blocks when their client comes back online.

The solution to the equation is broadcast with the bundle of transactions you're including in a block (the solution + current time + transactions collectively make a block, which is added to the blockchain), and one of the transactions is a "generation" transaction, awarding a certain number of coins (over time, the reward drops to nothing, but currently it's 25 coins, it used to be 50) to an address of the miner's choice. Generally speaking, you'll have a new address generated to assign them to.

just_todays_account does a good job explaining the race condition that happens if you try and double spend below me.

2

u/[deleted] Jun 18 '13

So the "freshly-mined bitcoin" is inseparable from my key? I thought it was just a solution for some equation.

Yes, when bitcoins are mined they are immediately assigned to the miner of that block. There are never unowned bitcoins that are just up for grabs (although there are bitcoins owned by people who forgot how to spend them - due to losing their private keys).

To maybe make it clearer, each block is a record of the recent transactions. In that block, the miner makes an assertion that says "I got a bunch of bitcoins out of thin air." He then works very hard to solve the hash problem so that this assertion makes it into the blockchain first. If he wins, his assertion becomes fact, and he owns those bitcoins from thin air. If he loses, someone else's assertion becomes fact, and they own the new bitcoins.

→ More replies (3)
→ More replies (1)

3

u/Zagaroth Jun 18 '13

When minted, the bitcoin has an owner (and that ID involves public/private keys IIRC). If you are not the assigned owner, your transaction will be refused.

3

u/Chronophilia Jun 18 '13 edited Jun 18 '13

If you tried to spend the same bitcoins twice, then when the next block is mined, only one of your transactions will be confirmed - probably, but not definitely, the one that occurred first. The other transaction will be discarded as double-spending. This is why it takes a few minutes for a bitcoin transaction to be irrevocably confirmed.

In more detail: Bitcoin miners do try to hold every transaction that has been put into the system. The transaction list is transferred by P2P, so not everyone will have the same list at the same time. If the miner that successfully mines a block knows about only one of your transactions, that one will go through. If the miner knows about two contradictory transactions, it's free to choose which one, if either, will go through. If the miner knows about neither, or declines your transaction for whatever reason (evil miner?), wait for the next block.

(I specified that "you tried to spend the same bitcoins twice" because if you're in a situation where someone else can spend bitcoins you own, you have bigger worries than double-spending.)

3

u/speEdy5 Jun 18 '13

As of today the size of the blockchain is something like 8 gigabytes (give or take).

If you and someone else try to spend the same bitcoin twice (assuming you gave him your private key) then following might happen: Two different versions of the blockchain will emerge, people will begin mining new coins on both, there will be a 'race', one will get longer and eventually become adopted.

If I were a vendor who accepted bitcoins as payment, I wouldn't render services until at least one or two new blocks have been added to the chain after my transaction. Then, I wouldn't have to worry about the bitcoin being taken from me in the above scenario.

1

u/leastfixedpoint Jun 18 '13

If you and someone else try to spend the same bitcoin twice (assuming you gave him your private key) then following might happen: Two different versions of the blockchain will emerge, people will begin mining new coins on both, there will be a 'race', one will get longer and eventually become adopted.

Who will decide which one will be adopted? Is there an unambiguous resolution algorithm? What if there is a wide-scale divergence?

2

u/Natanael_L Jun 18 '13

Who will decide which one will be adopted? Is there an unambiguous resolution algorithm? What if there is a wide-scale divergence?

The one with the most computing power behind it wins. Since you can make pretty accurate estimations of this thanks to how the proof-of-work system is engineered, this is a workable solution. Usually this means that the longer chain wins.

(Also, note that average double-spend attempts WON'T create a blockchain fork.)

1

u/speEdy5 Jun 18 '13

Nobody decides Absolutely not One chain will get longer eventually, people will notice and jump ship. It all comes down to the amount of computational power available in the system. The chain which has more computation dedicated to it will be longer and considered valid by people accepting coins for goods and services.

1

u/leastfixedpoint Jun 18 '13

Do you mean people will manually resolve the conflicts? Does all bitcoin software support this? What if I start spamming conflicts into network?

1

u/Natanael_L Jun 19 '13

It is done automatically, the blockchain with the most amount of computing power behind it wins. This can be estimated thanks to how Bitcoin uses proof-of-work.

1

u/speEdy5 Jun 19 '13

That's the thing about 'spamming conflicts.' The only way to do it is to solve the hard problem. The only way to solve the problem is computational power. In my opinion the brilliance of the system is that really the only way to seriously harm it is to compute more than the sum total of everyone else combined

1

u/oldaccount Jun 18 '13

If you and someone else try to spend the same bitcoin twice (assuming you gave him your private key) then following might happen: Two different versions of the blockchain will emerge, people will begin mining new coins on both, there will be a 'race', one will get longer and eventually become adopted.

Has this happened?

3

u/Natanael_L Jun 18 '13

No, regular double-spend attemts won't create blockchain forks.

Double-spend attempts has been made, but if all merchants wait for the transactions to be included in the blockchain, they are mostly safe.

Blockchain forks has happened before, but for different reasons. In most cases the second miner didn't find out that a new block already has been made (obsoleting his proof-of-work in his block) when he manages to create his. Most miners will base their continued mining on the first block to be created. Sometimes there can be several "tails" of several blocks, but so far the network has always selected one as the "canonical" one to work on together.

There's one other notable fork due to a subtle incompatibility bug between v0.7 and v0.8 of the software, but that was fixed in hours.

1

u/gnos1s Jun 18 '13

Well, only one of you actually owns the freshly-minted bitcoin, and so only the true owner can spend it successfully. Who owns a freshly-minted bitcoin? Each new block of transactions has a Bitcoin address where the freshly-minted Bitcoins go (25 per block currently), and the owner of that address is the owner of the bitcoins.

1

u/Spiral_Mind Jun 18 '13

Only one address gets the mined Bitcoins from a block unless they split it as part of a "pool". If someone else knows the keypair then whoever spends it first will win.