{"id":"XE-16990","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"701","source_url":"https://github.com/xeprotocol/xe/issues/701","reporter_id":2920,"title":"[Low] MemStore applies TopUp/ReducePending twice to pendings inserted via PutPendingSend (shared-pointer aliasing)","area":"leasing-ledger","claimed_tier":null,"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-17T08:13:52.166083+00:00","updated_at":"2026-11-22T23:26:14.701332+00:00","source_created_at":"2026-11-17T08:12:45+00:00","told_at":"2026-11-22T23:26:14.743198+00:00","status_changed_at":"2026-11-22T23:26:14.717851+00:00","url":"https://bounty.xe.network/XE-16990","body":"## Summary\n\nMemStore 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*.\n\n## Root Cause\n\n- `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`).\n- 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).\n- BadgerStore: `addToPendingAmountTxn` (`store/badger_store.go:835`) updates the pending record once.\n- The `AddPending` paths already use a separate copy (`cp2 := cp`, `mem_store.go:289` and `:377`) — only `PutPendingSend` aliases.\n\n## Verification\n\nExecuted differential harness (MemStore vs BadgerStore):\n\n```\nA1 — PutPendingSend(amount 100) + CommitUndo ReducePending 10:   Mem = 80, Badger = 90\nA2 — PutPendingSend(amount 100) + CommitBlock TopUpPending 10:   Mem = 120, Badger = 110\nA3 (control) — pending via CommitBlock AddPending(100) + undo:   Mem = 90, Badger = 90\n```\n\nPending 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.\n\n## Note on related reports\n\n**#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).\n\n## Suggested fix\n\nStore a separate copy in the dest index in `PutPendingSend` (`cp2 := cp`), matching the `AddPending` paths.\n","patch_refs":[],"thread":[{"id":18840,"source":"desk","source_ref":"reply:16517","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-16990 and says what differs; it is read like any other.","created_at":"2026-11-22T23:26:14.701332+00:00"}]}