5

Is a Bitcoin block containing both a transaction that funds an output, and another transaction that immediately spends the same output, allowed by the protocol?

Does such behavior occur "in the wild", e.g. do any of the common clients allow spending unconfirmed Bitcoins? Would miners include such transactions?

8

allowed by the protocol?

Yes. It is possible to spend an output immediately. And two (three-four-etc) chaining transactions will be included in the same block. There are a lot of examples in blockchain. Note, that the their order in block is fixed.

do any of the common clients allow spending unconfirmed Bitcoins

Bitcoin-core client allows to send "raw transaction" to spend unconfirmed bitcoins. Also the "change" output can be spent without confirmations. Holding incoming bitcoins for several confirmations is an interface option only, not a protocol rule.

1

Sure. Miners simply receive both transactions and try to include them in a block.

Regarding confirmations, this is only a concern when wanting to claim a transaction you've received from someone else. If they're your own coins, there's no risk of a double spend.

  • There is risk of spending unconfirmed change because transactions are still malleable. – amaclin Sep 12 '14 at 15:50
  • Can you elaborate more on this? Not sure I understand. Change is only calculated once the block's hash is found and therefore both transactions are included within it. – Luca Matteis Sep 12 '14 at 15:56
  • 1
    OK, I will try to explain. I pay for a cup of coffee, sending tx1. One output 0.01 BTC for StarBucks and 0.01 change to myself. Right after that I spend my change for another cup of coffee for my girlfriend. Tx1 was malled by somebody and included in block with different hash. Tx2 becomes orphan and never be confirmed. Now StarBacks think that I (or my girlfriend?) am double-spender. Isn't is a risk for my reputation? – amaclin Sep 12 '14 at 17:55
  • @amaclin your statement that transactions content are malleable requires a reference. It can be malled to change the transaction hash, but the miners won't think it's a different transaction because they check inputs/outputs. – Luca Matteis Sep 12 '14 at 18:04
  • tx1 will still valid after [S := G-S] attack to ecdsa signature, but tx2 will not be confirmed, because its inputs refer to original hash of tx1. OK, it is not risk to lose your funds. It is a risk not to pay for something you want to pay. So, it does not matter - are you spending your own change, or funds incoming from anyone – amaclin Sep 12 '14 at 18:20

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.