CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

From one fix

155 lessons found. All lessons

Page 10 of 13

Molecule table encoding of absent optional fieldsWorkingFrom one fix

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 · Sources (1) · 2026-10-09

CKB blake160 is the first 20 bytes of the 32 byte ckbhashBasicFrom one fix

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 · Sources (1) · 2026-10-09

Type Script group membership and group witness index derived from the full script hashWorkingFrom one fix

When locating a Type Script group off chain, match input and output cells by the blake2b hash of the complete Script (code_hash, hash_type, args), never by code hash alone. By convention (RFC 22 for lock groups), a group's witness sits at the transaction index of its first input, or of its first output if the group has no inputs. CKB does not enforce this: the script picks which witness it reads, and which WitnessArgs field (input_type or output_type) holds the data is the protocol's own choice.

#Witnesses and signatures #Transaction building and fees · Sources (1) · 2026-10-09

Script hash_type selects the VM version: data2 (4) or type (1) for a VM2 targetWorkingFrom one fix

CKB picks the VM version from the Script hash_type: data (0) runs VM0, data1 (2) runs VM1, data2 (4) runs VM2, and type (1) runs the latest activated VM. Code deployed for VM2 and pinned by data hash must be referenced with hash_type data2. The same code hash with data or data1 still resolves to the same cell but runs under an older VM, so tooling should reject those hash types for a VM2 target rather than only checking that the code hash matches.

#Cell deps and script lookup #Type ID and upgrades · Sources (1) · 2026-10-09

Secp256k1 sighash lock groups cover non contiguous later group witnessesWorkingFrom one fix

With the bundled secp256k1 blake160 sighash lock, all inputs sharing the same lock form one group even when another owner's inputs sit between them. The signature goes in the witness at the group's first input index, and changing a later group witness (which leaves the tx hash unchanged) still fails verification at Inputs[first].Lock. So composed multi owner transactions must place one signature placeholder per lock group at its first input and finalize every group witness before signing.

#Witnesses and signatures #Transaction building and fees · Sources (1) · 2026-10-09

Reconstructing the live cell set at a past height from the CKB indexerAdvancedFrom one fix

The indexer's get_cells lists only cells live at its current tip. To get Nervos DAO deposits live at height H, read the indexer tip, list get_cells and keep those with block_number <= H, then read the indexer tip again as T. Then query get_transactions on the DAO type script with filter block_range [H+1, T+1) (the end is exclusive), keep io_type input, follow each input's previous_output to the creating tx and its header, and add back cells created at or below H. In both passes keep only real deposits (DAO type and 8 zero bytes of data), since withdrawing cells share the type script, and retry if either tip hash is no longer canonical per get_block_hash.

#Indexer queries and cell collection #Network and RPC reliability · Sources (1) · 2026-10-08

Verify a self indexed tip against the node's canonical block hash before serving itWorkingFrom one fix

A locally maintained index of CKB blocks can lag the node or still hold an orphaned block after a reorg, so before serving its tip as an anchor, fetch the node's tip number, wait briefly for the index to reach it, then ask the node for the canonical block hash at the indexed height and refuse (503 with NOT_SYNCED or REORGANIZING) unless it equals the indexed hash. The check narrows the window but is not atomic, so a client that signs over the anchor should also compare it with an independent source.

#Network and RPC reliability #Indexer queries and cell collection · Sources (1) · 2026-10-08

Wait for tx_pool_info tip to match chain tip before submitting on devnetWorkingFrom one fix

After generate_block, CKB's tx pool updates its snapshot asynchronously, so a transaction spending just-committed outputs can be rejected (e.g. "Resolve failed Unknown") even though get_live_cell sees them. Before send_transaction or send_test_transaction, poll tx_pool_info until its tip_hash and tip_number equal get_tip_header's hash and number.

#Testing and devnet #Network and RPC reliability · Sources (1) · 2026-10-08

CKB node script debug logs may use ckb_script::verify target, not only ckb-scriptWorkingFrom one fix

When filtering a CKB node's run.log or log subscription for contract debug output (ckb_debug / debug! syscalls), records can come with target `ckb_script` or a `ckb_script::` submodule such as `ckb_script::verify` rather than the legacy `ckb-script` target. For those targets, match only messages containing `DEBUG OUTPUT:`, because the same target also emits ordinary verification lines.

#Testing and devnet · Sources (1) · 2026-10-08

Wait for the indexer to reach the block before truncating the devnet chain in reorg testsWorkingFrom one fix

In a devnet reorg test, the inclusion status a client reads from the node does not mean your own indexing service has processed that block. Before truncating the chain below block n, poll that service's indexed block number until it reaches n. Otherwise it never sees the block, never records a rollback, and the test times out on slow CI runners.

#Testing and devnet #Indexer queries and cell collection · Sources (1) · 2026-10-08

EVM owners may hold Omnilock lock args with auth flag 0x12, not only 0x01WorkingFrom one fix

When mapping an Ethereum address to the CKB lock scripts it controls, match Omnilock args 0x12 || addr20 || 0x00 (Ethereum displaying, used by CCC's EVM signer for new addresses) as well as 0x01 || addr20 || 0x00 and PW Lock args = addr20. Otherwise deposits held by CCC created EVM addresses are not recognised. The commit notes this is still pending confirmation in a wallet proof of concept.

#Witnesses and signatures #Login and authorization · Sources (1) · 2026-10-08

Verifying Neuron style signed messages against a secp256k1_blake160 lockWorkingFrom one fix

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) · Sources (2) · 2026-10-08

Page 10 of 13

Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. JSON · Want a lesson changed or removed? Open an issue.