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
n = first // 4 - 1Taken 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)
- 2026-10-19 · ckb-service-runner/csr-network-monitor · more from this project
More about Other
- Recognizing a Nervos DAO deposit cell (not a withdrawing one)
- Hand-encoding WitnessArgs in molecule
- Restrict script hashType to data, type, data1, data2 when loading config
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.