[Lease Accounting] LeaseCancel after LeaseRenew refunds only the base cost — renewal top-up funds vanish (supply conservation broken)
Report
Suggested severity: Medium (2,500 XE).
Summary
After a lease_renew, the pending escrow grows by the renewal top-up (core/lease_renew.go:137-138, applied as pending += topUp in store/mem_store.go:338-343). But validateAndAddLeaseCancel computes the refund as expectedBal := oldBal + leaseBlock.Amount (core/ledger.go:1853), where leaseBlock.Amount is only the BASE segment cost, and then deletes the entire pending escrow (DeletePendingID + CancelLeaseHash, core/ledger.go:1858-1867). The difference — the total renewal cost — is neither refunded to the consumer nor paid to the provider: it vanishes from circulation (a supply-conservation break, deflationary).
Impact
A consumer who renews and then cancels loses exactly the renewal amount. This is provably a bug, not design: validateAndAddLeaseForceSettle (core/ledger.go:1879) correctly refunds pending.Amount (base + renewals) and settle burns the full pending. Only cancel uses the base figure.
Steps to Reproduce (local, no real funds)
- Consumer creates a lease (base cost C) and the provider accepts it.
- Consumer renews (top-up R); observe pending escrow becomes C + R.
- Consumer cancels (via the cancel-wins path if the accept is not yet finalized).
- Observed: consumer balance after cancel is initial - R (refund is only C); the R top-up is gone; the pending escrow is deleted in full; the lease ends Cancelled. Measured locally: initial 500,000,000,000 -> after renew 499,999,940,000 -> after cancel 499,999,970,000 (base 30,000 refunded, renewal 30,000 lost).
Recommendation
Compute the cancel refund from pending.Amount (base + all renewal top-ups), exactly as force-settle does, and clear stale Renewals in the cancel-wins rollback path.
Honest caveat: the victim here is the consumer cancelling their own lease (not theft by an attacker), which is why this is filed as Medium, not High/Critical. This is a different function and root cause from force-settle accounting: cancel refunds leaseBlock.Amount instead of pending.Amount.
Payout address: to be provided on request.
Thread
Thanks for the reports. To pay out we need an XE payout address in the report itself: please edit the issue body to add a line "Payout address: xe_..." and say here when it is done. The desk entry is https://bounty.xe.network/XE-0067.
Done — I have added my payout address to the issue body: xe_a52c0b32eeAAf26015Fb27e2AfFDddA41ff9CE4c
Still reproduces at HEAD 89a542e (testnet-0005, 2026-11-10).
validateAndAddLeaseCancel (core/ledger.go:1852-1867) refunds only the base cost (expectedBal := oldBal + leaseBlock.Amount) while deleting the whole pending escrow.
PoC (local go test, TestPOCAreaB_XE0067_CancelAfterRenew): escrow 2,668 (base 1,334 + renewal 1,334); after cancel the consumer holds 9,998,666 vs 10,000,000 start — the 1,334 renewal top-up vanished.
Note force-settle (ledger.go:1970) and the staged validator (ledger.go:2817) both use the full pending amount, so the codebase disagrees with itself here.