api: GET /accounts offset paging skips and duplicates accounts under concurrent balance changes (no cursor, re-sort per page)
Report
GET /accounts offset paging skips and duplicates accounts under concurrent balance changes (no cursor, re-sort per page)
Summary
GET /accounts pages with a numeric offset over a list that is re-sorted by live XE balance on every request. Any send/receive that changes any account's XE balance between two page fetches re-orders the whole list, shifting the offset window: an account crossing the page boundary is returned twice or never. There is no snapshot, no cursor, and no total anywhere in the path, so a consumer walking the enumeration (explorer, indexer, SDK, supply census) silently misses or double-counts accounts.
This is the GET /accounts instance of the offset-paging defect class filed as XE-17296 for GET /pending — but with a strictly stronger trigger: /pending shifts only on insert/delete of the key set, while /accounts re-sorts on every balance change anywhere on the network, i.e. on every balance-changing block.
Target
- Repo:
xeprotocol/xe@8cc209d65c16089158da8fabd392628b71fe0711(remote HEAD, verified 2026-11-17). - Files:
api/handler.go:714-716(handleGetAllAccounts),node/node.go:1037-1056(GetAccountsPage),core/account_summary.go:110-122(AccountsByXEBalance),:40-73(refreshSummariesLocked),api/handler.go:640-656(parsePagination).
Code path
// api/handler.go:714-716
func (h *Handler) handleGetAllAccounts(w http.ResponseWriter, r *http.Request) {
offset, limit := parsePagination(r)
writeJSON(w, http.StatusOK, h.node.GetAccountsPage(offset, limit))
}
// node/node.go:1037-1056
func (n *Node) GetAccountsPage(offset, limit int) []AccountSummary {
all := n.Ledger.AccountsByXEBalance()
if offset >= len(all) { return []AccountSummary{} }
end := min(offset+limit, len(all))
out := make([]AccountSummary, 0, end-offset)
for _, s := range all[offset:end] { out = append(out, ...) }
return out
}
// core/account_summary.go:110-122
func (l *Ledger) AccountsByXEBalance() []*AccountSummary {
l.summaryMu.Lock()
defer l.summaryMu.Unlock()
l.refreshSummariesLocked()
if l.summaryByXE == nil {
l.summaryByXE = slices.SortedFunc(maps.Values(l.summaries), func(a, b *AccountSummary) int {
if c := cmp.Compare(b.xe, a.xe); c != 0 { return c } // XE balance DESC
return strings.Compare(a.Account, b.Account)
})
}
return l.summaryByXE
}
The sort key is a mutable value: refreshSummariesLocked (:40-73) rebuilds the affected summaries whenever any account is dirty and ends with l.summaryByXE, l.summaryByID = nil, nil — the cached order is discarded and the next request re-sorts from scratch. Each page request therefore materialises a fresh ordering of the live collection and slices it by numeric offset, with no snapshot held across pages, no cursor, and no total in the bare-array response. A balance change anywhere between page N and page N+1 re-orders the list and shifts every entry after the change point by ±1: the walk skips one account and duplicates another.
parsePagination (api/handler.go:640-656) takes only offset/limit; no cursor parameter exists anywhere in the accounts path.
Reproduction (read-only, no crafted input)
GET https://test.network/api/v1/accounts?limit=100&offset=0— 100 accounts, strictly XE-balance descending (verified live 2026-11-17: top balances 41,000,000,000,000, 996,941,000,000, 322,000,000).- Wait for any balance-changing block to land, then
GET .../accounts?limit=100&offset=100. - Diff the boundary: an account whose balance changed between the two fetches — or any account ranked after it — can appear in both pages or in neither.
Deterministic variant: two consecutive full walks during normal network activity disagree at the boundary whenever a balance changed mid-walk. (Live scale on testnet-0006: ~1,300 accounts, default limit 100 → a 13-page walk; every balance-changing block is a re-sort event.)
Impact
Medium — same class and tier as XE-17296. No direct fund loss: the defect corrupts enumeration, not balances. Anyone paginating /accounts — explorers, indexers, the SDK, a supply census — silently misses accounts or counts them twice, with no total to detect the loss. The trigger is the network's normal operation (any send/receive), not an attacker action, and the re-sort happens on every balance-changing block, so the hazard is exercised far more often than the insert-only variants on other endpoints.
Suggested fix
Snapshot the sorted list under summaryMu for the duration of a walk, or add a keyset cursor (e.g. (xe_balance, address) — the sort key is already total), or at minimum return a total plus a stable-ordering guarantee so consumers can detect a shifted walk.
Distinctness
- XE-17296 (Medium, filed this cycle) is
GET /pendingonly — different endpoint, different trigger (pending-set insert/delete vs balance re-sort). Its body does not mention/accounts. - XE-16443 (High) is the five endpoints loading the full collection before paginating — a performance defect (cost), not a correctness defect (wrong enumeration). Different mechanism, different fix.
- XE-0058 / XE-14068 are silent truncation (bare array, no
total, 100-item default) — a detection problem, not the skip/duplicate mechanism. The missingtotalis cited here only as why the loss is undetectable. - XE-11844 (Minor, docs) claims
/accountspaging IS stable because the handler sorts before slicing — verified live with two back-to-back pages at rest. It does not consider the concurrent-mutation case at all: its "stable" claim holds only while no balance changes between the fetches, which is exactly the gap this report closes. Its suggested fix (document/accountsas sorting before slicing) would enshrine the wrong stability claim. Different defect (docs error vs enumeration correctness), different fix. - XE-5929 / XE-13614 / XE-14166 are docs staleness about the sort claim, not the paging hazard.
- XE-13265 / XE-8285 are per-request cost (full load / full chain read), not correctness.
- Corpus searches over all 2,869 public tickets:
offset/cursor/pagination/skip+accounts— no ticket names an offset-paging skip/duplicate on/accounts. Sibling endpoints with the same root cause (/frontiers,/conflicts,/leases,/reputation,/statechain/kv,/directory) were audited in the same sweep; they are recorded separately as follow-up candidates, not claimed here.
Honest limitations
- Live observation: three back-to-back two-page walks (~40 s, 2026-11-17) showed no shift — the boundary accounts' balances did not change inside those windows. The defect is proven in code (re-sort on every dirty account + offset slicing with no snapshot), and the shift requires a balance-changing block landing between the two page fetches; on a quiet testnet that is intermittent, on a busy network it is routine. No live skip/duplicate was captured in this run.
- The walk is 13 pages at the default limit; the hazard needs a balance change between two specific page fetches, so a single walk may or may not exhibit it — the defect is in the paging contract, not in any single response.
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-17331 and says what differs; it is read like any other.