[Track 1 Bug Bounty] Multi-Step Cascade Unwind Stale Store Reads, Missing SwapBlock Credential Verification, Renewed Lease Reputation Drop, and BadgerStore Pending/CAS Desync
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:
- [Critical / Severe] Multi-Step Cascade Unwind Reads Stale Pre-Cascade Store State Instead of
cascadeBuildOverlay (core/rollback.go:87-144, 163-184,core/ledger.go:2976-2998) - [Severe]
SwapBlockBypassesverifyBlockCredentialon 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) - [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) - [High]
BadgerStore.CommitCascadeOmission of Pre-Undo Lease CAS (ExpectLeaseHash/ExpectLeaseState/ExpectLeaseEffectiveDurationSecs) & Unbounded DuplicateprefixPendingDstAppend (store/badger_store.go:778, 1063, 1110-1127) - [Medium] In-Memory Map Poisoning Across
rebuildKeysets,rebuildAccountKeys, andrebuildDelegation(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
- Multi-step lease unwind corruption: When a cascade unwinds multiple lease-related blocks (e.g., unwinding
BlockLeaseSettlefollowed byBlockLeaseRenewand/orBlockLeaseAccept),priorLease,priorLeasePopRenewal, andescrowPendingOfread the pre-cascadeLeasefroml.storerather than the intermediateRestoreLeasealready recorded incascade.restoreLease. Consequently, popped renewals re-appear in subsequentRestoreLease/AddPendingrecords, orStake/Statereverts to stale values. - XUSD balance miscalculation during cascade: If
BlockLeaseAccept(orBlockLease) was unwound incascade.restoreLease(settingStake = 0or deleting the lease),xusdBalanceOnChainstill queriesls.GetLease(b.Source)from the underlying store and adds the stalelease.Stake, corruptingparentBalandgetAssetBalanceOverlay(account, "XUSD").
Vulnerability 2: SwapBlock Bypasses verifyBlockCredential on Replacement Winner Blocks & Reads Stale Keyset/AccountKey Caches During Cascade Validation
Root Cause
- In
SwapBlock(core/ledger.go:2876-2885) andswapBlockLocked(core/ledger.go:3004), the replacement blocknewBlockis checked only withVerifyBlock(newBlock)(core/crypto.go:145-167) before callingdispatchValidateAndAdd(newBlock, true).- Crucially,
VerifyBlock(b)returnsnilwithout verifying any signature wheneverb.Previous != "0"orlen(b.Signatures) > 0(core/crypto.go:158-164), deferring signature and multisig verification tol.verifyBlockCredential(b). - Because
dispatchValidateAndAdddoes not callverifyBlockCredential(b), any direct call toSwapBlockwith a non-open replacement block or multisig block skips signature verification entirely!
- Crucially,
- Even when
verifyBlockCredential(b)is called (core/ledger.go:1416-1465), it readsl.GetKeyset(b.Account)(lines 1426, 1447),l.GetAccountKey(b.Account)(line 1456), andl.store.GetAccountChain(account)inresolveMissingKeyset(line 1468) instead ofl.getKeysetOverlay(b.Account),l.getAccountKeyOverlay(b.Account), andl.getAccountChainOverlay(account). - Furthermore,
cascadeBuild(core/cascade_commit.go:21, 66-68) tracksdeleteKeyset(undo.DeleteKeysetAccount) but omitsdeleteAccountKey(undo.DeleteAccountKeyAccount). If an account's open block is unwound during a cascade and replaced by a new open block or multisig open block, staleaccountKeysorkeysetsremain visible during cascade validation.
Impact
- Replacement blocks in
SwapBlockbypassverifyBlockCredentialunless 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
- When a lease with one or more
BlockLeaseRenewsegments is settled or rebuilt:validateAndAddLeaseSettle(core/ledger.go:2239-2245) passesDurationSecs: lease.Durationinstead oflease.EffectiveDurationSecs().rebuildReputation(core/ledger.go:652-658) passesDurationSecs: lease.Durationinstead oflease.EffectiveDurationSecs().buildBlockUndo(core/rollback.go:262) revertsDurationSecs: restoreLease.Durationinstead ofrestoreLease.EffectiveDurationSecs().
- In
lookupLeaseSettleTimestamp(core/ledger.go:688, 695) andlookupLeaseForceSettleTimestamp(core/ledger.go:701, 708), the fallback timestamp is computed aslease.StartTime + int64(lease.Duration)*1e9instead oflease.EffectiveExpiry(), ignoring all renewal durations.
Impact
- Every renewed lease permanently loses 100% of its renewal duration seconds in
LeaseHoursSettledAsProviderandLeaseHoursSettledAsConsumeracross 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
- Compare
MemStore.CommitCascade(store/mem_store.go:467-513) withBadgerStore.CommitCascade(store/badger_store.go:1110-1127):MemStore.CommitCascadeevaluates the post-undo lease state before mutating state and enforces the winner commit'sExpectLeaseHash,ExpectLeaseState, andExpectLeaseEffectiveDurationSecsCAS invariants.BadgerStore.CommitCascadecompletely omitted this pre-undo check and relied onapplyCommitTxnrunning afterapplyUndoTxn, or failed to account for lease mutations cleanly before applying undo steps.
- In
applyCommitTxn(store/badger_store.go:778) andapplyUndoTxn(store/badger_store.go:1063), adding aPendingSendunconditionally appendsSendHashtodestHashesinprefixPendingDstwithout checking ifSendHashis already present.- When an undo re-adds a
PendingSendwhose hash was still present inprefixPendingDst,GetPendingByDestreturns duplicatePendingSendentries for the sameSendHash(diverging fromMemStore, which keyspendingbySendHashin a map).
- When an undo re-adds a
Impact
- Storage backend divergence between
MemStoreandBadgerStoreduring cascade commits and duplicate pending-send entries returned byBadgerStore.GetPendingByDest.
Vulnerability 5: In-Memory Map Poisoning Across rebuildKeysets, rebuildAccountKeys, and rebuildDelegation
Root Cause
rebuildKeysets()(core/ledger.go:1489),rebuildAccountKeys()(core/ledger.go:1402), andrebuildDelegation()(core/ledger.go:2572) iterate over the store and populatel.keysets,l.accountKeys,l.delegation, andl.weightswithout clearing existing entries first (unlikerebuildReputation(), which callsl.reputation.Reset()).- In addition,
commitBlockWrite(core/ledger.go:2292-2346) did not updatel.setKeyset(c.Account, c.PutKeyset)insidecommitBlockWriteitself (relying on callers aftercommitBlockWrite), whereasPutAccountKeywas applied insidecommitBlockWrite.
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
Submitted complete fix and regression unit tests in PR #227: https://github.com/xeprotocol/xe/pull/227
XE Payout Wallet: 23bd7ef9c17e79ee76e9f656d618cf0f7c2cda4a700b58d065917d14e97a304a
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.
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.