h4sh3d/xmr-btc-atomic-swap

Combine BTX-lock and BTX-refund conditions

Norfolks opened this issue · 1 comments

Great work.
Why is not possible to make one transaction script for three possible withdrawals?

  1. Swap as expected
  2. Bob refund by timelock
  3. Alice takes bitcoins after time lock

Smth like?

OP_IF  
   OP_SHA256 <h_a> OP_VERIFY
   OP_SHA256 <h_s> OP_VERIFY
   <B_a> OP_CHECKSIG
OP_ELSE
   <t_0> OP_CHECK
   OP_SHA256 <h_b> OP_VERIFY
   <B_b> OP_CHECKSIG
OP_ElSE
   <t_1> OP_CHECK
   <B_a> OP_CHECKSIG
OP_ENDIF

Because you introduce an race condition.

In that case Alice can wait on Bob to start a refund with path 2, when she sees <h_b> value she can try to complete the swap on the BTC side (path 1) with higher fees AND get the Monero back with <h_a> and <h_b>.

If she managed to do it, she gets BTC and XMR. (At that point Bob can also race, all values are revealed.)

To be safe Bob needs to:

  1. Broadcast the Refund transaction,
  2. Wait enough confirmations invalidating path 1, and
  3. Complete the refund, reveling <h_b>

No race is possible in that scenario.