A cross-chain swap enables trading tokens across different blockchains without using an intermediary party (e.g. an exchange service) in the process.
Symbol follows the Hashed TimeLock Contract (HTLC) protocol to create a trustless environment for the decentralized exchange of assets. The protocol guarantees that if all participants agree, the swap will take place. On the other hand, if some of them decide not to conclude the process, each participant should receive their locked funds back.
HTLC uses hashlocks and timelocks to reduce the counterparty risk. Every participant in the exchange of tokens needs to present proof (hashlock) to complete it. Failing to do so, the locked assets are released back to each original owner after the timelock expires.
A thorough explanation of the protocol can be found on the Bitcoin Wiki.
Alice and Bob want to exchange 10 alice.tokens for 10 bob.tokens.
The problem is that they are not in the same network: alice.token is defined in Symbol’s public chain whereas bob.token is only present in a private chain using Symbol tech.
Trading tokens directly from one blockchain to the other is not possible, due to the technological differences between them.
In the case of Symbol public and private chain, the same mosaic name could have a different definition and distribution or even not exist. Between Bitcoin and Symbol, the difference is even more evident, as each blockchain uses an entirely different technology.
Instead of transferring tokens between different chains literally, the trade will be performed inside each chain.
The cross chan swap protocol will ensure that the token swap occurs atomically.
Before starting with the swap, all participants involved int the swap must own at least one account in each blockchain.
proof
. The proof should have a size between 10
and 1000
bytes.secret
.TX1 Property | Value |
---|---|
Type | SecretLockTransaction |
Mosaic | 10 alice.token |
Recipient | Bob’s address (Private Chain) |
Algorithm | h |
Duration | 96 h |
Secret | h(proof) |
Network | Private Chain |
Once announced, this transaction will remain locked until someone discovers the proof that matches the secret. If no one unlocks it before the duration set is reached, the locked funds will be returned back to Alice.
Note
Bob should retrieve the secret from the chain. It is Bob’s responsibility to verify the secret correctness.
TX2 Property | Value |
---|---|
Type | SecretLockTransaction |
Mosaic | 10 bob.token |
Recipient | Alice’s address (Public Chain) |
Algorithm | h |
Duration | 84 h |
Secret | h(proof) |
Network | Public Chain |
TX3 Property | Value |
---|---|
Type | SecretProofTransaction |
Recipient | Alice’s address (Public Chain) |
Algorithm | h |
Secret | h(proof) |
Proof | proof |
Network | Public Chain |
TX4 Property | Value |
---|---|
Type | SecretProofTransaction |
Recipient | Bob’s address (Private Chain) |
Algorithm | h |
Secret | h(proof) |
Proof | proof |
Network | Private Chain |
The process is atomic, but should be completed with lots of time before the deadlines:
maxRollBackBlocks
between announcements to prevent experiencing transaction rollbacks.Atomic cross-chain swap between public and private chain
Trade tokens between different blockchains without using an intermediary party in the process.
Continue: Cryptography.
Did you find what you were looking for? Give us your feedback.