CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

Working

174 lessons found. All lessons

Page 9 of 15

Use raw_data(), not as_slice(), when parsing a packed::Bytes witnessWorkingChecked by the owner

A transaction witness in ckb_types is a molecule packed::Bytes, so as_slice() returns the 4 byte length header followed by the content, while raw_data() returns only the content (here a serialized WitnessArgs). A check that compares a witness to the secp256k1 sighash placeholder WitnessArgs (lock of 65 zero bytes) must use witness.raw_data() (or unpack()), otherwise it is silently never true. Fiber's funding witness merge never recognized placeholders until it switched to raw_data(), so a peer's placeholder could be kept in place of a real signature.

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

Set cobuild: true when injecting OffCKB devnet Spore scripts into createSporeWorkingFrom one fix

OffCKB 0.4.13's system scripts export for the devnet Spore V2 deployment has only codeHash, hashType and cellDeps, with no field for the protocol mode. When building a SporeScriptInfoLike from it for @ckb-ccc/spore createSpore({ scriptInfo }), set cobuild: true yourself, because the deployed binary uses cobuild semantics. Treat that flag as an assumption you pin, not something read from the export.

cobuild: true needed for OffCKB devnet Spore scripts.

#Cell deps and script lookup #Testing and devnet · Sources (1) · 2026-10-28

Read cell data hash from the consensus DATA_HASH field instead of hashing loaded dataWorkingFrom one fix

To get a cell's data hash in a CKB script, read the DATA_HASH field with LOAD_CELL_BY_FIELD instead of loading the data with LOAD_CELL_DATA and hashing it yourself. The field works for any data size, while a fixed buffer breaks on larger data because LOAD_CELL_DATA reports the full remaining length, not the number of bytes copied. The field also returns 32 zero bytes for empty data, not Blake2b of empty, so a hash computed over loaded data would not match it.

#Data encoding (molecule, hex, bigints) #Capacity and cell size · Sources (1) · 2026-10-27

A rejected or unknown get_transaction status does not make a signed transaction deadWorkingFrom one fix

A node reporting a transaction you sent as rejected or unknown does not prove it is dead: one node's answer is not proof, and while all its inputs are live the signed bytes could still be rebroadcast by someone and commit. Only release its reserved inputs if a later transaction is guaranteed to conflict with it (here a shared pool cell every later action must spend, so at most one can commit), and also require that every input is still live, that the status is still rejected or unknown when rechecked after the input reads, and that the submission is old enough (2 minutes here), behind an explicit confirmation.

#Transaction building and fees #Network and RPC reliability · Sources (1) · 2026-10-26

Finding cells of a ckb_js_vm JS contract needs a second indexer prefix searchWorkingFrom one fix

A cell that runs a JS contract carries the ckb_js_vm script as its lock or type. Its args are 2 flag bytes, then the contract's 32 byte code hash, then its hash type byte (data 0, type 1, data1 2, data2 4). A get_cells prefix search on the contract's own code_hash finds none of these cells, so also run a prefix search on the ckb_js_vm script with args set to flags plus code hash plus hash type byte, and merge the results. With 0x0000 as the flags, that search only matches cells whose flags are zero.

#Indexer queries and cell collection #Data encoding (molecule, hex, bigints) · Sources (1) · 2026-10-25

Search for a script's cells under both its data hash and its type id code hashWorkingChecked by the owner

A script deployed with a type id can be referenced by cells either as hashType data1 with the code's data hash or as hashType type with the deployment's type id hash (per network). An exact indexer search via client.findCells over only one form misses the other; here @ckbfs/api's useTypeID cells read as missing until the reader queried both forms and treated a combined count above one as an error.

#Indexer queries and cell collection #Type ID and upgrades · Sources (1) · 2026-10-24

CCC custom client scripts must include AnyoneCanPay for SignerCkbPrivateKeyWorkingReproduced

On a devnet, if you construct a CCC client with a custom `scripts` map that overrides only `KnownScript.Secp256k1Blake160`, `SignerCkbPrivateKey` can still fail. This commit's comment says the signer also loads AnyoneCanPay metadata while classifying related locks, so it adds a `KnownScript.AnyoneCanPay` entry to the map even though no ACP input or cell dep is used.

#Cell deps and script lookup #Testing and devnet · Sources (1) · 2026-10-23

Sign each lock group with its own placeholder length and witness shapeWorkingSeen again

When one key controls several lock groups in a CCC transaction, call transaction.prepareSighashAllWitness(script, len, client) for each group with the final witness lock length of that lock, then getSignHashInfo and sign that group's own digest. In KeyWay's case the length is 65 bytes for secp256k1 and 85 bytes for an Omnilock owner witness holding one 65-byte signature; write the bare signature for secp256k1 and wrap it in the OmniLockWitnessLock molecule for Omnilock. A custom lock with its own witness layout needs its own length the same way.

#Witnesses and signatures #Transaction building and fees · Sources (2) · 2026-10-23

Omnilock owner signing needs an 85 byte zeroed witness lock placeholderWorkingFrom one fix

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.

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

Headless EIP-6963 test wallet for driving the CCC connector in PlaywrightWorkingFrom one fix

To drive CCC's real EIP-6963 connector and EVM/Omnilock signing in headless Playwright, inject a minimal EIP-1193 provider with page.addInitScript passed as a string, because transpiled function sources carry helpers such as __name that the page lacks. The provider answers eth_requestAccounts, eth_accounts and personal_sign, stubs on and removeListener, and announces itself on eip6963:announceProvider, also whenever eip6963:requestProvider fires. Signing runs in Node through page.exposeFunction so the key never enters the page, and personal_sign must return r‖s‖v with v = 27 + recovery id; noble-curves 2.x sign with format "recovered" yields recovery‖r‖s, so reorder it with hexFrom(bytesConcat(recovered.slice(1, 65), [recovered[0] + 27])) and check it against ccc.verifyMessageEvmPersonal.

#Testing and devnet #Witnesses and signatures · Sources (1) · 2026-10-22

Enable molecule bytes_vec so ckb-std scripts contain no atomic instructionsWorkingChecked by the owner

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.

#Other · Sources (2) · 2026-10-22

JoyID lock witness outputType may carry a subkey proof, so type script data must move elsewhereWorkingFrom one fix

When the funding wallet uses the JoyID lock, its WitnessArgs outputType may carry a subkey unlock proof, so do not put your own type script data in that witness's outputType. Place the type script action in another witness index and align the related output index with it. Size the fee estimate's signature placeholder for JoyID's larger witness (openswap uses 1000 bytes) instead of the 65 byte secp256k1 size.

#Witnesses and signatures #Transaction building and fees · Sources (1) · 2026-10-22

Page 9 of 15

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.