CKB Pulse

Todas as lições · Developer tooling · Começa aqui · Glossário

Charging load_program bytes as cycles when building a custom ckb-vm machineAvançadoDe uma correção

De uma correção · Verificação: certa · Verificada em 2026-11-19

When you build a ckb-vm machine yourself (DefaultMachineBuilder or AsmMachine) and call load_program, charge the returned byte count with machine.add_cycles_no_checking(ckb_script::cost_model::transferred_byte_cycles(bytes)). That count covers the loaded program and the stack and argument setup, and TransactionScriptsVerifier charges it on chain, so without it your cycle count comes out too low (in ckb-debugger the fib test went from 1361 to 3364 cycles). For AsmMachine call it on the inner machine, and pass the error up instead of unwrapping.

Porque importa: A hand-built ckb-vm machine that skips charging the loaded program bytes reports fewer cycles than on-chain verification does (the fib example showed 1361 instead of 3364), so cycle estimates and limits based on it are wrong.

Padrão

Preferir
machine.add_cycles_no_checking(transferred_byte_cycles(bytes))?;

Tirado do commit, encurtado.

Um teste mudou no mesmo commit

Está ao lado da correcção. Nós não o corremos.

Conceitos
Testing and devnet, Other
Evidência
De uma correção: de um projeto, verificada contra o commit
Vista pela primeira vez
2026-11-03
Última mudança
2026-11-03
Ú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 Developer tooling

Ver as 35 deste tema

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

Citar esta lição
LusoCryptoLabs, "Charging load_program bytes as cycles when building a custom ckb-vm machine", CKB lessons, https://pulse.lusocryptolabs.com/learned/tooling/charging-load-program-bytes-as-cycles-when-building-a-custom, CC BY 4.0, last changed 2026-11-03.

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.