[Low] MemStore applies TopUp/ReducePending twice to pendings inserted via PutPendingSend (shared-pointer aliasing)
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.PutPendingSendstores the same pointer in both maps (store/mem_store.go:150-155:m.pending[ps.SendHash] = &cpandm.pendingByDest[ps.Destination][ps.SendHash] = &cp).- Both amount-adjustment paths then update through both maps:
applyUndoLockedReducePending (:263ps.Amount -= …and:266dps.Amount -= …, wheredps == ps) andapplyCommitLockedTopUpPending (:397and:400, same pattern). - BadgerStore:
addToPendingAmountTxn(store/badger_store.go:835) updates the pending record once. - The
AddPendingpaths already use a separate copy (cp2 := cp,mem_store.go:289and:377) — onlyPutPendingSendaliases.
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
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.