CKB Pulse

All lessons · Other · Start here · Glossary

Strict validation of molecule table headers in hand written decodersWorkingFrom one fix

From one fix · Check: right · Checked 2026-11-19

When decoding a molecule table by hand (here, the CSR registry cell data), check that the leading u32 total size equals the data length, derive the field count as first_offset/4 - 1, and require first_offset == 4 + 4*count and ascending offsets. Reject a field count different from the schema; this parser is strict and does not accept extra trailing fields, so truncated, padded or extended tables raise ValueError, as the tests show.

Why it matters: Without these header checks, truncated, padded or extra-field cell data gets sliced into wrong field values instead of being rejected, so the decoder trusts malformed on-chain data.

table header validation, distinct from WitnessArgs encoding lesson

Pattern

Prefer
n = first // 4 - 1

Taken from the commit, shortened.

Concepts
Data encoding (molecule, hex, bigints)
Evidence
From one fix: from one project, checked against its commit
First seen
2026-10-19
Last changed
2026-10-19
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 Other

All 9 in this topic

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

Cite this lesson
LusoCryptoLabs, "Strict validation of molecule table headers in hand written decoders", CKB lessons, https://pulse.lusocryptolabs.com/learned/other/strict-validation-of-molecule-table-headers-in-hand-written, CC BY 4.0, last changed 2026-10-19.

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.