CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

“Since and time locks”

18 lessons found. All lessons

Page 2 of 2

Reset devnets instead of skewing the chain clockWorkingFrom one fix

Pushing devnet timestamps ahead leaves the chain clock skewed for every later run, which stalls services that compare the tip with wall time. Reset the devnet for each scenario. At the start, assert that |tip timestamp − now| is small, for example under 600 s.

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

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

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

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

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

Verify header_deps against independently fetched headers, not against the tx's own listWorkingFrom one fix

When checking a transaction that uses header_deps for entropy (for example, headers at fixed offsets from a cell's inclusion block), derive the expected headers yourself: get the creating tx with get_transaction, then get_header on its block_hash, then get_header_by_number for the scheduled heights. Only then compare them to the tx's header_deps. Taking the headers from header_deps makes the check circular, since it only confirms the transaction agrees with itself.

#Since and time locks #Network and RPC reliability · Sources (1) · 2026-10-02

Page 2 of 2

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.