Consensus ledger desync: GetAssetBalanceAtBlock bypasses cascade overlay during conflict reorgs, causing false balance mismatch and winner promotion rejection
Report
Vulnerability Summary
In core/ledger.go:3014-3040, GetAssetBalanceAtBlock(account, asset, blockHash string) computes the historical asset balance of an account up to a specific block boundary. This function is called directly by the consensus engine in core/quorum.go:306-313 during confirmConflict:
if result.ConflictPrev != "0" {
parentBalance = qm.ledger.GetAssetBalanceAtBlock(result.ConflictAccount, asset, result.ConflictPrev)
}
if err := qm.ledger.ValidateStagedBlock(winnerBlock, parentBalance); err != nil {
log.Printf("confirmConflict: staged winner %s failed validation: %v — refusing promotion", shortHash(result.WinnerHash), err)
return fmt.Errorf("confirmConflict: invalid staged winner: %w", err)
}
However, while xusdBalanceOnChain in core/rollback.go was patched to consult lease state during reorgs, GetAssetBalanceAtBlock in core/ledger.go:
- Reads directly from the underlying physical store via
l.store.GetAccountChain(account)instead ofl.getAccountChainOverlay(account). - Resolves lease settlements via
ls.GetLease(b.Source)directly from the physical store instead ofl.getLeaseOverlay(b.Source).
When confirmConflict or SwapBlock executes a reorg unwinding across dependent blocks, an active cascadeCommit overlay is in place. Because GetAssetBalanceAtBlock completely ignores the active cascade overlay, it returns a stale/desynchronized parentBalance. Consequently, ValidateStagedBlock fails with a false balance mismatch, causing the node to refuse promotion of the legitimate BFT quorum winner and deadlocking consensus conflict resolution.
Vulnerable Code Location
In core/ledger.go:3014-3040:
func (l *Ledger) GetAssetBalanceAtBlock(account, asset, blockHash string) uint64 {
chain, err := l.store.GetAccountChain(account) // <-- Bypasses account chain overlay!
if err != nil || chain == nil {
return 0
}
ls, hasLeases := l.store.(LeaseStore)
xusd := asset == "XUSD"
var bal uint64
for _, b := range chain.Blocks {
a := b.Asset
if a == "" {
a = "XE"
}
if a == asset {
bal = b.Balance
}
if xusd && b.Type == BlockLeaseSettle && hasLeases {
if lease, lerr := ls.GetLease(b.Source); lerr == nil && lease != nil { // <-- Bypasses lease overlay!
bal += lease.Stake
}
}
if b.Hash == blockHash {
break
}
}
return bal
}
Failure Mechanism
- Conflict Resolution During Reorg: A conflict winner (
winnerBlock) is selected by 67%+ quorum on an account that has uncommitted/unwound blocks under an active cascade overlay. - Historical Balance Calculation:
confirmConflictinvokesGetAssetBalanceAtBlock(account, asset, prev)to establish the parent balance baseline before validating the staged winner. - Overlay Bypass:
GetAssetBalanceAtBlockreads blocks and lease states directly from the persistent store (l.store), completely oblivious to the unwound state in the active cascade overlay.- If previous blocks in the account chain or related lease settlements were modified/reverted in the cascade overlay,
GetAssetBalanceAtBlockcalculates an incorrect balance.
- Promotion Refusal:
ValidateStagedBlockverifieswinnerBlock.Balance == parentBalance - amount(or+ amount).- Due to the desynchronized
parentBalance,ValidateStagedBlockreturnsbalance mismatch: expected X, got Y. confirmConflictlogsrefusing promotionand halts consensus resolution for the conflict.
Proposed Mitigation
Update GetAssetBalanceAtBlock in core/ledger.go to respect active cascade overlays:
- Use
l.getAccountChainOverlay(account)instead ofl.store.GetAccountChain(account). - Use
l.getLeaseOverlay(b.Source)instead ofls.GetLease(b.Source).
Thread
Thanks for the report. We read it against the code and could not confirm a bug in what it describes.
This report is closed as invalid. If we have missed something, file a new report that links https://bounty.xe.network/XE-4323 and says what; it is read like any other.