CKB Pulse
Lessons

What CKB learned

Start here · Glossary · Test yourself · Feed

“Witnesses and signatures”

48 lessons found. All lessons

Page 1 of 4

Witnesses do not follow reordered inputsWorkingFrom one fix

Witnesses are matched to inputs by position: witness i belongs to input i, and a script reading GroupInput witnesses sees the witnesses at its group's input positions. Reordering inputs does not move the witnesses, so after reordering, check and rebuild the witness list so each input's position again holds the intended witness.

#Witnesses and signatures #Transaction building and fees · Sources (1) · 2026-11-16

Do not detect DER signatures by a leading 0x30 byteWorkingFrom one fix

When converting secp256k1 signatures to DER for a CKB contract (here the Perun channel script, which uses k256 and expects low-S), a 64 or 65 byte compact R||S(||V) signature can begin with 0x30 because R is arbitrary. Dispatch on the fixed lengths first, and parse anything else with a full asn1.Unmarshal that has no trailing bytes, followed by a check that R and S lie in [1, n).

#Witnesses and signatures #Data encoding (molecule, hex, bigints) · Sources (1) · 2026-11-10

Multisig sighash placeholder lock: script plus M zeroed signaturesWorkingFrom one fix

When computing the signing message for a secp256k1_blake160_multisig_all input, set the first witness's WitnessArgs.lock to the multisig script bytes followed by threshold × 65 zero bytes (a single key sighash lock uses just 65 zero bytes), and keep the inputType and outputType fields, before calling CCC's tx.getSignHashInfo(script, client). The same placeholder length must be used here as in the signed witness, otherwise the message differs from what the lock script hashes on chain.

#Witnesses and signatures #Transaction building and fees · Sources (2) · 2026-11-08

secp256k1_blake160_multisig_all signature matching rulesWorkingFrom one fix

The system multisig lock (secp256k1_blake160_multisig_all) expects the witness to carry exactly M signatures (threshold), uses each member key at most once, and requires all of the first R keys (require_first_n) to be among them. A tool collecting partial signatures should dedupe per member key and check the first R are present before finalizing, since any M valid distinct signers that include the first R form a complete set.

#Witnesses and signatures · Sources (1) · 2026-11-08

JoyID sub key signatures depend on the live CoTA cell dep holding the sub key rootAdvancedChecked by the owner

A JoyID sub key (second device) signature is checked by the JoyID lock against the sub key root held in the account's CoTA cell, which the transaction carries as a cell dep. Adding a device spends that CoTA cell and creates a new one with a new root. Two separate things follow: a transaction that still lists the old CoTA out point has a cell dep that is no longer live, and the lock run against the old root data does not accept the sub key signature.

JoyID specific: sub key root lives in the CoTA cell dep.

#Cell deps and script lookup #Witnesses and signatures · Sources (1) · 2026-11-06

JoyID signer prices fees with a 1,000 byte signature placeholderWorkingFrom one fix

With CCC and @ckb-ccc/joy-id, prepareTransaction fills the JoyID witness lock with a 1,000 byte placeholder before the fee is computed as ceil((serialized size + 4) x rate / 1000). The real signature is usually shorter (347 bytes in one testnet order), so the committed transaction is smaller and its measured rate is higher than the rate it was built at (7,278 against 5,000 shannons/KB). To recover the build rate, clone the transaction, set the JoyID witness lock back to 1,000 zero bytes, and compute the rate on that size, confirming with tx.estimateFee(rate) equal to the paid fee.

#Transaction building and fees #Witnesses and signatures · Sources (1) · 2026-10-30

Secp256k1 sighash lock groups cover non contiguous later group witnessesWorkingFrom one fix

With the bundled secp256k1 blake160 sighash lock, all inputs sharing the same lock form one group even when another owner's inputs sit between them. The signature goes in the witness at the group's first input index, and changing a later group witness (which leaves the tx hash unchanged) still fails verification at Inputs[first].Lock. So composed multi owner transactions must place one signature placeholder per lock group at its first input and finalize every group witness before signing.

#Witnesses and signatures #Transaction building and fees · Sources (1) · 2026-10-09

ckb-cli tx sign-inputs stores signatures in the file's signatures map, not witness 0WorkingFrom one fix

ckb-cli `tx sign-inputs --add-signatures` leaves witness 0's lock zero-filled and records the signature in the tx file's `signatures` map keyed by lock arg; `tx send` assembles the final witnesses from that map. A checker that inspects witness 0 for a signature before `tx send` will wrongly report the transaction as unsigned, so read `doc.signatures[lockArg]` instead.

#Witnesses and signatures #Transaction building and fees · Sources (1) · 2026-09-23

Script group hash is the hash of the whole Script, not the code_hashWorkingFrom one fix

A script group is identified by BLAKE2b-256 with the 'ckb-default-hash' personalization over the Molecule-encoded Script (code_hash, hash_type byte data=0/type=1/data1=2/data2=4, args). Lock groups come only from inputs. Type groups come from inputs and outputs, and lock and type groups with the same hash stay distinct. Passing the code_hash as the group hash yields ScriptNotFound.

#Data encoding (molecule, hex, bigints) #Witnesses and signatures · Sources (1) · 2026-11-16

Identify script groups by type and hashWorkingFrom one fix

In CKB the same script hash can be both a lock script group and a type script group in one transaction, and each group has its own input and output indices. When selecting or reporting a script group, for example from a verifier's group list, match on group type together with script hash, never on the hash alone.

#Witnesses and signatures #Other · Sources (1) · 2026-11-16

JoyID sub-key signing needs the COTA aggregator and CSP allowancesWorkingFrom one fix

If you strip external hosts from a CCC bundle or restrict CSP connect-src, keep CCC's COTA aggregator host (cota.nervina.dev) and allow it, because the JoyID signer calls it before signing for sub-key wallets. Also allow the RPC websocket hosts your CCC client uses, such as wss://testnet.ckb.dev.

Low confidence: inferred from the commit message only. The diff showed just a rebuilt bundle.

#Witnesses and signatures #Network and RPC reliability · Sources (1) · 2026-11-16

Witness data in input_type and folding sub-minimum changeWorkingFrom one fix

Put the type script's witness data in WitnessArgs.input_type of each input it guards (the type script reads the first witness of its own input group), so the lock field stays free for the wallet's signature and one signature can cover several such inputs. If the change left after a fixed fee is below a plain cell's minimum occupied capacity, add it to an existing output whose scripts accept extra capacity; if there is no such output, refuse the build instead of creating a cell that cannot exist.

#Witnesses and signatures #Transaction building and fees #Capacity and cell size · Sources (1) · 2026-11-14

Page 1 of 4

Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. JSON · Want a lesson changed or removed? Open an issue.