CKB Pulse
Lessons

Start here

New to CKB, or to a part of it? Read these in order: the basic ones first, then the ones for a developer who ships code, then the rest. Each says why it matters.

All lessons · Glossary · Test yourself

Basic 5

For your first transaction or script. The most useful first.

Occupied capacity minimum for every output

Every output must hold at least its occupied capacity: (8 for the capacity field + 33 + lock args length, plus 33 + type args length if a type script is present, plus data length) × 10^8 shannons. That is 61 CKB for a plain secp256k1 lock with 20 byte args and 63 CKB for a JoyID lock. A fixed payout or fee output set below the recipient lock's minimum is rejected, so choose a constant at or above the largest minimum among the locks you accept.

Why it matters: A fee or payout output set below the recipient lock's occupied capacity is rejected, so the whole transaction cannot be built or submitted.

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.

Why it matters: Lock args derived from a 20 byte blake2b digest do not match the pubkey hash that the secp256k1 blake160 lock checks, so cells sent to that lock cannot be unlocked.

Keep at least 61 CKB in the change cell when sending from a secp256k1 wallet

A plain secp256k1_blake160 cell occupies 61 CKB, so when a wallet sends X it must keep at least 61 CKB (the occupied capacity of its own lock) in the change cell, plus the fee, and refuse the send otherwise. The recipient output must also be at least the occupied capacity of the recipient's lock, never less than 61 CKB for a plain address. Enforce the change floor in the transaction builder, and use extra headroom (this runner uses threshold >= amount + 100) for automatic sweeps so fee and change always fit.

Why it matters: A transaction whose change or recipient output holds less than its occupied capacity (61 CKB for a plain secp256k1 cell) is rejected by the node, so the send fails.

Output type scripts need cell deps too, including the native DAO type

CKB runs the type script of every output (not only input locks and input types), so a transaction that creates a native DAO deposit must include the DAO type's code cell (genesis tx0 index 2) as a cell dep, or the node rejects it with ScriptNotFound on Outputs[i].Type. Pre-send checks that only verify deps for input locks will miss this; check every input lock, input type and output type, deduplicated by code_hash and hash_type.

Why it matters: A DAO deposit built without the DAO type's code cell as a dep is rejected by the node with ScriptNotFound on Outputs[i].Type, and pre-send checks that look only at input locks pass it anyway.

Plain CKB transfer with a CCC signer

With CCC, a simple CKB transfer is built as ccc.Transaction.from({ outputs: [{ lock, capacity }] }), then transaction.completeInputsByCapacity(signer) and transaction.completeFeeBy(signer) are called before signer.sendTransaction(transaction). The recipient lock comes from ccc.Address.fromString(address, signer.client), and its .script is used as the output lock.

Why it matters: Without completeInputsByCapacity and completeFeeBy the transaction has no inputs to fund the output and no fee, so the node rejects it.

All 5 of this level

Working 174

For a developer who ships CKB code.

Wait for get_indexer_tip to reach the commit block before re-reading cells

After get_transaction reports tx_status committed, poll get_indexer_tip until its block_number is at least the transaction's block number before calling get_cells. If you query first, the indexer silently returns the pre-transaction cell set with no error.

Why it matters: Without this wait, a client re-reads cells right after commit, gets the pre-transaction cell set with no error, and shows stale state (here, a ticket count that did not move) or records a wrong empty selection.

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

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.

Why it matters: Reading the raw epoch hex as a number, or masking it wrongly, gives nonsense epoch numbers for window checks. Ignoring the index fraction makes time-to-epoch estimates off by up to a whole epoch, about four hours.

get_live_cell may return "unknown" rather than "dead" for a spent output

On CKB node 0.210.0 devnet, get_live_cell for an output already consumed by a committed transaction returned status "unknown" instead of "dead", so a check requiring "dead" fails. Accept "dead" or "unknown" and prove consumption by calling get_transaction on the creating and consuming transactions, confirming both are committed and that the consumer's inputs reference the out point exactly once.

Why it matters: A check that demands "dead" fails on a cell that was correctly spent, and accepting "unknown" alone would also pass for an out point that never existed, so consumption has to be proven from the committed transactions.

Median time vs tip timestamp for deadlines

On-chain since checks use the median time of past blocks, but clients often use the tip header's timestamp, and the two can diverge widely after devnet time travel. Compute deadlines from max(ceil(tipMs/1000), medianSeconds) so minimum-term checks hold on both sides.

