Bitcoin–Monero Cross-chain Atomic Swap
Go to file
bors[bot] 639b3169d8
Merge #179
179: Watch only tmp monero wallet r=da-kami a=da-kami

When initializing Monero wallet, try to open temporary wallet, if opening errors then try to create it. If creating errors then fail with message asking the user to configure the wallet RPC.
If opening / creation succeeds get the block_height to verify that connection to wallet works, then proceed to swap. 

Note: RPC error handling is hacky, but I don't see the value of investing time into that at this point. The problem is, that we don't deal with the json rpc errors properly for calls were we don't serialize the result into an object (because the response is empty). Eventually we should switch to using https://github.com/thomaseizinger/rust-jsonrpc-client but that does not support parameters `by-name` yet, see: https://github.com/thomaseizinger/rust-jsonrpc-client/issues/20

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-02-10 04:09:11 +00:00
.github/workflows Add --force flag for cancel and refund 2021-02-08 21:19:38 +11:00
docs Implement new behaviour for execution setup 2021-02-05 16:42:46 +11:00
monero-harness Remove newline in use statements 2021-02-10 15:07:37 +11:00
swap Rename temporary wallet to blockchain monitoring wallet 2021-02-10 15:06:26 +11:00
.gitignore Push cargo lock to git as we are building a binary 2020-12-01 09:31:41 +11:00
.mergify.yml Add Mergify rule to delete merged branch and bors+ 2020-12-21 16:09:21 +11:00
bors.toml Updates bors to include all docker tests 2021-01-29 15:41:49 +11:00
BTC_XMR_atomic_swap_protocol.svg Fix embedded image 2020-10-09 09:45:48 +11:00
Cargo.lock Cancel command 2021-02-08 21:11:39 +11:00
Cargo.toml Merge xmr_btc crate 2021-01-08 12:34:33 +11:00
LICENSE Change license to GPLv3 2020-10-12 17:13:25 +11:00
README.md Fix typo 2020-10-09 09:49:39 +11:00
rust-toolchain Upgrade toolchain 2021-02-04 15:18:33 +11:00
rustfmt.toml Upgrade toolchain 2021-02-04 15:18:33 +11:00

XMR to BTC Atomic Swap

This repository is a proof of concept for atomically swapping XMR for BTC.

We define:

  • Alice to be the actor that initially holds XMR.
  • Bob to be the actor that initially holds BTC.

In the best-case scenario the protocol looks like this:

  1. Alice and Bob exchange a set of addresses, keys, zero-knowledge proofs and signatures.
  2. Bob publishes Tx_lock, locking up his bitcoin in a 2-of-2 multisig output owned by Alice and Bob. Given the information exchanged in step 1, Bob can refund his bitcoin if he waits until time t_1 by using Tx_cancel and Tx_refund. If Bob doesn't refund after time t_1, Alice can punish Bob for being inactive by first publishing Tx_cancel and, after t_2, spending the output using Tx_punish.
  3. Alice sees that Bob has locked up the bitcoin, so she publishes Tx_lock on the Monero blockchain, locking up her monero in an output which can only be spent with a secret key owned by Alice (s_a) and a secret key owned by Bob (s_b). This means that neither of them can actually spend this output unless they learn the secret key of the other party.
  4. Bob sees that Alice has locked up the monero, so he now sends Alice a missing key bit of information which will allow Alice to redeem the bitcoin using Tx_redeem.
  5. Alice uses this information to spend the bitcoin to an address owned by her. When doing so she leaks her Monero secret key s_a to Bob through the magic of adaptor signatures.
  6. Bob sees Alice's Tx_redeem on Bitcoin, extracts Alice's secret key from it and combines it with his own to spend the monero to an address of his own.

BTC/XMR atomic swap protocol

The repository is structured as a library and a single test function that executes the swap. The library has the following modules:

  • alice: Defines the state machine that describes the swap for Alice. This includes the messages sent to/from Alice.
  • bob: Defines the state machine that describes the swap for Bob. This includes the messages sent to/from Bob.
  • bitcoin: Keys, signing functions, transactions etc. for Bitcoin. Also includes a test wallet (see below).
  • monero: Keys, signing functions, transactions etc. for Monero. Also includes a test wallet (see below).

Currently we have a single test function that proves the following:

  • Interaction with both block chains and their respective wallets works.
  • The messages required are correct and can manually drive the state transitions to execute a swap.
  • It is possible to interact with, and watch, the monero blockchain using monero-wallet-rpc.
  • It is possible to watch a bitcoind instance using bitcoin-harness (we already knew this :)

Currently we do not do:

  • Actual network communication.
  • Verification that the UI is acceptable. Since we do everything in a single test function there is no user interaction, this is unrealistic for a real product.

Testing

We wrote a few additional libraries to facilitate testing:

Wallets

  • bitcoin module contains a test wallet by way of bitcoind.
  • monero: module contains a test wallet by way of monero-wallet-rpc.

Blockchain harnesses

We have written two harnesses for interacting with bitcoin and monero.

These harnesses wrap interaction with bitcoind and monerod/monero-wallet-rpc.

We use testcontainers-rs to spin up bitcoind, monerod, and monero-wallet-rpc in docker containers during unit/integration testing.