Table of Contents

LikeCoin chain KaiTak Technical Intro

Table of Contents

The development of the first version of LikeCoin chain, codenamed KaiTak, is almost done. This article will introduce the technical components and principles behind LikeCoin chain.

Features

LikeCoin chain KaiTak will be a consortium chain run by a few cooperating organizations, including but not limited to BlockSquare, Forbole, Matters, Gianthouse, and LikeCoin Foundation. In the future, we may further develop it into a public chain, but for now we would like to focus on the product features.

LikeCoin chain KaiTak will support basic token features, including:

  • LikeCoin deposit from Ethereum to LikeCoin chain
  • LikeCoin withdrawal from LikeCoin chain to Ethereum
  • Transferring LikeCoin within LikeCoin chain
  • Querying LikeCoin chain account info
  • Atomic swap, which is used for accelerating withdrawals

Architecture

A LikeCoin chain node is constructed by a few components:

  • Tendermint blockchain engine
  • Application BlockChain Interface Proxy (ABCI proxy) which processes actual application logic
  • IAVL tree as storage engine
  • Auxiliary services processing deposit and withdrawal
LikeCoin chain KaiTak Technical Intro

Tendermint

Tendermint is a blockchain engine, providing Byzantine fault tolerance consensus. It collects transactions into blocks, then the blockchain validators can vote to agree on the content of the block. In this way, an append-only ordered set of transactions is generated.

Application BlockChain Interface (ABCI) Proxy

To map the ordered set of transactions into actual state (e.g. account balances), a component which understands the application logic of the blockchain is needed.

In Tendermint, this is done by ABCI Proxy. After confirming transactions, the Tendermint engine calls the ABCI Proxy with transactions and block metadata, and the ABCI Proxy is responsible for aggregating the transactions into application state.

Since the state is completely defined by the ABCI Proxy, the ABCI Proxy is also responsible for verifying transactions based on the state before it actually enters the block for voting (e.g. checking the account balance for a Transfer transaction) and querying application state (e.g. querying account balance).

IAVL Tree

In order to verify that all nodes have consensus on exactly the same application state, the Tendermint engine needs to gain the application hash as a summary of the current state from ABCI Proxy. The author of the ABCI Proxy can generate the application hash by any method according to the application’s own logic and storage organization.

In LikeCoin chain, we use the IAVL tree library provided by the Tendermint team as the storage engine. IAVL tree is a Merklized AVL tree with snapshot function. IAVL tree can efficiently add, update and remove tree nodes, compute the root hash of the whole tree, generate proof of existence of tree nodes, and retrieve previous tree snapshots. In LikeCoin chain, the root hash is used as application hash, while the proof generation and snapshot features are useful in LikeCoin chain-Ethereum interaction.

Services

In order to enable interaction between LikeCoin chain and Ethereum (i.e. to transfer LikeCoin between two chains), some components outside the chain are needed to pass messages between the chains.

There are two major services:

  • Deposit service, which monitors Ethereum and passes relevant messages (deposit events) onto LikeCoin chain by LikeCoin chain Deposit transactions
  • Withdraw service, which submits application hash onto Ethereum periodically through Ethereum smart contract calls

LikeCoin chain-Ethereum interaction

We want users to be able to transfer LikeCoin between LikeCoin chain and Ethereum. While doing so, we must ensure that the total number of LikeCoin usable in the two chains remains constant.

This is done by locking LikeCoin in a special smart contract (Relay) on Ethereum and mint LikeCoin from LikeCoin chain. The Relay ensures that the LikeCoin on Ethereum are locked, until there is a message from LikeCoin chain indicating that certain amount of LikeCoin are burnt on LikeCoin chain. When such a message comes, the Relay releases the same amount of LikeCoin from Ethereum, making the total number of LikeCoin usable constant.

LikeCoin chain KaiTak Technical Intro

LikeCoin from Ethereum to LikeCoin chain (deposit)

When LikeCoin are transferred into the Relay contract, there will be ERC-20 Transfer events emitted from the LikeCoin ERC-20 token contract on Ethereum.

On LikeCoin chain, there will be a group called deposit approvers, who are responsible for oraclizing LikeCoin chain the LikeCoin Transfer events to the Relay contract on Ethereum. The deposit approvers will run the deposit service, which captures the LikeCoin Transfer events and aggregates them into Deposit transactions on LikeCoin chain. When enough number of deposit approvers approved the same deposit events, LikeCoin will be minted and given to the addresses accordingly on LikeCoin chain.

LikeCoin from LikeCoin chain to Ethereum (withdraw)

When users on LikeCoin chain want to withdraw their LikeCoin onto Ethereum, they do so by sending a Withdraw transaction on LikeCoin chain, which burns the LikeCoin on LikeCoin chain and leaves a withdraw record in the IAVL tree. The withdraw record will be reflected in the Merkle root of the IAVL tree, which is the application hash in the block metadata.

Then, when the withdraw service is waken (or anyone does this manually), the application hash with the block height will be committed on the Relay contract. The Relay contract will check that the information committed is indeed signed by enough number of LikeCoin chain validators. Then it will accept the application hash as the application state summary of LikeCoin chain on the given block height.

After that, the withdraw service will query the Merkle proofs of the withdraw records in the IAVL tree and submits them onto the Relay contract. The Relay contract will verify that the withdraw are not yet executed on the contract, and the proof are responsible to the previously committed application hash.

After verification, the Relay contract will unlock the LikeCoin and give it to the address according to the submitted withdraw record.

Atomic swap

Committing application hash onto the Relay contract requires one to collect all signatures of a block, and the Relay contract needs to verify all committed signatures. This is costly, therefore is done infrequently (e.g. once per day), making withdrawals slow.

To solve this problem, LikeCoin chain supports another form of withdraw through atomic swap and HTLC contract on Ethereum.

The HTLC contract is a smart contract which can lock LikeCoin within a certain period of time. When LikeCoin is transferred into the contract, the sender can set a receiver of the LikeCoin transferred, a commitment which is a 32-bytes hash, and a expiry time of this transfer.

To get the LikeCoin, the receiver must submit the pre-image of the commitment hash before the expiry time, i.e. find out secret such that SHA256(secret) == commitment. Since SHA-256 is (currently) a secure cryptographic hash function, only the original sender can tell the receiver what the secret is.

To get the secret from the sender, the receiver submits a HashedTransfer transaction onto LikeCoin chain, with the same claiming condition to the HTLC contract on Ethereum. To get the LikeCoin on LikeCoin chain, the original sender needs to submit the secret for the commitment on LikeCoin chain. When the original sender does so, the secret will be publicly known by anyone who are monitoring ClaimHashedTransfer transactions on LikeCoin chain. Hence the original receiver can get the secret of the commitment and unlock the LikeCoin in the HTLC contract on Ethereum.

Future plans

As you can see, LikeCoin chain KaiTak only supports very basic token features. It is currently used as a scalability solution of the LikeCoin token.

In the future versions, codenamed Sheungwan and Fotan, we will improve the current functionality of LikeCoin chain, and also add new features.

Improvements

This includes better processing on transaction fees, introducing the concept of gas, and making the chain more public.

New features

This includes features listed in the whitepaper, mainly the recording of content metadata on chain, which enables utilizing LikeCoin chain to reward contents through LikeCoin.

Releated links: Intro to LikeCoin chain | Transfer Delegation