{"id":"XE-9639","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":730,"title":"Cascade Rollback Asymmetry: SwapBlock and planRollbackFrom omit BlockLease cascade unwinding","area":"consensus","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0022","tracked":true,"internal_ref":"#1090","internal_url":"https://github.com/xeprotocol/core/issues/1090","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-12T06:09:43.596709+00:00","updated_at":"2026-11-20T00:33:21.885690+00:00","source_created_at":null,"told_at":"2026-11-20T00:33:21.915008+00:00","status_changed_at":"2026-11-20T00:33:21.896466+00:00","url":"https://bounty.xe.network/XE-9639","body":"## Vulnerability Summary\n\nIn `core/rollback.go` and `core/ledger.go`, the ledger implements descendant cascade rollback (`planCascade`, `planRollbackOfSend`, `planRollbackFrom`, and `SwapBlock`) to unwind blocks across accounts when a conflict winner replaces a prior block.\n\nWhile `buildBlockUndo` (`core/rollback.go:220-243`) implements undo logic for lease-related block types (`BlockLease`, `BlockLeaseAccept`, `BlockLeaseSettle`, `BlockLeaseCancel`, `BlockLeaseRenew`), the cascade planner functions `planRollbackFrom` and `SwapBlock` **completely omit `BlockLease` from cascade expansion and unwinding**:\n\n1. In `core/rollback.go:68-73` (`planRollbackFrom`):\n```go\n\t\tswitch b.Type {\n\t\tcase BlockSend, BlockReceive, BlockBurn, BlockMint:\n\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"cascade: unsupported block type %q (%s) on %s — reversing its lease/keyset/reputation side-effects is not yet implemented\", b.Type, shortHash(b.Hash), shortAddr(account))\n\t\t}\n```\nIf an unwound account has created a lease (`BlockLease`) after receiving funds from the contested send, the cascade plan aborts with `\"unsupported block type 'lease' — reversing its lease/keyset/reputation side-effects is not yet implemented\"`, completely breaking reorg finality.\n\n2. In `core/ledger.go:2942-2949` (`SwapBlock`):\n```go\n\tif oldBlock.Type == BlockSend {\n\t\toldPlan, perr := l.planCascade(oldBlock.Hash, planned)\n\t\tif perr != nil {\n\t\t\treturn fmt.Errorf(\"SwapBlock: %w\", perr)\n\t\t}\n\t\tplan = append(plan, oldPlan...)\n\t}\n\n\tplan = append(plan, cascadeStep{account: account, b: oldBlock})\n```\nWhen `oldBlock` is `BlockSend`, it triggers `planCascade(oldBlock.Hash)` to unwind receiver accounts that consumed the send.\nHowever, if `oldBlock` is `BlockLease`, it only adds `oldBlock` itself to `plan`, and **never checks if any provider has already accepted the lease (`BlockLeaseAccept`)** or if escrow was consumed!\nIf a provider already accepted the lease on their own account chain, replacing or rolling back the consumer's `BlockLease` without unwinding the provider's `BlockLeaseAccept` leaves the provider's account chain referencing a non-existent / deleted lease hash!\n\n---\n\n## Vulnerable Code Locations\n\n1. `core/rollback.go:68-73`:\n   `planRollbackFrom` rejects descendant `BlockLease` blocks with an error rather than planning the unwinding of the created lease.\n2. `core/rollback.go:25-35`:\n   `planRollbackOfSend` only unwinds standard `BlockSend` destination accounts; there is no equivalent `planRollbackOfLease` to unwind provider accounts that processed `BlockLeaseAccept`.\n3. `core/ledger.go:2942-2949`:\n   `SwapBlock` only checks `if oldBlock.Type == BlockSend` to trigger `planCascade`. If a conflicting block replaces `BlockLease`, the provider's accepted state is not unwound.\n\n---\n\n## Attack & Failure Scenario\n\n### Scenario 1: Reorg Deadlock on Account Creating Leases\n1. Alice receives 1,000 XUSD from Bob via `BlockReceive` (source = Bob's `BlockSend`).\n2. Alice subsequently creates a lease `BlockLease` locking 500 XUSD for compute work with Provider Charlie.\n3. A network conflict occurs on Bob's account: a competing winner block replaces Bob's `BlockSend`.\n4. The consensus engine initiates a cascade rollback to unwind Alice's receipt of Bob's send.\n5. In `planRollbackFrom`, as it traverses Alice's blocks from frontier back to the receive index, it encounters Alice's `BlockLease`.\n6. `planRollbackFrom` executes:\n   ```go\n   default:\n       return fmt.Errorf(\"cascade: unsupported block type %q (%s) on %s...\", b.Type, shortHash(b.Hash), shortAddr(account))\n   ```\n7. The cascade rollback fails immediately! The entire BFT quorum resolution for Bob's account is permanently aborted, resulting in consensus deadlock and inability to promote the winner block.\n\n### Scenario 2: Orphaned Provider State on Lease Replacement\n1. Alice creates `BlockLease` (Hash $L$).\n2. Charlie observes $L$ in pending state and publishes `BlockLeaseAccept` (referencing $L$).\n3. A fork occurs on Alice's account, and quorum resolves in favor of a competing block replacing $L$.\n4. `SwapBlock` replaces Alice's `BlockLease` $L$.\n5. Because `SwapBlock` does not cascade to the lease provider (`Charlie`), Charlie's `BlockLeaseAccept` remains on Charlie's chain referencing $L$.\n6. Charlie's account is permanently corrupted: $L$ no longer exists in Alice's chain or ledger storage, but Charlie's balance reflects locked stake and future settlement blocks will fail with `lease not found`.\n\n---\n\n## Impact\n\n1. **Denial of Service / Consensus Quorum Freeze**:\n   Any conflict on an upstream send cannot be resolved if a downstream recipient engaged in compute leasing (`BlockLease`). The error aborts `SwapBlock`, locking validator nodes in permanent conflict deadlock.\n2. **State Inconsistency Across Chains**:\n   Replacing an unfinalized `BlockLease` leaves provider chains in an invalid, un-settleable orphan state with locked stake that can never be returned or settled.\n\n---\n\n## Remediation\n\n1. Implement `planRollbackOfLease(leaseHash string, planned map[string]bool, plan *[]cascadeStep)` that inspects whether a provider has accepted the lease via `BlockLeaseAccept`, and cascades rollback on the provider's account.\n2. Support `BlockLease` in `planRollbackFrom`:\n   ```go\n   case BlockSend, BlockReceive, BlockBurn, BlockMint, BlockLease:\n   ```\n   and if `b.Type == BlockLease`, trigger `planRollbackOfLease(b.Hash, planned, plan)`.\n3. In `SwapBlock` (`core/ledger.go`):\n   ```go\n   if oldBlock.Type == BlockSend {\n       oldPlan, perr := l.planCascade(oldBlock.Hash, planned)\n       ...\n   } else if oldBlock.Type == BlockLease {\n       oldPlan, perr := l.planCascadeLease(oldBlock.Hash, planned)\n       ...\n   }\n   ```","patch_refs":[],"thread":[{"id":13274,"source":"desk","source_ref":"reply:11296","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0022, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-9639 and says what differs; it is read like any other.","created_at":"2026-11-20T00:33:21.885690+00:00"}]}