CKB Contract Flow

zk-Lock(Groth16 证明解锁)约束zk-Lock (Groth16 proof-unlocked) Constraints

来源:CECILIA-MULANDI/zk-Lock @699c63a crates/zk-lock-core/src、contracts/zk-lock、contracts/zk-lock-bound · Pudge 测试网 generic 0x2417…fa7b (type) / bound 0xfbb4…028e (type) · 部署见 README.md「Pudge testnet」Source: CECILIA-MULANDI/zk-Lock @699c63a crates/zk-lock-core/src, contracts/zk-lock, contracts/zk-lock-bound · Pudge testnet generic 0x2417…fa7b (type) / bound 0xfbb4…028e (type) · deployments in README.md "Pudge testnet"
Lock 脚本Lock script身份 / 钱包Identity / wallet零知识证明 / ZKZero-knowledge / ZK测试网Testnet开源Open source社区Community
贡献者:Contributed by @CECILIA-MULANDI @CECILIA-MULANDI

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

0 → 1锁定:创建 zk-Lock cell(lock 不运行)Lock: create a zk-Lock cell (lock does not run)

Inputs 输入Inputs
任意输入any inputs由各自的 lock 授权authorized by their own locks
Outputs 输出Outputs
zk-Lock cellzk-Lock cellCell{ capacity: C, lock: ZK_LOCK{ args: vk_hash ‖ pi_commitment }, type: 任意 }Cell{ capacity: C, lock: ZK_LOCK{ args: vk_hash ‖ pi_commitment }, type: any }
lock.args 字节布局(64B)lock.args byte layout (64B)
vk_hash32B
pi_commitment32B
  • vk_hash32B验证密钥 cell 的 data hash(blake2b-256, ckb-default-hash)data hash of the verifying-key cell (blake2b-256, ckb-default-hash)恰好 1 个 cell_dep 的 data hash 等于它exactly one cell_dep has this data hash14 / 21
  • pi_commitment32B公开输入承诺 = blake2b-256(公开输入字节);bound 模式下不含第 0 个public-input commitment = blake2b-256(public-input bytes); excludes input 0 in bound mode= blake2b(witness 中的公开输入体)= blake2b(public-input body in witness)15
vk_hash0x58480ee31438fa04fd733af8ec1821498462be31ffa89694d5b6de76bbfffab5
pi_commitment0x2567e69254d608455e5a462e0d8d74dd32b89920a58b1a0d8930ba26549bc675
示例:Pudge 测试网 tx 0x929a6507…ecd5 输出 0 的 lock.args;总长必须恰好 64 字节,否则 10Example: lock.args of output 0 in Pudge tx 0x929a6507…ecd5; length must be exactly 64 bytes, else 10

1 → Ngeneric 解锁(Binding::None,contracts/zk-lock):任意交易中提交有效证明Generic unlock (Binding::None, contracts/zk-lock): any valid proof, in any transaction

