All lessons · Rust scripts and ckb-std · Start here · Glossary
Treat an absent WitnessArgs.lock as a load failure in ckb-std lock scriptsWorkingFrom one fix
From one fix · Check: right · Checked 2026-11-19
With ckb-std, `load_witness_args(0, Source::GroupInput)` can succeed while `WitnessArgs.lock` is an empty BytesOpt, so call `lock().to_opt()` and return an error on None before reading `raw_data()`. The commit's ckb-testtool tests check both a missing witness and a WitnessArgs with no lock field, and both fail with the load witness error.
Why it matters: A WitnessArgs whose lock field is absent still deserializes successfully, so a script that only checks the load result will either panic on unwrap or run its signature logic against missing data instead of rejecting with a clear error code.
Pattern
let lock_opt = witness_args.lock().to_opt().ok_or(ERR_LOAD_WITNESS)?;Taken from the commit, shortened.
A test changed in the same commit
It sits next to the fix. We did not run it.
- salmansarwarr/Tranfr:
tests/src/tests.rs
- Concepts
- Witnesses and signatures, Data encoding (molecule, hex, bigints)
- Evidence
- From one fix: from one project, checked against its commit
- First seen
- 2026-09-25
- Last changed
- 2026-09-25
- 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-09-25 · salmansarwarr/Tranfr · more from this project
More about Rust scripts and ckb-std
- Use raw_data(), not as_slice(), when parsing a packed::Bytes witness
- CKB blake160 is the first 20 bytes of the 32 byte ckbhash
- Creation witness for an output type script goes in WitnessArgs.output_type
Do you maintain a project this lesson came from? Confirm or correct it
Cite this lesson
LusoCryptoLabs, "Treat an absent WitnessArgs.lock as a load failure in ckb-std lock scripts", CKB lessons, https://pulse.lusocryptolabs.com/learned/scripts/treat-an-absent-witnessargs-lock-as-a-load-failure-in-ckb-st, CC BY 4.0, last changed 2026-09-25.