Bounty
XE-0135 · Bounty

[Track 1 Bug Bounty] Multi-Step Cascade Unwind Stale Store Reads, Missing SwapBlock Credential Verification, Renewed Lease Reputation Drop, and BadgerStore Pending/CAS Desync

Accepted xe#226 filed 2026-10-31 01:08 UTC by ket4min-susan

Report

Summary

This report details 5 distinct, non-overlapping consensus, ledger rollback, and storage engine vulnerabilities in core/ and store/ (master branch), accompanied by deterministic unit tests and a complete surgical fix PR:

  1. [Critical / Severe] Multi-Step Cascade Unwind Reads Stale Pre-Cascade Store State Instead of cascadeBuild Overlay (core/rollback.go:87-144, 163-184, core/ledger.go:2976-2998)
  2. [Severe] SwapBlock Bypasses verifyBlockCredential on Replacement Winner Blocks & Reads Stale Keyset/AccountKey Caches During Cascade Validation (core/ledger.go:1426, 1447, 1456, 2876, 3004, core/cascade_commit.go:21, 66-68)
  3. [High] Renewed Lease Duration Dropped in Reputation Settlement/Undo & Fallback Timestamp Corruption on Rebuild (core/ledger.go:657, 688, 695, 700, 708, 2244, core/rollback.go:262)
  4. [High] BadgerStore.CommitCascade Omission of Pre-Undo Lease CAS (ExpectLeaseHash / ExpectLeaseState / ExpectLeaseEffectiveDurationSecs) & Unbounded Duplicate prefixPendingDst Append (store/badger_store.go:778, 1063, 1110-1127)
  5. [Medium] In-Memory Map Poisoning Across rebuildKeysets, rebuildAccountKeys, and rebuildDelegation (core/ledger.go:1402, 1489, 2572)

Vulnerability 1: Multi-Step Cascade Unwind Reads Stale Pre-Cascade Store State Instead of cascadeBuild Overlay

Root Cause

During conflict promotion (SwapBlock -> swapBlockLocked at core/ledger.go:2976-2998), buildBlockUndo is invoked sequentially for each step in the cascade plan before activateCascade(cascade) is called, and getAssetBalanceOverlay(account, "XUSD") calls l.xusdBalanceOnChain(ch) during winner validation.

However, four helper functions in core/rollback.go read directly from l.store.(LeaseStore).GetLease(leaseHash) instead of consulting the in-progress cascadeBuild lease overlay (cb.restoreLease / cb.deleteLease):

  • priorLease (core/rollback.go:87-107)
  • escrowPendingOf (core/rollback.go:109-130)
  • priorLeasePopRenewal (core/rollback.go:132-144)
  • xusdBalanceOnChain (core/rollback.go:163-184)

Impact

  1. Multi-step lease unwind corruption: When a cascade unwinds multiple lease-related blocks (e.g., unwinding BlockLeaseSettle followed by BlockLeaseRenew and/or BlockLeaseAccept), priorLease, priorLeasePopRenewal, and escrowPendingOf read the pre-cascade Lease from l.store rather than the intermediate RestoreLease already recorded in cascade.restoreLease. Consequently, popped renewals re-appear in subsequent RestoreLease / AddPending records, or Stake / State reverts to stale values.
  2. XUSD balance miscalculation during cascade: If BlockLeaseAccept (or BlockLease) was unwound in cascade.restoreLease (setting Stake = 0 or deleting the lease), xusdBalanceOnChain still queries ls.GetLease(b.Source) from the underlying store and adds the stale lease.Stake, corrupting parentBal and getAssetBalanceOverlay(account, "XUSD").

Vulnerability 2: SwapBlock Bypasses verifyBlockCredential on Replacement Winner Blocks & Reads Stale Keyset/AccountKey Caches During Cascade Validation

Root Cause

  1. In SwapBlock (core/ledger.go:2876-2885) and swapBlockLocked (core/ledger.go:3004), the replacement block newBlock is checked only with VerifyBlock(newBlock) (core/crypto.go:145-167) before calling dispatchValidateAndAdd(newBlock, true).
    • Crucially, VerifyBlock(b) returns nil without verifying any signature whenever b.Previous != "0" or len(b.Signatures) > 0 (core/crypto.go:158-164), deferring signature and multisig verification to l.verifyBlockCredential(b).
    • Because dispatchValidateAndAdd does not call verifyBlockCredential(b), any direct call to SwapBlock with a non-open replacement block or multisig block skips signature verification entirely!
  2. Even when verifyBlockCredential(b) is called (core/ledger.go:1416-1465), it reads l.GetKeyset(b.Account) (lines 1426, 1447), l.GetAccountKey(b.Account) (line 1456), and l.store.GetAccountChain(account) in resolveMissingKeyset (line 1468) instead of l.getKeysetOverlay(b.Account), l.getAccountKeyOverlay(b.Account), and l.getAccountChainOverlay(account).
  3. Furthermore, cascadeBuild (core/cascade_commit.go:21, 66-68) tracks deleteKeyset (undo.DeleteKeysetAccount) but omits deleteAccountKey (undo.DeleteAccountKeyAccount). If an account's open block is unwound during a cascade and replaced by a new open block or multisig open block, stale accountKeys or keysets remain visible during cascade validation.

