Cheque(lock)约束Cheque (lock) Constraints

来源:nervosnetwork/ckb-cheque-script / src/entry.rs, claim.rs, withdraw.rs · mainnet 0xe4d4…fb0c / testnet 0x60d5…0d5b,hash_type type(RFC 0039)Source: nervosnetwork/ckb-cheque-script / src/entry.rs, claim.rs, withdraw.rs · mainnet 0xe4d4…fb0c / testnet 0x60d5…0d5b, hash_type type (RFC 0039)
Lock 脚本Lock script代币 / UDTToken / UDTDeFiDeFi主网Mainnet测试网Testnet开源Open sourceNervos 官方Nervos

0 → 1发送方创建 chequeSender creates a cheque

Inputs 输入Inputs
发送方 cellsender cellsCell{ lock: SENDER(secp256k1), type: UDT?, data: amount }
➜
Outputs 输出Outputs
cheque cellCell{ lock: { codeHash: CHEQUE, args: receiver_lock_hash[0..20] ‖ sender_lock_hash[0..20] }, type: UDT, data: amount }
args 字节布局args byte layout
receiver_lock_hash[0..20]20B
sender_lock_hash[0..20]20B
  • receiver_lock_hash[0..20] 20B 接收方 lock script hash 前 20 字节first 20 bytes of receiver lock hash args 恰 40Bargs exactly 40B (5)
  • sender_lock_hash[0..20] 20B 发送方 lock script hash 前 20 字节first 20 bytes of sender lock hash — (5)

限制Constraints

  • create:: 创建不运行 cheque lock(lock 只在花费时执行)creation does not run the cheque lock (locks run only when spent) (—)

1 → 0接收方领取 claimReceiver claims

Inputs 输入Inputs
cheque cellCell{ lock: CHEQUE(args), capacity: C, since: 0 }
接收方输入(1.b,无 cheque 签名时)receiver input (1.b, when the cheque has no signature)Cell{ lock: RECEIVER, witness.lock: signature }
发送方输入(可选)sender inputs (optional)Cell{ lock: SENDER, capacity: S }
➜
Outputs 输出Outputs
接收方 UDTreceiver UDTCell{ lock: RECEIVER, type: UDT, data: amount }
退还发送方refund to senderCell{ lock: SENDER, Σcapacity = S + C }

限制Constraints

  • since:: 所有 cheque 输入 since = 0every cheque input since = 0 (10)
  • capacity:: Σ sender 输入 + Σ cheque 输入 = Σ sender 输出(容量原样退回发送方)Σ sender inputs + Σ cheque inputs = Σ sender outputs (capacity goes back to sender) (8)
  • 1.a signature:: cheque witness 签名恢复出的 secp256k1 lock hash[0..20] = receivercheque witness signature recovers to a secp256k1 lock hash[0..20] = receiver (12 / 13)
  • 1.b input:: 无签名时需有 lock hash[0..20] = receiver 的输入,且其 witness.lock 非空without signature, an input with lock hash[0..20] = receiver whose witness.lock is non-empty (6 / 7)

1 → 0发送方取回 withdraw(6 epoch 后)Sender withdraws (after 6 epochs)

Inputs 输入Inputs
cheque cellCell{ lock: CHEQUE(args), since: 0xA000000000000006 }
发送方输入(2.b)sender input (2.b)Cell{ lock: SENDER, witness.lock: signature }
➜
Outputs 输出Outputs
outputs任意(通常回到发送方)any (usually back to sender)

限制Constraints

  • since:: 所有 cheque 输入 since = 0xA000000000000006(相对 6 epoch)every cheque input since = 0xA000000000000006 (relative 6 epochs) (11)
  • 2.a / 2.b:: 签名属于 sender,或存在 sender 输入且其 witness.lock 非空signature belongs to sender, or a sender input with non-empty witness.lock (6 / 7 / 13)
部署与来源Deployments & source 未核验unverified
源码source nervosnetwork/ckb-cheque-script@4ca3e62a · contracts/ckb-cheque-script/src (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
mainnet0xe4d4ecc6e5f9a059bf2f7a82cca292083aebc0c421566a52484fe2ec51a9fb0c type0x04632cc459…c6f8d268:0 dep_group0xcc467d7450…6e8699d10x28f25f0e9d…9ba35ec10x0a34aeea12…d43760a6 #4740722
testnet0x60d5f39efce409c587cb9ea359cefdead650ca128f0bd9cb3855348f98c70d5b type0x7f96858be0…c721ccab:0 dep_group0x67e12cba7b…ca5857030xbe734faa9e…b18e79b90x1b16769dc5…46608b6c #1223129
链上数据核对于 on-chain data checked 2026-10-20
错误码:5 InvalidArgument · 6 NoMatchedInputs · 7 WitnessSignatureWrong · 8 SenderCapacityNotSame · 9 WrongPubKey · 10 ClaimChequeInputSinceNotZero · 11 WithdrawChequeInputSinceError · 12 Secp256k1 · 13 NoMatchedSignature(签名路径的错误都会变成 13);1–4 为系统调用错误Error codes: 5 InvalidArgument · 6 NoMatchedInputs · 7 WitnessSignatureWrong · 8 SenderCapacityNotSame · 9 WrongPubKey · 10 ClaimChequeInputSinceNotZero · 11 WithdrawChequeInputSinceError · 12 Secp256k1 · 13 NoMatchedSignature (signature-path errors all surface as 13); 1–4 are syscall errors
签名路径只认 secp256k1_blake160 lock(code_hash 0x9bd7…cce8, type)The signature path only recognizes the secp256k1_blake160 lock (code_hash 0x9bd7…cce8, type)
GitHub · gpBlockchain/ckb-contract-flow-html