RFC: UDT info in witness draft spec

1. Overview

There is a solution to put UDT info in the cell for reading, but if we don’t change info often, we can treat UDT Info as static data and put it in witness. This solution is an additional solution to info_cell and does not conflict with info_cell.

The advantage is that it can reduce the state occupation on the chain. When UDT is useless, no state will be occupied, and there will be no situation where the state is still occupied on the chain after the EOS fundraising ends. The disadvantage is that if adding CKB will cut the block, the information may be lost.

2. Info_data format

decimals: uint8
name: Common knowledge Byte
symbol: CKB
extra: {website:"https://nervos.org"} // optional

In info_data, the most basic information that must be included is token_name, token_symbol and decimals. The current total supply and balance can be obtained by indexing the live cell.

The UDT information format in the specification is as follows:

data:

-decimals: (uint8 type) The number of decimal places used by the token. If decimals is 8, it means that the token can be divisible by at least 0.00000001.
-tokenname: Token name, UTF8 encoded character array.
-symbol: The identifier of the token, such as “HIX”, an array of characters encoded in UTF8.
-extra: anything you want to write, such as the website, the hash value of a certain picture, etc.

The first three items are parameters that must be filled in, and information can be added as required.

3. For Single Owner sUDT

The issuance of sUDT on CKB is controlled by lockscript, so the simplest sUDT is issued by an individual or organization using a lockscript controlled by a private key, such as USDC and other stable coins.

// Issue new UDT/UDT_Info
Inputs:
    <... one of the input cell must have owner lock script as lock>
Outputs:
    UDT_Cell:
        Data:
            amount: uint128
        Type:
            code_hash: simple_udt type script
            args: owner lock script hash (...)
        Lock:
            <user defined>
witnesses:
...
<Corresponding to owner cell>lock:signature,input_type:...,output_type:udt_info_data
...

For a single owner controlled UDT, info_data satisfies the following rules:

  • Rule 1: First check according to the rules of info_cell, if there is a corresponding info_cell, use info_cell.
  • Rule 2: When there is no corresponding info_cell, scan the entire chain for the minting transaction corresponding to UDT, and look for the first transaction that has data in the format of info_data in the output_type of the witness corresponding to owner_cell, and it can be determined as the info of the UDT .

4. For Script-drive sUDT

Script-driven UDT stands for, the owner_lock of udt is not a lock controlled by a private key, but a special script.

// Issue new SUDT/SUDT_Info
Inputs:
    <... one of the input cell must have owner lock script as lock>
Outputs:
    UDT_Cell:
        Data:
            amount: uint128
        Type:
            code_hash: simple_udt type script
            args: owner lock script hash (...)
        Lock:
            <user defined>
witnesses:
...
<Corresponding to owner cell>lock:signature,input_type:...,output_type:udt_info_data
...

For a script-drive UDT, info_data satisfies the following rules:

  • Rule 1: First check according to the rules of info_cell, if there is a corresponding info_cell, use info_cell.
  • Rule 2: When there is no corresponding info_cell, scan the entire chain for the minting transaction corresponding to UDT, and look for the first transaction that has data in the format of info_data in the output_type of the witness corresponding to owner_cell, and the hash of info_data is equal to owner The first 32 bytes of the args of lockscript.

置于Witness的UDT info

目前已有将UDT info置于Cell里以供检索的方案,但如果不经常更改info,即Info默认为静态数据,在此前提下,可以将info信息放在Witness内绑定某个UDT,并且作为info_cell的附加方案而存在,不与info_cell冲突。

好处是可以减少链上状态占用,在UDT无用处的时候不会占用任何状态,不会出现EOS募资结束后链上还占用状态的情况。坏处是,加入CKB会进行区块裁剪的话,witness信息会丢失。

info_data 格式

decimals: uint8
name: Common knowledge Byte
symbol: CKB
extra: {website:"https://nervos.org"} // optional

在 info_data 中,必须包含的最基本信息是 token_name、token_symbol和精度。 当前总量和余额可以通过对live cell的索引来获得。

规范中的 UDT info_data 格式如下所示:

数据:

  • decimals:(uint8 类型)token 使用的小数位数,如果decimals 为8 表示token 至少可以被整除为0.00000001。
  • tokenname: 令牌名称,UTF8编码的字符数组。
  • symbol: 令牌的标识符,例如“HIX”,UTF8编码的字符数组。
  • extra:你想写的任何东西,比如网站,某张图片的哈希值等。

前三项是必须填写的参数,extra可以根据需要添加信息,格式可以选择json。

单独控制的UDT

CKB 上 sUDT 的发行是由 lockscript 控制的,所以最简单的 sUDT 是由个人或组织使用由私钥控制的 lockscript 发行的,例如 USDC 和其他稳定币。

// Issue new SUDT/SUDT_Info
Inputs:
    <... one of the input cell must have owner lock script as lock>
Outputs:
    UDT_Cell:
        Data:
            amount: uint128
        Type:
            code_hash: simple_udt type script
            args: owner lock script hash (...)
        Lock:
            <user defined>
witnesses:
...
<Corresponding to owner cell>lock:signature,input_type:...,output_type:udt_info_data
...

对于单独控制的UDT,info_data满足如下规则:

  • 规则一:首先按照info_cell的规则进行检查,如果存在对应info_cell,则以info_cell为准。

  • 规则二:在不存在对应info_cell的时候,扫描整条链对应UDT的铸造交易,以寻找第一个铸币交易,其在owner_cell对应的Witness的output_type里有对应info_data格式的数据,该udt_info_data 被确定为该UDT的info。

脚本驱动的UDT

脚本驱动的UDT代表UDT的Owner_lock不是一个私钥控制的账户lock,而是一个特制的脚本。

// Issue new SUDT/SUDT_Info
Inputs:
<any cell>
Outputs:
   UDT_Cell:
        Data:
            amount: uint128
        Type:
            code_hash: simple_udt type script
            args: owner lock script hash (...)
        Lock:
            <user defined>
witnesses:
...
<Corresponding to owner cell>lock:signature,input_type:...,output_type:udt_info_data
...

对于脚本控制的UDT,满足如下规则:

规则一:首先按照info_cell的规则进行检查,如果存在对应info_cell,则以info_cell为准。

规则二:在不存在对应info_cell的时候,扫描整条链对应UDT的铸造交易,以寻找第一个铸币交易,一个在owner_lock对应cell的Witness的output_type里,有对应info_data格式的数据的,并且info_data的哈希等于owner lockscript的args的前32个字节。