CKB Contract Flow

groth16-ckb 验证器 Type Script 约束groth16-ckb Verifier Type Script Constraints

来源:CECILIA-MULANDI/groth16-ckb @e969ad1 script/crates/{ckb-script,verifier-core,wire-decode,groth16-schema}、schemas/groth16.mol · testnet 0xc884…2dfb (data1),取自 README 链接的 e2e 交易 · 预审计,勿上主网Source: CECILIA-MULANDI/groth16-ckb @e969ad1 script/crates/{ckb-script,verifier-core,wire-decode,groth16-schema}, schemas/groth16.mol · testnet 0xc884…2dfb (data1), taken from the e2e tx linked in the README · pre-audit, not for mainnet
Type 脚本Type script零知识证明 / ZKZero-knowledge / ZK测试网Testnet开源Open source社区Community
贡献者:Contributed by @CECILIA-MULANDI @CECILIA-MULANDI

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

0 → 1创建触发 cell(不验证)Create a trigger cell (no verification)

Inputs 输入Inputs
任意输入(不含该 type)any inputs (without this type)——
Outputs 输出Outputs
触发 celltrigger cellCell{ type: GROTH16_VERIFIER{ args: vk_data_hash 32B }, data: any }
type.args(32B)type.args (32B)
vk_data_hash32B
  • vk_data_hash32BVK cell 数据的 blake2b-256(ckb-default-hash)blake2b-256 of the VK cell data (ckb-default-hash)长度 = 32length = 3211
vk_data_hash0x1bac22cfcd79a18a529c5038d9f795a91fbfe5dcf972a91563cba365696ab638

限制Constraints

  • scriptload_script 成功load_script succeeds10
  • script.args长度 = 32length = 3211
  • group 输入group inputs为空 → 直接返回 0(不检查 witness / VK / proof)none → return 0 immediately (no witness / VK / proof checks)—

1 → *消费触发 cell:验证 Groth16 证明Consume a trigger cell: verify the Groth16 proof

Inputs 输入Inputs
触发 cell(group 输入)trigger cell (group input)Cell{ type: GROTH16_VERIFIER{ args: vk_data_hash } }
witness[group 输入 0]witness[group input 0]WitnessArgs{ input_type: Groth16Witness }
Outputs 输出Outputs
outputs:任意outputs: any同 type 的输出也不受限制outputs with the same type are unrestricted too
witness[group 输入 0].input_type = Groth16Witness(molecule)witness[group input 0].input_type = Groth16Witness (molecule)
table hdr12B
version2B u16 LE
union id4B
proof128B
public_inputsFrVec: u32 n ‖ 32B × n
  • table hdr12Bmolecule table 头(total ‖ 2 偏移)molecule table header (total ‖ 2 offsets)结构合法well-formed17
  • version2B u16 LE线格式版本wire-format version= 1= 118
  • union id4BWitnessContent 联合:0 = Bn254WitnessWitnessContent union: 0 = Bn254Witness= 0(唯一变体)= 0 (only variant)17
  • proof128BProofBn254 { a: G1 32B, b: G2 64B, c: G1 32B }(arkworks 压缩)ProofBn254 { a: G1 32B, b: G2 64B, c: G1 32B } (arkworks compressed)可反序列化、非无穷远deserializable, not infinity2
  • public_inputsFrVec: u32 n ‖ 32B × nBN254 Fr 公开输入(小端)BN254 Fr public inputs (LE)规范编码;n + 1 = VK ic 数canonical; n + 1 = VK ic count3 / 4
header0xc2000000 0c000000 0e000000
version0x0100
union id0x00000000
proof0x3dc6d41b…637c17 (128B)
public_inputs0x01000000 ‖ 0x3100…00
示例:Pudge tx 0xc658f9e8…3c96 的 witness[0].input_type(194B)Example: witness[0].input_type of Pudge tx 0xc658f9e8…3c96 (194B)
VK cell data = Groth16VerifyingKey(molecule)VK cell data = Groth16VerifyingKey (molecule)
version2B
union id4B
alpha_g132B
beta/gamma/delta_g264B × 3
gamma_abc_g1G1Vec
  • version2B线格式版本wire-format version= 1= 118
  • union id4B0 = VerifyingKeyBn2540 = VerifyingKeyBn25414
  • alpha_g132B非无穷远not infinity1
  • beta/gamma/delta_g264B × 3非无穷远not infinity1
  • gamma_abc_g1G1VecIC 点IC points≥ 1 个,均非无穷远≥ 1, none at infinity1
cell_dep 中 data hash = type.args 的 cell;look_for_dep_with_data_hash 取第一个匹配(两个相同 data hash 的 cell 字节相同)the cell_dep whose data hash = type.args; look_for_dep_with_data_hash takes the first match (same data hash ⇒ same bytes)
cell_deps: [ verifier code, VK cell: data hash = args ]cell_deps: [ verifier code, VK cell: data hash = args ]

