Noir owned counter(type)约束Noir owned counter (type) Constraints
来源:wamimi/noir-ckb-verifier @ bf09ccf / contracts/crates/owned-counter/src/main.rs · testnet 0x79d7…0a88 (data1) · 研究软件,仅测试网,单方 trusted setupSource: wamimi/noir-ckb-verifier @ bf09ccf / contracts/crates/owned-counter/src/main.rs · testnet 0x79d7…0a88 (data1) · research software, testnet only, single-party setup
给 AI agent:For AI agents: noir_owned_counter.md · llms.txt
0 → 1创建计数器(count = 0)Create counter (count = 0)
Inputs 输入Inputs
inputs[0]:任意(通常是 owner 的资金 cell)inputs[0]: any (usually the owner's funding cell)Cell{
lock: 与输出 counter 的 lock 相同
}
(不含 counter type)Cell{
lock: same lock as the output counter
}
(no counter type)
Outputs 输出Outputs
counter cell(唯一)counter cell (exactly one)Cell{
lock: secp256k1_blake160(owner 20B),
type: { codeHash: OWNED_COUNTER (data1),
args: 0x01 ‖ type_id 32B },
data: 0x01 ‖ 0u64 LE
}Cell{
lock: secp256k1_blake160(owner 20B),
type: { codeHash: OWNED_COUNTER (data1),
args: 0x01 ‖ type_id 32B },
data: 0x01 ‖ 0u64 LE
}
type.args 字节布局(33B)type.args byte layout (33B)
ver1B
type_id32B
- ver1B版本version必须 = 0x01must be 0x0141
- type_id32Btype-id(ckb-std validate_type_id)type-id (ckb-std validate_type_id)创建时 = blake2b(inputs[0] ‖ 输出序号);更新时不变on create = blake2b(inputs[0] ‖ output index); unchanged on update44
ver0x01
type_id0x6037891531ed72328710ac5a8e6c8341c05039af411f473eaecd83144b4f4740
script.hash_type 必须是 data1(否则 41)script.hash_type must be data1 (else 41)
cell data 字节布局(9B)cell data byte layout (9B)
ver1B
count8B
- ver1B版本version必须 = 0x01must be 0x0143
- count8B计数 u64 LEcounter u64 LE创建时必须 = 0(53);更新时 new = old + 1 由证明保证must be 0 on create (53); new = old + 1 is enforced by the proof43 / 53
ver0x01
count0x0100000000000000 (=1)
限制Constraints
- argsargs 长度 = 33、args[0] = 0x01、hash_type = data1args length 33, args[0] = 0x01, hash_type = data141
- txinputs / outputs / cell_deps 任一数量 ≥ 64any of inputs / outputs / cell_deps count ≥ 6452
- tx全交易中同 code_hash+hash_type 的输入 ≤ 1、输出 = 1,且 group 输出 = 1、group 输入 = 该输入数(不可销毁、不可分裂、不可合并)across the whole tx: inputs with the same code_hash+hash_type ≤ 1, outputs = 1; group outputs = 1, group inputs = that input count (no burn, split or merge)42
- argsckb-std validate_type_id(args[1..])ckb-std validate_type_id(args[1..])44
- output.data恰好 9 字节且 data[0] = 0x01exactly 9 bytes and data[0] = 0x0143
- output.lockcode_hash = secp256k1_blake160 (0x9bd7…cce8)、hash_type = type、args 20B;cell_deps(展开后)中恰好 1 个 type hash = 0x9bd7…cce8 的 cell,且其 data hash = 0x709f…8649code_hash = secp256k1_blake160 (0x9bd7…cce8), hash_type = type, args 20B; exactly one cell_dep (after expansion) with type hash 0x9bd7…cce8 and its data hash = 0x709f…864945
- syscall任何 syscall 加载失败any syscall load failure40
- output.datadata[1..9] 必须全 0data[1..9] must be all zero53
- inputs[0].lock交易第一个输入(不是 group 输入)的 lock hash = 输出 counter 的 lock hashlock hash of the tx's first input (not a group input) = output counter lock hash46
1 → 1证明授权的更新(count + 1)Proof-authorized update (count + 1)
Inputs 输入Inputs
旧 counter cell(group 输入)old counter cell (group input)Cell{
capacity: C,
lock: L,
type: OWNED_COUNTER(args),
data: 0x01 ‖ old u64
}Cell{
capacity: C,
lock: L,
type: OWNED_COUNTER(args),
data: 0x01 ‖ old u64
}
witness[group 第一个输入位置]witness[at the group's first input]WitnessArgs{
lock: owner secp256k1 签名(由 lock 检查),
input_type: Groth16Witness(proof, public)
}
总长 ≤ 512BWitnessArgs{
lock: owner secp256k1 signature (checked by the lock),
input_type: Groth16Witness(proof, public)
}
total ≤ 512B
Outputs 输出Outputs
新 counter cell(唯一)new counter cell (exactly one)Cell{
capacity: = C,
lock: = L(lock hash 相同),
type: OWNED_COUNTER(args 不变),
data: 0x01 ‖ new u64
}Cell{
capacity: = C,
lock: = L (same lock hash),
type: OWNED_COUNTER(args unchanged),
data: 0x01 ‖ new u64
}
cell data 字节布局(9B)cell data byte layout (9B)
ver1B
count8B
- ver1B版本version必须 = 0x01must be 0x0143
- count8B计数 u64 LEcounter u64 LE创建时必须 = 0(53);更新时 new = old + 1 由证明保证must be 0 on create (53); new = old + 1 is enforced by the proof43 / 53
ver0x01
count0x0100000000000000 (=1)
witness.input_type 字节布局(Groth16Witness,290B)witness.input_type byte layout (Groth16Witness, 290B)
hdr12B
version2B
union id4B
bn hdr12B
proof128B
public132B
- hdr12Bmolecule table 头:total_size + 2 个 offsetmolecule table header: total_size + 2 offsets可解码must decode48
- version2Bwire 版本 Uint16 LEwire version Uint16 LE由 wire-decode 校验checked by wire-decode48
- union id4BWitnessContent union 序号(0 = Bn254Witness)WitnessContent union id (0 = Bn254Witness)由 wire-decode 校验checked by wire-decode48
- bn hdr12BBn254Witness table 头Bn254Witness table header可解码must decode48
- proof128BA(G1 32B) ‖ B(G2 64B) ‖ C(G1 32B),arkworks 压缩A(G1 32B) ‖ B(G2 64B) ‖ C(G1 32B), arkworks compressedGroth16 验证通过Groth16 verify must pass51
- public132BFrVec:count u32 LE(=4) ‖ old ‖ new ‖ ctx_lo ‖ ctx_hi(各 32B LE)FrVec: count u32 LE(=4) ‖ old ‖ new ‖ ctx_lo ‖ ctx_hi (32B LE each)必须逐字节等于合约重建的 expectedmust equal the contract-rebuilt expected byte for byte49
header0x220100000c0000000e000000
version0x0100
union id0x00000000
bn hdr0x100100000c0000008c000000
public[0..4]0x04000000
整个 WitnessArgs ≤ 512B(读入固定缓冲区,超出即 48);lock 字段可同时携带 owner 的 secp256k1 签名。wire 格式字段名取自 crates/artifact-adapter/src/wire.rs,具体解码在外部 crate groth16-ckb@d64c769 wire-decode(未逐行阅读)Whole WitnessArgs ≤ 512B (fixed buffer, else 48); the lock field may carry the owner's secp256k1 signature. Field names from crates/artifact-adapter/src/wire.rs; decoding lives in the external crate groth16-ckb@d64c769 wire-decode (not read line by line)
expected public inputs(132B,合约重建)expected public inputs (132B, rebuilt by the contract)
n4B
old32B
new32B
ctx_lo32B
ctx_hi32B
- n4B4u32 LE4 as u32 LE= 4= 449
- old32Bold.count u64 LE,其余补 0old.count u64 LE, zero-padded= 输入 cell data[1..9]= input cell data[1..9]49
- new32Bnew.count u64 LE,其余补 0new.count u64 LE, zero-padded= 输出 cell data[1..9]= output cell data[1..9]49
- ctx_lo32Bdigest[0..16],其余补 0digest[0..16], zero-paddeddigest 见下方digest see below49
- ctx_hi32Bdigest[16..32],其余补 0digest[16..32], zero-paddeddigest 见下方digest see below49
digest = blake2b_ckb("noir-ckb/owned-counter/context/v1\0" ‖ NETWORK_DOMAIN(测试网 genesis 哈希) ‖ blake2b_ckb("noir-ckb/owned-counter/v1") ‖ 本 type script hash ‖ args[1..33] ‖ 0x01 ‖ 被消耗 cell 的 OutPoint(36B) ‖ old data 9B ‖ new data 9B ‖ 输出 lock hash ‖ 输出 capacity u64 LE)digest = blake2b_ckb("noir-ckb/owned-counter/context/v1\0" ‖ NETWORK_DOMAIN (testnet genesis hash) ‖ blake2b_ckb("noir-ckb/owned-counter/v1") ‖ this type script hash ‖ args[1..33] ‖ 0x01 ‖ consumed cell OutPoint (36B) ‖ old data 9B ‖ new data 9B ‖ output lock hash ‖ output capacity u64 LE)
cell_deps: [ secp256k1 dep_group, OWNED_COUNTER code, VK cell (data hash 0x685b…58fe) ]
限制Constraints
- argsargs 长度 = 33、args[0] = 0x01、hash_type = data1args length 33, args[0] = 0x01, hash_type = data141
- txinputs / outputs / cell_deps 任一数量 ≥ 64any of inputs / outputs / cell_deps count ≥ 6452
- tx全交易中同 code_hash+hash_type 的输入 ≤ 1、输出 = 1,且 group 输出 = 1、group 输入 = 该输入数(不可销毁、不可分裂、不可合并)across the whole tx: inputs with the same code_hash+hash_type ≤ 1, outputs = 1; group outputs = 1, group inputs = that input count (no burn, split or merge)42
- argsckb-std validate_type_id(args[1..])ckb-std validate_type_id(args[1..])44
- output.data恰好 9 字节且 data[0] = 0x01exactly 9 bytes and data[0] = 0x0143
- output.lockcode_hash = secp256k1_blake160 (0x9bd7…cce8)、hash_type = type、args 20B;cell_deps(展开后)中恰好 1 个 type hash = 0x9bd7…cce8 的 cell,且其 data hash = 0x709f…8649code_hash = secp256k1_blake160 (0x9bd7…cce8), hash_type = type, args 20B; exactly one cell_dep (after expansion) with type hash 0x9bd7…cce8 and its data hash = 0x709f…864945
- syscall任何 syscall 加载失败any syscall load failure40
- input.data旧 cell data 恰好 9 字节且 data[0] = 0x01old cell data exactly 9 bytes and data[0] = 0x0143
- lock输入与输出的 lock hash 相同(不可转让)input and output lock hash equal (non-transferable)46
- capacity输出 capacity = 输入 capacityoutput capacity = input capacity47
- witnesswitness 缺失 / 超 512B / 非 WitnessArgs / 无 input_type / wire 解码失败witness missing / > 512B / not WitnessArgs / no input_type / wire decode fails48
- public证明中的 public inputs ≠ 重建的 expected(132B)proof public inputs ≠ rebuilt expected (132B)49
- cell_depsdata hash = VK_DATA_HASH 的 cell_dep 必须恰好 1 个,读入 ≤ 512B 且可解码exactly one cell_dep with data hash = VK_DATA_HASH, ≤ 512B and decodable50
- proofGroth16(BN254) 验证失败Groth16 (BN254) verification fails51
部署与来源Deployments & source 未核验unverified
源码source
wamimi/noir-ckb-verifier@bf09ccfa · contracts/crates/owned-counter/src/main.rs · contracts/crates/owned-counter/build.rs · crates/artifact-adapter/src/wire.rs · circuits/owned-counter-v1/src/main.nr (commit read when writing this spec; deployment constants from releases/owned-counter-v1-testnet/manifest.json and evidence/week-15-testnet.md)
二进制核验binary check
未核验unverified the committed release binary at this commit matches the deployed data hash, but building it from source (with the pinned policy env + VK) was not reproduced, so status stays unverified
0x79d7e7614f…2b7d0a88: listed in evidence/week-15-public/deployment.json; committed release binary releases/owned-counter-v1-testnet/owned-counter hashes (blake2b ckb) to this data hash
0x79d7e7614f…2b7d0a88: listed in evidence/week-15-public/deployment.json; committed release binary releases/owned-counter-v1-testnet/owned-counter hashes (blake2b ckb) to this data hash
| 网络network | code_hash | cell_dep | type_id args | 数据哈希data hash | 部署交易deploy tx |
|---|---|---|---|---|---|
| testnet | 0x79d7e7614ff1689cb6c6fbbd376ab2fa959dc92394abea35cbafb1bd2b7d0a88 data1 | 0x0ee39d5471…44f27ad1:0 code | — | 0x79d7e7614f…2b7d0a88 | 0x0ee39d5471…44f27ad1 #22664421 |
链上数据核对于 on-chain data checked 2026-10-29
错误码(main.rs):40 LOAD · 41 ARGS · 42 SHAPE · 43 STATE · 44 ID · 45 OWNER · 46 OWNER_CHANGED · 47 CAPACITY · 48 WITNESS · 49 PUBLIC · 50 VK · 51 PROOF · 52 LIMIT · 53 INITError codes (main.rs): 40 LOAD · 41 ARGS · 42 SHAPE · 43 STATE · 44 ID · 45 OWNER · 46 OWNER_CHANGED · 47 CAPACITY · 48 WITNESS · 49 PUBLIC · 50 VK · 51 PROOF · 52 LIMIT · 53 INIT
NETWORK_DOMAIN / OWNER_CODE_HASH / OWNER_DATA_HASH / VK_DATA_HASH 是编译期常量(build.rs 从环境变量写入);测试网部署值见 releases/owned-counter-v1-testnet/manifest.jsonNETWORK_DOMAIN / OWNER_CODE_HASH / OWNER_DATA_HASH / VK_DATA_HASH are build-time constants (build.rs reads env vars); testnet values in releases/owned-counter-v1-testnet/manifest.json
没有销毁路径:任何交易都必须恰好输出 1 个 counter cell(42)No burn path: every tx must output exactly one counter cell (42)
同仓库的 capsule-binding(早期示例)与 private-tally(v2,设计已定未部署)未收录:无官方部署capsule-binding (earlier example) and private-tally (v2, designed, not deployed) in the same repo are not included: no official deployment
NETWORK_DOMAIN / OWNER_CODE_HASH / OWNER_DATA_HASH / VK_DATA_HASH 是编译期常量(build.rs 从环境变量写入);测试网部署值见 releases/owned-counter-v1-testnet/manifest.jsonNETWORK_DOMAIN / OWNER_CODE_HASH / OWNER_DATA_HASH / VK_DATA_HASH are build-time constants (build.rs reads env vars); testnet values in releases/owned-counter-v1-testnet/manifest.json
没有销毁路径:任何交易都必须恰好输出 1 个 counter cell(42)No burn path: every tx must output exactly one counter cell (42)
同仓库的 capsule-binding(早期示例)与 private-tally(v2,设计已定未部署)未收录:无官方部署capsule-binding (earlier example) and private-tally (v2, designed, not deployed) in the same repo are not included: no official deployment