All lessons · Rust scripts and ckb-std · Start here · Glossary
CKB VM2 READ and INHERITED_FDS syscalls take a length pointer and return status in a0AdvancedFrom one fix
From one fix · Check: right · Checked 2026-11-19
In CKB VM2, READ takes (fd, buffer_addr, length_addr) and INHERITED_FDS takes (buffer_addr, length_addr), with *length_addr set to the buffer capacity before the ecall. The syscall returns only a status in a0 (0 on success) and writes the delivered byte count or fd count back through length_addr, so never treat a0 as the payload. After checking a0, handle short pipe reads by looping or failing explicitly, and bounds-check an INHERITED_FDS index against the smaller of the returned count and the capacity you passed.
Why it matters: A bare ecall passes garbage in a1/a2 and returns the status word as if it were the data, so the script reads wrong values or faults.
Pattern
// READ takes (fd, buffer_addr, length_addr): the scheduler writes the payload to the buffer and the delivered byte count back through length_addr, with SUCCESS in a0.Taken from the commit, shortened.
A test changed in the same commit
It sits next to the fix. We did not run it.
- CellScript-Labs/CellScript:
services/registry-api/test/sql-registry-store.test.ts,tests/deferred_ckb_semantics.rs,tests/examples.rs
- Concepts
- Other
- Evidence
- From one fix: from one project, checked against its commit
- First seen
- 2026-10-29
- Last changed
- 2026-10-29
- 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-29 · CellScript-Labs/CellScript · more from this project
More about Rust scripts and ckb-std
- Enable molecule bytes_vec so ckb-std scripts contain no atomic instructions
- Close spawn pipe descriptors when an IPC channel is freed
- Disable overflow checks for ckb-std when using its dummy-atomic polyfills
Do you maintain a project this lesson came from? Confirm or correct it
Cite this lesson
LusoCryptoLabs, "CKB VM2 READ and INHERITED_FDS syscalls take a length pointer and return status in a0", CKB lessons, https://pulse.lusocryptolabs.com/learned/scripts/ckb-vm2-read-and-inherited-fds-syscalls-take-a-length-pointe, CC BY 4.0, last changed 2026-10-29.