{"id":"XE-0103","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"175","source_url":"https://github.com/xeprotocol/xe/issues/175","reporter_id":36,"title":"[Lease Economics] LeaseAccept locks emission terms from any of the last 4 epochs — provider-selected stale terms are paid out at settle","area":"leasing-ledger","claimed_tier":"medium","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T13:57:27.479560+00:00","updated_at":"2026-11-10T00:11:49.573775+00:00","source_created_at":"2026-10-29T08:05:30+00:00","told_at":"2026-11-08T20:19:03+00:00","status_changed_at":"2026-11-08T20:17:53.238112+00:00","url":"https://bounty.xe.network/XE-0103","body":"Suggested severity: Medium (2,500 XE)\nArea: ledger / lease settlement economics\nRepo pin: 9787859 (testnet-0005)\n\n## Summary\n\nWhen a provider accepts a lease, the emission terms locked into the lease (R, PayoutCap, TWAP) are validated against **any of the last 4 epochs**, not against the single epoch that was active at the attested start time. The provider authors the LeaseAccept block, so the provider chooses which of those epochs to lock. LeaseSettle later pays out at the locked terms with no revalidation. The moment emission parameters differ between epochs, any provider can lock the most favourable recent epoch and be paid at stale terms — repeatedly, on every lease.\n\nI am reporting this as Medium with an honest caveat up front: on the live testnet today the per-epoch parameters have never diverged (measurement below), so the *realised* overpayment today is zero. The flaw is live in the validation logic and becomes a direct overpayment the first time R moves between epochs.\n\n## Where\n\n- `core/ledger.go:223` — `const EpochLockTolerance = 3`\n- `node/node.go` (epochAtFn, ~L440-460) — returns epochs with `StartNS <= ns`, newest first, truncated to `EpochLockTolerance+1` = 4 candidates\n- `core/ledger.go:2090` — `validateLockedEmissionAt` accepts the block if its locked (R, PayoutCap, TWAP) matches **any** candidate epoch\n- `core/ledger.go:1607` — `validateAndAddLeaseAccept` locks terms via the above; `core/ledger.go:2117` — `validateAndAddLeaseSettle` pays at the locked terms\n\n## Proof of concept\n\nLocal harness against `Ledger.AddBlock`, repo untouched at the pinned commit. Two identical leases differing only in which epoch's terms the provider locks:\n\n- Lock terms from a stale in-window epoch, R=900 → LeaseAccept **accepted**; LeaseSettle pays **601 XE**\n- Lock terms from the current epoch, R=100 → LeaseSettle pays **67 XE**\n- Same lease, 9.0x payout, chosen by the provider\n\nNegative controls (both rejected, confirming the bound is exactly the tolerance window):\n\n- Terms from the 5th epoch back (R=9999) → **rejected**\n- Terms from a non-existent epoch (R=12345) → **rejected**\n\n## Live-testnet measurement (2026-10-29)\n\n`GET https://ldn.core.test.network/statechain/kv?prefix=epoch.` — 1,000 epochs sampled (range: epoch 0 to the current epoch 1898). In every sampled epoch: `r_effective = 2000`, `payout_cap = 1527`, `twap_milli_usd = 250`. Spread across the current last-4 window is therefore 1.0x today. The epoch schema already carries the machinery for R to move (`phase`, `twap_trigger_met`, `volume_trigger_met`, `r_source`); when it does, this selection window is immediately monetisable by any provider.\n\n## Why this is not just sync tolerance\n\nA multi-epoch tolerance makes sense for a *validator* whose statechain view lags during sync — and the codebase already has that distinction: the sync path runs with `skipSkew`. The problem here is that the tolerance is exercisable by the *block author* on the live accept path, and the author is the party who gets paid at the locked terms. A lagging validator and a choosing provider are different trust positions; the second one should not inherit the first one's allowance.\n\n## Suggested fix\n\nOn the live accept/renew path, require locked terms to equal the epoch active at the attested time (`candidates[0]`). If multi-epoch tolerance is needed for statechain catch-up, keep it on the sync/replay path only (the `skipSkew` call sites), not on author-submitted blocks.\n\n## Reporter\n\nXE payout address: 24b1be6a99de922902aceccce2456abc3769e4ab1cac463ea86fb23496b868b3\nDiscovered: 2026-10-29, against the public testnet implementation at the pinned commit. No mainnet exists yet; no other users' funds, keys or workloads were touched — reproduction was local, the live check above is a read-only API query.","patch_refs":[{"id":175,"repo":"xeprotocol/xe","kind":"pr","ref":"176","title":"fix(core): restrict LeaseAccept and LeaseRenew locked emission terms to active epoch on live path (fixes #175)","url":"https://github.com/xeprotocol/xe/pull/176","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"}],"thread":[{"id":1169,"source":"github","source_ref":"6726598614","author":"Joseph Denne","team":true,"body":"Thanks for the report. We have confirmed the behaviour you describe and it is being handled; we will update this ticket when there is more to share.","created_at":"2026-11-08T20:19:03+00:00"},{"id":3122,"source":"github","source_ref":"6787311204","author":"zafrans","team":false,"body":"**Payout address update**\n\nHi team — a quick correction to the Reporter section of this report.\n\nThe XE payout address previously listed here (`24b1be6a99de922902aceccce2456abc3769e4ab1cac463ea86fb23496b868b3`) is no longer accessible to me — I no longer control the key for that wallet. Please disregard it.\n\nMy current XE payout address is:\n\n`5dc48847412ffe94e4f7097b81ee111b9e207b47c9c1f3bab988f08b63bcc7e3`\n\nPlease use this address for any award for this report. I am posting the same update on my other reports (#175, #183, #184, #191). Thank you.","created_at":"2026-11-11T04:48:11+00:00"},{"id":3123,"source":"github","source_ref":"6796805812","author":"ahmad32","team":false,"body":"Related observation on the same root — flagging here rather than filing separately, since one fix closes both.\n\n`epochAtFn` (node/node.go:440-460) includes any stored epoch with `StartNS <= now` and never checks `EndNS`, so an epoch whose window has already ended still counts as \"active\" and its terms (R, PayoutCap, TWAP) can be locked into a LeaseAccept. The last-4-epochs window in this ticket is one half of the staleness; the missing EndNS check is the other half.\n\nSeparately, `validateEpochValue` (statechain/kvstore.go:333) validates EndNS > StartNS, phase, payout cap, and the R fields, but never checks epoch ordering — a new epoch can be written with an Epoch number or window that overlaps or precedes existing epochs, with nothing rejecting it.\n\nBoth are the same root as this ticket (stale/unguarded epoch terms feeding LeaseAccept). A fix that validates epoch ordering at write time plus EndNS at read time would close both.\n\nVerified by direct code reading (no Go toolchain run). Writing epochs still needs the trusted oracle key, so this is not a new privilege — same impact as XE-0103.","created_at":"2026-11-11T13:14:47+00:00"}]}