CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

From one fix

155 lessons found. All lessons

Page 4 of 13

Separate submit and commit verification environmentsAdvancedFrom one fix

When verifying a transaction offline with ckb-script, use TxVerifyEnv::new_submit(&tip) for the submit phase. It evaluates since at tip number + 1 + proposal_window.closest, so it is more permissive than inclusion in the next block. For the commit phase, use TxVerifyEnv::new_commit(&candidate), where candidate is a header whose parent_hash is the real tip and whose number is tip + 1, and take median time from env.parent_hash() rather than tip.parent_hash().

#Since and time locks #Testing and devnet · Sources (1) · 2026-11-12

Pre-sign checkers must mirror every on-chain comparisonWorkingFrom one fix

A pre-sign checker that reuses the builder's assumptions will miss the builder's bugs, so make it compare every field the script compares, outputs_data included. When you add data to an output, count those bytes in its occupied capacity (8 + data + lock + type). Replay refused transactions in ckb-debugger against the deployed binaries to confirm the fix.

#Capacity and cell size #Transaction building and fees #Testing and devnet · Sources (1) · 2026-11-11

Check indexer lag with get_indexer_tip before signingWorkingFrom one fix

The built-in CKB indexer can trail the chain tip, so cells it returns may be stale. Before signing, compare the block_number from get_indexer_tip with the height from get_tip_header, show a notice when the gap is large, and refuse to sign while it is. daowow flags the indexer as lagging when it is more than 8 blocks behind, and its entry, refund and claim guards refuse to proceed in that state.

#Indexer queries and cell collection #Network and RPC reliability #Transaction building and fees · Sources (1) · 2026-11-10

get_consensus dao_type_hash is the DAO code hash, not the DAO type script hashWorkingFrom one fix

The dao_type_hash field returned by the get_consensus RPC is the native Nervos DAO code hash (used with hash_type type, args 0x). A contract that checks deposits with load_cell_type_hash needs the hash of the whole script, ccc Script{codeHash: dao_type_hash, hashType: "type", args: "0x"}.hash() (0xcc77c4de... on testnet); committing the raw dao_type_hash makes every deposit fail the check.

#Cell deps and script lookup #Data encoding (molecule, hex, bigints) · Sources (2) · 2026-11-10

One prefix get_cells scan per type code hash instead of one scan per roundWorkingFrom one fix

When many logical groups (here rounds) share one type script code hash, query the indexer's get_cells once with script_type "type", args "0x" and script_search_mode "prefix" to get every cell under that code hash, then bucket the cells client side by data length and args. Querying per group repeats the same scan and grows with the group count against a public node. The indexer returns cells in type args order, not age order, so sort the results yourself.

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

Rebuild an append-only on-chain accumulator from transaction history, not from live cellsAdvancedFrom one fix

When a cell stores only the root of an append-only accumulator (an MMR) that commits to every entry ever added, spending an entry cell removes it from the indexer's live set while the root still counts it. Replaying live cells builds a different tree and membership proofs fail (the first refund works, the second fails). If each append transaction carries its entries in a witness and spends the previous head at input 0, recover the full set by walking get_transaction backwards through input 0 and parsing each witness with a strict exact-length check, so unrelated WitnessArgs or empty witnesses are not read as entries. Refuse to act unless the recovered count equals the frozen entry count, and fail if the node no longer serves an old transaction.

Joined with daowow@765895a407.

#Indexer queries and cell collection #Witnesses and signatures · Sources (2) · 2026-11-10

Do not detect DER signatures by a leading 0x30 byteWorkingFrom one fix

When converting secp256k1 signatures to DER for a CKB contract (here the Perun channel script, which uses k256 and expects low-S), a 64 or 65 byte compact R||S(||V) signature can begin with 0x30 because R is arbitrary. Dispatch on the fixed lengths first, and parse anything else with a full asn1.Unmarshal that has no trailing bytes, followed by a check that R and S lie in [1, n).

#Witnesses and signatures #Data encoding (molecule, hex, bigints) · Sources (1) · 2026-11-10

Placeholder JoyID lock args are 22 bytes when quoting capacityWorkingFrom one fix

When quoting capacity before a wallet is connected, use a placeholder lock shaped like the wallet you expect. A JoyID lock has 22 byte args, 2 bytes more than a secp256k1 lock's 20, so every cell carrying the user's lock needs 2 CKB more occupied capacity. Pass the placeholder (for example args of 22 zero bytes) to the same quote function used after connecting, so the pre-connect total is not lower than what a JoyID user will actually commit.

#Capacity and cell size #Transaction building and fees · Sources (1) · 2026-11-10

Sign a prepared transaction without broadcasting via CCC signOnlyTransactionWorkingFrom one fix

signer.signOnlyTransaction(tx) asks the CCC signer to sign a transaction you already completed (inputs, fee, cell deps, zero placeholder witness) without preparing or sending it. Treat the wallet as untrusted: pass it a copy, recheck the connected account after it returns, and verify the signed result against the sign hash you got from tx.getSignHashInfo(lock, client) on the prepared transaction (same tx hash, other witnesses untouched, signature recovers to the expected public key).

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

Check original tx unknown and input live on independent nodes before same input cancellationWorkingFrom one fix

Before signing a same-input cancellation for a deployment whose broadcast outcome is unknown, check on two separate RPC endpoints that get_transaction for the original hash returns status 'unknown' and that get_live_cell for the shared input returns 'live', and fail closed if either endpoint errors or times out. Repeat the check before sending. 'unknown' only means the nodes have not seen the tx yet, so the cancellation is a race: if the original is relayed and committed first, the cancellation fails.

#Network and RPC reliability #Transaction building and fees · Sources (1) · 2026-11-09

CKB log subscription notifications may carry params.result as a JSON stringWorkingFrom one fix

When subscribing to the CKB node's "log" topic over the TCP subscription RPC, the notification's params.result can be a JSON-encoded string of the log entry (message, level, target, date) rather than an object. Parse it with JSON.parse when it is a string, and skip malformed payloads instead of stopping the stream; otherwise script debug output (target ckb_script::verify) is silently dropped.

#Network and RPC reliability #Testing and devnet · Sources (1) · 2026-11-09

Indexer get_cells order is by script args, not by cell ageWorkingFrom one fix

Cells returned by a prefix search on type script args (as findRounds does here) come back in indexer key order, sorted by type args, not by creation time, so taking the first result does not give the newest cell. To get the latest, sort by a field stored in the cell (here the round config's entryStart).

#Indexer queries and cell collection · Sources (1) · 2026-11-09

Page 4 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.