<!-- XE-16836 · [Medium] CommitUndo ReducePending: MemStore wraps uint64 on underflow and ignores missing pendings; BadgerStore fails · testnet -->
*Markdown view of <https://bounty.xe.network/XE-16836>. The page is the record; this is the same page for reading.*

XE-16836 · Bounty

# \[Medium\] CommitUndo ReducePending: MemStore wraps uint64 on underflow and ignores missing pendings; BadgerStore fails

Closed · duplicate
—claimed Medium
[xe#665](https://github.com/xeprotocol/xe/issues/665)
filed 2026-11-17 06:31 UTC
by kecedanzz77-bit

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Medium

Area
:   Leasing / ledger

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-22 23:26 UTC

Told
:   2026-11-22 23:26 UTC

### Patches

None linked.

### History

- [770263](https://bounty.xe.network/log/770263) 2026-11-22 23:26 UTC reply.mirror\_failed
- [769892](https://bounty.xe.network/log/769892) 2026-11-22 23:26 UTC proposal.adopted
- [769891](https://bounty.xe.network/log/769891) 2026-11-22 23:26 UTC reply.sent
- [769890](https://bounty.xe.network/log/769890) 2026-11-22 23:26 UTC proposal.adopted
- [769889](https://bounty.xe.network/log/769889) 2026-11-22 23:26 UTC ticket.status new → closed
- [768873](https://bounty.xe.network/log/768873) 2026-11-22 23:25 UTC proposal.adopted
- [768872](https://bounty.xe.network/log/768872) 2026-11-22 23:25 UTC ticket.facts area
- [768871](https://bounty.xe.network/log/768871) 2026-11-22 23:25 UTC proposal.adopted
- [768870](https://bounty.xe.network/log/768870) 2026-11-22 23:25 UTC ticket.facts
- [768869](https://bounty.xe.network/log/768869) 2026-11-22 23:25 UTC proposal.adopted
- [768868](https://bounty.xe.network/log/768868) 2026-11-22 23:25 UTC ticket.facts
- [766573](https://bounty.xe.network/log/766573) 2026-11-22 23:17 UTC note.added

[Full history](https://bounty.xe.network/log?ref=XE-16836) · [JSON](https://bounty.xe.network/v1/tickets/XE-16836) · [markdown](https://bounty.xe.network/XE-16836.md)

### 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.ReducePendingAmount` with 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

**Joseph Denne**team2026-11-22 23:26 UTCdesk

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.
