{"id":"XE-0049","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"68","source_url":"https://github.com/xeprotocol/xe/issues/68","reporter_id":21,"title":"Supply monitor under-counts lease-renewal escrow → false conserved:false with empty notes (XUSD discrepancy −32318)","area":"leasing-ledger","claimed_tier":"medium","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0015","tracked":true,"internal_ref":"#1083","internal_url":"https://github.com/xeprotocol/core/issues/1083","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T13:57:19.734081+00:00","updated_at":"2026-11-10T00:11:54.259737+00:00","source_created_at":"2026-10-26T13:17:28+00:00","told_at":"2026-11-08T20:35:48+00:00","status_changed_at":"2026-10-29T14:22:10.509858+00:00","url":"https://bounty.xe.network/XE-0049","body":"# Supply conservation monitor under-counts lease-renewal escrow → permanent false `conserved:false` with empty `notes`\n\n**Component:** `core/supply.go` (`SupplyAuditor`) — `GET /supply` conservation audit\n**Version observed:** `xe/92d83d1` (`testnet-0005`), reproduced live on `ldn`, `ffm`, `nyc`\n**Source commit inspected:** `978785929bc17a2f4ab30c383e5fc9cf4d634512`\n**Suggested severity:** MEDIUM — \"accounting mismatch · API inconsistency\" per the published tier table (target 2,500 XE). Accounting-integrity defect in the audit layer; **no fund loss, no mint, no double-spend**, so not Critical/Severe and filed publicly per the rules.\n**Phase 1 surface:** transactions & running a node (the `/supply` invariant check)\n\n---\n\n## Summary\n\nThe node's own supply auditor reports XUSD as **not conserved** on a healthy network:\n\n```json\n\"XUSD\": { ... \"discrepancy\": -32318, \"conserved\": false },\n\"conserved\": false, \"notes\": [], \"stable\": true\n```\n\nThis is a **false alarm**. The underlying ledger conserves XUSD to the exact micro-unit. The discrepancy is caused entirely by `SupplyAuditor` omitting `lease_renew` escrow top-ups from its `escrow_burned` term.\n\nTwo documented contracts of `GET /supply` are violated simultaneously (per `docs/api.md`):\n\n1. *\"`notes` — every reason the report is not clean … **Empty on a healthy network**.\"* → Here `conserved:false` is reported with **`notes: []`** — the monitor flags non-conservation but supplies **no reason**, so an operator cannot tell a false alarm from a real leak.\n2. *\"`conserved` … never reports `true` on incomplete data\"* — the converse failure: it reports `false` on **complete, correct** ledger data because the auditor's own model is incomplete.\n\nImpact: the protocol's documented integrity canary is permanently tripped once any lease is renewed, which **masks any future real XUSD leak** — the exact failure mode a conservation monitor exists to catch.\n\n---\n\n## Affected code\n\n`core/supply.go`, `termsFromChain` (block classification) — the `switch b.Type` has cases for `BlockLease`, `BlockLeaseAccept`, `BlockLeaseSettle`, but **no case for `BlockLeaseRenew`**:\n\n```go\n// core/supply.go  (termsFromChain, ~L88-103)\nswitch b.Type {\ncase BlockGenesis:     c.genesis[b.Asset] += b.Balance\ncase BlockMint:        c.minted[b.Asset]  += b.Amount\ncase BlockBurn:        c.burned[b.Asset]  += b.Amount\ncase BlockLease:       c.leaseCost[b.Hash]      = b.Amount   // base cost only\ncase BlockLeaseAccept: c.acceptStake[b.Source]  = b.Amount\ncase BlockLeaseSettle: c.settleEmission[b.Source] = b.Amount\ndefault:                                                      // <-- lease_renew falls here, ignored\n}\n```\n\nThe escrow-burn term is then derived from `leaseCost` (base only):\n\n```go\n// core/supply.go  walk(), ~L242-250\nfor h, em := range emissions {\n    add(&get(AssetXE.Symbol).Emitted, em)\n    if cost, ok := costs[h]; ok {\n        add(&get(AssetXUSD.Symbol).EscrowBurned, cost)   // base lease cost ONLY\n    } else { ... }\n}\n```\n\nBut the real ledger escrow grows on each renewal and is burned in full at settle:\n\n- `core/lease_renew.go` L137-138 — renewal tops up the live escrow pending:\n  ```go\n  commit.TopUpPendingID     = b.Source\n  commit.TopUpPendingAmount = b.Amount\n  ```\n- `core/ledger.go` L2226 (`lease_settle`) — the **entire** escrow pending (base + all renewals) is removed:\n  ```go\n  commit.DeletePendingID = b.Source\n  ```\n\nSo at settle the ledger correctly removes `base + Σ renewals` from `in_flight`, but the auditor only adds `base` to `escrow_burned`. The missing `Σ renewals` makes `accounted < created` by exactly that sum → negative `discrepancy`.\n\n---\n\n## Reproduction (live, read-only)\n\n```bash\n# 1. The monitor reports non-conservation with an empty notes array:\ncurl -s https://ldn.core.test.network/supply \\\n  | jq '{conserved, stable, notes, XUSD: .assets.XUSD | {discrepancy, conserved, created, minted, balances, escrow_burned}}'\n# => \"discrepancy\": -32318, \"conserved\": false, notes: [], stable: true\n#    (identical on ffm and nyc)\n\n# 2. Reconstruct the discrepancy from lease data — it equals the renewal escrow the auditor omits:\ncurl -s \"https://ldn.core.test.network/leases?state=settled\" > settled.json\njq '[.[].renewals[]?.cost] | add' settled.json     # => 32318   (== -discrepancy, exactly)\njq '[.[].cost] | add'          settled.json         # => 67738   (base; == auditor escrow_burned)\n```\n\n### Exact conservation proof (XUSD)\n\n| Term | Value (micro-XUSD) | Source |\n|---|---|---|\n| `created` (= `minted`) | 213,000,000 | `/supply` |\n| `balances` (live accounts) | 212,899,944 | `/supply` |\n| `escrow_burned` reported | 67,738 | `/supply` (base cost of 98 settled leases) |\n| renewal escrow **omitted** | 32,318 | Σ `renewals[].cost` over settled leases (46 segments) |\n\n```\nbalances + escrow_burned(base) + renewals_omitted\n  = 212,899,944 + 67,738 + 32,318\n  = 213,000,000\n  = created                         ✓ conserves exactly once the renewal term is included\n```\n\n`discrepancy = accounted − created = (212,899,944 + 67,738) − 213,000,000 = −32,318`, i.e. precisely the omitted renewal escrow. The XE asset is unaffected (`discrepancy: 0, conserved: true`), as expected since only XUSD funds lease escrow.\n\nDeterministic and stable: observed identical (`−32318`, `stable:true`, `notes:[]`) on all three public nodes and across repeated reads during live block production.\n\n---\n\n## Why this is NOT a fund-safety issue\n\nThe real ledger conserves. Verified:\n\n- Escrow top-up/reduce is a symmetric, underflow-guarded `int64` delta (`store.addToPendingAmountTxn`); settle burns the full pending via `DeletePendingID`; rollback pops renewals symmetrically (`priorLeasePopRenewal` + `ReducePendingAmount`).\n- Independent full-state reconstruction balances to the exact micro-XUSD (table above).\n- XE emission/supply is independently `conserved: true` and stable over time.\n\nThe defect is confined to the **audit model** in `supply.go`, not to any balance-mutating path. No XUSD is created, lost, or double-counted on-chain.\n\n---\n\n## Impact\n\n- **Integrity canary disabled.** `GET /supply` is documented as *the* conservation authority (`docs/api.md`: \"This endpoint is the authority\"). Once any lease is renewed, it permanently reports `conserved:false`. A genuine future XUSD leak would be indistinguishable from this baseline false alarm.\n- **Contract violation / operator confusion.** `conserved:false` with `notes:[]` contradicts the documented guarantee that `notes` carries \"every reason the report is not clean\" and is \"empty on a healthy network.\" Monitoring/alerting built on `conserved` or `notes` will either alarm forever or (if operators learn to ignore it) ignore a real breach.\n\nNo external attacker interaction is required; it is a protocol self-report defect.\n\n---\n\n## Suggested fix\n\nAccount for renewal escrow in the auditor so the burned term matches what the ledger actually removes.\n\n```go\n// core/supply.go — add a renewal-cost map to chainTerms\ntype chainTerms struct {\n    // ...\n    leaseCost      map[string]uint64\n    leaseRenewCost map[string]uint64 // NEW: Source -> Σ renewal top-ups\n    // ...\n}\n\n// in termsFromChain switch:\ncase BlockLeaseRenew:\n    c.leaseRenewCost[b.Source] += b.Amount\n\n// in walk(), fold renewal cost into EscrowBurned wherever the base escrow is burned\n// (settle path, and the LeaseExpired loop), keyed consistently with how costs[h] is keyed.\n```\n\nEquivalent alternative: derive `escrow_burned` for a burned lease directly from the stored `Lease` (`Cost + Σ Renewals[].Cost`) rather than from the base lease block amount, so the auditor and the ledger use the same escrow total by construction.\n\nAfter the fix, `GET /supply` should return `XUSD.discrepancy: 0, conserved: true, notes: []` on the current testnet state.\n\n---\n\n## Metadata\n\n- **Reporter contact:** govrex5@gmail.com\n- **XE payout address:** `0x05055eE6Bffc9467aa8aad5F8e8665871dC71060`\n- **Suggested severity:** MEDIUM (accounting mismatch + API inconsistency). Final severity at XE core team discretion.\n- **Channel:** public GitHub issue on `xeprotocol/xe` (not funds/network-risking, so not the private `security@xe.network` channel).\n- **Affected files:** `core/supply.go` (primary); cross-referenced `core/lease_renew.go` L137-138, `core/ledger.go` L2226.\n- **Reproducible:** yes, read-only `GET /supply` + `GET /leases?state=settled`, no state mutation, no special access.\n","patch_refs":[{"id":155,"repo":"xeprotocol/xe","kind":"pr","ref":"136","title":"fix(core,node): account for lease-renewal escrow in supply auditor","url":"https://github.com/xeprotocol/xe/pull/136","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"}],"thread":[{"id":1209,"source":"github","source_ref":"6726786619","author":"Joseph Denne","team":true,"body":"Thanks, this was well put together and the numbers were useful. It has the same root cause as finding 3 in #4 (lease-renewal escrow not counted by the supply auditor), which was filed first and is being fixed, so this one closes as a duplicate and your data points are folded into that ticket. If you believe it is a different bug, reply with what differs and we will look again.","created_at":"2026-11-08T20:35:48+00:00"}]}