{"id":"XE-9608","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":730,"title":"Reorg State Desync: cascadeBuild omits accountKey overlay and verifyBlockCredential bypasses cascade state","area":"consensus","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0135","tracked":true,"internal_ref":"#1064","internal_url":"https://github.com/xeprotocol/core/issues/1064","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-12T05:54:31.303484+00:00","updated_at":"2026-11-20T00:33:20.062727+00:00","source_created_at":null,"told_at":"2026-11-20T00:33:20.088035+00:00","status_changed_at":"2026-11-20T00:33:20.070923+00:00","url":"https://bounty.xe.network/XE-9608","body":"## Vulnerability Summary\n\nIn `core/rollback.go:297-333`, when unwinding blocks during a chain reorganization / cascade rollback, the ledger tracks `DeleteAccountKeyAccount`:\n\n```go\n\tdeleteAccountKeyAccount := \"\"\n\tif b.PubKey != \"\" {\n\t\tdeleteAccountKeyAccount = b.Account\n\t}\n...\n\tundo := &BlockUndo{\n\t\t...\n\t\tDeleteAccountKeyAccount: deleteAccountKeyAccount,\n\t}\n...\n\tapply := func() {\n\t\t...\n\t\tif deleteAccountKeyAccount != \"\" {\n\t\t\tl.accountKeyMu.Lock()\n\t\t\tdelete(l.accountKeys, deleteAccountKeyAccount)\n\t\t\tl.accountKeyMu.Unlock()\n\t\t}\n\t}\n```\n\nHowever, in `core/cascade_commit.go`, `cascadeBuild` completely omits support for `DeleteAccountKeyAccount` and account key tracking:\n\n1. `cascadeBuild` tracks `chains`, `addPending`, `delPending`, `restoreLease`, `deleteLease`, `deleteKeyset`, and `delegation`, but has **zero fields** for account keys (`deleteAccountKey map[string]bool` or `accountKeys map[string]string`).\n2. In `addUndo(undo *BlockUndo, apply func())`:\n   - It records `cb.deleteKeyset[undo.DeleteKeysetAccount] = true` for keysets.\n   - But it **completely ignores `undo.DeleteAccountKeyAccount`**!\n3. `core/cascade_commit.go` defines `getKeysetOverlay`, `getLeaseOverlay`, `getPendingSendOverlay`, and `getAccountChainOverlay`, but **does not provide any `getAccountKeyOverlay`**.\n4. In `core/ledger.go:1416-1465`, `verifyBlockCredential(b *Block)` verifies block signatures:\n   - For multisig accounts, it calls `l.GetKeyset(b.Account)` directly instead of `l.getKeysetOverlay(b.Account)`.\n   - For standard accounts, when `b.Previous != \"0\"`, it calls `l.GetAccountKey(b.Account)` directly, which queries `l.accountKeys[account]` and disk `l.store.GetAccountChain(account)`, completely bypassing the active cascade overlay.\n\n---\n\n## Vulnerable Code Locations\n\n1. `core/cascade_commit.go:7-26`:\n   `cascadeBuild` struct definition omits `deleteAccountKey map[string]bool`.\n2. `core/cascade_commit.go:42-73`:\n   `addUndo` fails to record `undo.DeleteAccountKeyAccount` into `cb`.\n3. `core/cascade_commit.go:143-150`:\n   No `getAccountKeyOverlay` function is provided; `getKeysetOverlay` is implemented but unused in credential verification.\n4. `core/ledger.go:1447-1460`:\n   ```go\n   if l.GetKeyset(b.Account) != nil { // BUG: does not use getKeysetOverlay(b.Account)\n       return fmt.Errorf(\"multisig account requires signatures\")\n   }\n   ...\n   pubKey = l.GetAccountKey(b.Account) // BUG: does not check overlay chain or cascadeBuild deleted keys\n   ```\n\n---\n\n## Attack & Failure Scenario\n\nConsider 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:\n\n### Case 1: Staged Block Validation During Cascade\n1. An open block is scheduled for rollback in an active cascade build (`l.activeCascade`).\n2. While the cascade build is active, `ValidateStagedBlock` is called on a candidate winner block.\n3. `ValidateStagedBlock` invokes `verifyBlockCredential(b)`.\n4. Because `verifyBlockCredential` checks `l.GetKeyset(b.Account)` and `l.GetAccountKey(b.Account)` without inspecting `l.activeCascade`:\n   - If an account was previously a multisig account whose `multisig_open` block is rolled back in the cascade, `l.GetKeyset(b.Account)` still returns the old in-memory keyset (since `deleteKeyset` in overlay is ignored by `verifyBlockCredential`).\n   - Standard single-key candidate blocks for this account are falsely rejected with `\"multisig account requires signatures\"`.\n   - Conversely, if an account key should have been deleted or restored, `GetAccountKey` queries the disk chain which still holds the unrolled-back blocks, reading stale keys.\n\n### Case 2: Memory Leak and State Desynchronization on Cascade Abort\n1. During cascade construction, multiple undos are registered.\n2. If `DeleteAccountKeyAccount` is executed upon final application, but intermediate validation fails or crashes before commit, `accountKeys` in memory is inconsistent with disk state.\n3. More critically, while `activeCascade` is active, any concurrent read or validation seeing the intermediate state sees stale keysets and public keys.\n\n---\n\n## Impact\n\n1. **False Validation Failures of Quorum Winner Blocks**:\n   When resolving conflicts that involve rolled-back open blocks or multisig conversions, `ValidateStagedBlock` fails with `\"multisig account requires signatures\"` or signature verification errors, preventing legitimate BFT quorum winners from being promoted.\n2. **Consensus Deadlock**:\n   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.\n\n---\n\n## Remediation\n\n1. Add `deleteAccountKey map[string]bool` to `cascadeBuild` in `core/cascade_commit.go`.\n2. In `addUndo`, record:\n   ```go\n   if undo.DeleteAccountKeyAccount != \"\" {\n       cb.deleteAccountKey[undo.DeleteAccountKeyAccount] = true\n   }\n   ```\n3. Implement `getAccountKeyOverlay(account string) string`:\n   ```go\n   func (l *Ledger) getAccountKeyOverlay(account string) string {\n       cb := l.activeCascadeFor()\n       if cb != nil && cb.deleteAccountKey[account] {\n           return \"\"\n       }\n       if ch, ok := l.overlayChain(account); ok {\n           for _, b := range ch.Blocks {\n               if b.PubKey != \"\" {\n                   return b.PubKey\n               }\n           }\n           return \"\"\n       }\n       return l.GetAccountKey(account)\n   }\n   ```\n4. In `verifyBlockCredential(b *Block)`:\n   - Use `l.getKeysetOverlay(b.Account)` instead of `l.GetKeyset(b.Account)`.\n   - Use `l.getAccountKeyOverlay(b.Account)` instead of `l.GetAccountKey(b.Account)`.","patch_refs":[],"thread":[{"id":13243,"source":"desk","source_ref":"reply:11265","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0135, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-9608 and says what differs; it is read like any other.","created_at":"2026-11-20T00:33:20.062727+00:00"}]}