<!-- XE-0135 · [Track 1 Bug Bounty] Multi-Step Cascade Unwind Stale Store Reads, Missing SwapBlock Credential Verification, Renewed Lease Reputation Drop, and BadgerStore Pending/CAS Desync · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0135>. The page is the record; this is the same page for reading.*

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](https://github.com/xeprotocol/xe/issues/226)
filed 2026-10-31 01:08 UTC
by ket4min-susan

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   —

Area
:   Consensus

Duplicate of
:   —

Tracked
:   internally

Updated
:   2026-11-14 20:59 UTC

Told
:   2026-11-14 20:58 UTC

### Patches

- [xe#227](https://github.com/xeprotocol/xe/pull/227) open by ket4min-susan
  fix(core,store): cascade overlay lease/credential reads, renewed lease reputation duration, and BadgerStore CAS/pending dedup (Fixes #226)
- [xe#232](https://github.com/xeprotocol/xe/pull/232) open by tipprb
  fix(core,store): cascade overlay lease/credential reads, renewed lease reputation duration, and BadgerStore CAS/pending dedup (Fixes #226)

### History

- [206235](https://bounty.xe.network/log/206235) 2026-11-14 20:58 UTC reply.mirrored
- [206211](https://bounty.xe.network/log/206211) 2026-11-14 20:57 UTC reply.sent
- [205870](https://bounty.xe.network/log/205870) 2026-11-14 20:42 UTC github.labels
- [205863](https://bounty.xe.network/log/205863) 2026-11-14 20:42 UTC ticket.status triaging → accepted
- [43825](https://bounty.xe.network/log/43825) 2026-11-08 20:19 UTC github.labels
- [43796](https://bounty.xe.network/log/43796) 2026-11-08 20:18 UTC reply.mirrored
- [43315](https://bounty.xe.network/log/43315) 2026-11-08 20:18 UTC proposal.adopted
- [43314](https://bounty.xe.network/log/43314) 2026-11-08 20:18 UTC reply.sent
- [40076](https://bounty.xe.network/log/40076) 2026-11-08 20:17 UTC proposal.adopted
- [40075](https://bounty.xe.network/log/40075) 2026-11-08 20:17 UTC ticket.facts area
- [40074](https://bounty.xe.network/log/40074) 2026-11-08 20:17 UTC proposal.adopted
- [40073](https://bounty.xe.network/log/40073) 2026-11-08 20:17 UTC ticket.facts

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

### 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-susan**2026-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 Denne**team2026-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 desk**team2026-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.
