CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

toastmanAu/daowow

Lessons from toastmanAu/daowow

github.com/toastmanAu/daowow

Do you maintain this project? Confirm lessons 1 to 30 · Confirm lessons 31 to 51

51 lessons found. All lessons

Page 2 of 5

Nervos DAO phase-one withdrawal layoutWorkingFrom one fix

In phase one, output i must mirror deposit input i (same capacity, lock and DAO type), with its data set to the deposit block number as a u64 LE, and the deposit block hash must be in header_deps. Put any fee-paying input and output after all deposits. A custom lock that enforces a full 180-epoch term before phase one pushes payout to the next cycle boundary (about deposit + 360 epochs, roughly 60 days).

#Since and time locks #Transaction building and fees #Cell deps and script lookup · Sources (1) · 2026-11-13

Nervos DAO phase-two withdrawal since and amountWorkingFrom one fix

Set the phase-two input since to an absolute epoch counted from the DEPOSIT header, not the withdrawing block. Round the elapsed epochs up to whole 180-epoch cycles, compare epoch fractions by cross-multiplication, and keep the deposit's epoch index and length. The withdrawable amount is occupied + (capacity − occupied) × AR_withdraw / AR_deposit, where AR is a little-endian u64 read from bytes 8..16 of each header's dao field. WitnessArgs.input_type must hold the deposit header's index in header_deps as an 8-byte little-endian u64.

#Since and time locks #Witnesses and signatures #Capacity and cell size · Sources (1) · 2026-11-13

Mirror on-chain rules off-chain with mutation testsWorkingFrom one fix

A CKB script that refuses a transaction returns only an error code that names no rule, so port the contract's witness decoders to JS with the same refusals (bad version, truncation, trailing bytes, count or size limits). Check that they round-trip bytes produced by the Rust code. Before signing, run a checker that re-derives the contract's rules from the finished transaction, and pin each rule with a mutation test that breaks one field of a valid transaction and expects that rule's named reason.

#Testing and devnet #Data encoding (molecule, hex, bigints) #Since and time locks · Sources (1) · 2026-11-13

Wallet discovery with SignersControllerWorkingFrom one fix

To support every CCC wallet without the @ckb-ccc/connector UI, call `new ccc.SignersController().refresh(client, callback, {name, icon})`. Keep the callback registered and update the picker, because it fires again as EIP-6963 wallets announce themselves. Treat signers that are `instanceof ccc.SignerDummy` as download links, not connectable wallets.

Medium confidence.

#Witnesses and signatures #Login and authorization · Sources (1) · 2026-11-12

Validate header and epoch lookups before using timestampsWorkingFrom one fix

After get_header_by_number or get_epoch_by_number, treat a null result as unavailable and check that the returned number equals the one you asked for. To get an epoch's start time, read the header at the EpochView's start_number. Then check that this header's epoch field has the epoch number in its low 24 bits and 0 in bits 24 to 39 (the block's index within the epoch), so the block really is the first block of that epoch.

#Network and RPC reliability #Since and time locks #Data encoding (molecule, hex, bigints) · Sources (2) · 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

Decoding the packed epoch field (number, index, length)WorkingSeen again

A CKB header epoch field packs the epoch number in the low 24 bits, the index in the next 16 bits (shift 24) and the epoch length in the next 16 bits (shift 40). When estimating time to a target epoch from the tip, subtract the fraction already spent (index * epoch duration / length) and guard against length 0 to avoid division by zero.

#Since and time locks #Data encoding (molecule, hex, bigints) · Sources (3) · 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

Nervos DAO compensation from the header's accumulated rate (AR)WorkingSeen again

The DAO accumulated rate AR is the second little-endian u64 (bytes 8..16) of a header's `dao` field, for example from `get_header_by_number`. Interest accrues only on free = capacity minus occupied capacity, so compensation = free * AR_end / AR_deposit minus free, and the maximum withdraw is occupied + free * AR_end / AR_deposit. AR_deposit is the AR of the deposit block; AR_end is the AR of the block holding the withdrawing cell (phase 1) once withdrawal was requested, and only for a not yet withdrawn deposit is the tip AR used, as an estimate that is still growing.

#Capacity and cell size #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

Page 2 of 5

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.