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
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.
- toastmanAu/daowow:
apps/web/test/codec.test.js - toastmanAu/daowow:
apps/web/test/entry-codec.test.js,crates/daowow-core/tests/gen_vectors.rs
- 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)
- 2026-09-18 · toastmanAu/daowow · more from this project
- 2026-09-22 · toastmanAu/daowow · more from this project
More about Developer tooling
- ckb-vm-js 0.2.0 (npm) checks header hash instead of rejecting the field
- Emit shannon u64 values as strings in cross-language test vectors
- Mirror on-chain rules off-chain with mutation tests
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.