xUDT(Extensible UDT)合约约束xUDT (Extensible UDT) Contract Constraints

来源:RFC 0052 · ckb-production-scripts/c/xudt_rce.c(master)+ c/rce.h 错误码 · Mirana code_hash 0x50bd…1b95,hash_type data1Source: RFC 0052 · ckb-production-scripts/c/xudt_rce.c (master) + c/rce.h error codes · Mirana code_hash 0x50bd…1b95, hash_type data1
Type 脚本Type script代币 / UDTToken / UDT主网Mainnet测试网Testnet开源Open sourceNervos 官方Nervos

0 → N发行 / 增发(owner 模式)Issue / Mint (owner mode)

Inputs 输入Inputs
某个 input:ownersome input: ownerCell{ lock: hash(lock) == args[0..32] // 默认 // flags 0x80000000:input type hash 也可 // flags 0x40000000:output type hash 也可 // flags 0x20000000:禁用 input lock 方式 }Cell{ lock: hash(lock) == args[0..32] // default // flags 0x80000000: input type hash also accepted // flags 0x40000000: output type hash also accepted // flags 0x20000000: disables the input-lock method }
➜
Outputs 输出Outputs
output:xUDT celloutput: xUDT cellCell{ type: { codeHash: xUDT, args: owner lock hash 32B [flags u32 LE] [extension data] }, data: amount u128 LE (16B) [extension data] }

限制Constraints

  • type.args ≥ 32 字节≥ 32 bytes (-1)
  • owner 模式owner mode:: 满足任一启用的 owner 条件时跳过数量检查(扩展脚本仍执行)when any enabled owner condition holds, the amount check is skipped (extension scripts still run)

N → M转账 / 销毁Transfer / Burn

Inputs 输入Inputs
inputs:xUDT cell(同一 type)inputs: xUDT cells (same type)Cell{ type: { codeHash: xUDT, args: … }, data: amount_in u128 LE }
➜
Outputs 输出Outputs
outputs:xUDT cell(同一 type)outputs: xUDT cells (same type)Cell{ type: { codeHash: xUDT, args: … }, data: amount_out u128 LE }
type.args 字节布局type.args byte layout
owner lock hash32B
flags4B u32 LE(可选)4B u32 LE (optional)
扩展数据extension data变长variable
  • owner lock hash 32B owner 判定用 hashhash used for owner checks ≥ 32B (-1)
  • flags 4B u32 LE(可选)4B u32 LE (optional) 低位:0 无扩展 / 1 扩展在 args / 2 扩展在 witness;高 3 位:owner 模式开关low bits: 0 no extension / 1 extensions in args / 2 extensions in witness; top 3 bits: owner-mode switches 去掉 owner 位后 ∈ {0,1,2}∈ {0,1,2} after masking owner bits (44)
  • 扩展数据extension data 变长variable flags=1:ScriptVec;flags=2:20 字节 blake160(witness 中的 ScriptVec)flags=1: ScriptVec; flags=2: 20-byte blake160 of the ScriptVec in the witness flags=1 长度须与 ScriptVec 一致;flags=2 须为 20 字节且 hash 匹配flags=1 length must match the ScriptVec; flags=2 must be 20 bytes and the hash must match (45 / 44 / 49)

限制Constraints

  • data:: 长度 ≥ 16 字节,前 16 字节为 u128 LElength ≥ 16 bytes; first 16 bytes are u128 LE (-2)
  • Σ amount:: 累加不得溢出summation must not overflow (-51)
  • Σ amount_in ≥ Σ amount_out(非 owner 模式)≥ Σ amount_out (non-owner mode) (-52)
  • 扩展脚本extension scripts:: 每个扩展脚本的 validate 必须返回 0each extension script's validate must return 0 (具体错误码由扩展脚本决定error codes depend on the extension)
部署与来源Deployments & source 未核验unverified
源码source nervosnetwork/ckb-production-scripts@26b0b4f1 · c/xudt_rce.c (default-branch HEAD recorded at backfill 2026-10-21; spec/plugin were written from the default branch shortly before (exact read commit not recorded))
二进制核验binary check 未核验unverified no binary or checksum at the recorded commit matched the deployed data hash (reproducible build not attempted)
网络networkcode_hashcell_deptype_id args数据哈希data hash部署交易deploy tx
mainnet0x50bd8d6680b8b9cf98b73f3c08faf8b2a21914311954118ad6609be6e78a1b95 data10xc07844ce21…3f558ab7:0 code—0x50bd8d6680…e78a1b950xc07844ce21…3f558ab7 #11922670
testnet0x50bd8d6680b8b9cf98b73f3c08faf8b2a21914311954118ad6609be6e78a1b95 data10xbf6fb53876…9d337f5f:0 code0x44ec8b9666…63dda0ae0x50bd8d6680…e78a1b950xbf6fb53876…9d337f5f #8497330
testnet0x25c29dc317811a6f6f3985a7a9ebc4838bd388d19d0feeecf0bcd60f6c0975bb type0xbf6fb53876…9d337f5f:0 code0x44ec8b9666…63dda0ae0x50bd8d6680…e78a1b950xbf6fb53876…9d337f5f #8497330
链上数据核对于 on-chain data checked 2026-10-20
错误码数值来自 c/rce.h 枚举(ERROR_INVALID_FLAG=44,ERROR_INVALID_ARGS_FORMAT=45,ERROR_HASH_MISMATCHED=49);以 master 源码为准,已部署版本可能略有差异Numeric error codes come from the c/rce.h enum (ERROR_INVALID_FLAG=44, ERROR_INVALID_ARGS_FORMAT=45, ERROR_HASH_MISMATCHED=49); based on master, the deployed build may differ slightly
GitHub · gpBlockchain/ckb-contract-flow-html