Reorg State Desync: cascadeBuild omits accountKey overlay and verifyBlockCredential bypasses cascade state
Report
Vulnerability Summary
In core/rollback.go:297-333, when unwinding blocks during a chain reorganization / cascade rollback, the ledger tracks DeleteAccountKeyAccount:
deleteAccountKeyAccount := ""
if b.PubKey != "" {
deleteAccountKeyAccount = b.Account
}
...
undo := &BlockUndo{
...
DeleteAccountKeyAccount: deleteAccountKeyAccount,
}
...
apply := func() {
...
if deleteAccountKeyAccount != "" {
l.accountKeyMu.Lock()
delete(l.accountKeys, deleteAccountKeyAccount)
l.accountKeyMu.Unlock()
}
}
However, in core/cascade_commit.go, cascadeBuild completely omits support for DeleteAccountKeyAccount and account key tracking:
cascadeBuildtrackschains,addPending,delPending,restoreLease,deleteLease,deleteKeyset, anddelegation, but has zero fields for account keys (deleteAccountKey map[string]booloraccountKeys map[string]string).- In
addUndo(undo *BlockUndo, apply func()):- It records
cb.deleteKeyset[undo.DeleteKeysetAccount] = truefor keysets. - But it completely ignores
undo.DeleteAccountKeyAccount!
- It records
core/cascade_commit.godefinesgetKeysetOverlay,getLeaseOverlay,getPendingSendOverlay, andgetAccountChainOverlay, but does not provide anygetAccountKeyOverlay.- In
core/ledger.go:1416-1465,verifyBlockCredential(b *Block)verifies block signatures:- For multisig accounts, it calls
l.GetKeyset(b.Account)directly instead ofl.getKeysetOverlay(b.Account). - For standard accounts, when
b.Previous != "0", it callsl.GetAccountKey(b.Account)directly, which queriesl.accountKeys[account]and diskl.store.GetAccountChain(account), completely bypassing the active cascade overlay.
- For multisig accounts, it calls
Vulnerable Code Locations
core/cascade_commit.go:7-26:cascadeBuildstruct definition omitsdeleteAccountKey map[string]bool.core/cascade_commit.go:42-73:addUndofails to recordundo.DeleteAccountKeyAccountintocb.core/cascade_commit.go:143-150: NogetAccountKeyOverlayfunction is provided;getKeysetOverlayis implemented but unused in credential verification.core/ledger.go:1447-1460:if l.GetKeyset(b.Account) != nil { // BUG: does not use getKeysetOverlay(b.Account) return fmt.Errorf("multisig account requires signatures") } ... pubKey = l.GetAccountKey(b.Account) // BUG: does not check overlay chain or cascadeBuild deleted keys
Attack & Failure Scenario
Consider a scenario where an account's open block (which declared b.PubKey) is being rolled back in a cascade, or a competing winner block arrives that replaces an open block:
Case 1: Staged Block Validation During Cascade
- An open block is scheduled for rollback in an active cascade build (
l.activeCascade). - While the cascade build is active,
ValidateStagedBlockis called on a candidate winner block. ValidateStagedBlockinvokesverifyBlockCredential(b).- Because
verifyBlockCredentialchecksl.GetKeyset(b.Account)andl.GetAccountKey(b.Account)without inspectingl.activeCascade:- If an account was previously a multisig account whose
multisig_openblock is rolled back in the cascade,l.GetKeyset(b.Account)still returns the old in-memory keyset (sincedeleteKeysetin overlay is ignored byverifyBlockCredential). - Standard single-key candidate blocks for this account are falsely rejected with
"multisig account requires signatures". - Conversely, if an account key should have been deleted or restored,
GetAccountKeyqueries the disk chain which still holds the unrolled-back blocks, reading stale keys.
- If an account was previously a multisig account whose
Case 2: Memory Leak and State Desynchronization on Cascade Abort
- During cascade construction, multiple undos are registered.
- If
DeleteAccountKeyAccountis executed upon final application, but intermediate validation fails or crashes before commit,accountKeysin memory is inconsistent with disk state. - More critically, while
activeCascadeis active, any concurrent read or validation seeing the intermediate state sees stale keysets and public keys.
Impact
- False Validation Failures of Quorum Winner Blocks:
When resolving conflicts that involve rolled-back open blocks or multisig conversions,
ValidateStagedBlockfails with"multisig account requires signatures"or signature verification errors, preventing legitimate BFT quorum winners from being promoted. - Consensus Deadlock: Nodes attempting to promote a cascade-winner block reject valid winner blocks due to stale credential cache lookups, causing nodes to fork or halt progress on affected accounts.
Remediation
- Add
deleteAccountKey map[string]booltocascadeBuildincore/cascade_commit.go. - In
addUndo, record:if undo.DeleteAccountKeyAccount != "" { cb.deleteAccountKey[undo.DeleteAccountKeyAccount] = true } - Implement
getAccountKeyOverlay(account string) string:func (l *Ledger) getAccountKeyOverlay(account string) string { cb := l.activeCascadeFor() if cb != nil && cb.deleteAccountKey[account] { return "" } if ch, ok := l.overlayChain(account); ok { for _, b := range ch.Blocks { if b.PubKey != "" { return b.PubKey } } return "" } return l.GetAccountKey(account) } - In
verifyBlockCredential(b *Block):- Use
l.getKeysetOverlay(b.Account)instead ofl.GetKeyset(b.Account). - Use
l.getAccountKeyOverlay(b.Account)instead ofl.GetAccountKey(b.Account).
- Use
Thread
Thanks. This is the same finding as https://bounty.xe.network/XE-0135, 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-9608 and says what differs; it is read like any other.