Bounty
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 filed 2026-11-13 02:25 UTC by telas929

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