CKB Pulse

全部经验 · Rust scripts and ckb-std · 从这里开始 · 术语表

Partial load of a cell's type Script header to match code_hash and hash_type进阶来自一次修复

来自一次修复 · 核对结果:正确 · 核对于 2026-11-19

In a ckb-std script you can load a cell's type script into a fixed 49 byte buffer with syscalls::load_cell_by_field(..., CellField::Type), then compare code_hash at bytes 16..48 and hash_type at byte 48 of the molecule Script table, without allocating for args. A short buffer returns Err(SysError::LengthNotEnough) yet still fills the buffer, so treat that error like Ok, and treat ItemMissing as a cell with no type script.

为什么重要: Loading the full type Script of every input and output allocates for arbitrary, attacker-sized args, and treating LengthNotEnough as a failure would wrongly reject cells whose script header was in fact read correctly.

代码模式

推荐
Ok(_) | Err(SysError::LengthNotEnough(_)) => { if b[16..48] == script.code_hash().as_slice()[..] && b[48] == script.hash_type().as_slice()[0]

摘自提交,已缩短。

概念
Data encoding (molecule, hex, bigints), Cell deps and script lookup
证据
来自一次修复: 来自一个项目,已对照其提交核对
首次出现
2026-10-07
最近改动
2026-10-07
最近核对
2026-11-19
对照提交的核对结果
正确:这条经验出自该提交,并且在今天的代码中仍然成立

来源(1)

更多关于Rust scripts and ckb-std

查看此主题的全部 35 条

你维护这条经验的来源项目吗?请确认或纠正

引用这条经验
LusoCryptoLabs, "Partial load of a cell's type Script header to match code_hash and hash_type", CKB lessons, https://pulse.lusocryptolabs.com/learned/scripts/partial-load-of-a-cell-s-type-script-header-to-match-code-ha, CC BY 4.0, last changed 2026-10-07.

取自公开提交,并对照每条经验的来源提交和项目当前代码做了核对。使用前请先读来源。 文本采用 CC BY 4.0:请署名 LusoCryptoLabs, CKB lessons,并附上经验的链接。 想修改或撤下某条经验?请提交 issue。