{"id":"XE-16836","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"665","source_url":"https://github.com/xeprotocol/xe/issues/665","reporter_id":2920,"title":"[Medium] CommitUndo ReducePending: MemStore wraps uint64 on underflow and ignores missing pendings; BadgerStore fails","area":"leasing-ledger","claimed_tier":"medium","assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-17T06:33:15.050234+00:00","updated_at":"2026-11-22T23:26:13.151334+00:00","source_created_at":"2026-11-17T06:31:24+00:00","told_at":"2026-11-22T23:26:13.184072+00:00","status_changed_at":"2026-11-22T23:26:13.168992+00:00","url":"https://bounty.xe.network/XE-16836","body":"## Summary\n\nOn `CommitUndo` with `ReducePending`, MemStore subtracts without an underflow check and silently ignores a missing pending, while BadgerStore errors on both. An underflow wraps a pending balance to ~2^64, creating a phantom ~1.8e19 pending on MemStore that feeds the supply auditor and auto-receive.\n\n## Root cause\n\n- MemStore `applyUndoLocked` (`store/mem_store.go:~262-272`): `ps.Amount -= u.ReducePendingAmount` with no underflow check, and a missing pending is silently skipped (`if ps, ok := ...`).\n- BadgerStore `addToPendingAmountTxn` (`store/badger_store.go:~835-861`): errors on a missing pending (`ErrKeyNotFound` → \"not found\") and on underflow (`uint64(-delta) > ps.Amount`).\n\n## Verification\n\nDifferential harness, pending amount 100, undo with `ReducePendingAmount: 200`:\n- MemStore: `err=<nil>`, amount becomes **18446744073709551316** (2^64 - 100).\n- BadgerStore: `err=addToPendingAmount: pending sendhash0000 underflow (amount 100, delta -200)`, amount stays 100.\n- Missing pending: MemStore `err=<nil>`, BadgerStore errors.\n\n## Impact\n\nSilent corruption of pending balances on MemStore vs loud failure on Badger. Ledger-level trigger class: multi-step unwinds built from stale store reads (#226 V1 — related, not a duplicate: V1 is about `rollback.go` helpers reading stale state during cascade planning; this is the store layer's divergent handling of the resulting undo).\n\n## Note on related reports\n\nDistinct from #226 V1 (different layer/function) and from #395 (cancel staged-vs-full balance formulas).\n\n## Suggested fix\n\nCheck for underflow and for a missing pending in MemStore's undo path, matching BadgerStore.","patch_refs":[],"thread":[{"id":18816,"source":"desk","source_ref":"reply:16493","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-16836 and says what differs; it is read like any other.","created_at":"2026-11-22T23:26:13.151334+00:00"}]}