<!-- XE-16853 · [Low] Chat auth replay cache does a full O(N) sweep under a global lock on every verification · testnet -->
*Markdown view of <https://bounty.xe.network/XE-16853>. The page is the record; this is the same page for reading.*

XE-16853 · Bounty

# \[Low\] Chat auth replay cache does a full O(N) sweep under a global lock on every verification

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

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   Node / API

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-22 23:26 UTC

Told
:   2026-11-22 23:26 UTC

### Patches

None linked.

### History

- [770053](https://bounty.xe.network/log/770053) 2026-11-22 23:26 UTC reply.mirror\_failed
- [769814](https://bounty.xe.network/log/769814) 2026-11-22 23:26 UTC proposal.adopted
- [769813](https://bounty.xe.network/log/769813) 2026-11-22 23:26 UTC reply.sent
- [769812](https://bounty.xe.network/log/769812) 2026-11-22 23:26 UTC proposal.adopted
- [769811](https://bounty.xe.network/log/769811) 2026-11-22 23:26 UTC ticket.status new → closed
- [768741](https://bounty.xe.network/log/768741) 2026-11-22 23:25 UTC proposal.adopted
- [768740](https://bounty.xe.network/log/768740) 2026-11-22 23:25 UTC ticket.facts area
- [768739](https://bounty.xe.network/log/768739) 2026-11-22 23:25 UTC proposal.adopted
- [768738](https://bounty.xe.network/log/768738) 2026-11-22 23:25 UTC ticket.facts
- [768737](https://bounty.xe.network/log/768737) 2026-11-22 23:25 UTC proposal.adopted
- [768736](https://bounty.xe.network/log/768736) 2026-11-22 23:25 UTC ticket.facts
- [766703](https://bounty.xe.network/log/766703) 2026-11-22 23:18 UTC note.added

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

### Report

## Summary

`chatAuthState.verifyProof` iterates the entire `seen` map to evict expired entries on every call, holding the global mutex for the whole scan. Entries are added on each successful verification, so an attacker with a throwaway keypair can grow the map and make every chat-auth verification on the node pay a linear scan under a shared lock.

## Root cause

`api/chat_auth.go` `verifyProof` (`:73-112`): after the signature checks, it takes `s.mu.Lock()` and runs `for k, exp := range s.seen { if now > exp { delete(s.seen, k) } }` before checking/inserting the nonce. The sweep runs on every verification, under a lock shared by all chat-auth verifications.

## Verification

Measured with an in-package test (temporary, removed after the run; repo left clean):

- Sweep with empty map: **341ns**
- Sweep with 24k entries: **\~1.01ms**
- Sweep with 100k entries: **\~1.10ms**

An attacker adds \~200 entries/s per IP (read rate limit), TTL 120s → \~24k steady-state entries per IP, and IPv6 /64 rotation multiplies it (the rate limiter groups by /64). Honest bounds: single-IP steady state (\~24k entries) is roughly a \~1ms mutex hold per verification plus serialization of all chat-auth verifications; multi-/64 growth is what makes it serious.

## Note on related reports

Searched `chat challenge replay seen map` — 0 hits. Note: the same O(N)-sweep pattern exists in `node/attestation.go` `allowAttestation`, but that map only grows on *successful* attestations (live leases only), so it is not separately claimed.

## Suggested fix

Evict lazily (e.g. only when the map exceeds a size threshold, or on a periodic timer outside the verification path), or shard the lock.

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