LikeChain KaiTak Technical Intro

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

Features

LikeChain 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.

LikeChain KaiTak will support basic token features, including:

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

Architecture

A LikeChain 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

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 LikeChain, 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 LikeChain, the root hash is used as application hash, while the proof generation and snapshot features are useful in LikeChain-Ethereum interaction.

Services

In order to enable interaction between LikeChain 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 LikeChain by LikeChain Deposit transactions
  • Withdraw service, which submits application hash onto Ethereum periodically through Ethereum smart contract calls

LikeChain-Ethereum interaction

We want users to be able to transfer LikeCoin between LikeChain 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 LikeChain. The Relay ensures that the LikeCoin on Ethereum are locked, until there is a message from LikeChain indicating that certain amount of LikeCoin are burnt on LikeChain. When such a message comes, the Relay releases the same amount of LikeCoin from Ethereum, making the total number of LikeCoin usable constant.

LikeCoin from Ethereum to LikeChain (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 LikeChain, there will be a group called deposit approvers, who are responsible for oraclizing LikeChain 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 LikeChain. When enough number of deposit approvers approved the same deposit events, LikeCoin will be minted and given to the addresses accordingly on LikeChain.

LikeCoin from LikeChain to Ethereum (withdraw)

When users on LikeChain want to withdraw their LikeCoin onto Ethereum, they do so by sending a Withdraw transaction on LikeChain, which burns the LikeCoin on LikeChain 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 LikeChain validators. Then it will accept the application hash as the application state summary of LikeChain 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, LikeChain 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 LikeChain, with the same claiming condition to the HTLC contract on Ethereum. To get the LikeCoin on LikeChain, the original sender needs to submit the secret for the commitment on LikeChain. When the original sender does so, the secret will be publicly known by anyone who are monitoring ClaimHashedTransfer transactions on LikeChain. 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, LikeChain 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 LikeChain, 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 LikeChain to reward contents through LikeCoin.

Releated links: Intro to LikeChain | Transfer Delegation

Civic Liker is a movement to reward open contents. For the cost of a cup of coffee, you become a Civic Liker. Whatever you Like will then be turned into a tangible reward to creators.

Don’t miss out. Stay informed on LikeCoin