All lessons · Developer tooling · Start here · Glossary
Charging load_program bytes as cycles when building a custom ckb-vm machineAdvancedFrom one fix
From one fix · Check: right · Checked 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.
Why it matters: 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.
Pattern
machine.add_cycles_no_checking(transferred_byte_cycles(bytes))?;Taken from the commit, shortened.
A test changed in the same commit
It sits next to the fix. We did not run it.
- nervosnetwork/ckb-standalone-debugger:
ckb-debugger/tests/test_command.rs
- Concepts
- Testing and devnet, Other
- Evidence
- From one fix: from one project, checked against its commit
- First seen
- 2026-11-03
- Last changed
- 2026-11-03
- 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-11-03 · nervosnetwork/ckb-standalone-debugger · more from this project
More about Developer tooling
- ckb-vm-js 0.2.0 (npm) checks header hash instead of rejecting the field
- Derive devnet Spore and system script cell deps from a fresh OffCKB export
- Pass wasm bytes to ckb-vm-js createVerifier in Node
Do you maintain a project this lesson came from? Confirm or correct it
Cite this lesson
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.