Inputs 输入Inputs
zk-Lock cell(group 输入)zk-Lock cell (group input)Cell{ lock: ZK_LOCK(0x2417…fa7b){ args: vk_hash ‖ pi_commitment } }
witnessWitnessArgs{ lock: proof(128) ‖ pi_count u32 ‖ pi × 32 }
Outputs 输出Outputs
outputs:任意outputs: any不检查输出outputs not checked
witness.lock 字节布局(WitnessArgs.lock,位于 group 第一个输入的下标)witness.lock byte layout (WitnessArgs.lock at the group's first input index)
proof.A32B
proof.B64B
proof.C32B
pi_count4B u32 LE
pi × n32B × n
  • proof.A32BG1 压缩点(arkworks)G1 compressed (arkworks)非无穷远点,可反序列化not infinity, deserializable17
  • proof.B64BG2 压缩点G2 compressed非无穷远点not infinity17
  • proof.C32BG1 压缩点G1 compressed非无穷远点not infinity17
  • pi_count4B u32 LE公开输入个数 nnumber of public inputs n总长 = 128 + 4 + 32n;n + 1 = VK 的 ic_lentotal = 128 + 4 + 32n; n + 1 = VK ic_len13 / 19
  • pi × n32B × nBN254 Fr 元素(小端,规范编码)BN254 Fr elements (LE, canonical)< 模数< modulus18
proof0x3dc6d41b…637c17 (128B)
pi_count0x01000000 (= 1)
pi[0]0x3100000000000000000000000000000000000000000000000000000000000000
示例:Pudge tx 0xc967684e…7571 的 witness.lock(164B);blake2b(pi[0]) = 0x2567e692…c675 = args[32..64]Example: witness.lock of Pudge tx 0xc967684e…7571 (164B); blake2b(pi[0]) = 0x2567e692…c675 = args[32..64]
VK cell data(arkworks 压缩 VerifyingKey<Bn254>,原始字节,非 molecule)VK cell data (arkworks-compressed VerifyingKey<Bn254>, raw bytes, not molecule)
alpha_g132B
beta_g264B
gamma_g264B
delta_g264B
ic_len8B u64 LE
gamma_abc_g132B × ic_len
  • alpha_g132BG1G1非无穷远点not infinity16
  • beta_g264BG2G2非无穷远点not infinity16
  • gamma_g264BG2G2非无穷远点not infinity16
  • delta_g264BG2G2非无穷远点not infinity16
  • ic_len8B u64 LEgamma_abc_g1 个数number of gamma_abc_g1 points≥ 1;总长 = 232 + 32·ic_len≥ 1; total = 232 + 32·ic_len16
  • gamma_abc_g132B × ic_lenG1 点G1 points均非无穷远点none at infinity16
来自 groth16-ckb verifier-core(zk-lock-core 依赖 rev e969ad1)。该 cell 只作为 cell_dep,不被 zk-Lock 消费From groth16-ckb verifier-core (zk-lock-core pins rev e969ad1). The cell is only a cell_dep; zk-Lock never consumes it
cell_deps: [ zk-Lock code, VK cell: data hash = vk_hash(恰好 1 个) ]cell_deps: [ zk-Lock code, VK cell: data hash = vk_hash (exactly one) ]

限制Constraints

  • script.args长度 = 64 字节length = 64 bytes10
  • cell_depsdata hash = vk_hash 的 cell_dep 恰好 1 个;出现 2 个exactly one cell_dep with data hash = vk_hash; a second one先检测重复(21),再检测缺失(14)duplicate checked first (21), then missing (14)21
  • cell_deps找不到 data hash = vk_hash 的 cell_depno cell_dep with data hash = vk_hash14
  • witness[group 0].lockWitnessArgs.lock 必须存在WitnessArgs.lock must be presentwitness 不是合法 WitnessArgs 时由 ckb-std 返回 SysError → 4(Encoding);witness 缺失 → 1(IndexOutOfBound)if the witness is not valid WitnessArgs ckb-std returns SysError → 4 (Encoding); missing witness → 1 (IndexOutOfBound)11
  • witness.lock长度 ≥ 132(128 proof + 4 pi_count)length ≥ 132 (128 proof + 4 pi_count)12
  • witness.lock长度 = 128 + 4 + 32 × pi_countlength = 128 + 4 + 32 × pi_count13
  • pi_commitmentblake2b-256(全部公开输入字节,不含 pi_count) = args[32..64]blake2b-256(all public-input bytes, without pi_count) = args[32..64]15
  • VK cell data长度 ≥ 232、ic_len ≥ 1、长度 = 232 + 32·ic_len、点可反序列化且非无穷远length ≥ 232, ic_len ≥ 1, length = 232 + 32·ic_len, points deserialize and are not infinity16
  • proof128 字节、可反序列化、A/B/C 非无穷远128 bytes, deserializable, A/B/C not infinity17
  • public inputs每个 Fr 为规范编码each Fr canonically encoded18
  • pi_countpi_count + 1 = VK ic_lenpi_count + 1 = VK ic_len19
  • Groth16BN254 配对检查通过BN254 pairing check passes20

1 → N交易绑定解锁(Binding::Transaction,contracts/zk-lock-bound):pi[0] = tx_hash 标量Transaction-bound unlock (Binding::Transaction, contracts/zk-lock-bound): pi[0] = tx_hash scalar

Inputs 输入Inputs
zk-Lock bound cell(group 输入)zk-Lock bound cell (group input)Cell{ lock: ZK_LOCK_BOUND(0xfbb4…028e){ args: vk_hash ‖ pi_commitment(pi[1..n]) } }
witnessWitnessArgs{ lock: proof(128) ‖ pi_count u32 ‖ pi[0]=ctx ‖ pi[1..n] }
Outputs 输出Outputs
outputs:被 tx_hash 固定outputs: pinned by tx_hash任何字段变化都会改变 tx_hash → pi[0] 不匹配any change alters tx_hash → pi[0] mismatch
pi[0]:交易上下文标量(32B)pi[0]: transaction-context scalar (32B)
tx_hash[0..31]31B
0x001B
  • tx_hash[0..31]31B当前交易 tx_hash 的前 31 字节(不含 witness)first 31 bytes of this tx_hash (witnesses excluded)逐字节相等byte-equal22
  • 0x001B最高字节清零,保证 < BN254 模数top byte cleared to stay < BN254 modulus= 0x00= 0x0022
pi_commitment 只覆盖 pi[1..n];配对检查使用包含 pi[0] 的完整向量pi_commitment covers pi[1..n] only; the pairing check uses the full vector including pi[0]
witness.lock 字节布局(WitnessArgs.lock,位于 group 第一个输入的下标)witness.lock byte layout (WitnessArgs.lock at the group's first input index)
proof.A32B
proof.B64B
proof.C32B
pi_count4B u32 LE
pi × n32B × n
  • proof.A32BG1 压缩点(arkworks)G1 compressed (arkworks)非无穷远点,可反序列化not infinity, deserializable17
  • proof.B64BG2 压缩点G2 compressed非无穷远点not infinity17
  • proof.C32BG1 压缩点G1 compressed非无穷远点not infinity17
  • pi_count4B u32 LE公开输入个数 nnumber of public inputs n总长 = 128 + 4 + 32n;n + 1 = VK 的 ic_lentotal = 128 + 4 + 32n; n + 1 = VK ic_len13 / 19
  • pi × n32B × nBN254 Fr 元素(小端,规范编码)BN254 Fr elements (LE, canonical)< 模数< modulus18
proof0x3dc6d41b…637c17 (128B)
pi_count0x01000000 (= 1)
pi[0]0x3100000000000000000000000000000000000000000000000000000000000000
示例:Pudge tx 0xc967684e…7571 的 witness.lock(164B);blake2b(pi[0]) = 0x2567e692…c675 = args[32..64]Example: witness.lock of Pudge tx 0xc967684e…7571 (164B); blake2b(pi[0]) = 0x2567e692…c675 = args[32..64]
cell_deps: [ zk-Lock-bound code, VK cell: data hash = vk_hash(恰好 1 个) ]cell_deps: [ zk-Lock-bound code, VK cell: data hash = vk_hash (exactly one) ]

限制Constraints

  • script.args长度 = 64 字节length = 64 bytes10
  • cell_depsdata hash = vk_hash 的 cell_dep 恰好 1 个;出现 2 个exactly one cell_dep with data hash = vk_hash; a second one先检测重复(21),再检测缺失(14)duplicate checked first (21), then missing (14)21
  • cell_deps找不到 data hash = vk_hash 的 cell_depno cell_dep with data hash = vk_hash14
  • witness[group 0].lockWitnessArgs.lock 必须存在WitnessArgs.lock must be presentwitness 不是合法 WitnessArgs 时由 ckb-std 返回 SysError → 4(Encoding);witness 缺失 → 1(IndexOutOfBound)if the witness is not valid WitnessArgs ckb-std returns SysError → 4 (Encoding); missing witness → 1 (IndexOutOfBound)11
  • witness.lock长度 ≥ 132(128 proof + 4 pi_count)length ≥ 132 (128 proof + 4 pi_count)12
  • witness.lock长度 = 128 + 4 + 32 × pi_countlength = 128 + 4 + 32 × pi_count13
  • pi_count≥ 1(需要保留 pi[0])≥ 1 (pi[0] must exist)23
  • pi_commitmentblake2b-256(pi[1..n]) = args[32..64]blake2b-256(pi[1..n]) = args[32..64]15
  • pi[0]= tx_hash[0..31] ‖ 0x00= tx_hash[0..31] ‖ 0x0022
  • VK cell data长度 ≥ 232、ic_len ≥ 1、长度 = 232 + 32·ic_len、点可反序列化且非无穷远length ≥ 232, ic_len ≥ 1, length = 232 + 32·ic_len, points deserialize and are not infinity16
  • proof128 字节、可反序列化、A/B/C 非无穷远128 bytes, deserializable, A/B/C not infinity17
  • public inputs每个 Fr 为规范编码each Fr canonically encoded18
  • pi_countpi_count + 1 = VK ic_lenpi_count + 1 = VK ic_len19
  • Groth16BN254 配对检查通过BN254 pairing check passes20
部署与来源Deployments & source 未核验unverified
源码source
CECILIA-MULANDI/zk-Lock@699c63a7 · crates/zk-lock-core/src/lib.rs · crates/zk-lock-core/src/error.rs · contracts/zk-lock/src/main.rs · contracts/zk-lock-bound/src/main.rs (commit read when writing this spec (default-branch HEAD 2026-11-11); verifier-core read at CECILIA-MULANDI/groth16-ckb@e969ad154ea2c00df57f68238ddfbcbc9ceb1419 (the rev zk-lock-core pins). Deployment constants from README.md "Pudge testnet" and web/src/lib/config.ts. The generic code cell data hash 0x6aec96e2… is not listed in the repo (only the zk-lock-bound hash 0x21f2173b… is, in README.md); neither binary was rebuilt here.)
二进制核验binary check
未核验unverified no binary or checksum at the recorded commit matched the deployed data hash (reproducible build not attempted)
0x21f2173b72…4f191c2d: listed in README.md
网络networkcode_hashcell_deptype_id args数据哈希data hash部署交易deploy tx
testnet0x24172f2dc2ebd6634fe925a6f0beda7cfd4cdb9aab1214f2e1cbd3127ea1fa7b type0x7d80c7a278…fd0e06fb:0 code0x2fd91958f4…10f925c00x6aec96e2a9…30658f330x7d80c7a278…fd0e06fb #22278058
testnet0xfbb4acb5c3f8fc8b24216dc8dc8d6bb8f8d3ea9aab4b29a210571959a1f9028e type0x5f21b4d1e6…5b004011:0 code0x6efafd3260…ea52c74c0x21f2173b72…4f191c2d0x5f21b4d1e6…5b004011 #23029367
链上数据核对于 on-chain data checked 2026-11-12
错误码来自 crates/zk-lock-core/src/error.rs(#[repr(i8)]):1–5 为 ckb-std SysError 映射(1 IndexOutOfBound、2 ItemMissing、3 LengthNotEnough、4 Encoding、5 其他),10–23 为业务错误。检查顺序固定:10 → 21/14 → 11 → 12 → 13 →(bound: 23)→ 15 →(bound: 22)→ 16–20。Error codes from crates/zk-lock-core/src/error.rs (#[repr(i8)]): 1–5 map ckb-std SysError (1 IndexOutOfBound, 2 ItemMissing, 3 LengthNotEnough, 4 Encoding, 5 other); 10–23 are script errors. The check order is fixed: 10 → 21/14 → 11 → 12 → 13 → (bound: 23) → 15 → (bound: 22) → 16–20.
只读取 group 第 0 个输入的 witness:同一 group 的多个 cell 用一份证明一起解锁。generic 模式不检查输出,witness 可被任何看到它的人重放(README 也如此说明);bound 模式用 tx_hash 绑定整笔交易。Only the witness of group input 0 is read: several cells in one group unlock with one proof. Generic mode checks no outputs, so the witness is replayable by anyone who sees it (as the README states); bound mode binds the whole tx via tx_hash.
16–20 来自 groth16-ckb verifier-core(rev e969ad1)的 VerifyError;VK 在 zk-Lock 中是原始 arkworks 字节,而不是 groth16-ckb 类型脚本使用的 molecule Groth16VerifyingKey。16–20 come from groth16-ckb verifier-core (rev e969ad1) VerifyError; in zk-Lock the VK is raw arkworks bytes, not the molecule Groth16VerifyingKey used by the groth16-ckb type script.
解码器离线检查:args 长度、witness 长度、pi_commitment、bound 模式的 pi[0];VK cell_dep 查找与 Groth16 配对检查无法离线完成(NOT_CHECKED)。项目自述为测试网 / 未审计。The decoder checks offline: args length, witness length, pi_commitment, and pi[0] in bound mode; the VK cell_dep lookup and Groth16 pairing cannot be done offline (NOT_CHECKED). The project describes itself as testnet / unaudited.