In the previous article, we explain the concept of the LibraSwap. Next, we will introduce LibraBridge, which can be used to connect Libra with Ethereum by Libra SPV method. The idea to leverage SPV validation to implement cross-chain transfer is not new. It’s already done by several projects listed below. SPV proof is a way for light client to verify if interested transaction happened on the blockchain. With the help of smart contract, Libra SPV proof can be implemented on Ethereum. Namely, we can verify a Libra transaction through smart contract, along with some external information.
In this article, we will introduce how to build a trustless custodian between Libra and Ethereum. And the source code can be found here.
Problem statement
If we want to realize atomic swap between Libra and Ethereum, we need both blockchains to support Hash Timelock Contracts (HTLC). Though Libra claims it supports smart contract, but it’s still under development and the user currently cannot deploy contract on chain. Hence, in our LibraSwap article, we assume that coin swap happens correctly if there is a trusted third party but this design is far away from decentralization. Nevertheless, we still can build a trustless custodian by protocol design and SPV proof.
For example, I have a Libra token but want to exchange Libra for Ether. An exchange, called MAX, provides a Libra-Ether pair exchange so I can trade on the platform. So the easiest way is to deposit Libra on MAX and get Ether back under the assumption if I trust the service provider, MAX.
Noted that MAX is a fiat-to-crypto exchange in Taiwan. The transactions shown in the following figures mean on-chain payment instead of database update.
So the question becomes if we want to do token exchange, can we achieve it without trusting MAX?
Method
Firstly, we can use Libra SPV proof to verify a Libra transaction actually happened. By implementing Libra SPV proof in smart contract, we can communicate to contract for verifying Libra transaction directly. Next, we require two methods deposit and challenge to make MAX trustworthy. The idea is MAX needs to put the deposit in the contract, and the contract acts as an escrow to complete the trade. Once MAX misbehaves without transferring Ether to the user, the user can use challenge function to prove the Libra transaction happen.
Case 1
Let’s take a look at a normal case. MAX, as an escrow, will put some digital assets into the smart contract as security deposit. The deposit is locked within a period of time to ensure that MAX cannot move the fund itself. If there is a user wants to trade Libra for Ether, the user can query whether the smart contract has enough security deposit. If the response is true, the user can transfer its Libra token to MAX’s Libra address. Once the transaction is done and MAX receives the notification, MAX will transfer Ether to user’s ETH address to complete the trade.


Case 2
Similar to the normal case, MAX has to put security deposit in the contract to earn user’s trust so the user is willing to trade on the platform. However, if the user does not receive Ether after sending the Libra transaction at Step 4, we consider it as breach of contract. Then, the user can launch the challenge process. Since the contract includes Libra SPV verification, the user can submit the transaction proof to the smart contract. Though the Libra transaction is happened on Libra instead of Ethereum, off-chain payment can be verified if required information is provided. More detail is descried in this article. On the other side, the smart contract, which acts as a trusted third party, will verify the proof and transfer Ether or equivalent amount of assets to the user. In addition, the contract will slash a portion of deposit as the penalty to compensate the user to finish the trade.


Related
This is a fun project to connect Libra with Ethereum. If Move, Libra’s smart contract programming language, is getting more mature and open to developers to interact with on chain, we can imagine there will be more applications on it.
Following we will point out some items that can be improved in our projects.
- Support SHA3–256 in EVM
Currently, Libra uses SHA3–256 as its hash function. Unfortunately, SHA3–256 is not natively supported by EVM, only SHA-256, KECCAK-256 and RIPEMD-160 as well as BLAKE2b in the coming Istanbul upgrade are supported. We replace SHA3–256 with KECCAK-256, as a workaround, in Libra-core, so Libra SPV can work correctly in EVM. If EVM does not support it in the future, then implementing a SHA3–256 function in smart contract is required.
- Need a trusted source
In order to use Libra SPV, the light client needs to fetch merkle root and merkle branch for verification. If the information is wrong, SPV verification could be wrong too. In Libra, since validator nodes are permissioned, we can tentatively believe the information is correct.
Another way is to have a trusted smart contract to record versioned state root, but the cost is expensive for the following reasons. First, each transaction has a version. Second, Libra’s performance is faster than Ethereum. Third, on-chain transaction is costly even we only record checkpoints.
- Require a secure light client
For key management, Libra supports EdDSA algorithm and uses ed25519. One possible way to secure private key is to use iPhone’s secure enclave. Another way is adopting Threshold Signature Scheme to protect private key. ZenGo, a great wallet team, has released a Proof-of-Concept of the first Threshold Signatures wallet for Facebook’s Libra testnet. By the way, TSS is also developed at AMIS to protect private keys. In addition, we propose a method called HTSS to support TSS with partial accountability.
Summary
Libra SPV enables us to realize a trustless custodian service on Ethereum without the requirement for Libra to support smart contract. Besides, a trustless custodian service has the advantage on liquidity compared to peer-to-peer trading. In contrast, there are some challenges need to be conquered. Though this work is a fun project, we can see the potential if Libra in the future becomes global currency. Together with DeFi application on Ethereum and Libra’s deep liquidity, the DeFi economy will grow into one of the largest global markets accessible by everyone.
getamis
Using breakthrough blockchain technology, Amis has created…
Thanks to Yu-Te Lin.
Thanks to AMISChang-Wu Chen. He provides this article.