Interrupted `xe wallet create` leaves an orphan phrase file that blocks every later create/restore
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 →checkPhraseFileAbsentrefuses) norxe 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 createis 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:
- create
<wallet>.phrase(0600), write phrase + account + address; 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: samecheckPhraseFileAbsentgate 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:
checkPhraseFileAbsentrefuses:recovery phrase file already exists at …/wallet.phrase; refusing to overwrite itrestorePhraseWalletwith a different, valid phrase refuses with the same errorreadWalletSeedconfirms 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 phrasereports "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 forphrase,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--passphraseprompt 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
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