Rolling back a lease_cancel that won over an accept restores the lease to `created`, losing the accept and renewal history
Report
Suggested tier: Low
XE address (reward destination): 9b663fdac108be34a3b715ef78a9f9bd878af6ef8142f388c6514918e6852dd7
Summary
core/rollback.go, buildBlockUndo for BlockLeaseCancel always restores the lease to LeaseCreated (priorLease(b.Source, LeaseCreated)), regardless of the lease's pre-cancel state. But cancel has two possible pre-states: created, or accepted (cancel wins over a racing accept via resolveCancelWinsOverAccept). Undoing a cancel that won over an accept therefore zeroes StartTime / LockedR / LockedPayoutCap / LockedTWAP / Stake, while keeping Renewals and restoring the full escrow.
If the provider then re-accepts, the fresh PutLease carries no renewals, so a later settle pays only the base emission and deletes the whole pending escrow. The renewal escrow is destroyed with no corresponding emission.
Related to #391 (same symptom family — renewal escrow destroyed) but a different root cause (rollback.go undo-restore, not the cancel refund in ledger.go) and a different trigger (fork rollback via quorum conflict resolution, not the pre-finality race). #391's fix (refund pending.Amount on cancel) does NOT fix this path.
Impact
Bounded fund destruction, same order as #391: 517 micro-XUSD (~$0.0005) per renewal. No theft, no inflation. Requires: fork wins a quorum vote → cancel rolled back → provider re-accepts → provider settles. Reachable in production: core/quorum.go:321 confirmConflict → swapBlockLocked (Ledger.SwapBlock) undoes the loser block through exactly this buildBlockUndo path.
Steps to reproduce
Unit test against the real ledger code (github.com/xeprotocol/xe, testnet-0005):
git clone https://github.com/xeprotocol/xe
cd xe
cp round2_ledger_test.go core/
go test ./core -run TestRound2_UndoCancelLosesAcceptedState -v -count=1
Note: round2_ledger_test.go is NOT in the public repository — the PoC test file is attached to this issue; without it, the XE team cannot run this reproduction.
The test funds consumer + provider with 1,000,000 micro-XUSD each, creates a 60 s lease (cost 517 micro-XUSD), provider accepts, consumer renews for another 60 s (escrow 1034), consumer cancels, then SwapBlock replaces the cancel with a plain send (fork wins), provider re-accepts, provider settles.
Expected: after rollback the lease returns to accepted with accept metadata intact; after re-accept renewals = 1; after settle provider XE emission = 1034.
Actual (reproduced 2026-11-13, verified independently by re-running the PoC):
after cancel: consumer XUSD=999483 (F1: renewal 517 destroyed)
after undo-cancel: state=created settled=false start=0 lockedR=0 renewals=1
after undo-cancel: escrow restored=1034 (base+renewal=1034), total XUSD in system=2000000
after re-accept: state=accepted renewals=0 (was 1 before the rollback)
after settle: provider XE emission=517 (full base+renewal emission would be 1034); total XUSD in system=1998966
--- FAIL: TestRound2_UndoCancelLosesAcceptedState
Root cause
core/rollback.go, buildBlockUndo, BlockLeaseCancel case: restoreLease = l.priorLease(b.Source, LeaseCreated) — fixed target state. priorLease with target LeaseCreated additionally zeroes Stake, StartTime, LockedR, LockedPayoutCap, LockedTWAP. By contrast, undo of settle/force-settle always restores accepted (correct — those only run from accepted), undo of accept restores created (correct), and undo of renew pops exactly one renewal (correct, verified by control test).
Suggested fix
Restore the lease to its actual pre-cancel state instead of synthesising one from a fixed target: record the pre-cancel lease snapshot at cancel time (or in the BlockUndo, e.g. a RestoreLease built from the lease as it stood before the cancel, including State, StartTime, Locked*, Stake, Renewals). Defense-in-depth: make validateAndAddLeaseAccept preserve any existing Renewals on re-accept, and/or make validateAndAddLeaseSettle reject when escrow.Amount != lease.Cost + sum(renewal costs).
Controls verified (same PoC file, all PASS)
- Undo of
lease_renew: escrow back to exactly 517, settle pays base only. - Undo of
lease_settle: lease back toaccepted+ renewals, escrow 1034, re-settle pays full 1034 XE. - Force-settle after renew refunds the full pending escrow (consumer 998,966 → 1,000,000).
- Terminal-state guards: renew/cancel/second settle/force-settle after settle, and renew after cancel, all rejected.
Thread
Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-13379 and says what differs; it is read like any other.