CKB Pulse

All lessons · CCC (TypeScript SDK) · Start here · Glossary

completeFeeBy adds change instead of shrinking outputs, breaking output bound proofsWorkingFrom one fix

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

When a lock script commits to output 0's exact bytes (capacity included), the capacity must be decided before proving and must equal what the transaction ships. In CCC, tx.completeFeeBy(signer) pays the fee by pulling in the signer's cells and adding a change output, so output 0 keeps its capacity and the fee is then paid from extra inputs, which breaks the binding if the proof assumed inputCapacity minus fee. Instead compute the fee from tx.toBytes().length with the witness already at its final length, build output 0 at inputCapacity minus that fee, and check before sending that the fee recomputed on the real transaction equals the planned one.

Why it matters: The context was computed for output 0 at inputCapacity minus fee, but completeFeeBy left output 0 at inputCapacity and added a change output, so every bound unlock was rejected on chain with ContextMismatch.

Pattern

Avoid
await tx.completeFeeBy(signer);

Taken from the commit, shortened.

A test changed in the same commit

It sits next to the fix. We did not run it.

Reproduced by a test

A public test runs what this lesson says on @ckb-ccc/core 1.23.1, with no node. Anyone can run it. It covers a part of the lesson: what completeFeeBy does to the transaction, not the lock that commits to output 0.

tests/ccc/complete-fee-by-adds-change.test.mjs

Concepts
Transaction building and fees, Witnesses and signatures, Capacity and cell size
Evidence
From one fix: from one project, checked against its commit
First seen
2026-11-04
Last changed
2026-11-04
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 CCC (TypeScript SDK)

All 33 in this topic

Do you maintain a project this lesson came from? Confirm or correct it

Cite this lesson
LusoCryptoLabs, "completeFeeBy adds change instead of shrinking outputs, breaking output bound proofs", CKB lessons, https://pulse.lusocryptolabs.com/learned/ccc/completefeeby-adds-change-instead-of-shrinking-outputs-break, CC BY 4.0, last changed 2026-11-04.

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.