{"id":"XE-7716","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":606,"title":"[core] Reputation aggregate deleted on accept rollback although a timestamp-only live event remains; live vs rebuilt diverge","area":"node-api","claimed_tier":"minor","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-11T18:31:47.177230+00:00","updated_at":"2026-11-17T09:41:59.257619+00:00","source_created_at":null,"told_at":"2026-11-17T09:38:21.363192+00:00","status_changed_at":"2026-11-17T09:37:25.349327+00:00","url":"https://bounty.xe.network/XE-7716","body":"# [core] Reputation aggregate deleted on accept rollback although a timestamp-only live event remains; live vs rebuilt diverge\r\n\r\n- Area: core / reputation (`core/reputation.go`, `core/ledger.go`, `core/rollback.go`)\r\n- Network: testnet-0005 (in-process reproduction against repo code, no testnet traffic)\r\n- Reporter account: xe:b1bfb541 (desk key)\r\n- Claimed tier: Minor\r\n- Repo pin: 89a542e\r\n- Round: 8 (stateful fuzzing — reputation state machine), 2026-11-11/12\r\n- Cross-check record: `~/workspace/xe-bounty/crosscheck/r8-reputation-timestamp-only-deletion.md`\r\n\r\n## Summary\r\n\r\n`ReputationEngine.Revert` deletes an account's whole reputation aggregate\r\nas soon as all its counters reach zero (`hasNoCounters()`), without checking\r\nwhether the aggregate still carries live timestamp content. A\r\n`lease_cancelled` event for which the account is the PROVIDER contributes no\r\ncounter — only `FirstActivityAt` / `LastActivityAt` — so it creates a\r\ntimestamp-only aggregate. One unrelated revert (rolling back a lease-accept)\r\nthen deletes the evidence of that still-live cancelled lease. A fresh\r\n`NewLedger` over the same store (`rebuildReputation`, which scans the chain\r\nfor cancel blocks) resurrects the aggregate, so **live and rebuilt disagree**:\r\nlive `GET /accounts/{address}/reputation` reports no aggregate, while after\r\na node restart the same account reports a timestamp-only aggregate.\r\n\r\n## Evidence\r\n\r\n### 1. The code (xe @ 89a542e)\r\n\r\n`core/reputation.go:49-96` (`ApplyReputationDelta`): for\r\n`EventLeaseCancelled` only the consumer gets a counter; the provider still\r\nenters `AffectedAccounts()` and gets `FirstActivityAt` / `LastActivityAt`\r\nupdated (lines 88-93) — a timestamp-only aggregate is deliberately created.\r\n\r\n`core/reputation.go:98-148` (`RevertReputationDelta`): only decrements\r\ncounters; it never touches timestamps.\r\n\r\n`core/reputation.go:203-228` (`ReputationEngine.Revert`): after reverting,\r\n`if a.hasNoCounters()` → `delete(e.agg, acc)` + `DeleteReputation` — the\r\ndeletion never checks whether timestamps still record live activity.\r\n\r\n`core/rollback.go:256-267`: undoing a `BlockLeaseAccept` builds\r\n`repRevert = {EventLeaseAccepted, Provider, Consumer}`; `:366-367` calls\r\n`l.reputation.Revert(*repRevert)`.\r\n\r\n`core/ledger.go:607-690` (`rebuildReputation`): scans the chain for\r\n`BlockLeaseCancel` and applies\r\n`EventLeaseCancelled{Provider: leaseBlock.Destination, ...}` — rebuilding\r\nexactly the timestamp-only aggregate that live just deleted.\r\n\r\n### 2. Deterministic reproduction (in-process, repo APIs only)\r\n\r\nHarness: `TestReputationTimestampOnlyRepro` (seed 424242, provider =\r\nusers[1]); every step uses exported ledger APIs (`AddSyncedBlock`,\r\n`SwapBlock` via FINAL votes, `NewLedger` on the same store). Result:\r\n`REPRO CONFIRMED: live=nil, rebuilt=timestamp-only`.\r\n\r\n1. Consumer opens lease L1 with the provider, then cancels it while still\r\n   `Created` → live `Apply(EventLeaseCancelled{Provider})` creates a\r\n   timestamp-only aggregate for the provider: all counters 0,\r\n   `FirstActivityAt == LastActivityAt == 1700000430908943949`.\r\n2. Provider sends S1, then accepts lease L2 on top of S1 →\r\n   `LeasesAcceptedAsProvider == 1` (timestamps unchanged).\r\n3. Stage a sibling send S2 at the accept block's own prev; vote rep0+rep1\r\n   FINAL for S2 (750k ≥ 67%) → `SwapBlock` replaces the accept block itself\r\n   as the loser (NOT a descendant, so the XE-0022 stall does not apply) →\r\n   `buildBlockUndo` produces `repRevert(EventLeaseAccepted)` → `Revert` →\r\n   counters hit zero → aggregate DELETED (`hasNoCounters`).\r\n4. Result: **live `GetReputation(provider) == nil`**, while a fresh\r\n   `NewLedger` on the same store returns the timestamp-only aggregate\r\n   (`first=1700000430908943949 last=1700000430908943949`).\r\n\r\nThe same pattern was also found independently by the stateful engine fuzzer\r\n(`TestReputationEngineStateful`, random Apply/Revert sequences): an account\r\nwith 1 live event but no aggregate, whenever a timestamp-only event was the\r\nsole survivor.\r\n\r\n## Impact\r\n\r\n- API `GET /accounts/{address}/reputation` and `GET /reputation` (and the\r\n  `xe reputation` CLI) return \"no aggregate\" for a provider that has\r\n  recorded on-chain activity; after a node restart the aggregate reappears.\r\n  The data is lost until restart — not the \"briefly differ\" propagation lag\r\n  the API doc allows (\"best-effort; may briefly differ across nodes after a\r\n  settle propagates\").\r\n- No funds are lost and no consensus decision changes: reputation is\r\n  currently display-only (API/CLI) with no in-repo consumer using it for\r\n  decisions. Claimed tier: **Minor**. Not Medium: no loss of funds, no\r\n  consensus stall, and the effect is limited to API metadata.\r\n\r\n## Suggested fix\r\n\r\n`hasNoCounters()` should also consider timestamp content (e.g. do not\r\ndelete when `FirstActivityAt != 0`), or `Revert` should recompute the\r\ntimestamp bounds from the surviving events. Note this is the opposite\r\ndirection of XE-3084 (stale timestamps surviving a revert): one fix that\r\nrecomputes timestamp bounds on revert would close both failure modes.\r\n\r\n## Why this is not a duplicate\r\n\r\n- XE-3084 (\"Revert never unwinds FirstActivityAt or LastActivityAt\") is the\r\n  OPPOSITE direction: stale timestamps SURVIVING a revert (live has extra /\r\n  wrong data). This finding is an aggregate DELETED although a\r\n  timestamp-only event survives (live loses data). XE-3084's `hasNoCounters`\r\n  mention covers deletion when the reverted block was the account's ONLY\r\n  activity (correct deletion; rebuild is also empty) — not this case (a\r\n  live event remains; rebuild has the aggregate).\r\n- XE-5332 (counters surviving when a lease-OPEN loses a conflict) is the\r\n  opposite direction with a different trigger; its controls state rebuild\r\n  parity HOLDS for its case, while this finding VIOLATES rebuild parity.\r\n- XE-5320 (zombie lease / no escrow after force-settle + re-accept) is\r\n  about funds/state, not the reputation aggregate; this trigger has no\r\n  force-settle/re-accept.\r\n- XE-0135 Finding 3, XE-1767, XE-3065, XE-3445 are renewal-duration /\r\n  seconds-vs-hours value errors in the settled-hours fields — different\r\n  mechanism.\r\n- XE-0022 (SwapBlock stall on non-send descendants) is what BLOCKED the\r\n  original repro trigger; the final repro avoids it by making the accept\r\n  block the loser itself.\r\n- XE-6742 (destructive lease-open swap) touches escrow/lease records, not\r\n  the reputation aggregate.\r\n- XE-7259 (reputation/keyset routes 404 on the live deploy) is about API\r\n  route availability on testnet-0005, not the in-process reputation state\r\n  machine.","patch_refs":[],"thread":[{"id":9786,"source":"desk","source_ref":"reply:8224","author":"Joseph Denne","team":true,"body":"Thanks for the report. We have read it against the current code and confirmed the behaviour it describes. It is being handled.","created_at":"2026-11-17T09:38:21.356352+00:00"}]}