Impact

  • Replacement blocks in SwapBlock bypass verifyBlockCredential unless validated externally beforehand, and cascade validation of replacement blocks on accounts whose open/keyset block was unwound fails or validates against the unwound loser's public key / keyset.

Vulnerability 3: Renewed Lease Duration Dropped in Reputation Settlement/Undo & Fallback Timestamp Corruption on Rebuild

Root Cause

  1. When a lease with one or more BlockLeaseRenew segments is settled or rebuilt:
    • validateAndAddLeaseSettle (core/ledger.go:2239-2245) passes DurationSecs: lease.Duration instead of lease.EffectiveDurationSecs().
    • rebuildReputation (core/ledger.go:652-658) passes DurationSecs: lease.Duration instead of lease.EffectiveDurationSecs().
    • buildBlockUndo (core/rollback.go:262) reverts DurationSecs: restoreLease.Duration instead of restoreLease.EffectiveDurationSecs().
  2. In lookupLeaseSettleTimestamp (core/ledger.go:688, 695) and lookupLeaseForceSettleTimestamp (core/ledger.go:701, 708), the fallback timestamp is computed as lease.StartTime + int64(lease.Duration)*1e9 instead of lease.EffectiveExpiry(), ignoring all renewal durations.

Impact

  • Every renewed lease permanently loses 100% of its renewal duration seconds in LeaseHoursSettledAsProvider and LeaseHoursSettledAsConsumer across live settlement, undo, and startup reputation rebuilds, and fallback timestamps on renewed leases regress prior to actual expiry.

Vulnerability 4: BadgerStore.CommitCascade Omission of Pre-Undo Lease CAS & Unbounded Duplicate prefixPendingDst Append

Root Cause

  1. Compare MemStore.CommitCascade (store/mem_store.go:467-513) with BadgerStore.CommitCascade (store/badger_store.go:1110-1127):
    • MemStore.CommitCascade evaluates the post-undo lease state before mutating state and enforces the winner commit's ExpectLeaseHash, ExpectLeaseState, and ExpectLeaseEffectiveDurationSecs CAS invariants.
    • BadgerStore.CommitCascade completely omitted this pre-undo check and relied on applyCommitTxn running after applyUndoTxn, or failed to account for lease mutations cleanly before applying undo steps.
  2. In applyCommitTxn (store/badger_store.go:778) and applyUndoTxn (store/badger_store.go:1063), adding a PendingSend unconditionally appends SendHash to destHashes in prefixPendingDst without checking if SendHash is already present.
    • When an undo re-adds a PendingSend whose hash was still present in prefixPendingDst, GetPendingByDest returns duplicate PendingSend entries for the same SendHash (diverging from MemStore, which keys pending by SendHash in a map).

Impact

  • Storage backend divergence between MemStore and BadgerStore during cascade commits and duplicate pending-send entries returned by BadgerStore.GetPendingByDest.

Vulnerability 5: In-Memory Map Poisoning Across rebuildKeysets, rebuildAccountKeys, and rebuildDelegation

Root Cause

  • rebuildKeysets() (core/ledger.go:1489), rebuildAccountKeys() (core/ledger.go:1402), and rebuildDelegation() (core/ledger.go:2572) iterate over the store and populate l.keysets, l.accountKeys, l.delegation, and l.weights without clearing existing entries first (unlike rebuildReputation(), which calls l.reputation.Reset()).
  • In addition, commitBlockWrite (core/ledger.go:2292-2346) did not update l.setKeyset(c.Account, c.PutKeyset) inside commitBlockWrite itself (relying on callers after commitBlockWrite), whereas PutAccountKey was applied inside commitBlockWrite.

Proof of Concept / Reproduction Tests

Added in core/cascade_reputation_test.go and store/badger_cascade_test.go:

go test -v ./core -run "TestCascadeOverlayStaleStoreReadsInUndoAndXUSDBalance|TestRenewedLeaseReputationDurationAndFallbackTimestamps|TestSwapBlockCredentialVerificationAndOverlayKeyset"
go test -v ./store -run "TestBadgerStoreCommitCascadeEnforcesLeaseCASAndDeduplicatesPendingByDest"

Payout Address

  • XE Wallet Address: 23bd7ef9c17e79ee76e9f656d618cf0f7c2cda4a700b58d065917d14e97a304a

Thread

ket4min-susan2026-10-31 01:09 UTCgithub

Submitted complete fix and regression unit tests in PR #227: https://github.com/xeprotocol/xe/pull/227

XE Payout Wallet: 23bd7ef9c17e79ee76e9f656d618cf0f7c2cda4a700b58d065917d14e97a304a

Joseph Denneteam2026-11-08 20:18 UTCgithub

Thank you for the report and the accompanying pull request. We have reviewed the findings; part of what you describe is being handled and part did not reproduce against the current tree. We will update this ticket as the work progresses.

XE deskteam2026-11-14 20:58 UTCgithub

Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is updated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0135.