Why it matters: If the deadline is computed from the median time alone, a client that measures the minimum term from the tip timestamp rejects the deadline as too short. This happens after devnet time travel, when the tip runs far ahead of the median.

24-bit epoch number overflow

An absolute epoch since carries only a 24-bit epoch number (max 0xFFFFFF). When a script requires an input since at or after an epoch computed from cell data (for example entry_end plus a wait), compute it with checked addition. Refuse any result above 0xFFFFFF when the cell is created, otherwise the guarded transition can never be satisfied.

Why it matters: A round whose draw epoch is past 0xFFFFFF would accept tickets but could never be sealed or drawn, so the participants' funds could not be returned through the draw.

Absolute epoch since needs the 0x20 metric flag in the top byte

An input since meaning "not before epoch N" must be 0x2000000000000000 | N: top byte 0x20 (absolute, epoch metric) with the epoch number in the low 24 bits. Without the flag the node reads the value as an absolute block number, which for any realistic epoch is already past, so the node enforces no epoch bound. A script that reads since as an epoch must check the metric flag itself, as this project's contract does by refusing a since whose top byte is not 0x20.

Why it matters: Without the flag the node treats an epoch number as a long-past block number. The intended epoch lower bound is then not enforced by the node, and the input is either unlocked early or refused by a script that checks the metric.

Check chain-wide script users before consuming a deployed code cell

Before consuming a deployed code cell, call indexer get_cells across the whole chain with script_search_mode "prefix" and args "0x", once as lock and once as type. Query the cell's data hash with hash_type data, data1 and data2, and for a Type ID cell also its type script hash with hash_type type. Zero results only means no live cell uses the binary right now. Consuming the cell is irreversible, and a Type ID identity cannot be recreated, so treat unused Type ID cells with extra caution.

Why it matters: If you only check your own wallet's cells, you can consume a binary that someone else's live cells still depend on, and those cells become unspendable. Consuming a Type ID cell destroys an identity that cannot be recreated.

ckb-cli needs --skip-check to sign and send transactions with custom locks

ckb-cli refuses transactions whose inputs or outputs use a lock it cannot classify (for example a custom type script based lock with 1 byte of args). `tx sign-inputs` then signs nothing, reporting `invalid lock script ... args.length` and leaving the signatures map and witness empty, and `tx send` refuses the file. Pass `--skip-check` to both sign-inputs and send; otherwise send fails with -2 ERROR_ENCODING because the secp lock reads an empty witness. Since this disables ckb-cli's own checks, run your own verifier on the signed file between sign-inputs and send.

Why it matters: Without --skip-check on sign-inputs, ckb-cli leaves the signatures map and witness empty, and the node rejects the transaction with -2 ERROR_ENCODING when the secp lock reads an unsigned witness.

Comparing packed epoch values

Decode epochs into (number, index, length) before comparing them. Compare the fractional parts by cross-multiplying (index_a*length_b vs index_b*length_a), because epoch length varies and raw packed integers don't order correctly.

Why it matters: Without decoding, a test or script judges epoch maturity wrongly, because the packed layout puts length and index above the epoch number. The daowow test would then expect an Immature refusal after the savings term had already ended.

Derive devnet Spore and system script cell deps from a fresh OffCKB export

Do not hardcode devnet code hashes and cell dep out points (secp256k1, Spore, cluster) in an example: they come from the local OffCKB devnet and can drift when OffCKB's bundled scripts change. Export them with `offckb system-scripts --network devnet --export-style ccc` before start, fail if a needed script lacks codeHash, hashType or a cellDep outPoint, and build both the CCC client config and the Spore SDK lumos config from that one file.

Why it matters: Hardcoded devnet out points and code hashes go stale when the OffCKB devnet changes, so the CCC client and the Spore SDK end up pointing at wrong or missing cell deps and transactions fail.

Enable molecule bytes_vec so ckb-std scripts contain no atomic instructions

With ckb-std 0.16, molecule's default Bytes uses the external bytes crate, which emits lr.d/sc.d atomic instructions that the CKB VM rejects, so the built lock script was not executable on chain. Adding molecule 0.8 with default-features = false and features = ["bytes_vec"] to the script crate makes feature unification swap in molecule's Vec-backed Bytes, and the commit reports the artifact then had zero atomic instructions.

Why it matters: Without the bytes_vec feature, the external bytes crate's atomic refcounting compiles into the RISC-V script, so the CKB VM cannot execute the deployed script and cells locked by it cannot be unlocked on chain.

