{"id":"XE-6119","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":1339,"title":"dao: GET /v1/health recomputes the 30-day uptime aggregation on every request — unauthenticated, unmetered, uncached (~98 ms CPU per hit)","area":"dao-harness","claimed_tier":"medium","assessed_tier":"minor","verdict":"likely-valid","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"patched","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-11T12:46:03.446140+00:00","updated_at":"2026-11-15T12:17:48.340545+00:00","source_created_at":null,"told_at":"2026-11-15T12:17:49.351828+00:00","status_changed_at":"2026-11-15T12:02:32.591970+00:00","url":"https://bounty.xe.network/XE-6119","body":"## Summary\n\n`GET /v1/health` on the DAO portal recomputes the full 30-day uptime aggregation on **every** request. The route is unauthenticated, has no rate-limit bucket, and no response cache — unlike every other expensive public read in this codebase, which is either metered or cached.\n\n## Evidence (repo `xeprotocol/dao` @ `2efbfee`)\n\n- `dao/api/public.py:339` — `async def health(...)` calls `records.uptime_30d(ctx, db)` inline; the handler makes no rate-limit call (contrast the snapshot/legal handlers in the same file).\n- `dao/services/records.py:347` — `uptime_30d` selects **all** HealthCheck rows of the last 30 days (10-minute cadence ⇒ up to ~4,320 rows) on every call.\n- `dao/services/records.py:364` — `expected_checks` performs `Fraction` arithmetic (gcd-heavy rational adds) per row/edge over the whole window.\n\nMeasurement of the pure function at a full synthetic window:\n\n```python\nfrom dao.services.records import expected_checks\nrows = [(i * 600 * 10**9, 600) for i in range(4320)]   # 30 days of 10-min checks\nexpected_checks(rows, rows[0][0], rows[0][0] + 30*86400*10**9, 600)\n# -> 4320 expected, ~98 ms CPU per call (measured in a sandbox)\n```\n\nSo roughly 10 requests/second to a public, unauthenticated endpoint saturates about one CPU core, before counting the ~4,320-row database scan and JSONB extraction per request.\n\n## Why this is the odd one out\n\n- `/v1/snapshot` and other node-costly GETs use the `SNAPSHOT` / `NODE_READ` rate buckets (`dao/ratelimit.py`).\n- `/v1/log/verify` is cached for 60 s precisely *\"so the route cannot be used to make the database re-read the whole chain on demand\"* (`dao/services/records.py`) — the codebase's own stated rule for exactly this shape of route. `/v1/health` follows neither pattern.\n\n## Impact\n\nA cheap, unauthenticated CPU-exhaustion lever on the DAO portal: a trickle of requests pins a worker core and repeatedly scans a month of health rows. The fix is small and changes no payload: cache the response briefly (the existing `verify_cached` 60 s pattern) or place the route in the existing `NODE_READ` bucket.\n\n## Dedup note\n\nExisting health tickets (XE-0891, XE-0908, XE-1618, XE-1620, XE-1639, XE-2374) all concern the *correctness of the figure* — none concerns the per-request cost of computing it. XE-0227 is a closed volume-test pre-notice, not this code finding.\n\nReporter payout address (XE, at mainnet genesis): bce9914ea94de329cebc38d288e927dd8e70b1057133f697f1f230f8f42b469c","patch_refs":[{"id":631,"repo":"xeprotocol/dao","kind":"commit","ref":"e6a0eca","title":"","url":"https://github.com/xeprotocol/dao/commit/e6a0eca","note":"","state":"","author":"","added_by":"token:5","created_at":"2026-11-15T09:03:38.794722+00:00"}],"thread":[{"id":5227,"source":"desk","source_ref":"reply:3907","author":"Joseph Denne","team":true,"body":"Thanks for the report. We have confirmed the reading against the current tree and it is being handled. The assessment and any award follow the fix.","created_at":"2026-11-15T10:18:43.806337+00:00"},{"id":5762,"source":"desk","source_ref":"reply:4430","author":"XE desk","team":true,"body":"Thanks for the report. This is fixed in xeprotocol/dao@e6a0eca. The desk entry is https://bounty.xe.network/XE-6119. If you can,\nre-run your reproduction against the next testnet build and say so here; if it still reproduces,\nreopen with what you saw.","created_at":"2026-11-15T12:17:48.340545+00:00"}]}