Todas as lições · Rust scripts and ckb-std · Começa aqui · Glossário
Use raw_data(), not as_slice(), when parsing a packed::Bytes witnessPráticoVerificada pelo dono
Verificada pelo dono · Verificação: certa · Verificada em 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.
Porque importa: 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.
Padrão
is_secp_sighash_placeholder_witness(&witness.raw_data())Tirado do commit, encurtado.
Um teste mudou no mesmo commit
Está ao lado da correcção. Nós não o corremos.
- nervosnetwork/fiber:
crates/fiber-lib/src/fiber/tests/channel.rs - LusoCryptoLabs/ckb-script-pitfalls:
code/tests/tests/pitfalls.rs
- Conceitos
- Data encoding (molecule, hex, bigints), Witnesses and signatures
- Evidência
- Verificada pelo dono: verificada pelo dono do projeto de onde veio, que também publica estas lições
- Vista pela primeira vez
- 2026-10-29
- Última mudança
- 2026-10-29
- Ú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 (2)
- 2026-10-29 · nervosnetwork/fiber · mais deste projeto
- 2026-10-29 · LusoCryptoLabs/ckb-script-pitfalls · mais deste projeto
Mais sobre 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
Verificada por @LusoCryptoLabs (dono do projeto), 2026-11-19.
Manténs um projeto de onde esta lição veio? Confirma ou corrige
Citar esta lição
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.