<!-- XE-13371 · [Consensus/Severe] core/ledger, core/rollback: Incomplete block type filter in SwapBlock and planRollbackFrom halts fork resolution on accounts with lease or multisig descendants · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13371>. The page is the record; this is the same page for reading.*

XE-13371 · Bounty

# \[Consensus/Severe\] core/ledger, core/rollback: Incomplete block type filter in SwapBlock and planRollbackFrom halts fork resolution on accounts with lease or multisig descendants

Closed · duplicate
—
[xe#525](https://github.com/xeprotocol/xe/issues/525)
filed 2026-11-13 02:25 UTC
by telas929

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   Consensus

Duplicate of
:   [XE-0022](https://bounty.xe.network/XE-0022) patched

Tracked
:   internally

Updated
:   2026-11-20 13:01 UTC

Told
:   2026-11-20 13:00 UTC

### Patches

- [xe#911](https://github.com/xeprotocol/xe/pull/911) open by tipprb
  fix(xe): consensus-severe--core-ledger (fixes #525)

### History

- [599212](https://bounty.xe.network/log/599212) 2026-11-20 13:00 UTC reply.mirrored
- [598806](https://bounty.xe.network/log/598806) 2026-11-20 13:00 UTC github.state\_pushed
- [598741](https://bounty.xe.network/log/598741) 2026-11-20 13:00 UTC github.labels
- [597675](https://bounty.xe.network/log/597675) 2026-11-20 12:59 UTC proposal.adopted
- [597674](https://bounty.xe.network/log/597674) 2026-11-20 12:59 UTC reply.sent
- [597673](https://bounty.xe.network/log/597673) 2026-11-20 12:59 UTC ticket.status new → closed
- [594421](https://bounty.xe.network/log/594421) 2026-11-20 12:58 UTC proposal.adopted
- [594420](https://bounty.xe.network/log/594420) 2026-11-20 12:58 UTC ticket.facts area
- [594419](https://bounty.xe.network/log/594419) 2026-11-20 12:58 UTC proposal.adopted
- [594418](https://bounty.xe.network/log/594418) 2026-11-20 12:58 UTC ticket.facts
- [594417](https://bounty.xe.network/log/594417) 2026-11-20 12:58 UTC proposal.adopted
- [594416](https://bounty.xe.network/log/594416) 2026-11-20 12:58 UTC ticket.facts

[Full history](https://bounty.xe.network/log?ref=XE-13371) · [JSON](https://bounty.xe.network/v1/tickets/XE-13371) · [markdown](https://bounty.xe.network/XE-13371.md)

### Report

## Summary

During 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.

However, both `SwapBlock` (lines 2926–2931) and `planRollbackFrom` (lines 68–73) employ an overly restrictive block type whitelist during cascade planning:

```
switch b.Type {
case BlockSend, BlockReceive, BlockBurn, BlockMint:
default:
    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))
}
```

The 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`).

Because 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.

---

## Root Cause Analysis

1. **Restrictive Whitelist in `core/ledger.go:2926-2931` (`SwapBlock`)**:
   When replacing an unfinalized block at index `idx` on an account chain, `SwapBlock` iterates backwards through descendant blocks (`i > idx`) to schedule undos:

   ```
   for i := len(chain.Blocks) - 1; i > idx; i-- {
       b := chain.Blocks[i]
       if planned[b.Hash] {
           continue
       }
       switch b.Type {
       case BlockSend, BlockReceive, BlockBurn, BlockMint:

       default:
           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))
       }
       // ...
   }
   ```

   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.
2. **Identical Filter in `core/rollback.go:68-73` (`planRollbackFrom`)**:
   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`:

   ```
   for i := len(chain.Blocks) - 1; i >= recvIdx; i-- {
       b := chain.Blocks[i]
       if planned[b.Hash] {
           continue
       }
       switch b.Type {
       case BlockSend, BlockReceive, BlockBurn, BlockMint:

       default:
           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))
       }
       // ...
   }
   ```

   If the recipient created or accepted a lease after receiving the unfinalized funds, the cascade rollback halts.
3. **Discrepancy with `buildBlockUndo` (`core/rollback.go:220-269`)**:
   The actual rollback execution engine in `buildBlockUndo` already fully supports unwinding these block types:

   - `BlockLease`: Deletes pending escrow (`deletePendingID = b.Hash`) and removes the lease entry (`deleteLeaseHash = b.Hash`).
   - `BlockLeaseAccept`: Restores lease state to `LeaseCreated` and reverts provider/consumer reputation delta.
   - `BlockLeaseSettle` \& `BlockLeaseForceSettle`: Restores lease state to `LeaseAccepted`, restores pending escrow, restores XUSD stake debit, and reverts reputation settling hours.
   - `BlockLeaseCancel`: Restores lease state to `LeaseCreated` and restores pending escrow.
   - `BlockLeaseRenew`: Restores previous lease segment via `priorLeasePopRenewal` and reduces pending escrow.
   - `BlockMultisigOpen`: Removes keyset entry (`deleteKeysetAccount = b.Account`).

   The planning whitelist fell out of sync when lease and multisig support were added to `buildBlockUndo`.
4. **Permanent Consensus Finality Stall in `core/quorum.go:321-329`**:
   In `confirmConflict`:

   ```
   if err := qm.ledger.swapBlockLocked(result.ConflictAccount, loserHash, result.WinnerHash, winnerBlock); err != nil {
       if errors.Is(err, ErrWinnerFullValidation) && !IsRetryableError(err) {
           qm.failedPromotions[failedPromotionKey(result.ConflictAccount, result.ConflictPrev, result.WinnerHash)] = Now()
           log.Printf("confirmConflict: winner %s ... failed full validation deterministically: quarantining for %s...", ...)
       }
       return fmt.Errorf("confirmConflict: SwapBlock: %w", err)
   }
   ```

   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.

---

## Impact

- **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.
- **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.

---

## Recommended Remediation

Update 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`:

```
--- a/core/ledger.go
+++ b/core/ledger.go
@@ -2926,6 +2926,9 @@ func (l *Ledger) SwapBlock(account string, oldHash, newHash string, newBlock *Bl
 		switch b.Type {
 		case BlockSend, BlockReceive, BlockBurn, BlockMint:
+		case BlockLease, BlockLeaseAccept, BlockLeaseSettle, BlockLeaseForceSettle, BlockLeaseCancel, BlockLeaseRenew:
+		case BlockMultisigOpen:
 		default:
 			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))
 		}

--- a/core/rollback.go
+++ b/core/rollback.go
@@ -68,6 +68,9 @@ func (l *Ledger) planRollbackFrom(account, consumedSend string, planned map[stri
 		switch b.Type {
 		case BlockSend, BlockReceive, BlockBurn, BlockMint:
+		case BlockLease, BlockLeaseAccept, BlockLeaseSettle, BlockLeaseForceSettle, BlockLeaseCancel, BlockLeaseRenew:
+		case BlockMultisigOpen:
 		default:
 			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))
 		}
```

### Thread

**Joseph Denne**team2026-11-20 13:00 UTCgithub

Thanks. This is the same finding as https://bounty.xe.network/XE-0022, 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-13371 and says what differs; it is read like any other.
