CKB Pulse

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

Prefer
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.

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)

More about Rust scripts and ckb-std

All 35 in this topic

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.

Drawn from public commits and checked against the commit each one came from and the project's code today. Read the source before you rely on one. Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. Want a lesson changed or removed? Open an issue.