[Medium] CommitUndo ReducePending: MemStore wraps uint64 on underflow and ignores missing pendings; BadgerStore fails
Report
Summary
On 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.
Root cause
- MemStore
applyUndoLocked(store/mem_store.go:~262-272):ps.Amount -= u.ReducePendingAmountwith no underflow check, and a missing pending is silently skipped (if ps, ok := ...). - BadgerStore
addToPendingAmountTxn(store/badger_store.go:~835-861): errors on a missing pending (ErrKeyNotFound→ "not found") and on underflow (uint64(-delta) > ps.Amount).
Verification
Differential harness, pending amount 100, undo with ReducePendingAmount: 200:
- MemStore:
err=<nil>, amount becomes 18446744073709551316 (2^64 - 100). - BadgerStore:
err=addToPendingAmount: pending sendhash0000 underflow (amount 100, delta -200), amount stays 100. - Missing pending: MemStore
err=<nil>, BadgerStore errors.
Impact
Silent 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).
Note on related reports
Distinct from #226 V1 (different layer/function) and from #395 (cancel staged-vs-full balance formulas).
Suggested fix
Check for underflow and for a missing pending in MemStore's undo path, matching BadgerStore.
Thread
Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-16836 and says what differs; it is read like any other.