2

Many sources describe the double spending problem by saying something like "people cannot be able to spend the same bitcoin twice." [1][2][3] So are bitcoins, or the smallest allowable bitcoin fractions, distinctly labeled entities? My understanding was that they are not, and that the blockchain only records information on the amount of bitcoins each user has.

Also, if I am correct, what would double spending actually look like in the bitcoin system? If I send a transaction to one miner saying "I pay user X 1 bitcoin" and another transaction to a different miner saying "I pay user Y 1 bitcoin", then it seems like I haven't double-spent, but rather just paid two bitcoins in total, one to each user. Right?

7

So are bitcoins, or the smallest allowable bitcoin fractions, distinctly labeled entities?

They are unspent amounts (outputs of prior transactions) associated with addresses. Unspent transaction outputs are abbreviated UTXO.

Bitcoins or fractions (millibits, Satoshis etc) don't exist as entities in computers running Bitcoin software. The computers just keep track of the movement of amounts, they keep track of UTXOs, transactions, addresses and so on. Those are the identified entities.

what would double spending actually look like in the bitcoin system?

Two transactions with the same input UTXOs.

The first one to be mined and "confirmed" will be valid, the second one will be regarded as invalid. There can be a period in which the outcome is uncertain until a consensus emerges.

See also Replace By Fee (RBF)

  • So, does the amount in a single transaction (with one UTXO) have to all be spent at once? Suppose I received 1 BTC in one transaction (with 1 UTXO), and then I create two transactions, each referencing the same UTXO and each paying 0.5 BTC to different users. Have I double-spent? – WillG Sep 3 '18 at 3:06
  • @willg that is not a double-spend. You could do it as a single transaction or as two with the second using change returned from the first. The change UTXO is new. – RedGrittyBrick Sep 3 '18 at 7:32
4

So are bitcoins, or the smallest allowable bitcoin fractions, distinctly labeled entities?

No, but almost. Bitcoins are literally just a value which is assigned to a script (see Scripts below). There are many consensus rules that determine whether that value is valid bitcoin. The most important of which is that It must be from a valid unspent transaction output. This is labeled, by a txid and vout index.

Bitcoin uses a TXO (Transaction Ouput) model instead of a account model. This means, a transaction always has at least one input and one output (but can have multiple).

Example Transaction:

txid: f5d8ee39a430901c91a5917b9f2dc19d6d1a0e9cea205b009ca73dd04470b9a6

Inputs             vin    Outputs                   vout
1 BTC to Address 1 0   -> 0.999 Address 2           0
                       -> 0.0009 Address 1 (Change) 1

Note: The leftover 0.0001 btc can be claimed by the miner as a tx fee.

Let's say that vin 0 references a txid and vout which has already been referenced in a previous transaction. If that is the case, then that txo has been spent (the entire blockchain is checked for unspent outputs), and that transaction would be considered a double spend, and rejected by the Bitcoin network.

Scripts

An amount of bitcoin is locked by a specific script. The script can represent a public key (P2PKH - Pay to Public Key Hash) or multiple (multisig P2SH - Pay to Script Hash), for example. But, the spender has to be able to satisfy the script in order to spend the bitcoin. Usually the script requires signing the transaction with a private key.

3

Bitcoins are labeled by the Unspent Outputs ("UTXO"). When a transaction pays to an address, the bitcoins are kept in a container named UTXO. (In other words, addresses don't keep bitcoins, unspent outputs do.) To make a transaction from that address, the transaction must reference the UTXO:

  • Transaction id of the transaction who created it.
  • Which output of the transaction it is. ("vout")

When someone spends it (and gets one confirmation), the database removes that UTXO. If you try to respend it, it won't find that UTXO, thus an error will be thrown.

Different UTXO are used for different payments, unless the UTXO is large enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.