<!-- XE-16990 · [Low] MemStore applies TopUp/ReducePending twice to pendings inserted via PutPendingSend (shared-pointer aliasing) · testnet -->
*Markdown view of <https://bounty.xe.network/XE-16990>. The page is the record; this is the same page for reading.*

XE-16990 · Bounty

# \[Low\] MemStore applies TopUp/ReducePending twice to pendings inserted via PutPendingSend (shared-pointer aliasing)

Closed · duplicate
—
[xe#701](https://github.com/xeprotocol/xe/issues/701)
filed 2026-11-17 08:12 UTC
by kecedanzz77-bit

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   Leasing / ledger

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-22 23:26 UTC

Told
:   2026-11-22 23:26 UTC

### Patches

None linked.

### History

- [770267](https://bounty.xe.network/log/770267) 2026-11-22 23:26 UTC reply.mirror\_failed
- [769977](https://bounty.xe.network/log/769977) 2026-11-22 23:26 UTC proposal.adopted
- [769976](https://bounty.xe.network/log/769976) 2026-11-22 23:26 UTC reply.sent
- [769975](https://bounty.xe.network/log/769975) 2026-11-22 23:26 UTC ticket.status new → closed
- [769035](https://bounty.xe.network/log/769035) 2026-11-22 23:25 UTC proposal.adopted
- [769034](https://bounty.xe.network/log/769034) 2026-11-22 23:25 UTC ticket.facts area
- [769033](https://bounty.xe.network/log/769033) 2026-11-22 23:25 UTC proposal.adopted
- [769032](https://bounty.xe.network/log/769032) 2026-11-22 23:25 UTC ticket.facts
- [769031](https://bounty.xe.network/log/769031) 2026-11-22 23:25 UTC proposal.adopted
- [769030](https://bounty.xe.network/log/769030) 2026-11-22 23:25 UTC ticket.facts
- [766400](https://bounty.xe.network/log/766400) 2026-11-22 23:17 UTC note.added
- [766385](https://bounty.xe.network/log/766385) 2026-11-22 23:17 UTC proposal.created

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

### Report

## Summary

MemStore applies TopUp/ReducePending **twice** to pendings inserted via `PutPendingSend`: the primary map and the dest index store the *same pointer*, and both amount-adjustment paths update the entry through both maps, so the delta lands twice on the same object. BadgerStore has a single source of truth and applies it once. Notably, the commit/undo `AddPending` paths already avoid this with a separate copy — only `PutPendingSend` aliases, so MemStore's arithmetic depends on *how the pending was inserted*.

## Root Cause

- `MemStore.PutPendingSend` stores the *same* pointer in both maps (`store/mem_store.go:150-155`: `m.pending[ps.SendHash] = &cp` and `m.pendingByDest[ps.Destination][ps.SendHash] = &cp`).
- Both amount-adjustment paths then update through *both* maps: `applyUndoLocked` ReducePending (`:263` `ps.Amount -= …` and `:266` `dps.Amount -= …`, where `dps == ps`) and `applyCommitLocked` TopUpPending (`:397` and `:400`, same pattern).
- BadgerStore: `addToPendingAmountTxn` (`store/badger_store.go:835`) updates the pending record once.
- The `AddPending` paths already use a separate copy (`cp2 := cp`, `mem_store.go:289` and `:377`) — only `PutPendingSend` aliases.

## Verification

Executed differential harness (MemStore vs BadgerStore):

```
A1 — PutPendingSend(amount 100) + CommitUndo ReducePending 10:   Mem = 80, Badger = 90
A2 — PutPendingSend(amount 100) + CommitBlock TopUpPending 10:   Mem = 120, Badger = 110
A3 (control) — pending via CommitBlock AddPending(100) + undo:   Mem = 90, Badger = 90
```

Pending amounts feed balances/auto-receive/supply audit, but the trigger path is test-only: `PutPendingSend` has **no production callers** (verified by grep: only the `core/store.go:15` interface definition; production pendings enter via `CommitBlock AddPending`, which uses separate copies). So this corrupts MemStore-based test arithmetic, not production state. Hence Low, not Medium.

## Note on related reports

**#665 is distinct but related — read this carefully:** #665 covers underflow \+ missing pending in `CommitUndo` only. Notably, #665's own PoC number (amount `18446744073709551316` for amount 100, reduce 200\) *is* the double-apply signature: 2^64 − 18446744073709551316 \= 300, i.e. 100 − 2×200 — but #665 attributes it to underflow and mislabels it "2^64 − 100". Fixing underflow alone leaves this finding intact — A1/A2 above involve no underflow. The TopUp half lives in `applyCommitLocked`, which #665 never touches. **#664 is distinct** (TopUp only for a *missing* pending). **#226 V4 is distinct** (Badger dest-list duplicate appends \+ CommitCascade CAS — different mechanism and backend). **#8 Finding 2 is distinct** (ledger-level rollback planning, not store-layer aliasing).

## Suggested fix

Store a separate copy in the dest index in `PutPendingSend` (`cp2 := cp`), matching the `AddPending` paths.

### 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-16990 and says what differs; it is read like any other.
