Repository navigation
fix(TBC777): reject negative escrow claim amounts - #524
Conversation
There was a problem hiding this comment.
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.
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.
a4a3ebd to
f8a1ce5
Compare
|
Thanks for finding this and for the fix. Rejecting a non-bigint or negative claim in I rebased onto staging so this sits alongside the deposit-credit tests from #523, regenerated |
Summary
EscrowAuditorsums claim amounts as signed bigints. An escrow can list a negative claim for a token that neverwithdraws, and that entry offsets a larger claim in the totals. For example,
[t, 100n]and[dummy, -94n]againsta 6n deposit add up to exactly the deposit, so the available balance comes out as 0 and
tcould claim 100n.On
stagingthis is rejected today, but only because in-contractcomputer.syncreturns negative bigints asstrings (
-94nbecomes"-94n"), so the sum throwsCannot mix BigInt and other types. Once that is fixed in thelib, 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-negativebigint.
collectRevisionscalls it, and every claim that is paid comes fromstates[0], which it also checks.Testing
stagingit is rejected only by the TypeError.tbc777.test.tstest passes. The only failure seen was an intermittenttxn-mempool-conflictintbc777m.test.ts, which this PR doesn't touch; that file passed 3/3 on rerun.Notes
change that makes in-contract
syncreturn negative bigints as bigints. Merging the lib change first would makethe offset claim go through.
tbc777.test.ts. The two willconflict there, and I'll rebase whichever lands second.
_rootfrom the running method #521 (fix/security-review) doesn't touch the auditor, and this patch applies cleanly on top of it.build/isn't rebuilt here.