Filtering get_cells for plain, typeless, empty funding cells

To collect plain funding cells of a lock with the indexer get_cells (or get_cells_capacity) RPC, search with script_type "lock" and add filter output_data_len_range ["0x0","0x1"] and script_len_range ["0x0","0x1"]. Ranges are half-open [start, end), so this keeps only cells with empty data, and since the search is by lock, script_len_range applies to the type script, so only cells with no type script come back. Sorting by capacity on the client only sees the page returned (limit), so page through the results if the lock may own more cells than the limit.

Why it matters: Without the filter, typed or data-carrying cells such as DAO deposits are counted as ordinary balance or picked as funding inputs, which breaks the balance and the transaction built from them.

get_consensus dao_type_hash is the DAO code hash, not the DAO type script hash

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.

Why it matters: If a config pins the raw code hash, no deposit's type script hashes to it, so the node rejects every aggregate with -28 on Inputs[0].Type and the round can never aggregate; its entries have to be refunded after the deadline.

get_transaction returns an object with a null transaction for rejected and unknown txs

The CKB node's get_transaction RPC does not return a null result for rejected or unknown hashes: it returns an object whose transaction field is null and whose tx_status.status is "rejected" (with tx_status.reason holding the rejection reason) or "unknown". Check res.transaction, not just res, before reading outputs, surface tx_status.reason to users, and make test mocks return this shape rather than result null.

Why it matters: Code that treats only a null result as 'not found' misreads unknown or rejected hashes: it crashes or misbehaves on the null transaction field, hides the node's rejection reason, and test mocks returning null guard against a shape real nodes never send.

Indexer free cell discovery by block scan plus get_live_cell on a local chain

Without an indexer on a small local chain, cells for a lock can be found by walking get_block_by_number from 0 to the tip, matching output locks, and confirming each hit with get_live_cell (with_data true). The commit also checks get_block_hash per height and at the end, then rechecks each match, so the result is treated as a snapshot that a reorg or spend can invalidate.

Why it matters: Without the get_live_cell check, outputs that were already spent are returned as funding cells. The test shows this: after the genesis transaction, the owner's original cell at index 3 must drop out and only the new change cell at index 1 remain, otherwise a later transaction would try to spend a dead input.

Light client scan absence does not prove a DAO withdrawing cell was spent

With the CKB light client, a DAO withdrawing cell older than the script's sync start is never returned by the scan, and the phase-2 unlock output is a plain cell that does not point back at it. So absence from the scan cannot mark the position spent: retire it only when the unlock transaction is confirmed (a verified local inclusion, or getTransactionStatus reporting committed on the node), keep it shown as confirming while the unlock is in flight, and never treat an unreachable node or an unknown transaction as a spend.

Why it matters: Retiring on absence alone makes a still-unspent DAO position vanish from the screen and the balance, and the unlock preflight then insists it was already claimed, with no way back.

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.

Why it matters: Comparing a code_hash against the wrong preimage, such as the ELF hash for a type-mode Script or a type hash for a data-mode Script, wrongly rejects a correct binding or accepts the wrong code Cell. A type selection also fails when the Cell has no Type Script.

Minimum capacity of a cell depends on its lock args length

A cell with no type and no data needs at least 8 (capacity) + 32 (code hash) + 1 (hash type) + args length in CKB: 61 CKB for a secp256k1_blake160 lock (20-byte args), 63 CKB for a JoyID lock with 22-byte args. A contract that knows a recipient lock only by hash cannot measure it, so a hardcoded floor for the fee output must be at least the largest lock it may face on each network, and a test should measure the real lock against it. Otherwise the fee output cannot be built.

Why it matters: If a contract hardcodes a capacity floor below what the recipient lock actually occupies, it demands an output too small for consensus to accept, so the fee output cannot be built and the operation that requires it (here registration) can never succeed.

Multisig sighash placeholder lock: script plus M zeroed signatures

When computing the signing message for a secp256k1_blake160_multisig_all input, set the first witness's WitnessArgs.lock to the multisig script bytes followed by threshold × 65 zero bytes (a single key sighash lock uses just 65 zero bytes), and keep the inputType and outputType fields, before calling CCC's tx.getSignHashInfo(script, client). The same placeholder length must be used here as in the signed witness, otherwise the message differs from what the lock script hashes on chain.

