Wallet passphrase recovery

An offline tool I built to brute-force the forgotten passphrase on my own SLIP-39 hardware wallet.

PythonTrezorSLIP-39BIP-39

I hadn't used my Trezor Safe 5 in almost a year. When I plugged it back in, I couldn't remember the PIN. Then I realised I couldn't remember the passphrase either.

Nine guesses in

The Safe 5 gives you 16 attempts at the PIN. Every wrong guess triggers an exponential backoff delay, and the 16th wipes the device. I got to about 9 and stopped. With each guess my confidence in recovering the funds slipped further, until it felt like gambling.

A wiped device on its own isn't the end. I still had my recovery backup, and that is the wallet. The passphrase was the part that scared me. Without it, the backup opens nothing I own.

Why a wrong passphrase never looks wrong

Most hardware wallets back up with BIP-39: 12 to 24 words from a fixed list of 2048. The words encode random entropy, which is stretched with PBKDF2 into a 512-bit seed. Every key in the wallet is derived from that seed. For Ethereum, the first address sits at m/44'/60'/0'/0/0.

SLIP-39 is Trezor's alternative, and it's the default. It splits the secret with Shamir's Secret Sharing into shares, for example 3, of which any 2 rebuild the wallet. Lose one share and you're fine. Steal one and you learn nothing.

Both support an optional passphrase. In BIP-39 it goes into the seed stretching. In SLIP-39 it encrypts the master secret. Either way it is a second factor: someone who finds your backup gets a wallet, just not yours.

That's also what makes forgetting it so brutal. There is no wrong passphrase. Every guess opens a valid wallet, almost always an empty one, and nothing tells you that you got it wrong. The only test is whether the wallet that opens is the one holding your funds.

Brute-forcing it

I knew which words the passphrase was built from. I just didn't know the order. Rather than guessing on a device, I did the whole search in software.

I wrote a script that takes the candidate words, joins them in every order, derives the Ethereum address each passphrase produces and checks it. My first version asked a public RPC node for each address's balance and stopped at the first one holding funds.

I gave it 7 words and expected to be waiting a long time. It found the passphrase in about 20 minutes.

A second wallet

Finding it in software wasn't the same as having my funds back. Getting into the Safe 5 meant wiping it and restoring from the backup, and that device was the only thing I had that held the wallet. I wasn't going to wipe it on the strength of a script's output.

So I bought a Keystone. It supports SLIP-39 too, and it's fully open source, which is always a plus. I restored my shares onto it, entered the passphrase, and my wallet was there.

With a second working copy in hand, I wiped the Safe 5, restored it from the backup, set a new PIN and entered the passphrase. Same wallet, now on two devices.

Making it usable

Then I cleaned it up for anyone in the same spot:

  • Offline. It now matches each derived address against one you know is in the wallet, instead of checking balances. No network calls, so it can run on an air-gapped machine.
  • SLIP-39 and BIP-39. Shamir shares, or a standard 12 to 24 word phrase.
  • Tested against the official Trezor test vectors for both.

How far it goes

Dropping the network calls made it much quicker. The same 7-word search now covers all 13,700 combinations in 3 minutes 12 seconds on one core of an M4 Max, about 72 guesses a second. Each extra word multiplies the work:

Words Combinations Time
6 1,957 27 s
7 13,700 3 min
8 109,601 25 min
9 986,410 4 h
10 9,864,101 1.6 days
11 108,505,112 17 days
12 1,302,061,345 7 months

Up to 9 words finishes the same day. 10 is fine if you can leave a machine running over a weekend. Beyond that, it's quicker to trim the list than to wait, so cut any word you're not fairly sure about.