Background
In the previous article, we introduced the Libra blockchain. In this article, we will introduce LibraSwap, an experimental project to bridge Libra with Ethereum. It aims to implement a minimum viable prototype to fulfill token swap between Libra and Ethereum. There are two reasons why we choose this fun project. On the one hand, we want to learn more on how Libra works. On the other hand, we are familiar with Ethereum blockchain. However, due to the limitation of Libra testnet, we can not deploy and interact with Libra smart contract. We implement a unilateral Libra swap instead of the standard atomic swap.
Problem statement
This project is based on Loi Luu’s article, “Bringing Bitcoin to Ethereum”, implementing token swap between Libra and Ethereum. The main idea is that someone has LIB tokens and would like to exchange for other’s ETH.
Assume LIB:ETH = 1:1
- A has 1 LIB
- B has 1 ETH
- A and B want to make an atomic swap
Result:
- A will get 1 ETH
- B will get 1 LIB
Technically, we could implement atomic swap between two blockchains if they both support smart contracts. However, due to the limitation on Libra, we simplify the implementation.
Overview of LibraSwap
Standard atomic swap:


Due to the limitation on Libra, we simplified the process to:


Process flow


DEMO
The following demo is open source — “Libra swap”.
Step 1
Deploy smart contracts.


Step 2
B generates a secret and its hash.


Step 3
B initiates a swap contract, specifies A as the receiver , and deposits 1 ETH into the contract.


Step 4
A transfers 1 LIB to B.


Step 5
B verifies the transaction. If it is successful, B will sends the secret to A privately.


Step 6
A uses the secret to redeem the funds locked in the contract.


Conclusion
In this article, we implement the minimum viable prototype of LibraSwap by simplifying the locked process on Libra and the swap contract on Ethereum. However, in this implementation, there is a risk for A as A needs to trust that B will provide the secret after A transferred LIB token. Therefore, in this scenario, B is more like a trusted custodian.
Next article, we will introduce LibraSwap on trustless custodian and get rids of trusted third party. We need to leverage smart contract to verify Libra’s transaction on Ethereum.
Thanks to AMIS徐粲邦. He provides this article.