In the fair coin toss thread
I pointed out that protocols which depend on precomputed refunds to prevent holdup risk are currently unsafe in Bitcoin because of transaction malleability. Turns out they can be partially rescued even before we fix malleability— this is good news because completely fixing malleability will likely take a long time.
This applies to protocols like this:
(1) Alice wants to put 1 BTC into a 2 of 2 Alice + Bob escrow, but is concerned that Bob might try to extort her by refusing to sign according to their prior agreements.
(2) Alice writes a transaction paying to 2of2 Alice,Bob.
(3) Before announcing this transaction Alice also writes a refund transaction, sending that 1 BTC back to Alice, with a lock time sufficiently far in the future.
(4) Alice asks Bob to sign the refund transaction without ever giving bob the escrow payment. Bob signs it.
(5) Alice then announces the escrow payment. Confident that if all else fails she can get her funds back later using the refund.
The attack is this:
After (5) bob grabs the escrow payment off then network and mutates the signature to produce an equivalent transaction with a different transaction id. E.g. he replaces the signature (r,s) with (r,s+order). He then gets lucky or pays a miner to mine his instead.
Now alice's refund is no good and bob is free to extort her if she ever wants her 1 BTC back.
But P2SH can save the day:
We change the protocol so that the escrow payment is to P2SH(2 of 2 Alice2, Bob2) and Alice2 and Bob2 are new keys that they've never used elsewhere and Bob does not know Alice2.
Alice computes the refund but instead of telling bob the refund transactions, she tells Bob only the hash value she wants signed with Bob2.
When Alice announces the payment into the escrow, Bob cannot identify it— unless its the only P2SH transaction of the expected value— and so he would have to mutate every possible transaction in order to get a mutant mined instead. This would be much harder/more costly (at least if P2SH were widely used).
After the escrow payment is confirmed Alice can show it to Bob along with the refund, and so Bob is also confident that the protocol has been followed faithfully.