Introduction to cross-chain transactions
One of the biggest problems in the blockchain sphere nowadays is the interoperability. We have plenty of different blockchains, but they are standalone, isolated systems that cannot communicate to each other in a decentralized, secure and transparent way. E.g. there is no way to transfer data or value between Ethereum and Bitcoin blockchain in purely decentralized way…
A lot of teams are searching for solutions to this problem. There are some second layer solutions, oracles, even new blockchains that are trying to handle this interoperability mess. I could point some of the best projects working in right direction:
There are also another class of solutions working on the first layer. They are decentralized, secure and transparent. Although, currently these solutions are not very fast and user friendly, I truly believe this would be improved. The solution that I talk about is the so-called Cross-Chain Atomic Swap. This method is entirely based on mathematics and cryptography.
What is the problem with cross-chain exchanges?
[1]The problem of an atomic swap is one where (at least) two parties, Alice and Bob, own coins, and want to exchange them without having to trust a third party (centralized exchange). A non-atomic trivial solution would have Alice send her coins to Bob, and then have Bob send other coins to Alice . Unfortunately, here Bob has the option of going back on his end of the bargain and simply not following through with the protocol, ending up with both sets of coins. Atomic swaps could be used for trading between bitcoin and another cryptocurrency. In our case we would like to use atomic swaps to implement cross-chain exchanges between Aeternity and Ethereum. It will be very efficient, due to the fact that we will need only a few transactions on both of the networks. Moreover, the whole swap could be executed in a few minutes. The most important requirement in order to execute cross-chain transactions between two blockchains is that both of the blockchains support exactly the same hashing function — e.g. [2]SHA-3.
What is the algorithm[1]?
- A picks a random number x
- A creates TX1: “Pay w BTC to <B’s public key> if (x for H(x) known and signed by B) or (signed by A & B)”
- A creates TX2: “Pay w BTC from TX1 to <A’s public key>, locked 48 hours in the future, signed by A”
- A sends TX2 to B
- B signs TX2 and returns to A
- 1) A submits TX1 to the network
- B creates TX3: “Pay v alt-coins to <A-public-key> if (x for H(x) known and signed by A) or (signed by A & B)”
- B creates TX4: “Pay v alt-coins from TX3 to <B’s public key>, locked 24 hours in the future, signed by B”
- B sends TX4 to A
- A signs TX4 and sends back to B
- 2) B submits TX3 to the network
- 3) A spends TX3, revealing x
- 4) B spends TX1 using x
- This is atomic (with timeout). If the process is halted, it can be reversed no matter when it is stopped.
- Before 1: Nothing public has been broadcast, so nothing happens
- Between 1 & 2: A can use refund transaction after 72 hours to get his money back
- Between 2 & 3: B can get refund after 24 hours. A has 24 more hours to get his refund
- After 3: Transaction is completed by 2
- A must spend his new coin within 24 hours or B can claim the refund and keep his coins
- B must spend his new coin within 72 hours or A can claim the refund and keep his coins
- For safety, both should complete the process with lots of time until the deadlines
We will use similar strategy to implement atomic swaps between Ethereum and Aeternity. This approach could be used to swap tokens between any given pair of blockchain that have the same hashing function e.g. SHA 256.
Are there any working Solutions?
WeiDex team have implemented the first working solution. WeiDex’s solution is innovative and uses Hash Time Locked Contract[3]. HTLC is a class of payments that use hashlocks and timelocks to ensure one the following:
- the receiver acknowledges receiving the payment prior to a deadline by generating cryptographic proof
- the receiver refuses to claim the payment, returning it to the payer.
The HTLCs on both Solidity and Sophia are already deployed and working on the mainnet. This solution is modification of the top mentioned algorithm. It uses two HTLCs. You could check the repos in github:
Next Steps
WeiDex team will need the following components to build user-friendly MVP for atomic swaps:
- Improve Smart Contract on Aeternity
- Improve Smart Contract on Ethereum
- UI/UX (frontend)
- Cron job (to broadcast transactions — this is optional)
On Figure 1 you could see simple version of the UI:
References:
1 https://en.bitcoin.it/wiki/Atomic_swap
2 https://github.com/chatch/hashed-timelock-contract-ethereum
3 https://en.wikipedia.org/wiki/SHA-3
Source: Crypto New Media