Why it matters: If the placeholder lock has a different length or content from the final signed lock, the signers sign a message the on-chain multisig script never reproduces, so every signature fails verification.

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

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.

Why it matters: Reading the wrong word of the dao field, applying the rate to the whole capacity, or using the tip AR for a cell already in withdrawal gives a wrong compensation figure. That last mistake keeps adding interest that has in fact stopped.

Nervos DAO phase 1 withdrawing cells keep the DAO type; count deposits by 8 zero bytes of data

A Nervos DAO cell in phase 1 of withdrawal still has the DAO type script (code hash 0x82d76d...3f2e, hash_type type, args 0x), so filtering by type alone counts it as a deposit. Only cells whose output data is exactly 0x0000000000000000 are deposits; a withdrawing cell's data holds its deposit block number. The commit's testnet test shows a type-only count giving 500 CKB where the true deposit total is 300 CKB.

Why it matters: Counting Nervos DAO cells by type script alone also counts phase 1 withdrawing cells as deposits, so a deposit already being withdrawn still adds weight; in the testnet history this gave 500 CKB instead of 300 CKB.

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.

Why it matters: A sighash digest computed over a 65 byte placeholder differs from the one Omnilock verifies against the 85 byte OmniLockWitnessLock, so the signature does not verify and the spend fails.

Pin JS cell data encoders and decoders to Rust generated vectors

When JS code encodes or decodes CKB cell data or script args that an on chain Rust script parses, test it against vectors exported from the Rust crate's own encoder, not against the JS code's own expectations. Assert every decoded field and every encoded byte, because a length check cannot catch a shifted offset. Give each field a distinct non zero value so a one byte shift gives a visibly wrong result. Read u64 shannon fields as BigInt (DataView.getBigUint64) and reject data of the wrong length.

Why it matters: A JS codec checked only against its own expectations or a size check can read or write a neighbouring offset and still produce a plausible number of the right length, so the browser builds or reports cells the on chain script reads differently, and Number would silently round shannon amounts above 2^53.

Pinning JS codecs and derivations to Rust test vectors

When off-chain JS encodes or derives cell data that a Rust type script decodes or re-derives byte for byte, test the JS against JSON vectors generated by the Rust code, using a distinct value in every field so a wrong offset fails. Mirror the contract's validation refusals and its exact ordering and rounding: BTreeMap ascending key order, BigInt floor division with the dust going to fixed indices, and merging duplicates before dividing. The chain only returns a bare error code, so only this off-chain check can tell you which rule failed.

Why it matters: If the JS sorts, rounds or assigns dust differently from the script, it builds settlement data the script refuses with a bare error code that names no rule.

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.

Why it matters: Without the exact type and data check, look alike scripts and phase one withdrawing cells are counted as live deposits, so stake or voting weight survives a withdrawal or can be faked.

All 174 of this level

Advanced 19

Protocol and node details, and unusual cases.

Rebuild an append-only on-chain accumulator from transaction history, not from live cells

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.

Why it matters: Membership proofs built by replaying only the indexer's live cells target a different tree than the committed root. Once one entry cell is spent, every later refund is refused on chain.

Simulating a real CKB reorg with two devnet nodes over P2P

To exercise genuine fork choice on a Dummy devnet, partition two nodes with set_network_active(false) plus remove_node, wait until get_peers is empty on both, then mine a longer competing branch on one node with generate_block. Reconnect with set_network_active(true) and add_node(node_id, /ip4/.../tcp/port), and wait until both nodes report the same get_tip_header hash and the same tx_pool_info tip_hash before checking reorg recovery.

Why it matters: Without a confirmed partition the peer simply syncs the main branch and no competing fork forms. Without waiting for both the tip hash and tx_pool_info tip_hash to converge, reorg checks such as liveness, recovery and dependency rejection run against a node that has not yet switched branches or refreshed its pool.

Binding an off-chain lock proof to the live cell deps it ran with

When an off-chain signature proof is verified by running the lock against cell deps read live from the chain, record every out point those deps resolved to, dep group members included. Treat the resulting authorization as valid only while all of those cells are still live. A lock upgrade, a redeployment, or a key rotation or recovery in a lock that keeps its keys in a dep cell spends one of them, and the owner must prove again.

Why it matters: Without the recorded out points, a binding keeps trusting a proof made under lock code or key cells that were later upgraded, rotated or recovered away.

Charging load_program bytes as cycles when building a custom ckb-vm machine

