{"id":"XE-12968","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":2305,"title":"Badger MANIFEST loss opens the store as a fresh database silently, and a plain restart permanently deletes the orphaned SSTs","area":"node-api","claimed_tier":"minor","assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T14:51:11.698023+00:00","updated_at":"2026-11-20T19:45:53.601872+00:00","source_created_at":null,"told_at":"2026-11-20T19:45:53.631637+00:00","status_changed_at":"2026-11-20T19:45:53.610162+00:00","url":"https://bounty.xe.network/XE-12968","body":"## Summary\n\n`NewBadgerStore` (`store/badger_store.go:47-54`) opens Badger with bare\n`badger.DefaultOptions(dir)` — no checks on directory contents. When the\n`MANIFEST` file is missing (or truncated to a few bytes), Badger opens the\ndirectory as a FRESH database: no error, no warning.\n`preflightDataDirGenesis` (`node/genesis.go:140`) returns nil immediately when\n`IsEmpty()` is true, so it cannot distinguish a genuinely fresh dir from a dir\nholding orphaned SSTs but no MANIFEST. Genesis is re-applied and the node\nproceeds with an empty ledger. Worse, Badger's open/close cycle DELETES the\norphaned SST files even when the opener performs zero writes — so merely\nstarting the node once with a lost MANIFEST permanently destroys the ledger\ndata on disk, silently. Only network resync could restore it afterwards.\n\n## Reproduction (local, on copies of a 50-send store, xe @ 89a542e)\n\nHarness `faultprobe badger-fillverify` (real `store.NewBadgerStore`):\n\n1. Delete `MANIFEST` → `OPEN_OK`, chain len 0, genesis re-applied\n   (\"Genesis block applied: 42000000000000 XE\"). Reseed on the \"empty\" store\n   succeeded; after reseed + clean close, `000001.sst` went from 186,449 bytes\n   to 1,283 bytes; reopen showed chain length 1 only. The original 50 sends\n   are destroyed.\n2. Truncate `MANIFEST` to 10 bytes → identical silent-empty behaviour.\n3. Read-only open + close with `MANIFEST` deleted, ZERO writes\n   (`badger-fillverify n=0` → `OPEN_OK`, `readErrs=0 mismatch=0`) → the\n   orphaned `000001.sst` (186,449 bytes) NO LONGER EXISTS afterwards\n   (directory listing confirms: only vlogs, DISCARD, KEYREGISTRY, and a fresh\n   16-byte MANIFEST remain). Independently re-run with identical output.\n4. Control: flip 64 bytes inside `MANIFEST` → clean `OPEN_ERR: manifest has\n   checksum mismatch`. Only delete/truncate-to-small are silent.\n\n## Impact (stated honestly)\n\nSilent + irreversible local destruction of the node's entire ledger history\non a plain restart, plus silent empty-state rejoin (no operator warning\nanywhere in the path). The distinctive harm vs. ordinary corruption is the\nDESTRUCTION: without the restart, the SST data is still on disk; after one\nstart, it is gone. Trigger is local file loss/corruption (disk fault,\nbad/partial restore, operator error) — no remote trigger demonstrated. No\ncross-node or fund impact demonstrated: the node rejoins empty and would\nresync from peers. Minor.\n\nBoard precedent that this class is valued: XE-9241 (statechain replay brick\nfrom stored-state corruption, local crash trigger, \"no funds at risk\",\nMedium claim) and XE-1838 (silent identity swap on operator double-start,\nlocal-only, no funds, triaging at Minor).\n\n## Duplicate check (bodies read in full)\n\n- XE-9241: statechain replay gap — corrupt stored VALUES brick startup.\n  Different code path (`statechain/chain.go:51-86`) and opposite failure\n  shape (brick vs silent reset+destroy).\n- XE-12805: SyncWrites power-loss durability — missing sync barrier, QEMU\n  power-cut repro; process kill-9 / MANIFEST loss is a different mechanism.\n- XE-8799: GetChain error-swallowing — different helper.\n- XE-8742: restart rebuild trusts tampered blocks — tampered-but-valid\n  content trusted; here genuine data is destroyed with no tampering.\n- XE-1838: double-start identity swap — different files/mechanism.\n- Queries: `MANIFEST` (14, none about Badger MANIFEST), `badger manifest`\n  (0), `empty ledger` (1, unrelated), `fresh database` (0), `IsEmpty` (1,\n  unrelated), `data loss` (10, none store-related), `orphaned` (43, none\n  Badger-manifest), `corruption` (74 titles scanned). No duplicate found.\n\n## Suggested fix\n\nRefuse to open a non-empty directory without a valid MANIFEST (or warn loudly\nand require an explicit `--recover` flag); make `preflightDataDirGenesis`\ncheck directory contents (SST/vlog presence) before treating the dir as fresh.","patch_refs":[],"thread":[{"id":15307,"source":"desk","source_ref":"reply:13198","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, 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-12968 and says what differs; it is read like any other.","created_at":"2026-11-20T19:45:53.601872+00:00"}]}