7

I am writing a bitcoin app and looking to implement a 'cancel' feature. All over reddit are references that if under 3 confirmation have occurred, technically a payment can be stopped. Maybe only a minute or 2 available, but still. I cannot find any reference in the bitcoin api docs to demonstrate how this would be done. I know that one altcoin uses an intentional 60 min gap to confirm for this very reason.

Anyone know how this is done?

brad
  • 870
  • 2
  • 13
  • 38
  • Might merit its own question, but thought it could be related: It happened to me, on a couple occasions, that I would send someone some dogecoins, close the client after some seconds, and then wonder why the other person kept telling me they hadn't received anything after several hours - until I reopened the client. Thru experimentation I learned I had to keep opened the client and let it go idle until at least one confirmation was received, then it could be closed. Why is it so? Could this be a way to "cancel", in a way, a transaction? – Joe Pineda Jan 24 '14 at 20:11
  • If I tried sending some bitcoins, and then tried sending someone else *the same* bitcoins, miners are supposed to regard this case as a double-spend attempt and reject at least one of the transactions. If there were a way to broadcast such a conflicting transaction, right before first confirmation, that causes *both* trans. to be rejected by all miners that could be the simplest way to implement a "cancel payment" feature that I can think of. – Joe Pineda Jan 24 '14 at 20:15

3 Answers3

14

Is it possible to cancel a Bitcoin transaction ...

... which was not yet broadcasted?

Yes, obviously it is possible. I'd propose you choose this method in your Bitcoin app by showing the user a confirmation screen for some seconds with information about the transaction and some buttons saying cancel and confirm. @nahtnam proposed a 60 minute delay which is too much, considering you may lose internet access or want the transaction to appear in the blockchain as soon as possible.

... which was already broadcasted?

Maybe... To cancel such a transaction, you'd need to create a block yourself which moves the inputs of the original transaction to one of your own addresses. (Effectively invalidating the original transaction.) However, creating a block costs several thousand dollars as of now and finding a block is not guaranteed.

Another possibility would be to broadcast another transaction taking the same inputs as the original one and targeting the outputs at one of your own addresses/wallets. To motivate miners to include this transaction instead of the original one, you increase the transaction fee. However, some clients may not relay such double spent transaction to the miners and some miners may reject the double spent transaction and include the original one (the one they received first), instead. (c.f. Bitpay encountered zero double spent in the first 10000 transactions. and Cancelling an unconfirmed transaction by @theymos (bitcoin.stackexchange))

There are some tricks to hide your initial transaction from miners by creating a so-called "non-standard" transaction. Alternatively, the transaction could include a very low fee to make miners reject it for economic reasons. (c.f. Significant losses by double-spending unconfirmed transactions (bitcoin-dev mailing list) and Double-spending by @petertodd (Reddit)) However, this makes your transaction look suspicious to the receiver if they look closer at it and they will most likely ask you to wait until it has one or more confirmations.

Finally, it is also possible if you set a flag on the original transaction to indicate replaceability. You can then replace the original transaction with another one by including the same (one or more) inputs in the replacement transaction. Also, you must pay a higher fee. However, not all miners honour this flag and some might still include your initial transaction. (c.f. Reference to BIP 125: Opt-in Full Replace-by-Fee Signaling)

... which is included in one or more blocks?

No, very unlikely to impossible. You'd need to control a substantial amount of hashing power to create a fork by rebuilding the blockchain starting at the block before the original transaction happened and ending at the block with height = (current public blockchain height) + 1. Therefore, "the more confirmations you have, the more difficult, expensive, and unreliable an attack like this is." Source: @DannyHamilton (Bitcointalk) The bitcoin paper by Satoshi Nakamoto explains that this is always possible when you control more than 50% of the hashing power, and possible with a probability less than 1, but greater than 0, if you control less than 50% hashing power. See Bitcoin: A Peer-to-Peer Electronic Cash System. Though, if you control a substantial amount of hashing power, you are likely incentivised to not undermine the trust in bitcoin by undoing transactions and indirectly hurting your revenue stream from mining.

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
user2084795
  • 704
  • 1
  • 7
  • 20
3

No. It is impossible to stop a bitcoin transaction. Thats what makes bitcoin so different. There is no way to reverse a transaction except for getting the receiver to send it back to you.

On another note, you could still have a cancel feature. You could set a delay of 60 minutes before you send a transaction and in that gap, someone can cancel but as I mentioned before there is no way to stop a transaction that has already reached the blockchain.

nahtnam
  • 2,659
  • 1
  • 18
  • 31
  • 1
    Actually you are incorrect. YEs there IS a way to save a borked transmission. Though a restart of the wallet and a lot of patience typically fixes the issue. "How to stop/reverse a Bitcoin transaction with 1 or less confirmations" Run bitcoind and with -zapwallettxes This puts stale tx or transmissions back into your wallet. Cheers! – brad Feb 26 '14 at 19:14
  • @brad Thanks. I will look into this a little more. – nahtnam Feb 26 '14 at 23:17
  • Theoretically is not impossible, you just have to create a double spending and provide more proof of work than the original transaction so the network takes your fork of the blockchain. I don't see any good reason with most transactions to do this except maybe with the objective to do damage at your own expense since is likely better to earn bitcoins than try to reverse some transaction unless this transaction contains a huge amount of bitcoins and reversing a payment provides more than mining to create a reversal. – Waldo Alvarez Jan 16 '15 at 23:03
  • @brad, 1+ confirmation transactions **cannot** be reclaimed unless you either control +50% hash power or have it happen on the wrong side of a chain split and double-spend it on the other before reconciliation (very unlikely, happened once with a bug/split in Bitcoin 0.8). Unconfirmed tx can be reclaimed if it has RFB enabled and you submit a higher-fee tx to yourself before it gets included in a block (before first confirmation). Without RFB, you might get lucky and either your tx falls off after some time during high backlog times or you manage to get a non-rfb double-spend accepted anyway. – Thomas Guyot-Sionnest Aug 14 '17 at 05:12
-1

Work out the strategy before making a bitcoin payment. Check that both bitcoin addresses for payer and recipient are correct (use the copy and paste facility). Check that details of the product/service and $ amount are correct. Check that you have the correct private key details. Expect to wait at least 24 hours for confirmation. This allows time for the miners to validate the transaction. Then check your bitcoin account to ensure that the transaction is completed correctly by inserting your private key details into Google search, or check your bitcoin software for the transaction details. It is complicated and expensive to cancel a transaction. So before you make payment, check, check and check again before sending.