CKB Pulse
经验

CKB 学到了什么

从这里开始 · 术语表 · 自测 · 订阅

经验用英文撰写,请用英文搜索。

#Data encoding (molecule, hex, bigints)

找到 44 条经验。 全部经验

第 3 页,共 4 页

Omnilock owner signing needs an 85 byte zeroed witness lock placeholder实践来自一次修复

For an Omnilock cell spent in owner (secp256k1) mode, the WitnessArgs.lock is an 85 byte OmniLockWitnessLock (a 20 byte molecule header 0x5500000010000000550000005500000041000000 plus the 65 byte signature), so the sighash digest must be computed with an 85 byte zeroed placeholder (e.g. CCC prepareSighashAllWitness(lock, 85, client)). A digest taken over the usual 65 byte secp256k1 placeholder does not verify, which the test confirms against a real testnet spend.

#Witnesses and signatures #Data encoding (molecule, hex, bigints) · 来源(2) · 2026-10-23

Recognizing a Nervos DAO deposit cell (not a withdrawing one)实践再次出现

Treat a cell as a Nervos DAO deposit only if its type script exactly matches the DAO type script and its data is exactly 8 zero bytes. The DAO type script has code hash 0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e, hash_type type and empty args. A phase one withdrawing cell has the same type script but a nonzero block number in its 8 data bytes, so it fails this check, as do data of any other length and look alike type scripts.

joined with the ckb-service-runner card teaching the same check

#Indexer queries and cell collection #Data encoding (molecule, hex, bigints) · 来源(2) · 2026-10-20

Strict validation of molecule table headers in hand written decoders实践来自一次修复

When decoding a molecule table by hand (here, the CSR registry cell data), check that the leading u32 total size equals the data length, derive the field count as first_offset/4 - 1, and require first_offset == 4 + 4*count and ascending offsets. Reject a field count different from the schema; this parser is strict and does not accept extra trailing fields, so truncated, padded or extended tables raise ValueError, as the tests show.

table header validation, distinct from WitnessArgs encoding lesson

#Data encoding (molecule, hex, bigints) · 来源(1) · 2026-10-19

Transaction size for fee rate is serialized bytes plus 4实践来自一次修复

To get a transaction's size as the node counts it, take the molecule serialized size of the full transaction with witnesses (for example ccc.Transaction.from(...).toBytes().length) and add 4 bytes for its offset in the block. A size-based fee rate is fee * 1000 / size in shannons per 1000 bytes; the node's pool actually uses weight, the larger of size and cycles scaled, so it can be higher for cycle-heavy transactions. get_transaction returns snake_case JSON, so map the fields (code_hash to codeHash, dep_type dep_group to depGroup) before passing it to ccc.Transaction.from.

#Transaction building and fees #Data encoding (molecule, hex, bigints) · 来源(1) · 2026-10-17

Address balance via get_cells_capacity with snake_case lock script实践来自一次修复

To show a CKB address balance, convert the address to a lock script (ckb-sdk-utils addressToScript returns camelCase codeHash/hashType) and pass it to the indexer RPC get_cells_capacity with snake_case fields (code_hash, hash_type, args) and script_type "lock". The returned capacity is a hex shannon string, so parse it with BigInt and divide by 10^8 for CKB.

#Indexer queries and cell collection #Data encoding (molecule, hex, bigints) · 来源(1) · 2026-10-15

Convert Fiber RPC snake_case scripts to CCC camelCase ScriptLike实践已复现

Fiber RPC returns scripts as { code_hash, hash_type, args }, but CCC's ScriptLike expects { codeHash, hashType, args }. In this commit a Fiber shaped lock was passed to a CCC based sweep as if it were a ccc.ScriptLike and the sweep failed, so map the fields explicitly before handing the script to CCC.

#Data encoding (molecule, hex, bigints) #Channels and payments · 来源(1) · 2026-10-14

Computing a transaction's molecule packed size from RPC JSON进阶来自一次修复

A CKB Transaction's packed size (the length of get_transaction with verbosity 0) can be computed from its RPC JSON without serializing it. It is 12 (table header) + RawTransaction + witnesses. RawTransaction is 28 (table header) + 4 (version) + cell_deps (4 + 37 each) + header_deps (4 + 32 each) + inputs (4 + 44 each) + outputs + outputs_data. Each CellOutput is 16 + 8 + lock size, plus the type script size only when a type is present. Each Script is 53 + len(args). A dynvec costs 4 + 4 * count + the sum of its item sizes, and every Bytes item in outputs_data and witnesses costs 4 + len.

#Data encoding (molecule, hex, bigints) #Transaction building and fees · 来源(1) · 2026-10-10

Molecule table encoding of absent optional fields实践来自一次修复

A molecule table or dynvec (Script, CellOutput, WitnessArgs) is serialized as a u32 total size, then one u32 offset per field, then the fields. There is no separate count; readers derive it from the first offset. An absent Opt field takes zero bytes, so its offset equals the next offset, or the total size if it is last. A hand-rolled encoder that inserts a u32 count after the total size, as this commit's dyn_collection does, produces malformed molecule.

#Data encoding (molecule, hex, bigints) #Witnesses and signatures · 来源(1) · 2026-10-09

CKB blake160 is the first 20 bytes of the 32 byte ckbhash基础来自一次修复

CKB blake160, used for lock args and pubkey hashes, is the first 20 bytes of the 32 byte blake2b digest personalized with "ckb-default-hash". A blake2b hasher configured with a 20 byte output length gives a different value, because the digest length is part of blake2b's parameter block. Always hash to 32 bytes and then truncate.

#Data encoding (molecule, hex, bigints) #Witnesses and signatures · 来源(1) · 2026-10-09

Matching a Script code_hash to its code Cell by hash_type实践再次出现

To check that a Script points at a given deployed code Cell, compare its code_hash with ckb blake2b256 of the Cell's output data when hash_type is data, data1 or data2 (0, 2, 4), and with the hash of that Cell's Type Script when hash_type is type (1). A type selection needs the code Cell to actually carry a Type Script, and other hash_type values are rejected.

#Cell deps and script lookup #Data encoding (molecule, hex, bigints) · 来源(2) · 2026-10-09

Verifying Neuron style signed messages against a secp256k1_blake160 lock实践来自一次修复

To verify a Neuron "Sign Message" signature, hash with CKB Blake2b over UTF-8("Nervos Message:" followed by the text), recover the compressed public key from the 65 byte r||s||v signature (v is 0 or 1, not 27/28), and accept the owner only if the lock has the exact code_hash and hash_type of the secp256k1_blake160 template and its args equal blake160 of the recovered key (comparing args alone is not enough). Neuron signs low-s; if you choose to also accept high-s, normalise s to n minus s and flip v before recovery, because some verify helpers (CCC's) reject high-s.

#Witnesses and signatures #Data encoding (molecule, hex, bigints) · 来源(2) · 2026-10-08

Parse raw CKB blocks with from_compatible_slice to accept BlockV1 extension实践来自一次修复

Serialized CKB blocks may be BlockV1, which appends a consensus extension field after the Block molecule fields, so a strict packed::BlockReader::from_slice can reject them. This commit parses block bytes with ckb-gen-types 1.1.1 packed::BlockReader::from_compatible_slice, which accepts the extra field while still exposing header() and transactions().

#Data encoding (molecule, hex, bigints) · 来源(1) · 2026-10-07

第 3 页,共 4 页

文本采用 CC BY 4.0:请署名 LusoCryptoLabs, CKB lessons,并附上经验的链接。 JSON · 想修改或撤下某条经验?请提交 issue。