Skip to main content

CoTA Protocol Overview

The CoTA (aka. Compact Token Aggregator) protocol is a layer-1.5 account based fungible / non-fungible token and k-v data managment solution on Nervos CKB. The basic idea of CoTA is to manage and verify enormous number of data by a Sparse Merkle Tree (SMT) with a constant size of on-chain storage space, like 32bytes. The draft version of the CoTA protocol was published on Nervos Talk at 2021. Since then, the CoTA protocol has evolved rapidly and extended to more user scenarios, including unique CCID, 3rd-party data storage, JoyID, etc.

Basic data structure

The CoTA Cell simply consists of two necessary parts, the SMT root in the cell data field, and the CoTA typescript in the cell type field. They stand for the personal data and operation verification logic separately.

 # CoTA cell data structure
data:
version: byte
smt_root: byte32
type:
code_hash: cota_type
args: lockscript_hash[0..20] # must match self.lockscript
lock:
--

CoTA cell illustration

Two-step operation design pattern

One of the major pain points in the application scenarios of sudt protocol is the token transfer operation requires an update to both the sender's and receiver's cell simultaneously. The receiver has to use an anyone-can-pay style lock to their cells, which introduces security risks, composability issues and inconvenient user experiences.

To solve this problem, we introduce a two-step operation design pattern. The principle is simple, the sender first minus token and leaves a proof in their cell, and then the receiver restores the token in their cell according to the mathematical proof. With this method, everyone operates their cells only. And the receiver can immediately confirm the token transfer as soon as the sender completes the first step.

CoTA two-steps

Decentralized global registry

There should be only one CoTA cell for one address to prevent double-claim issues. Otherwise, multiple CoTA cells with the same address could repeatedly claim tokens according to the same proof. So a global registry must exist to ensure the CoTA cell's uniqueness.

FT, NFT, and account model on UTXO chain

CoTA protocol builds in standard token define, mint, and transfer operations, covering fungible and non-fungible tokens. The CoTA cell stores the token issuance, distribution, and holding records under one address. So it's an account model layer over the UTXO model chain, and this feature makes the programming and achieving composability much easier on CKB.

K-V structure for CoTA SMT

Key type

The data.smt_root is the essential data field in the design. Data stored in the SMT is managed by key-value pair, and several kinds of data are stored and compressed in this hash root. The CoTA typescript (smart contract) processes the transaction logic according to its value. We use a two-bytes variable smt_root.key.smt_type to identify different key types.

type name1st byte2nd bytedescription
cota-NFT-define0x81 (NFT)0x00NFT issuance definition
cota-NFT-hold0x81 (NFT)0x01current hold NFT
cota-NFT-withdrawal0x81 (NFT)0x02NFT withdrawal record
cota-NFT-claim0x81 (NFT)0x03NFT claim record
cota-FT-define0x82 (FT)0x00FT issuance definition
cota-FT-hold0x82 (FT)0x01current hold FT
cota-FT-withdrawal0x82 (FT)0x02FT withdrawal record
cota-FT-claim0x82 (FT)0x03FT claim record
extension-data0xF00x00user-defined data
reservedother----