<!-- XE-1839 · Interrupted `xe wallet create` leaves an orphan phrase file that blocks every later create/restore · testnet -->
*Markdown view of <https://bounty.xe.network/XE-1839>. The page is the record; this is the same page for reading.*

XE-1839 · Bounty

# Interrupted \`xe wallet create\` leaves an orphan phrase file that blocks every later create/restore

Triaging
claimed Minor
web
filed 2026-11-09 07:37 UTC
by Darkarmy921

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   Minor

Area
:   SDK / docs / web

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-14 22:57 UTC

Told
:   2026-11-10 14:00 UTC

### Patches

None linked.

### History

- [211831](https://bounty.xe.network/log/211831) 2026-11-14 22:57 UTC proposal.adopted
- [211830](https://bounty.xe.network/log/211830) 2026-11-14 22:57 UTC ticket.award
- [84120](https://bounty.xe.network/log/84120) 2026-11-10 14:00 UTC proposal.adopted
- [84119](https://bounty.xe.network/log/84119) 2026-11-10 14:00 UTC reply.sent
- [83982](https://bounty.xe.network/log/83982) 2026-11-10 14:00 UTC proposal.adopted
- [83981](https://bounty.xe.network/log/83981) 2026-11-10 14:00 UTC ticket.status new → triaging
- [83693](https://bounty.xe.network/log/83693) 2026-11-10 14:00 UTC proposal.adopted
- [83692](https://bounty.xe.network/log/83692) 2026-11-10 14:00 UTC ticket.facts area
- [83691](https://bounty.xe.network/log/83691) 2026-11-10 14:00 UTC proposal.adopted
- [83690](https://bounty.xe.network/log/83690) 2026-11-10 14:00 UTC ticket.facts
- [83689](https://bounty.xe.network/log/83689) 2026-11-10 14:00 UTC proposal.adopted
- [83688](https://bounty.xe.network/log/83688) 2026-11-10 14:00 UTC ticket.facts

[Full history](https://bounty.xe.network/log?ref=XE-1839) · [JSON](https://bounty.xe.network/v1/tickets/XE-1839) · [markdown](https://bounty.xe.network/XE-1839.md)

### Report

## Title

Interrupted `xe wallet create` leaves an orphan phrase file that blocks every later create/restore

## Summary

`writeNewPhraseWallet` (`xe/cmd/xe/main.go:536`) writes the wallet in
two separate, non-atomic steps: the recovery-phrase file
(`wallet.phrase`) first, then the seed file (`wallet.seed`). Cleanup of
the phrase file happens only when the seed write returns an *error*.
If the process dies between the two writes (kill -9, power loss, OOM
kill), the `.phrase` file is left behind with no seed file. The phrase
in it belongs to a key whose seed was never saved, so it is useless as
a backup — yet its mere presence makes every later `xe wallet create`
and `xe wallet restore` refuse with "recovery phrase file already
exists at …; refusing to overwrite it". The CLI offers no recovery
path: the user must discover and manually delete the orphan file, and
until then the wallet cannot be created or restored at all. The error
message does not say the file is orphaned or that no wallet exists.

## Impact

- **Wallet setup fully blocked.** After an interrupted create, neither
  `xe wallet create` (seed missing → proceeds → `checkPhraseFileAbsent`
  refuses) nor `xe wallet restore` (same check, before reading stdin)
  can proceed. A new user who hit this once cannot set up a wallet
  without manually deleting a file the CLI never told them about.
- **Orphan phrase is a trap, not a backup.** The phrase on disk
  corresponds to a keypair whose seed was never written, so it cannot
  recreate any wallet — but a user who carefully saved it has saved
  nothing usable, while the file still blocks their real restore.
- **Scope limit (stated plainly).** The trigger is a crash in a
  millisecond-scale window between two writes, or a user who
  interrupts the command at the wrong moment. No funds are at risk
  (no wallet exists yet), no remote attacker is involved, and the fix
  for the user is one `rm`. The defect is the missing crash-consistency
  plus the misleading error, not data loss.

## Severity reasoning

- **Minor, not Low:** no funds, no existing wallet, and no adversary;
  the window is small and the user-side workaround (delete one file)
  is trivial once known. Impact is a confusing hard block on wallet
  setup, not loss or corruption of an existing wallet.
- **Minor, not Informational:** `xe wallet create` is the onboarding
  path, and the failure mode is a *permanent-looking* refusal with an
  error that points at the wrong conclusion ("refusing to overwrite"
  a phrase file for a wallet that does not exist). A wallet CLI should
  not be brickable by a crash in its own two-step write.

## Root cause

`writeNewPhraseWallet` (`xe/cmd/xe/main.go:536-561`) does two
independent `O_EXCL` creates in sequence:

1. create `<wallet>.phrase` (0600), write phrase \+ account \+ address;
2. `writeNewWalletSeed` — create `<wallet>.seed` (0600), write hex seed.

On a *returned* error from step 2 the phrase file is removed
(`if err != nil { _ = os.Remove(phrasePath) }`), but a crash/kill
between the steps leaves step 1's file behind with no cleanup and no
marker. Both entry points then refuse on the orphan:

- `cmdWalletCreate`: seed missing → `checkPhraseFileAbsent` →
  `errWalletPhraseExists` → fatal.
- `cmdWalletRestore` / `restorePhraseWallet`: same
  `checkPhraseFileAbsent` gate before any phrase is read.

`checkPhraseFileAbsent` (`main.go:524`) treats "phrase file exists"
as "a wallet backup exists", without verifying that a seed file (or
any wallet) exists alongside it.

## Local PoC

In-process Go test only; no live traffic, no production code modified.

- `xe/cmd/xe/xe_r5_verify_test.go` —
  `TestR5OrphanPhraseFileBlocksCreateAndRestore`. Run:
  `~/go1.25/go/bin/go test ./cmd/xe/ -run TestR5OrphanPhraseFileBlocksCreateAndRestore -v -count=1`

The test simulates the interrupted create deterministically by placing
a valid `.phrase` file (phrase \+ account \+ address lines, exactly as
`writeNewPhraseWallet` writes them) with no seed file, then asserts:

- `checkPhraseFileAbsent` refuses: `recovery phrase file already exists at …/wallet.phrase; refusing to overwrite it`
- `restorePhraseWallet` with a different, valid phrase refuses with
  the same error
- `readWalletSeed` confirms no wallet exists at all

Observed output (2026-11-09): both refusals reproduced, test PASSes.
The crash itself (kill between the two writes) is established by code
inspection of the two-step sequence in `writeNewPhraseWallet` — the
test pins the resulting stuck state, which is the user-visible defect.

## Suggested fix

- Write the seed file first, then the phrase file (an orphan seed
  with no phrase is harmless: `wallet phrase` reports "no recovery
  phrase", and create/restore of a seed is already refused as
  "wallet already exists").
- Or make creation atomic: write both files to temp names in the same
  directory and rename into place, and/or record a marker.
- Or make `checkPhraseFileAbsent` (and the error) distinguish the
  orphan case: if the phrase file exists but no seed file exists, say
  so explicitly ("orphaned phrase file from an interrupted create;
  no wallet exists — delete … to proceed") instead of refusing as if a
  backup were being protected.

## Reachability limits

- Trigger is local only: a crash/kill in the window between the two
  writes during `xe wallet create`. No network or adversarial path.
- The stuck state is fully deterministic once the orphan file exists;
  the probabilistic part is only landing in the window.
- No existing wallet, key, or fund is affected — this blocks setup of
  a *new* wallet only.

## Dedup note

- Searched the public ticket list snapshot (`/tmp/xe-tickets-r5.json`,
  186 public tickets, max XE-1799, 2026-11-09 \~14:19 WIB) by title for
  `phrase`, `wallet create`, `wallet restore`, `orphan`: no match.
  Closest are XE-0038 (Windows autocrlf rewrites the embedded BIP39
  wordlist — wordlist encoding, different) and XE-0915 (Windows
  `--passphrase` prompt hardcodes `/dev/tty` — different). No body
  text is in the snapshot, so this is a title-sweep dedup; a
  sealed/private ticket could still overlap.

## Payout address

Payout address: `052e33e0ed9c43e2bdf07faff9a90d25642b51d53d96f49f5d45b81f6584b3da`

### Thread

**Joseph Denne**team2026-11-10 14:00 UTCdesk

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