限制Constraints

  • scriptload_script 成功load_script succeeds10
  • script.args长度 = 32length = 3211
  • witness[group 0]可加载为 WitnessArgsloads as WitnessArgs15
  • WitnessArgs.input_type必须存在must be present16
  • cell_deps存在 data hash = args 的 cella cell with data hash = args exists12
  • VK cell可加载loadable13
  • VK cell dataGroth16VerifyingKey molecule 合法valid Groth16VerifyingKey molecule14
  • versionVK 与 witness 的 version 均 = 1VK and witness version both = 118
  • input_typeGroth16Witness molecule 合法valid Groth16Witness molecule17
  • VK重建的 arkworks VK:长度、ic_len ≥ 1、可反序列化、点非无穷远rebuilt arkworks VK: length, ic_len ≥ 1, deserializable, no infinity points1
  • proof128B、可反序列化、A/B/C 非无穷远128B, deserializable, A/B/C not infinity2
  • public_inputs长度 = 4 + 32n,Fr 规范编码length = 4 + 32n, canonical Fr3
  • public_inputsn + 1 = VK ic_lenn + 1 = VK ic_len4
  • Groth16BN254 配对检查通过BN254 pairing check passes5
部署与来源Deployments & source 未核验unverified
源码source
CECILIA-MULANDI/groth16-ckb@e969ad15 · script/crates/ckb-script/src/main.rs · script/crates/verifier-core/src/lib.rs · script/crates/wire-decode/src/lib.rs · script/crates/groth16-schema/src · schemas/groth16.mol (commit read when writing this spec (default-branch HEAD 2026-11-04). No code_hash is published; the testnet deployment is derived on chain from the cell_deps of the e2e tx 0xc658f9e8…3c96 linked in README.md (Phase 3, 2026-05-15). That code cell predates this commit, so the deployed binary may come from earlier source. Pre-audit.)
二进制核验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
testnet0xc884d0c2b45ebe5db3e559b5a2450f52defaf6945f78c5d7e9da6ed0b5852dfb data10x8e849c9650…f7d3a75e:0 code—0xc884d0c2b4…b5852dfb0x8e849c9650…f7d3a75e #21097898
链上数据核对于 on-chain data checked 2026-11-12
错误码来自 script/crates/ckb-script/src/main.rs 常量:1 INVALID_VK、2 INVALID_PROOF、3 INVALID_PUBLIC_INPUTS、4 PUBLIC_INPUT_COUNT_MISMATCH、5 VERIFICATION_FAILED、10 SCRIPT_LOAD_FAILED、11 BAD_ARGS_LENGTH、12 VK_CELL_NOT_FOUND、13 VK_LOAD_FAILED、14 VK_MOLECULE_DECODE、15 WITNESS_LOAD_FAILED、16 WITNESS_MISSING_INPUT_TYPE、17 WITNESS_MOLECULE_DECODE、18 VERSION_MISMATCH;19 UNSUPPORTED_CURVE 保留未用。Error codes are the constants in script/crates/ckb-script/src/main.rs: 1 INVALID_VK, 2 INVALID_PROOF, 3 INVALID_PUBLIC_INPUTS, 4 PUBLIC_INPUT_COUNT_MISMATCH, 5 VERIFICATION_FAILED, 10 SCRIPT_LOAD_FAILED, 11 BAD_ARGS_LENGTH, 12 VK_CELL_NOT_FOUND, 13 VK_LOAD_FAILED, 14 VK_MOLECULE_DECODE, 15 WITNESS_LOAD_FAILED, 16 WITNESS_MISSING_INPUT_TYPE, 17 WITNESS_MOLECULE_DECODE, 18 VERSION_MISMATCH; 19 UNSUPPORTED_CURVE is reserved and unused.
只验证 group 第 0 个输入的 witness:同一 group 的多个触发 cell 共用一份证明。脚本不检查输出,也不把证明绑定到交易(公开输入不含 tx 上下文),所以证明可被重放;绑定需由上层 lock / 电路实现。Only the witness of group input 0 is verified: several trigger cells in one group share one proof. The script checks no outputs and does not bind the proof to the transaction (public inputs carry no tx context), so a proof is replayable; binding must come from an outer lock / circuit.
部署来源:仓库未公布 code_hash;本页 testnet 常量取自 README 链接的 Pudge e2e 交易 0xc658f9e8…3c96 的 cell_deps(code cell 0x8e849c96…a75e:0,2026-05 部署,早于本 commit),数据哈希不在仓库中,二进制未核验。README:预审计基础设施,勿部署到主网。Deployment source: the repo publishes no code_hash; the testnet constant here is taken from the cell_deps of the Pudge e2e tx 0xc658f9e8…3c96 linked in the README (code cell 0x8e849c96…a75e:0, deployed 2026-05, before this commit). The data hash is not in the repo; binary unverified. README: pre-audit infrastructure, do not deploy to mainnet.