CKB Pulse

Todas as lições · Rust scripts and ckb-std · Começa aqui · Glossário

Partial load of a cell's type Script header to match code_hash and hash_typeAvançadoDe uma correção

De uma correção · Verificação: certa · Verificada em 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.

Porque importa: 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.

Padrão

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

Tirado do commit, encurtado.

Conceitos
Data encoding (molecule, hex, bigints), Cell deps and script lookup
Evidência
De uma correção: de um projeto, verificada contra o commit
Vista pela primeira vez
2026-10-07
Última mudança
2026-10-07
Última verificação
2026-11-19
Verificação contra o commit
certa: a lição sai do commit e continua a valer no código de hoje

Fontes (1)

Mais sobre Rust scripts and ckb-std

Ver as 35 deste tema

Manténs um projeto de onde esta lição veio? Confirma ou corrige

Citar esta lição
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.

Tiradas de commits públicos e verificadas contra o commit de onde cada uma veio e o código de hoje do projeto. Lê a fonte antes de confiar numa. Texto sob CC BY 4.0: dá crédito à LusoCryptoLabs, CKB lessons, com uma ligação para a lição. Queres que uma lição seja mudada ou retirada? Abre um issue.