CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

“Cell deps and script lookup”

31 lessons found. All lessons

Page 3 of 3

Absence of on-chain references does not mean a code cell is safe to consumeWorkingFrom one fix

Before consuming a deployed code cell, search live cells for its data hash as lock and type script code hash (prefix mode, hash types data, data1 and data2), and compare its data hash (blake2b with personalization ckb-default-hash) against the binaries you currently build. Zero references does not mean superseded: a contract unchanged by a rebuild has no users yet and is still the live deployment. This search does not see type ID references or cell dep use, so treat a cell that anything may resolve by type ID or as a dep as still needed.

#Type ID and upgrades #Indexer queries and cell collection #Cell deps and script lookup · Sources (1) · 2026-09-20

Restrict script hashType to data, type, data1, data2 when loading configWorkingFrom one fix

CKB hash_type encodes as data=0, type=1, data1=2, data2=4 (no value 3), so a config loader should reject any hashType string outside data/type/data1/data2 rather than map it loosely. A wrong code hash or hash type makes cell discovery watch the wrong cells and silently return empty results.

hash_type validation, not covered

#Cell deps and script lookup #Data encoding (molecule, hex, bigints) · Sources (1) · 2026-09-18

Separate builds for test-only contract constantsWorkingFrom one fix

Put test variants that change protocol constants behind a Cargo feature, built as a separate binary with its own code hash and deployment file. Client deployment parsing and deploy scripts should reject that variant on mainnet. Off-chain code should read the constant from the deployment rather than hardcode the default.

#Testing and devnet #Cell deps and script lookup #Type ID and upgrades · Sources (1) · 2026-11-16

Registering NervosDao on devnetWorkingSeen again

A CCC client for a devnet only knows the scripts you give it, and fee completion looks up KnownScript.NervosDao, so register it by hand. Take the cell dep from genesis block tx 0: find the output whose type script, hashed with Script.from({codeHash: o.type.code_hash, hashType: o.type.hash_type, args: o.type.args}).hash(), equals the DAO code hash 0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e, and fail loudly if none is found. Register it as {codeHash, hashType: 'type', cellDeps: [{cellDep: {outPoint: {txHash: genesisTx0Hash, index: '0x' + daoIndex.toString(16)}, depType: 'code'}}]}.

#Cell deps and script lookup #Testing and devnet · Sources (2) · 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

Iterating group inputs and outputs with ckb-std until IndexOutOfBoundWorkingFrom one fix

In a ckb-std script, walk the cells of a source with the high-level loaders, for example load_cell_type_hash(i, Source::GroupInput) or load_cell_lock_hash(j, Source::Output), in an index loop. Break on Err(SysError::IndexOutOfBound), and return a script error code for any other SysError. Accumulate the u64 capacities you load in a u128 so that a sum over many cells cannot overflow.

#Capacity and cell size #Cell deps and script lookup · Sources (1) · 2026-11-08

Lock code hashes differ between testnet and mainnet for Omnilock, JoyID, ACP and PW lockWorkingChecked by the owner

When identifying a wallet's lock by its code hash, Omnilock, JoyID, anyone-can-pay and PW lock have different code hashes on testnet and mainnet (per CCC's known scripts), while secp256k1 and multisig share one across networks. Code that compares against a single testnet hash will misclassify or fail to filter mainnet locks, so keep a hash per network (or look it up from the client's known scripts).

#Cell deps and script lookup · Sources (1) · 2026-11-08

Page 3 of 3

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.