CKB Pulse

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

Prefer
// 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.

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)

More about Rust scripts and ckb-std

All 35 in this topic

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.

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.