CKB Pulse

Todas as lições · CCC (TypeScript SDK) · Começa aqui · Glossário

completeFeeBy adds change instead of shrinking outputs, breaking output bound proofsPráticoDe uma correção

De uma correção · Verificação: certa · Verificada em 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.

Porque importa: 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.

Padrão

Evitar
await tx.completeFeeBy(signer);

Tirado do commit, encurtado.

Um teste mudou no mesmo commit

Está ao lado da correcção. Nós não o corremos.

Reproduzida por um teste

Um teste público corre o que esta lição diz em @ckb-ccc/core 1.23.1, sem nó. Qualquer pessoa o pode correr. Cobre uma parte da lição: what completeFeeBy does to the transaction, not the lock that commits to output 0.

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

Conceitos
Transaction building and fees, Witnesses and signatures, Capacity and cell size
Evidência
De uma correção: de um projeto, verificada contra o commit
Vista pela primeira vez
2026-11-04
Última mudança
2026-11-04
Ú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 (1)

Mais sobre CCC (TypeScript SDK)

Ver as 33 deste tema

Manténs um projeto de onde esta lição veio? Confirma ou corrige

Citar esta lição
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.

Tiradas de commits públicos e verificadas contra o commit de onde cada uma veio e o código de hoje do projeto. Lê a fonte antes de confiar numa. Texto sob CC BY 4.0: dá crédito à LusoCryptoLabs, CKB lessons, com uma ligação para a lição. Queres que uma lição seja mudada ou retirada? Abre um issue.