{"id":"XE-1640","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"310","source_url":"https://github.com/xeprotocol/xe/issues/310","reporter_id":154,"title":"node: archiveExpiredLease destroys lease escrow with no block — clock-driven, per-node, unreplayable (Severe)","area":"leasing-ledger","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-08T21:12:28.281211+00:00","updated_at":"2026-11-10T00:11:59.537471+00:00","source_created_at":"2026-11-08T21:11:01+00:00","told_at":"2026-11-09T10:24:43+00:00","status_changed_at":"2026-11-09T10:24:11.102401+00:00","url":"https://bounty.xe.network/XE-1640","body":"> **Note from the reporter (2026-11-09):** I filed this publicly by mistake. The bounty desk at\n> https://bounty.xe.network/report is private by default and is the correct channel; I used this\n> public issue because it was the only submission route reachable without signing in. I am redacting\n> the step-by-step detail below and will file the full report through the desk. **Maintainers:\n> please treat the detail here as withdrawn and read the desk ticket instead.** I have asked the\n> desk to link this issue once filed.\n\n## Summary (redacted)\n\n`node.archiveExpiredLease` (`node/node.go:1881`) resolves a stale lease by calling\n`store.DeletePendingSend(lease.LeaseHash)` and `PutLease` with `State = LeaseExpired`,\n`Settled = true` — **and emits no block**. There is no `core.SignBlock`, no `solvePoW`, no\n`Ledger.AddBlock`, and nothing gossiped.\n\nThe trigger is each node's own wall clock: `shouldArchiveExpiredLease` (`node/node.go:1858`)\nreturns true when `core.Now().UnixNano() >= lease.EffectiveExpiry() + core.LeaseEscrowExpiry +\ncore.LeaseArchiveGap` (`core/ledger.go:151-152` — 365 days + 1 hour), re-evaluated by\n`settleLoop()` (`node/node.go:1756`) every 10 seconds.\n\nEvery other value-moving lease transition in the same file — notably `forceSettleLease`\n(`node/node.go:1900`) — builds, signs, PoWs and `AddBlock`s a `BlockLeaseForceSettle`. This path\nis the only one that skips all of it.\n\n## Secondary observation\n\n`core/supply.go:281-283` reconciles the archive by crediting `EscrowBurned += l.Cost` for every\n`LeaseExpired` lease. That is a census assumption rather than an observation of a burn, and it\ncredits only the base-cost field. `core/lease_renew.go:137-138` accumulates renewal top-ups into\nthe same pending via `TopUpPendingID`/`TopUpPendingAmount` (applied at `store/mem_store.go:340`\nand `store/badger_store.go:867`), and those top-ups are recorded in `lease.Renewals[].Cost`\nrather than `lease.Cost`. So for a renewed lease the amount actually destroyed by\n`DeletePendingSend` exceeds what the auditor credits.\n\n## Why it matters\n\n* A value-moving state transition bypasses block validation entirely — no signature, no PoW, no\n  quorum, nothing a peer can validate or replay.\n* The decision is per-node wall clock, so nodes reach different conclusions about the same lease\n  at different times, and their `/pending`, `/leases` and `/supply` outputs disagree in between.\n* Chain replay cannot reproduce the archive, because it is a function of each node's clock rather\n  than of any block.\n\n## Suggested direction\n\nEither emit a signed, PoW'd block for the archive exactly as `forceSettleLease` does, or — if the\nintent really is \"both parties offline, refund nobody\" — derive the decision from a signed\ntimekeeper attestation or from block height so all nodes converge, and have the auditor count the\namount actually destroyed rather than the bare `lease.Cost` field.\n\n## Dedupe\n\nFull desk pulled (`/v1/tickets?kind=bounty&status=all`, 499 tickets, all pages). Zero tickets\nmention the archive path. Closest items — XE-0105 (lease-mutation merge races) and XE-0102\n(force-settle/escrow lock) — are different mechanisms and do not mention the archive burn or the\ncensus.\n\n---\n\n*Redacted at the reporter's request. Full detail filed privately at the bounty desk. Analysis by\nsource review of `github.com/xeprotocol/xe` at master (`02e9641`) plus read-only probing of\n`ldn.core.test.network`; no accounts created, no testnet state modified.*","patch_refs":[{"id":478,"repo":"xeprotocol/xe","kind":"pr","ref":"311","title":"fix(core, node): gate lease archive on timekeeper attestations and account for renewal escrow in supply","url":"https://github.com/xeprotocol/xe/pull/311","note":"","state":"open","author":"tipprb","added_by":"desk","created_at":"2026-11-10T00:12:01.832547+00:00"}],"thread":[{"id":1253,"source":"github","source_ref":"6727218232","author":"Lydicius","team":false,"body":"## Correction to my own report — the material gap is the renewal top-up, not `lease.Stake`\n\nOn re-verification I need to correct one claim in the report above. I wrote that the auditor\n\"ignores `l.Stake`\". That is technically true but **practically vacuous**, and it distracted from\nthe real gap. Correcting it here rather than leaving the report imprecise.\n\n### `lease.Stake` is always zero\n\n`core/ledger.go:116`:\n\n```go\nLeaseStakeDivisor = uint64(0)\n```\n\nand `core/ledger.go:44-52`:\n\n```go\nfunc LeaseStake(cost uint64) uint64 {\n\tif LeaseStakeDivisor == 0 {\n\t\treturn 0\n\t}\n\t...\n}\n```\n\nSo `lease.Stake` is structurally always `0`, and the `Cost+Stake` in the archive log line is\nreally just `Cost`. Please disregard that half of my claim.\n\n### The real gap: renewal top-ups accumulate into the same escrow pending\n\n`core/lease_renew.go:137-138`:\n\n```go\ncommit.TopUpPendingID     = b.Source\ncommit.TopUpPendingAmount = b.Amount\n```\n\nand the renewed lease records the top-up only in `lease.Renewals[]`, **not** in `lease.Cost`:\n\n```go\nrenewed.Renewals = append(append([]LeaseSegment(nil), lease.Renewals...), LeaseSegment{\n\tRenewHash: b.Hash,\n\tDuration:  b.Duration,\n\tCost:      b.Amount,     // ← lives here, NOT in lease.Cost\n\t...\n})\n```\n\nThe pending is then **accumulated in place** under the lease hash, not replaced:\n\n`store/mem_store.go:338-343`:\n\n```go\nif c.TopUpPendingID != \"\" {\n\tif ps, ok := m.pending[c.TopUpPendingID]; ok {\n\t\tps.Amount += c.TopUpPendingAmount\n\t}\n\t...\n}\n```\n\n`store/badger_store.go:866-867`:\n\n```go\nif c.TopUpPendingID != \"\" {\n\tif err := addToPendingAmountTxn(txn, c.TopUpPendingID, int64(c.TopUpPendingAmount)); err != nil {\n```\n\nSo the escrow pending behind a lease is **base cost + every renewal top-up**, all under one ID.\n\n`archiveExpiredLease` deletes that whole pending with `DeletePendingSend(lease.LeaseHash)`.\n`core/supply.go:281-283` credits only `l.Cost` — the base field.\n\n### Concrete numbers\n\n1. Consumer opens a lease, base cost `10,000` µXUSD → escrow pending = `10,000`, `lease.Cost = 10,000`\n2. Consumer renews with `5,000` → `TopUpPendingAmount = 5,000`, pending becomes `15,000`;\n   `lease.Cost` stays `10,000`; the `5,000` lives only in `lease.Renewals[0].Cost`\n3. Both parties go offline. After `expiry + 365d + 1h` each node archives:\n   `DeletePendingSend` removes the full `15,000` from `InFlight`, `State = LeaseExpired`\n4. Auditor credits `EscrowBurned += l.Cost = 10,000` only\n5. Net: `Accounted` drops by `5,000` relative to `Created` → `Discrepancy = -5,000`, `Conserved = false`\n\nThe `5,000` is destroyed with no block and never appears in `Destroyed` at all.\n\n### Why this strengthens rather than weakens the report\n\nThe stake half of my original claim was vacuous (always zero). The renewal top-up is **real,\nnon-zero value** that a lease accrues over its lifetime, and it is the part that actually breaks\nconservation. The suggested fix is unchanged in kind but should be stated precisely:\n\n> Count the amount actually destroyed — the pending behind `lease.LeaseHash` at archive time, or\n> equivalently `lease.Cost + Σ lease.Renewals[].Cost` — not the bare `lease.Cost` field.\n\nThe same one-line fix covers the settle branch at `core/supply.go:246` and this expired branch at\n`core/supply.go:281`, which is why I expect the conservation half to be triaged alongside XE-0511.\nThe un-cited parts of this report remain the ones I originally flagged: the archive path emits no\nblock, and the trigger is per-node wall clock.\n\nApologies for the imprecision in the first pass — I would rather correct it on the ticket than let\nit stand.","created_at":"2026-11-08T21:14:57+00:00"},{"id":1402,"source":"github","source_ref":"6737678350","author":"Joseph Denne","team":true,"body":"Thanks for the report and for the correction you added. The lease archive behaviour you describe was reported earlier and is being handled under https://bounty.xe.network/XE-1640; this ticket is closed as a duplicate of it. The accounting point you raise is also already tracked with the earlier reports in that family.","created_at":"2026-11-09T10:24:43+00:00"}]}