CKB Pulse

All lessons · Developer tooling · Start here · Glossary

Pin JS cell data encoders and decoders to Rust generated vectorsWorkingFrom one fix

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

When JS code encodes or decodes CKB cell data or script args that an on chain Rust script parses, test it against vectors exported from the Rust crate's own encoder, not against the JS code's own expectations. Assert every decoded field and every encoded byte, because a length check cannot catch a shifted offset. Give each field a distinct non zero value so a one byte shift gives a visibly wrong result. Read u64 shannon fields as BigInt (DataView.getBigUint64) and reject data of the wrong length.

Why it matters: A JS codec checked only against its own expectations or a size check can read or write a neighbouring offset and still produce a plausible number of the right length, so the browser builds or reports cells the on chain script reads differently, and Number would silently round shannon amounts above 2^53.

Joined with toastmanAu/daowow@e08898943c.

Pattern

Prefer
assert.strictEqual(got.minimumTickets, BigInt(f.minimum_tickets), "minimumTickets");

Taken from the commit, shortened.

A test changed in the same commit

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

Concepts
Data encoding (molecule, hex, bigints), Testing and devnet
Evidence
From one fix: from one project, checked against its commit
First seen
2026-09-18
Last changed
2026-09-22
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, "Pin JS cell data encoders and decoders to Rust generated vectors", CKB lessons, https://pulse.lusocryptolabs.com/learned/tooling/pin-js-cell-data-encoders-and-decoders-to-rust-generated-vec, CC BY 4.0, last changed 2026-09-22.

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.