CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

Hanssen0-Alter-Ego/ckb-vm-js

Lessons from Hanssen0-Alter-Ego/ckb-vm-js

github.com/Hanssen0-Alter-Ego/ckb-vm-js

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

7 lessons found. All lessons

Script group hash is the hash of the whole Script, not the code_hashWorkingFrom one fix

A script group is identified by BLAKE2b-256 with the 'ckb-default-hash' personalization over the Molecule-encoded Script (code_hash, hash_type byte data=0/type=1/data1=2/data2=4, args). Lock groups come only from inputs. Type groups come from inputs and outputs, and lock and type groups with the same hash stay distinct. Passing the code_hash as the group hash yields ScriptNotFound.

#Data encoding (molecule, hex, bigints) #Witnesses and signatures · Sources (1) · 2026-11-16

Decoding InvalidDepGroup OutPointsWorkingFrom one fix

InvalidDepGroup prints the OutPoint in molecule encoding: a 32-byte tx_hash followed by a 4-byte little-endian index. Reverse the index bytes, then match only dep_group cell_deps on both tx_hash and index.

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

Identify script groups by type and hashWorkingFrom one fix

In CKB the same script hash can be both a lock script group and a type script group in one transaction, and each group has its own input and output indices. When selecting or reporting a script group, for example from a verifier's group list, match on group type together with script hash, never on the hash alone.

#Witnesses and signatures #Other · Sources (1) · 2026-11-16

Use BigInt for uint64 RPC quantitiesWorkingFrom one fix

CKB RPC quantities such as max_cycles and max_block_cycles are uint64 hex strings, and Number or parseInt silently round anything above 2^53. When turning a decimal string a user typed into one, accept only /^[0-9]+$/, parse it with BigInt, reject n >= 1n<<64n, and format it as `0x${n.toString(16)}` (no leading zeros). To show an RPC hex value as decimal, use BigInt(hex).toString(10), never Number.

#Data encoding (molecule, hex, bigints) · Sources (1) · 2026-11-16

Witnesses do not follow reordered inputsWorkingFrom one fix

Witnesses are matched to inputs by position: witness i belongs to input i, and a script reading GroupInput witnesses sees the witnesses at its group's input positions. Reordering inputs does not move the witnesses, so after reordering, check and rebuild the witness list so each input's position again holds the intended witness.

#Witnesses and signatures #Transaction building and fees · Sources (1) · 2026-11-16

Exact CKB-to-shannon conversion with BigIntWorkingFrom one fix

Convert user-entered CKB amounts to shannons with BigInt string arithmetic: BigInt(whole) * 100000000n + BigInt(fraction.padEnd(8, '0')). Never use parseFloat(amount) * 1e8. First validate the input with /^\d+(\.\d{1,8})?$/, which rejects exponents, hex and commas, and reject any result above u64::MAX (0xffffffffffffffffn).

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

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

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.