CKB Pulse

All lessons · Rust scripts and ckb-std · Start here · Glossary

Place a script's raw witness at the index of the input it validatesWorkingFrom one fix

From one fix · Check: right · Checked 2026-11-19

When a type script reads its proof with load_witness(index, Source::Input) for its own input, the builder must put that raw witness at exactly that input's index. This commit puts the ledger cell at input 0 so its proof is witness 0, and pads the remaining witnesses with "0x" so witnesses.length equals inputs.length and a later funding/signing step appends rather than displaces it.

Why it matters: If the proof sits at any other witness index, the type script's load_witness(index, Source::Input) reads the wrong or empty bytes and the transaction is refused. An unpadded witness list also lets a later funding or signing step shift or overwrite the proof slot.

Pattern

Prefer
witnesses: [hex0x(ledgerWitness.encodeLedgerWitness(records)), ...entryCells.map(() => "0x"), "0x"]

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, Transaction building and fees
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, "Place a script's raw witness at the index of the input it validates", CKB lessons, https://pulse.lusocryptolabs.com/learned/scripts/place-a-script-s-raw-witness-at-the-index-of-the-input-it-va, 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.