Skip to content

feat(protocol): Early Bitcoin refund #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

binarybaron
Copy link

@binarybaron binarybaron commented May 21, 2025

Concept

If Alice has decided against locking her Monero, she can refund his Bitcoin for him immediately without having to wait for the timelock to expire. This is useful if:

  • Alice does not have the required funds in her Monero wallet
  • Alice does not manage to lock her funds within a set timeframe. This could happen for a bunch of reasons including (e.g the daemon being out of sync)
  • The Bitcoin mempool is overloaded and the fee set by Bob for the TxLock does not allow it to get into a block within one hour

On a technical level this works the following way:

  1. When Alice and Bob setup the swap, they construct a Bitcoin transaction (tx_early_refund) which spends the output created by tx_lock to a single output owned by the Bitcoin refund address of Bob. Bob signs his half of the PSBT and transmits his signature to Alice. Alice stores the signature.
  2. When Alice wants to refund the Bitcoin for Bob she signs the tx_early_refund with her private key

This is safe because:

  1. Alice cannot modify the refund address because Bobs signature is only valid for the correct output.
  2. Alice only ever shares / publishes the tx_early_refund if she has not locked her Monero. If she were to publish tx_early_refund and lock her Monero, she won't be able to recover the Monero (unless Bob gives her the keys)

Notable changes:

  • A new EarlyRefundable and EarlyRefunded states are added for Alice
  • A new EarlyRefunded state is added for Bob in which he transitions when he discover the tx_early_refund in the mempool

Alice can choose to let Bob refund his Bitcoin early (before TxCancel timelock expires)
feat(alice): if we cannot lock Monero within 2 minutes, early refund bitcoin
@binarybaron binarybaron marked this pull request as draft May 21, 2025 16:12
@binarybaron binarybaron added the P2 Priority 2 label May 21, 2025
@binarybaron
Copy link
Author

binarybaron commented May 27, 2025

TODO

  • Implement integration tests for this, simulating
    • Alice has an empty Monero wallet after the swap has been started
    • Alice's Monero wallet repeatedly fails to lock the Monero for an extended duration
  • Test manually on testnet
  • Add changelog for breaking change
  • Warn GUI users against swapping with older makers because swap initialization will fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Priority 2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant