CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

CellScript-Labs/CellScript

Lessons from CellScript-Labs/CellScript

github.com/CellScript-Labs/CellScript

Do you maintain this project? Confirm its lessons in one issue

7 lessons found. All lessons

CKB VM2 READ and INHERITED_FDS syscalls take a length pointer and return status in a0AdvancedFrom one fix

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.

#Other · Sources (1) · 2026-10-29

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

Type Script group membership and group witness index derived from the full script hashWorkingFrom one fix

When locating a Type Script group off chain, match input and output cells by the blake2b hash of the complete Script (code_hash, hash_type, args), never by code hash alone. By convention (RFC 22 for lock groups), a group's witness sits at the transaction index of its first input, or of its first output if the group has no inputs. CKB does not enforce this: the script picks which witness it reads, and which WitnessArgs field (input_type or output_type) holds the data is the protocol's own choice.

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

Matching a Script code_hash to its code Cell by hash_typeWorkingSeen again

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.

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

Script hash_type selects the VM version: data2 (4) or type (1) for a VM2 targetWorkingFrom one fix

CKB picks the VM version from the Script hash_type: data (0) runs VM0, data1 (2) runs VM1, data2 (4) runs VM2, and type (1) runs the latest activated VM. Code deployed for VM2 and pinned by data hash must be referenced with hash_type data2. The same code hash with data or data1 still resolves to the same cell but runs under an older VM, so tooling should reject those hash types for a VM2 target rather than only checking that the code hash matches.

#Cell deps and script lookup #Type ID and upgrades · Sources (1) · 2026-10-09

Wait for tx_pool_info tip to match chain tip before submitting on devnetWorkingFrom one fix

After generate_block, CKB's tx pool updates its snapshot asynchronously, so a transaction spending just-committed outputs can be rejected (e.g. "Resolve failed Unknown") even though get_live_cell sees them. Before send_transaction or send_test_transaction, poll tx_pool_info until its tip_hash and tip_number equal get_tip_header's hash and number.

#Testing and devnet #Network and RPC reliability · Sources (1) · 2026-10-08

Delegating script validation via exec to a hash bound cell depWorkingFrom one fix

This lifecycle type script stores a 32 byte data hash in its args, scans cell deps with load_cell_data_hash to find exactly one match (rejecting duplicates), then calls ckb_std syscalls::exec on that dep, which keeps the current Script context (GroupInput, GroupOutput, args) for the child. Because exec only returns when it fails, any code after the call must return an error instead of falling through to success.

#Cell deps and script lookup #Type ID and upgrades · Sources (1) · 2026-10-04

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.