When you build a ckb-vm machine yourself (DefaultMachineBuilder or AsmMachine) and call load_program, charge the returned byte count with machine.add_cycles_no_checking(ckb_script::cost_model::transferred_byte_cycles(bytes)). That count covers the loaded program and the stack and argument setup, and TransactionScriptsVerifier charges it on chain, so without it your cycle count comes out too low (in ckb-debugger the fib test went from 1361 to 3364 cycles). For AsmMachine call it on the inner machine, and pass the error up instead of unwrapping.

Why it matters: A hand-built ckb-vm machine that skips charging the loaded program bytes reports fewer cycles than on-chain verification does (the fib example showed 1361 instead of 3364), so cycle estimates and limits based on it are wrong.

CKB VM2 READ and INHERITED_FDS syscalls take a length pointer and return status in a0

In CKB VM2, READ takes (fd, buffer_addr, length_addr) and INHERITED_FDS takes (buffer_addr, length_addr), with *length_addr set to the buffer capacity before the ecall. The syscall returns only a status in a0 (0 on success) and writes the delivered byte count or fd count back through length_addr, so never treat a0 as the payload. After checking a0, handle short pipe reads by looping or failing explicitly, and bounds-check an INHERITED_FDS index against the smaller of the returned count and the capacity you passed.

Why it matters: A bare ecall passes garbage in a1/a2 and returns the status word as if it were the data, so the script reads wrong values or faults.

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.

Why it matters: Without the exact molecule layout, a tool cannot confirm the node's reported packed transaction size from RPC JSON. The cross-check against the measured node wire bytes would then fail or be skipped.

Conflict an orphaned transaction's input on the winning branch when testing a reorg rollback

In a CKB devnet reorg test, transactions from detached blocks can return to the txpool and be committed again on the winning branch, which hides the rollback you want to observe. Have the winning branch spend one input of the orphaned transaction, such as its fee input, before the branches reconnect. Resubmitting the old transaction is then rejected with TransactionFailedToResolve (-301), and you must rebuild it with fresh funding.

Why it matters: Without a conflicting spend, the orphaned transaction can be recommitted through the txpool after the reorg, so the test cannot show the rolled-back state.

Disable overflow checks for ckb-std when using its dummy-atomic polyfills

When a release profile sets overflow-checks = true and ckb-std (here =1.1.0 with the dummy-atomic feature) supplies the single-thread __atomic polyfills, add a per-package override turning overflow checks off for ckb-std. Atomic read/modify/write arithmetic is defined to wrap, so checked arithmetic in those polyfills would panic instead of wrapping.

Why it matters: With workspace-wide overflow checks, wrapping atomic arithmetic inside ckb-std's polyfills could trap instead of wrapping and abort the guest.

Forcing a real CKB devnet reorg via P2P partition RPCs

To force a real reorg between two Dummy devnet nodes without truncate or submit_block, call set_network_active(false) and remove_node on both, let the main node commit its transactions, then on the peer spend one input that those transactions consume and mine a longer branch with generate_block. Reconnect with set_network_active(true) on both and add_node, and treat convergence as reached only when get_tip_header and tx_pool_info.tip_hash both equal the winning hash on both nodes. Because the peer branch spent that input, the orphan transactions stay out of the chain and the pool, and replaying one of them fails with TransactionFailedToResolve (code -301).

Why it matters: Without a conflicting spend on the winning branch, detached transactions can come back through the tx pool and be recommitted, so no rollback is observed. Without waiting for tx_pool_info.tip_hash, checks may run before the pool has processed the reorg.

JoyID sub key membership is checked through the CoTA aggregator

A JoyID passkey from a second device is a sub key, so deriving the JoyID lock from the signer's public key does not find the account. Given the account's address, call JoyID's CoTA aggregator method generate_subkey_unlock_smt with alg_index 1 (the passkey algorithm), pubkey_hash set to the first 20 bytes of ckbHash(pubkey) for the same pubkey bytes JoyID signs with, and lock_script set to the serialized lock; a non-empty result.unlock_entry means the key belongs to that account. The aggregator is trusted and its SMT proof is not checked against the chain, and the positive case was not run against a real sub key here.

Why it matters: A login check that only derives the JoyID lock from the signer's public key fails to recognise anyone signing with a sub key from a second device, so legitimate account holders are rejected.

JoyID sub key signatures depend on the live CoTA cell dep holding the sub key root

