{"id":"XE-13371","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"525","source_url":"https://github.com/xeprotocol/xe/issues/525","reporter_id":1743,"title":"[Consensus/Severe] core/ledger, core/rollback: Incomplete block type filter in SwapBlock and planRollbackFrom halts fork resolution on accounts with lease or multisig descendants","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":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:12.829954+00:00","updated_at":"2026-11-20T13:01:19.001120+00:00","source_created_at":"2026-11-13T02:25:44+00:00","told_at":"2026-11-20T13:00:20+00:00","status_changed_at":"2026-11-20T12:59:46.192904+00:00","url":"https://bounty.xe.network/XE-13371","body":"## Summary\n\nDuring conflict resolution and fork replacement, `core/quorum.go` invokes `swapBlockLocked` (which calls `core/ledger.go:SwapBlock`) to rollback unfinalized blocks from the losing fork and promote the quorum-voted winner. To cleanly rewind account history across unfinalized transactions, `SwapBlock` and `planRollbackFrom` (in `core/rollback.go`) plan a cascade of undo steps.\n\nHowever, both `SwapBlock` (lines 2926–2931) and `planRollbackFrom` (lines 68–73) employ an overly restrictive block type whitelist during cascade planning:\n\n```go\nswitch b.Type {\ncase BlockSend, BlockReceive, BlockBurn, BlockMint:\ndefault:\n    return fmt.Errorf(\"SwapBlock: cannot unwind descendant %q (%s) of the replaced block — reversing its side-effects is not yet implemented\", b.Type, shortHash(b.Hash))\n}\n```\n\nThe error message states that reversing side-effects for other block types is not implemented. However, this is contradicted by `buildBlockUndo` in `core/rollback.go` (lines 220–269), which **already completely implements** state reversal for all compute lease operations (`BlockLease`, `BlockLeaseAccept`, `BlockLeaseSettle`, `BlockLeaseForceSettle`, `BlockLeaseCancel`, `BlockLeaseRenew`) as well as `BlockMultisigOpen` (and representative changes via `prevRep`).\n\nBecause the planning filter rejects valid lease and multisig block types, whenever an account has a lease or multisig operation following an unfinalized block that is subsequently replaced by consensus, `SwapBlock` aborts deterministically. Consequently, `confirmConflict` fails, the winner block cannot be promoted, and the node's account chain enters a permanent consensus stall, causing a persistent consensus fork split from the rest of the network.\n\n---\n\n## Root Cause Analysis\n\n1. **Restrictive Whitelist in `core/ledger.go:2926-2931` (`SwapBlock`)**:\n   When replacing an unfinalized block at index `idx` on an account chain, `SwapBlock` iterates backwards through descendant blocks (`i > idx`) to schedule undos:\n   ```go\n   for i := len(chain.Blocks) - 1; i > idx; i-- {\n       b := chain.Blocks[i]\n       if planned[b.Hash] {\n           continue\n       }\n       switch b.Type {\n       case BlockSend, BlockReceive, BlockBurn, BlockMint:\n\n       default:\n           return fmt.Errorf(\"SwapBlock: cannot unwind descendant %q (%s) of the replaced block — reversing its side-effects is not yet implemented\", b.Type, shortHash(b.Hash))\n       }\n       // ...\n   }\n   ```\n   If any descendant is a lease block (`lease`, `lease_accept`, `lease_settle`, `lease_cancel`, `lease_force_settle`, `lease_renew`) or a `multisig_open` block, `SwapBlock` returns an error immediately.\n\n2. **Identical Filter in `core/rollback.go:68-73` (`planRollbackFrom`)**:\n   If an unfinalized send from the losing fork was already received by a counterparty, `planRollbackFrom` attempts to cascade-rollback the counterparty's chain down to `recvIdx`:\n   ```go\n   for i := len(chain.Blocks) - 1; i >= recvIdx; i-- {\n       b := chain.Blocks[i]\n       if planned[b.Hash] {\n           continue\n       }\n       switch b.Type {\n       case BlockSend, BlockReceive, BlockBurn, BlockMint:\n\n       default:\n           return 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       }\n       // ...\n   }\n   ```\n   If the recipient created or accepted a lease after receiving the unfinalized funds, the cascade rollback halts.\n\n3. **Discrepancy with `buildBlockUndo` (`core/rollback.go:220-269`)**:\n   The actual rollback execution engine in `buildBlockUndo` already fully supports unwinding these block types:\n   - `BlockLease`: Deletes pending escrow (`deletePendingID = b.Hash`) and removes the lease entry (`deleteLeaseHash = b.Hash`).\n   - `BlockLeaseAccept`: Restores lease state to `LeaseCreated` and reverts provider/consumer reputation delta.\n   - `BlockLeaseSettle` & `BlockLeaseForceSettle`: Restores lease state to `LeaseAccepted`, restores pending escrow, restores XUSD stake debit, and reverts reputation settling hours.\n   - `BlockLeaseCancel`: Restores lease state to `LeaseCreated` and restores pending escrow.\n   - `BlockLeaseRenew`: Restores previous lease segment via `priorLeasePopRenewal` and reduces pending escrow.\n   - `BlockMultisigOpen`: Removes keyset entry (`deleteKeysetAccount = b.Account`).\n\n   The planning whitelist fell out of sync when lease and multisig support were added to `buildBlockUndo`.\n\n4. **Permanent Consensus Finality Stall in `core/quorum.go:321-329`**:\n   In `confirmConflict`:\n   ```go\n   if err := qm.ledger.swapBlockLocked(result.ConflictAccount, loserHash, result.WinnerHash, winnerBlock); err != nil {\n       if errors.Is(err, ErrWinnerFullValidation) && !IsRetryableError(err) {\n           qm.failedPromotions[failedPromotionKey(result.ConflictAccount, result.ConflictPrev, result.WinnerHash)] = Now()\n           log.Printf(\"confirmConflict: winner %s ... failed full validation deterministically: quarantining for %s...\", ...)\n       }\n       return fmt.Errorf(\"confirmConflict: SwapBlock: %w\", err)\n   }\n   ```\n   Because `SwapBlock` fails with `cannot unwind descendant`, `confirmConflict` returns an error. The node cannot apply the quorum-approved winner block, cannot update its final height, and remains stuck on the superseded branch while the rest of the network advances.\n\n---\n\n## Impact\n\n- **Severe Consensus Stall & Permanent Fork Desync**: Any account chain with active compute leases or multisig accounts cannot undergo conflict resolution if a fork arises prior to those blocks. Nodes that processed the losing branch cannot reconcile with the network winner.\n- **Trivial Finality Denial of Service (Anti-Rollback Poisoning)**: An adversarial user can intentionally create a conflict (two branches A and B) and append a valid `lease` or `lease_renew` block to branch A. When the network votes branch B as the legitimate winner, any node holding branch A will be permanently unable to execute `SwapBlock`, isolating those nodes into an unrecoverable consensus split.\n\n---\n\n## Recommended Remediation\n\nUpdate the block type switch statements in both `core/ledger.go` and `core/rollback.go` to include the block types whose undo transitions are fully handled by `buildBlockUndo`:\n\n```diff\n--- a/core/ledger.go\n+++ b/core/ledger.go\n@@ -2926,6 +2926,9 @@ func (l *Ledger) SwapBlock(account string, oldHash, newHash string, newBlock *Bl\n \t\tswitch b.Type {\n \t\tcase BlockSend, BlockReceive, BlockBurn, BlockMint:\n+\t\tcase BlockLease, BlockLeaseAccept, BlockLeaseSettle, BlockLeaseForceSettle, BlockLeaseCancel, BlockLeaseRenew:\n+\t\tcase BlockMultisigOpen:\n \t\tdefault:\n \t\t\treturn fmt.Errorf(\"SwapBlock: cannot unwind descendant %q (%s) of the replaced block — reversing its side-effects is not yet implemented\", b.Type, shortHash(b.Hash))\n \t\t}\n\n--- a/core/rollback.go\n+++ b/core/rollback.go\n@@ -68,6 +68,9 @@ func (l *Ledger) planRollbackFrom(account, consumedSend string, planned map[stri\n \t\tswitch b.Type {\n \t\tcase BlockSend, BlockReceive, BlockBurn, BlockMint:\n+\t\tcase BlockLease, BlockLeaseAccept, BlockLeaseSettle, BlockLeaseForceSettle, BlockLeaseCancel, BlockLeaseRenew:\n+\t\tcase BlockMultisigOpen:\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```\n","patch_refs":[{"id":739,"repo":"xeprotocol/xe","kind":"pr","ref":"911","title":"fix(xe): consensus-severe--core-ledger (fixes #525)","url":"https://github.com/xeprotocol/xe/pull/911","note":"","state":"open","author":"tipprb","added_by":"desk","created_at":"2026-11-19T23:58:24.705382+00:00"}],"thread":[{"id":14115,"source":"github","source_ref":"7040168485","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-13371 and says what differs; it is read like any other.","created_at":"2026-11-20T13:00:20+00:00"}]}