Skip to content

fix(TBC777): reject negative escrow claim amounts - #524

Merged
ClemensLey merged 2 commits into
bitcoin-computer:stagingfrom
codenlighten:fix/tbc777-claim-amounts
Sep 29, 2026
Merged

ClemensLey merged 2 commits into
bitcoin-computer:stagingfrom
codenlighten:fix/tbc777-claim-amounts

Conversation

@codenlighten

@codenlighten codenlighten commented Sep 28, 2026 •

Copy link
Copy Markdown

Summary

EscrowAuditor sums claim amounts as signed bigints. An escrow can list a negative claim for a token that never
withdraws, and that entry offsets a larger claim in the totals. For example, [t, 100n] and [dummy, -94n] against
a 6n deposit add up to exactly the deposit, so the available balance comes out as 0 and t could claim 100n.

On staging this is rejected today, but only because in-contract computer.sync returns negative bigints as
strings (-94n becomes "-94n"), so the sum throws Cannot mix BigInt and other types. Once that is fixed in the
lib, the offset would go through. This PR makes the auditor reject such claims explicitly.

Changes

  • EscrowAuditor.checkClaimAmount(): every regular and final claim amount for the lineage must be a non-negative
    bigint. collectRevisions calls it, and every claim that is paid comes from states[0], which it also checks.

Testing

  • New test "rejects a negative claim that would offset an over-claim". It passes with the fix (3/3 runs). On
    staging it is rejected only by the TypeError.
  • Full TBC777 suite: every tbc777.test.ts test passes. The only failure seen was an intermittent
    txn-mempool-conflict in tbc777m.test.ts, which this PR doesn't touch; that file passed 3/3 on rerun.

Notes

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The change is narrowly scoped, directly addresses the described audit-bypass vector, and is covered by a targeted regression test.

Review effort: Lite
Findings: None

What changed in this PR

This PR hardens TBC777’s escrow auditing against a signed-amount offset attack by explicitly rejecting negative (or non-bigint) claim amounts in escrow withdraws / finalWithdraws, ensuring totals cannot be manipulated to bypass the no-inflation invariant.

Changes:

  • Add EscrowAuditor.checkClaimAmount() and apply it while collecting regular and final claim entries for a lineage.
  • Add a regression test that demonstrates and asserts rejection of a negative claim used to offset an over-claim.
File Description
packages/​TBC777/​src/​tbc777.ts Validates claim amounts during audit collection to reject negative/non-bigint claims before summing authorizations.
packages/​TBC777/​test/​tbc777.test.ts Adds a test reproducing the offset scenario and asserting the auditor rejects the negative claim.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

codenlighten and others added 2 commits September 29, 2026 16:28
EscrowAuditor summed claim amounts as signed bigints, so an escrow could
list a negative claim for a token that never withdraws and use it to
offset a larger claim in the totals. This is rejected today only because
in-contract sync returns negative bigints as strings, which makes the sum
throw. Require every claim amount for the lineage to be a non-negative
bigint.
@ClemensLey
ClemensLey force-pushed the fix/tbc777-claim-amounts branch from a4a3ebd to f8a1ce5 Compare September 29, 2026 23:31
@ClemensLey
ClemensLey merged commit e1d3bd7 into bitcoin-computer:staging Sep 29, 2026
@ClemensLey

Copy link
Copy Markdown
Contributor

Thanks for finding this and for the fix. Rejecting a non-bigint or negative claim in collectRevisions is the right place to stop it from offsetting an over-claim.

I rebased onto staging so this sits alongside the deposit-credit tests from #523, regenerated build/ so the package entry includes checkClaimAmount, and merged. The full TBC777 suite passed. Tokens already inscribed keep their old code; new deploys from this package pick up the check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants