NervosDAO 合约约束NervosDAO Contract Constraints

来源:ckb-system-scripts / c/dao.c · DAO = type script(code_hash 0x82d7…3f2e,hash_type type)Source: ckb-system-scripts / c/dao.c · DAO = type script (code_hash 0x82d7…3f2e, hash_type type)
Type 脚本Type script系统 / 创世SystemDeFiDeFi主网Mainnet测试网Testnet开源Open sourceNervos 官方Nervos

0 → 1存款Deposit

Inputs 输入Inputs
input(任意普通 cell)input (any normal cell)Cell{ capacity: …, type: null }
➜
Outputs 输出Outputs
output[j]:deposit celloutput[j]: deposit cellCell{ capacity: X, lock: 任意, type: { codeHash: DAO, args: 0x }, data: 0x0000000000000000 }Cell{ capacity: X, lock: any, type: { codeHash: DAO, args: 0x }, data: 0x0000000000000000 }

限制Constraints

  • type.args:: 必须为空must be empty (-2)
  • data:: 恰好 8 字节,全为 0exactly 8 bytes, all zero (-19)
  • Σ输出 capacityΣ output capacity ≤ Σ输入 capacity≤ Σ input capacity (-15)

1 → 1提取第一阶段Withdraw Phase 1

Inputs 输入Inputs
input[i]:deposit cell(位于区块 D)input[i]: deposit cell (in block D)Cell{ capacity: X, type: { codeHash: DAO, args: 0x }, data: 0x0000000000000000 }
➜
Outputs 输出Outputs
output[i]:withdrawing celloutput[i]: withdrawing cellCell{ capacity: X, lock: 任意, type: { codeHash: DAO, args: 0x }, data: D.number (u64 LE) }Cell{ capacity: X, lock: any, type: { codeHash: DAO, args: 0x }, data: D.number (u64 LE) }
header_deps: [ D ]

限制Constraints

  • index:: 输出必须与 deposit 输入在同一 index ithe output must be at the same index i as the deposit input
  • type:: 与输入同一 DAO scriptsame DAO script as the input (-20)
  • capacity:: 与输入完全相等exactly equal to the input (-20)
  • data:: 8 字节 u64 LE,等于 D 的区块号8-byte u64 LE equal to block number of D (-20)
  • header_deps:: 必须包含区块 D 的 hashmust include the hash of block D
  • lock:: dao.c 不检查not checked by dao.c (CKB 节点可能要求 lock 大小相同,未核实the CKB node may require the same lock size; unverified)

1 → 0提取第二阶段Withdraw Phase 2

Inputs 输入Inputs
input[i]:withdrawing cell(位于区块 W)input[i]: withdrawing cell (in block W)Cell{ capacity: X, type: { codeHash: DAO, args: 0x }, data: D.number, since: ≥ 锁定期(绝对 epoch) }Cell{ capacity: X, type: { codeHash: DAO, args: 0x }, data: D.number, since: ≥ lock period (absolute epoch) }
witness[i]WitnessArgs{ lock: 签名, input_type: k (u64 LE, 8 字节) }WitnessArgs{ lock: signature, input_type: k (u64 LE, 8 bytes) }
➜
Outputs 输出Outputs
outputs:任意 celloutputs: any cellsCell{ capacity: Σ ≤ 上限, lock: 任意, type: 任意 }Cell{ capacity: Σ ≤ limit, lock: any, type: any }
header_deps: [ W, …, D(位于第 k 个) ]header_deps: [ W, …, D (at index k) ]

限制Constraints

  • witness.input_type:: 8 字节,值为 D 在 header_deps 中的下标 k8 bytes; value is k, the index of D in header_deps (-11)
  • header_deps:: 包含 D 和 W;D 的区块号必须等于 data,且 W 的 epoch 必须晚于 Dcontains D and W; D's block number must equal data, and W's epoch must be later than D's (-14)
  • since:: 绝对 epoch,且 ≥ D.epoch + ⌈存款 epoch 数 / 180⌉ × 180absolute epoch, and ≥ D.epoch + ⌈deposited epochs / 180⌉ × 180 (-17)
  • Σ输出 capacityΣ output capacity ≤ 普通输入 + Σ 最大可提取≤ normal inputs + Σ max withdraw (-15)
  • 最大可提取max withdraw = occupied + (X − occupied) × AR_W / AR_D (AR 取自区块头 dao 字段AR is read from the header's dao field)
部署与来源Deployments & source 未核验unverified
源码source nervosnetwork/ckb-system-scripts@72eb92fc · c/dao.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
mainnet0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e type0xe2fb199810…6d73ff5c:2 code0xb2a8500929…64bcf6260x32064a14ce…a60c79230xe2fb199810…6d73ff5c #0
testnet0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e type0x8f8c79eb66…42635c9f:2 code0xb2a8500929…64bcf6260x32064a14ce…a60c79230x8f8c79eb66…42635c9f #0
链上数据核对于 on-chain data checked 2026-10-20
GitHub · gpBlockchain/ckb-contract-flow-html