A JoyID sub key (second device) signature is checked by the JoyID lock against the sub key root held in the account's CoTA cell, which the transaction carries as a cell dep. Adding a device spends that CoTA cell and creates a new one with a new root. Two separate things follow: a transaction that still lists the old CoTA out point has a cell dep that is no longer live, and the lock run against the old root data does not accept the sub key signature.

Why it matters: A sub key signature checked against a stale or spent CoTA cell is rejected, and a binding made before the device was added stops being valid from the block that spent the old CoTA cell.

Light client sync progress poll racing set_scripts

If an app saves per-script sync progress from the light client's get_scripts while another path calls set_scripts to reset or re-register scripts, a get_scripts result read before the set landed can overwrite the reset progress. Do the get_scripts read and the progress write under the same lock that guards set_scripts, and have the poll use tryLock and skip that tick while a registration is in flight, so it never queues behind it. Pocket Node does this in SyncCoordinator.tryWithRegistrationLock.

Why it matters: A poll tick that read get_scripts before a resync's set_scripts landed writes the old block number back, so the user's reset is silently undone and the wallet resumes from stale progress.

Mock syscalls must write back output length

When a ckb-vm mock or fuzzing syscall layer implements inherited_fds, it must store the fd count back into length_addr with store64 after writing the fd buffer. Otherwise the script reads back the capacity it passed in and treats unwritten slots as fds. ckb-vm-contrib's fuzzing utils lacked this until v1.1.2.

Why it matters: Without the write back, a script running under the mock sees the capacity it passed in as the fd count and diverges from real CKB behaviour.

Partial load of a cell's type Script header to match code_hash and hash_type

In a ckb-std script you can load a cell's type script into a fixed 49 byte buffer with syscalls::load_cell_by_field(..., CellField::Type), then compare code_hash at bytes 16..48 and hash_type at byte 48 of the molecule Script table, without allocating for args. A short buffer returns Err(SysError::LengthNotEnough) yet still fills the buffer, so treat that error like Ok, and treat ItemMissing as a cell with no type script.

Why it matters: Loading the full type Script of every input and output allocates for arbitrary, attacker-sized args, and treating LengthNotEnough as a failure would wrongly reject cells whose script header was in fact read correctly.

Passing a pipe to a spawned child script via a zero-terminated inherited_fds list

When a lock spawns a verifier script from a cell dep with ckb-std 1.1.0 syscalls::spawn, it creates a pipe and passes the read fd in SpawnArgs.inherited_fds as an array ending in 0. After writing the full request, the parent closes write_fd so the child's read returns 0 or OtherEndClosed (end of input), then uses syscalls::wait(pid) == 0 as the verification result.

Why it matters: If the parent never closes the write end, the child's final end-of-input read cannot return 0 or OtherEndClosed, so the verifier rejects the request as malformed or blocks waiting for data.

Port CKB's sparse-merkle-tree byte for byte

nervosnetwork/sparse-merkle-tree folds runs of empty siblings into MergeWithZero nodes (merge byte 2; a normal merge uses byte 1 plus height and parent path), and bit 0 of a key is the low bit of byte 0. Compiled proofs use the opcodes 0x4c, 0x50, 0x51, 0x4f n (n=0 means 256) and 0x48. Test any off-chain port against vectors generated by the Rust code.

Why it matters: A port that follows a textbook sparse Merkle tree, or gets the bit order or merge prefixes wrong, produces roots and proofs that the on-chain Rust verifier rejects.

Raw cell_deps indexes match Source::CellDep only before the first dep group

When a script reads the raw transaction's cell_deps (via load_transaction) and uses a position there as a Source::CellDep index for load_cell_type_hash or load_cell_data, the mapping holds only for the leading run of dep_type code entries, because dep groups expand into their member cells and shift later indexes. This vote script restricts its proposal and deposit lookups to that direct prefix and lets wallet dep groups follow it.

Why it matters: Once a dep group sits before the wanted dep, a raw cell_deps position reads a different resolved cell, so the script checks the wrong proposal or deposit data, or fails.

Reconstructing the live cell set at a past height from the CKB indexer

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.

Why it matters: A plain get_cells snapshot misses every deposit that existed at H but was withdrawn later, and withdrawing cells or reorgs during the pass would corrupt the reconstructed set.

Separate submit and commit verification environments

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().

Why it matters: Treating the tip as the candidate block evaluates block and median time since locks at the wrong height, so a transaction can be reported valid at submit and then be rejected as immature when it is actually committed.

All 19 of this level