CKB Contract Flow

Cobuild OTX Lock 约束Cobuild OTX Lock Constraints

来源:xcshuan/cobuild-otx-contracts @f18eeaf contracts/cobuild-otx-lock/src、crates/cobuild-core/src、crates/cobuild-types/schemas · 无官方部署(参考实现,测试夹具用 data2)Source: xcshuan/cobuild-otx-contracts @f18eeaf contracts/cobuild-otx-lock/src, crates/cobuild-core/src, crates/cobuild-types/schemas · no official deployment (reference implementation; fixtures use data2)
Lock 脚本Lock script身份 / 钱包Identity / wallet开源Open source社区Community
贡献者:Contributed by @xcshuan @xcshuan

给 AI agent:For AI agents: cobuild_otx_lock.md · llms.txt

A交易级解锁:SighashAll / SighashAllOnly(无 OTX,或本 lock 有输入在 OTX 范围外)Tx-level unlock: SighashAll / SighashAllOnly (no OTX, or this lock has inputs outside the OTX range)

Inputs 输入Inputs
本 lock 的输入inputs with this lockCell{ lock: COBUILD_OTX_LOCK{ args: identity 20B } }
witness[group 第一个输入](carrier)witness[group's first input] (carrier)SighashAll{ seal, message } | SighashAllOnly{ seal }
witness[group 其他输入]witness[other group inputs]必须为空must be empty
Outputs 输出Outputs
outputs:任意outputs: any由签名 hash 覆盖covered by the signing hash
lock.args(20B)lock.args (20B)
identity20B
  • identity20Bblake2b-256(压缩 secp256k1 公钥)[0..20](ckb-default-hash)blake2b-256(compressed secp256k1 pubkey)[0..20] (ckb-default-hash)长度 = 20length = 2020
witness = WitnessLayout(molecule union,item id)witness = WitnessLayout (molecule union, item id)
SighashAll0xff000001
SighashAllOnly0xff000002
Otx0xff000003
OtxStart0xff000004
  • SighashAll0xff000001{ seal, message }:交易级签名 + Message{ seal, message }: tx-level signature + Message全交易至多 1 个at most one per tx33
  • SighashAllOnly0xff000002{ seal }:交易级签名{ seal }: tx-level signature
  • Otx0xff000003一个 OTX:message、append_permissions、base_*、append_segments、base_sealsone OTX: message, append_permissions, base_*, append_segments, base_seals必须紧跟 OtxStart 或上一个 Otxmust directly follow OtxStart or the previous Otx31
  • OtxStart0xff000004{ start_input_cell, start_output_cell, start_cell_deps, start_header_deps }{ start_input_cell, start_output_cell, start_cell_deps, start_header_deps }至多 1 个,后面至少 1 个 Otxat most one, followed by ≥ 1 Otx31
不带 cobuild id 的 witness 视为 legacy;带保留 id 但 molecule 不合法 → 31 / 30witnesses without a cobuild id are legacy; a reserved id with invalid molecule → 31 / 30
seal(65B,可恢复 secp256k1 签名)seal (65B, recoverable secp256k1 signature)
r ‖ s64B
rec_id1B
  • r ‖ s64BECDSA 签名ECDSA signature可解析parses50
  • rec_id1B恢复 ID(k256 RecoveryId)recovery id (k256 RecoveryId)0–3,恢复出的公钥 hash 前 20B = args0–3; recovered pubkey hash[0..20] = args50
长度 ≠ 65 也返回 50(VerifyFailure)length ≠ 65 also returns 50 (VerifyFailure)
签名 hash(blake2b-256,personal 16B)signing hash (blake2b-256, 16B personal)
personal16B
messagevar
tx_hash32B
inputsΣ
extra witnessesΣ
  • personal16B有 Message:"ckbcb_twm_core1\0";无:"ckbcb_tnm_core1\0"with Message: "ckbcb_twm_core1\0"; without: "ckbcb_tnm_core1\0"
  • messagevar唯一的 SighashAll.message(若有)the unique SighashAll.message (if any)30
  • tx_hash32B交易哈希tx hash61
  • inputsΣ每个输入:CellOutput ‖ u32 len ‖ dataeach input: CellOutput ‖ u32 len ‖ data62
  • extra witnessesΣ下标 ≥ 输入数的 witness:u32 len ‖ wwitnesses beyond input count: u32 len ‖ w长度 ≤ u32::MAXlength ≤ u32::MAX63
Action(Message.actions 的元素)Action (element of Message.actions)
script_info_hash32B
script_role1B
script_hash32B
dataBytes
  • script_info_hash32B脚本信息 hashscript info hash
  • script_role1B0 InputLock / 1 InputType / 2 OutputType0 InputLock / 1 InputType / 2 OutputType∈ {0,1,2}∈ {0,1,2}32
  • script_hash32B目标脚本 hashtarget script hash交易中存在该角色的脚本a script with that role exists in the tx32
  • dataBytes应用数据application data

限制Constraints

  • script.args长度 = 20length = 2020
  • witnesses每个带 cobuild id 的 witness 都能按 WitnessLayout 解析every witness carrying a cobuild id parses as WitnessLayout30 / 31
  • SighashAll全交易至多 1 个 SighashAll(带 Message)at most one SighashAll (with Message) in the tx33
  • carrier witnessgroup 第一个输入处的 witness 为 SighashAll 或 SighashAllOnlywitness at the group's first input is SighashAll or SighashAllOnly39
  • group 其他 witnessother group witnesses必须为空must be empty39
  • message.actions每个 action 的 (script_role, script_hash) 指向交易中的脚本each action's (script_role, script_hash) points to a script in the tx32
  • seal65B,恢复出的公钥 blake160 = args65B, recovered pubkey blake160 = args50
  • 签名要求signature requirements至少 1 个(否则说明本 lock 无需签名)at least one (otherwise nothing authorizes this lock)40

BOTX 解锁:base_seals / append segment seals(本 lock 输入全部在 OTX 范围内)OTX unlock: base_seals / append-segment seals (all of this lock's inputs inside the OTX range)

Inputs 输入Inputs
OTX 范围内的本 lock 输入this lock's inputs inside the OTX rangeCell{ lock: COBUILD_OTX_LOCK{ args: identity } }
witnesses… ‖ OtxStart ‖ Otx_1 ‖ … ‖ Otx_n(连续) ‖ …… ‖ OtxStart ‖ Otx_1 ‖ … ‖ Otx_n (contiguous) ‖ …
Outputs 输出Outputs
OTX base / append outputsOTX base / append outputs按 base_output_masks 与 append segment 覆盖签名signed per base_output_masks and append segments
Otx(molecule table)Otx (molecule table)
messageMessage
append_permissions1B
base_input_cellsu32
base_*_masksBytes
append_segmentsvec
base_sealsLockSealVec
  • messageMessageOTX 的 actionsOTX actionsaction 目标合法action targets valid32
  • append_permissions1Bbit0 inputs、bit1 outputs、bit2 cell_deps、bit3 header_depsbit0 inputs, bit1 outputs, bit2 cell_deps, bit3 header_deps高 4 位为 0;追加类别须被允许upper 4 bits zero; appended kinds must be permitted31
  • base_input_cellsu32base 输入数base input count≥ 1≥ 131
  • base_*_masksBytes输入 2 bit/个、输出 4 bit/个、cell_dep / header_dep 1 bit/个inputs 2 bits each, outputs 4 bits each, cell_deps / header_deps 1 bit each长度 = ceil(bits/8),未用高位为 0length = ceil(bits/8), unused high bits zero31
  • append_segmentsvec每段:segment_flags、各类数量、sealseach: segment_flags, counts, sealsflags ⊆ {0x01 允许后续段, 0x02 覆盖前段};非最后一段须有 0x01flags ⊆ {0x01 allow-more, 0x02 cover-previous}; non-last segments need 0x0131
  • base_sealsLockSealVec{ script_hash, seal } 列表list of { script_hash, seal }本 lock hash 恰好 1 个exactly one for this lock hash35 / 36
OTX 签名 hashOTX signing hashes
base"ckbcb_otb_core1\0"
segment"ckbcb_ots_core1\0"
  • base"ckbcb_otb_core1\0"message ‖ append_permissions ‖ base 输入/输出/cell_dep/header_dep(按 mask)message ‖ append_permissions ‖ base inputs/outputs/cell_deps/header_deps (by mask)
  • segment"ckbcb_ots_core1\0"base_hash ‖(0x02 时:前序段数 + 各段)‖ flags ‖ 本段实体base_hash ‖ (with 0x02: previous count + segments) ‖ flags ‖ this segment's entities
seal(65B,可恢复 secp256k1 签名)seal (65B, recoverable secp256k1 signature)
r ‖ s64B
rec_id1B
  • r ‖ s64BECDSA 签名ECDSA signature可解析parses50
  • rec_id1B恢复 ID(k256 RecoveryId)recovery id (k256 RecoveryId)0–3,恢复出的公钥 hash 前 20B = args0–3; recovered pubkey hash[0..20] = args50
长度 ≠ 65 也返回 50(VerifyFailure)length ≠ 65 also returns 50 (VerifyFailure)
lock.args(20B)lock.args (20B)
identity20B
  • identity20Bblake2b-256(压缩 secp256k1 公钥)[0..20](ckb-default-hash)blake2b-256(compressed secp256k1 pubkey)[0..20] (ckb-default-hash)长度 = 20length = 2020

限制Constraints

  • script.args长度 = 20length = 2020
  • witnesses每个带 cobuild id 的 witness 都能按 WitnessLayout 解析every witness carrying a cobuild id parses as WitnessLayout30 / 31
  • SighashAll全交易至多 1 个 SighashAll(带 Message)at most one SighashAll (with Message) in the tx33
  • OtxStart至多 1 个;其后紧跟 ≥ 1 个连续 Otx;Otx 不得出现在 OtxStart 之前at most one; followed by ≥ 1 contiguous Otx; no Otx before OtxStart31
  • OTX 范围OTX ranges从 OtxStart 起依次累加 base / append 数量,结束位置 ≤ 交易对应数量base / append counts accumulate from OtxStart; end ≤ the tx counts31
  • Otxbase_input_cells ≥ 1;append_permissions / segment_flags / masks 合法base_input_cells ≥ 1; append_permissions / segment_flags / masks valid31
  • message.actionsaction 目标存在action targets exist32
  • base 输入含本 lockbase inputs contain this lockbase_seals 中 script_hash = 本 lock hash 恰好 1 个exactly one base_seals entry with script_hash = this lock hash35 / 36
  • append 段输入含本 lockappend segment inputs contain this lock该段 seals 中本 lock hash 恰好 1 个exactly one entry for this lock hash in that segment's seals35 / 36
  • 覆盖coverage只有 OTX 签名时,本 lock 所有输入都在 OTX 输入总范围内with only OTX signatures, every input of this lock lies in the aggregate OTX input range34
  • seal每个签名要求:65B 可恢复签名,公钥 blake160 = argseach requirement: 65B recoverable signature, pubkey blake160 = args50
  • 签名要求signature requirements至少 1 个at least one40
部署与来源Deployments & source 未核验unverified
源码source
xcshuan/cobuild-otx-contracts@f18eeaf2 · contracts/cobuild-otx-lock/src · crates/cobuild-core/src · crates/cobuild-types/schemas (commit read when writing this spec (default-branch HEAD 2026-06-24). No deployment published in the repo; no code_hash, so deployments are empty.)
二进制核验binary check
未核验unverified no deployment resolved on chain
未在链上找到部署no on-chain deployment resolved
链上数据核对于 on-chain data checked 2026-11-12
错误码来自 contracts/cobuild-otx-lock/src/error.rs(Error::code):1–10 ckb-std SysError,20 InvalidArgs,30 MalformedCobuild,31 InvalidOtxLayout,32 InvalidMessageTarget,33 DuplicateSighashAll,34 MissingLockGroupCoverage,35 MissingLockSeal,36 DuplicateLockSeal,38 DuplicateMatchingAction,39 InvalidLockGroupWitness,40 LockSemanticFailure,41 ActionNotFound,50 VerifyFailure,60 InternalFailure,61 InvalidContextInput,62 MissingHashInput,63 HashInputTooLarge。38、41、60 在 lock 主流程中不出现(供 type 脚本 / 辅助 API 使用)。Error codes from contracts/cobuild-otx-lock/src/error.rs (Error::code): 1–10 ckb-std SysError, 20 InvalidArgs, 30 MalformedCobuild, 31 InvalidOtxLayout, 32 InvalidMessageTarget, 33 DuplicateSighashAll, 34 MissingLockGroupCoverage, 35 MissingLockSeal, 36 DuplicateLockSeal, 38 DuplicateMatchingAction, 39 InvalidLockGroupWitness, 40 LockSemanticFailure, 41 ActionNotFound, 50 VerifyFailure, 60 InternalFailure, 61 InvalidContextInput, 62 MissingHashInput, 63 HashInputTooLarge. 38, 41 and 60 do not occur in the lock flow (they serve type scripts / helper APIs).
同一 lock 可同时需要交易级签名和多个 OTX 签名(base + 每个包含其输入的 append 段),每个都必须通过。没有任何 cobuild witness 时不产生交易级要求 → 40。mask 的具体含义(哪些字段参与签名)见设计文档 docs/superpowers/specs/2026-06-22-otx-mask-default-value-signing-design.md,本页只列代码中的长度规则。One lock may need a tx-level signature and several OTX signatures at once (base + every append segment containing its inputs); each must pass. With no cobuild witness at all there is no tx-level requirement → 40. What the masks select for signing is described in docs/superpowers/specs/2026-06-22-otx-mask-default-value-signing-design.md; this page lists only the length rules in the code.
无官方部署、无链上交易:插件 match 为空,仅静态页。README 说明测试夹具使用 ScriptHashType::Data2。No official deployment and no on-chain txs: the plugin match is empty (static page only). The README says test fixtures use ScriptHashType::Data2.