All lessons · Rust scripts and ckb-std · Start here · Glossary
Use raw_data(), not as_slice(), when parsing a packed::Bytes witnessWorkingChecked by the owner
Checked by the owner · Check: right · Checked 2026-11-19
A transaction witness in ckb_types is a molecule packed::Bytes, so as_slice() returns the 4 byte length header followed by the content, while raw_data() returns only the content (here a serialized WitnessArgs). A check that compares a witness to the secp256k1 sighash placeholder WitnessArgs (lock of 65 zero bytes) must use witness.raw_data() (or unpack()), otherwise it is silently never true. Fiber's funding witness merge never recognized placeholders until it switched to raw_data(), so a peer's placeholder could be kept in place of a real signature.
Why it matters: A placeholder check run over as_slice() includes the 4 byte molecule length header, so it never matches; Fiber's funding witness merge therefore failed to swap its own placeholder for the peer's real signature, which the new test asserts.
Pattern
is_secp_sighash_placeholder_witness(&witness.raw_data())Taken from the commit, shortened.
A test changed in the same commit
It sits next to the fix. We did not run it.
- nervosnetwork/fiber:
crates/fiber-lib/src/fiber/tests/channel.rs - LusoCryptoLabs/ckb-script-pitfalls:
code/tests/tests/pitfalls.rs
- Concepts
- Data encoding (molecule, hex, bigints), Witnesses and signatures
- Evidence
- Checked by the owner: checked by the owner of the project it came from, who is also the publisher of these lessons
- First seen
- 2026-10-29
- Last changed
- 2026-10-29
- Last checked
- 2026-11-19
- Check against the commit
- right: the lesson follows from its commit and still holds in the code today
Sources (2)
- 2026-10-29 · nervosnetwork/fiber · more from this project
- 2026-10-29 · LusoCryptoLabs/ckb-script-pitfalls · more from this project
More about Rust scripts and ckb-std
- CKB blake160 is the first 20 bytes of the 32 byte ckbhash
- Treat an absent WitnessArgs.lock as a load failure in ckb-std lock scripts
- Creation witness for an output type script goes in WitnessArgs.output_type
Checked by @LusoCryptoLabs (owner of the project), 2026-11-19.
Do you maintain a project this lesson came from? Confirm or correct it
Cite this lesson
LusoCryptoLabs, "Use raw_data(), not as_slice(), when parsing a packed::Bytes witness", CKB lessons, https://pulse.lusocryptolabs.com/learned/scripts/use-raw-data-not-as-slice-when-parsing-a-packed-bytes-witnes, CC BY 4.0, last changed 2026-10-29.