{"id":"XE-1839","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":451,"title":"Interrupted `xe wallet create` leaves an orphan phrase file that blocks every later create/restore","area":"sdk-docs-web","claimed_tier":"minor","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-09T07:37:49.140349+00:00","updated_at":"2026-11-14T22:57:04.296924+00:00","source_created_at":null,"told_at":"2026-11-10T14:00:35.136249+00:00","status_changed_at":"2026-11-10T14:00:33.447976+00:00","url":"https://bounty.xe.network/XE-1839","body":"## Title\r\n\r\nInterrupted `xe wallet create` leaves an orphan phrase file that blocks every later create/restore\r\n\r\n## Summary\r\n\r\n`writeNewPhraseWallet` (`xe/cmd/xe/main.go:536`) writes the wallet in\r\ntwo separate, non-atomic steps: the recovery-phrase file\r\n(`wallet.phrase`) first, then the seed file (`wallet.seed`). Cleanup of\r\nthe phrase file happens only when the seed write returns an *error*.\r\nIf the process dies between the two writes (kill -9, power loss, OOM\r\nkill), the `.phrase` file is left behind with no seed file. The phrase\r\nin it belongs to a key whose seed was never saved, so it is useless as\r\na backup — yet its mere presence makes every later `xe wallet create`\r\nand `xe wallet restore` refuse with \"recovery phrase file already\r\nexists at …; refusing to overwrite it\". The CLI offers no recovery\r\npath: the user must discover and manually delete the orphan file, and\r\nuntil then the wallet cannot be created or restored at all. The error\r\nmessage does not say the file is orphaned or that no wallet exists.\r\n\r\n## Impact\r\n\r\n- **Wallet setup fully blocked.** After an interrupted create, neither\r\n`xe wallet create` (seed missing → proceeds → `checkPhraseFileAbsent`\r\nrefuses) nor `xe wallet restore` (same check, before reading stdin)\r\ncan proceed. A new user who hit this once cannot set up a wallet\r\nwithout manually deleting a file the CLI never told them about.\r\n- **Orphan phrase is a trap, not a backup.** The phrase on disk\r\ncorresponds to a keypair whose seed was never written, so it cannot\r\nrecreate any wallet — but a user who carefully saved it has saved\r\nnothing usable, while the file still blocks their real restore.\r\n- **Scope limit (stated plainly).** The trigger is a crash in a\r\nmillisecond-scale window between two writes, or a user who\r\ninterrupts the command at the wrong moment. No funds are at risk\r\n(no wallet exists yet), no remote attacker is involved, and the fix\r\nfor the user is one `rm`. The defect is the missing crash-consistency\r\nplus the misleading error, not data loss.\r\n\r\n## Severity reasoning\r\n\r\n- **Minor, not Low:** no funds, no existing wallet, and no adversary;\r\nthe window is small and the user-side workaround (delete one file)\r\nis trivial once known. Impact is a confusing hard block on wallet\r\nsetup, not loss or corruption of an existing wallet.\r\n- **Minor, not Informational:** `xe wallet create` is the onboarding\r\npath, and the failure mode is a *permanent-looking* refusal with an\r\nerror that points at the wrong conclusion (\"refusing to overwrite\"\r\na phrase file for a wallet that does not exist). A wallet CLI should\r\nnot be brickable by a crash in its own two-step write.\r\n\r\n## Root cause\r\n\r\n`writeNewPhraseWallet` (`xe/cmd/xe/main.go:536-561`) does two\r\nindependent `O_EXCL` creates in sequence:\r\n\r\n1. create `<wallet>.phrase` (0600), write phrase + account + address;\r\n2. `writeNewWalletSeed` — create `<wallet>.seed` (0600), write hex seed.\r\n\r\nOn a *returned* error from step 2 the phrase file is removed\r\n(`if err != nil { _ = os.Remove(phrasePath) }`), but a crash/kill\r\nbetween the steps leaves step 1's file behind with no cleanup and no\r\nmarker. Both entry points then refuse on the orphan:\r\n\r\n- `cmdWalletCreate`: seed missing → `checkPhraseFileAbsent` →\r\n`errWalletPhraseExists` → fatal.\r\n- `cmdWalletRestore` / `restorePhraseWallet`: same\r\n`checkPhraseFileAbsent` gate before any phrase is read.\r\n\r\n`checkPhraseFileAbsent` (`main.go:524`) treats \"phrase file exists\"\r\nas \"a wallet backup exists\", without verifying that a seed file (or\r\nany wallet) exists alongside it.\r\n\r\n## Local PoC\r\n\r\nIn-process Go test only; no live traffic, no production code modified.\r\n\r\n- `xe/cmd/xe/xe_r5_verify_test.go` —\r\n`TestR5OrphanPhraseFileBlocksCreateAndRestore`. Run:\r\n`~/go1.25/go/bin/go test ./cmd/xe/ -run TestR5OrphanPhraseFileBlocksCreateAndRestore -v -count=1`\r\n\r\nThe test simulates the interrupted create deterministically by placing\r\na valid `.phrase` file (phrase + account + address lines, exactly as\r\n`writeNewPhraseWallet` writes them) with no seed file, then asserts:\r\n\r\n- `checkPhraseFileAbsent` refuses: `recovery phrase file already\r\nexists at …/wallet.phrase; refusing to overwrite it`\r\n- `restorePhraseWallet` with a different, valid phrase refuses with\r\nthe same error\r\n- `readWalletSeed` confirms no wallet exists at all\r\n\r\nObserved output (2026-11-09): both refusals reproduced, test PASSes.\r\nThe crash itself (kill between the two writes) is established by code\r\ninspection of the two-step sequence in `writeNewPhraseWallet` — the\r\ntest pins the resulting stuck state, which is the user-visible defect.\r\n\r\n## Suggested fix\r\n\r\n- Write the seed file first, then the phrase file (an orphan seed\r\nwith no phrase is harmless: `wallet phrase` reports \"no recovery\r\nphrase\", and create/restore of a seed is already refused as\r\n\"wallet already exists\").\r\n- Or make creation atomic: write both files to temp names in the same\r\ndirectory and rename into place, and/or record a marker.\r\n- Or make `checkPhraseFileAbsent` (and the error) distinguish the\r\norphan case: if the phrase file exists but no seed file exists, say\r\nso explicitly (\"orphaned phrase file from an interrupted create;\r\nno wallet exists — delete … to proceed\") instead of refusing as if a\r\nbackup were being protected.\r\n\r\n## Reachability limits\r\n\r\n- Trigger is local only: a crash/kill in the window between the two\r\nwrites during `xe wallet create`. No network or adversarial path.\r\n- The stuck state is fully deterministic once the orphan file exists;\r\nthe probabilistic part is only landing in the window.\r\n- No existing wallet, key, or fund is affected — this blocks setup of\r\na *new* wallet only.\r\n\r\n## Dedup note\r\n\r\n- Searched the public ticket list snapshot (`/tmp/xe-tickets-r5.json`,\r\n186 public tickets, max XE-1799, 2026-11-09 ~14:19 WIB) by title for\r\n`phrase`, `wallet create`, `wallet restore`, `orphan`: no match.\r\nClosest are XE-0038 (Windows autocrlf rewrites the embedded BIP39\r\nwordlist — wordlist encoding, different) and XE-0915 (Windows\r\n`--passphrase` prompt hardcodes `/dev/tty` — different). No body\r\ntext is in the snapshot, so this is a title-sweep dedup; a\r\nsealed/private ticket could still overlap.\r\n\r\n## Payout address\r\n\r\nPayout address: `052e33e0ed9c43e2bdf07faff9a90d25642b51d53d96f49f5d45b81f6584b3da`","patch_refs":[],"thread":[{"id":2136,"source":"desk","source_ref":"reply:1503","author":"Joseph Denne","team":true,"body":"Thank you for this report. We have read it against the code and it is being handled. The assessment and any award follow the fix. https://bounty.xe.network/XE-1839","created_at":"2026-11-10T14:00:19.792775+00:00"}]}