CKB Pulse

All lessons · CCC (TypeScript SDK) · Start here · Glossary

Hand-rolled Script hash: hash_type byte mapping and molecule offsets, checked against CCCWorkingReproduced

Reproduced · Check: right · Checked 2026-11-19

If you serialise a CKB Script molecule yourself to compute its blake2b hash, use a 16 byte header (total size plus three u32 offsets 16, 48, 49) and map hash_type as data=0, type=1, data1=2, data2=4 (not 3). This commit cross checks the result against ccc.Script.from(...).hash() for all four hash types, and a single wrong offset or data2 mapped to 3 makes that test fail.

Why it matters: A wrong molecule offset or data2 mapped to 3 yields a plausible script hash that matches nothing, so a lock hash comparison such as entry-lock's committed participant check refuses the spend.

Pattern

Prefer
const hashType = { data: 0, type: 1, data1: 2, data2: 4 }[script.hashType];

Taken from the commit, shortened.

A test changed in the same commit

It sits next to the fix. We did not run it.

Reproduced by a test

A public test runs what this lesson says on @ckb-ccc/core 1.23.1, with no node. Anyone can run it.

tests/ccc/script-hash.test.mjs

Concepts
Data encoding (molecule, hex, bigints), Testing and devnet
Evidence
Reproduced: reproduced by a public test
First seen
2026-09-23
Last changed
2026-09-23
Last checked
2026-11-19
Check against the commit
right: the lesson follows from its commit and still holds in the code today

Sources (1)

More about CCC (TypeScript SDK)

All 33 in this topic

Do you maintain a project this lesson came from? Confirm or correct it

Cite this lesson
LusoCryptoLabs, "Hand-rolled Script hash: hash_type byte mapping and molecule offsets, checked against CCC", CKB lessons, https://pulse.lusocryptolabs.com/learned/ccc/hand-rolled-script-hash-hash-type-byte-mapping-and-molecule, CC BY 4.0, last changed 2026-09-23.

Drawn from public commits and checked against the commit each one came from and the project's code today. Read the source before you rely on one. Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. Want a lesson changed or removed? Open an issue.