CKB Pulse

All lessons · Developer tooling · Start here · Glossary

Matching a Script code_hash to its code Cell by hash_typeWorkingSeen again

Seen again · Check: right · Checked 2026-11-19

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.

Why it matters: Comparing a code_hash against the wrong preimage, such as the ELF hash for a type-mode Script or a type hash for a data-mode Script, wrongly rejects a correct binding or accepts the wrong code Cell. A type selection also fails when the Cell has no Type Script.

Pattern

Prefer
0 | 2 | 4 => artifact, 1 => type_hash.ok_or_else(|| invalid("Type-hash selection has no actual code Cell Type Script"))?,

Taken from the commit, shortened.

A test changed in the same commit

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

Concepts
Cell deps and script lookup, Data encoding (molecule, hex, bigints)
Evidence
Seen again: seen in two or more projects
First seen
2026-10-09
Last changed
2026-10-09
Last checked
2026-11-19
Check against the commit
right: the lesson follows from its commit and still holds in the code today

Sources (2)

More about Developer tooling

All 35 in this topic

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

Cite this lesson
LusoCryptoLabs, "Matching a Script code_hash to its code Cell by hash_type", CKB lessons, https://pulse.lusocryptolabs.com/learned/tooling/matching-a-script-code-hash-to-its-code-cell-by-hash-type, CC BY 4.0, last changed 2026-10-09.

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.