gurnec / btcrecover

An open source Bitcoin wallet password and seed recovery tool designed for the case where you already know most of your password/seed, but need assistance in trying different possible combinations.
GNU General Public License v2.0
1.24k stars 665 forks source link

SegWit P2WPKH-in-P2SH support for BIP39 password recovery? #174

Closed jonathancross closed 3 years ago

jonathancross commented 6 years ago

Hi, I'm trying to recover a password from a Trezor BIP32/39/43/49 wallet. By default these are SegWit-in-P2SH now (unless user chooses the Legacy option).

Is it true that only P2PKH addresses are supported?

./btcrecover.py --tokenlist tokens.txt --bip39 --language en --addr-limit 1 --addrs 39mQQwEkBQoXAibbNsesvfAimDUeVYpFw3 --bip32-path "m/49'/0'/0'/0/"

Starting btcrecover 0.17.9 on Python 2.7.12 64-bit, 16-bit unicodes, 64-bit ints
Traceback (most recent call last):
  File "./btcrecover.py", line 37, in <module>
    btcrpass.parse_arguments(sys.argv[1:])
  File "/Users/jc/dev/btcrecover/btcrecover/btcrpass.py", line 3472, in parse_arguments
    args.language, args.bip32_path, args.wallet_type, args.performance)
  File "/Users/jc/dev/btcrecover/btcrecover/btcrpass.py", line 2386, in __init__
    mpk, addresses, address_limit, hash160s, path, is_performance)
  File "/Users/jc/dev/btcrecover/btcrecover/btcrseed.py", line 577, in create_from_params
    self._known_hash160s = self._addresses_to_hash160s(addresses)
  File "/Users/jc/dev/btcrecover/btcrecover/btcrseed.py", line 210, in _addresses_to_hash160s
    raise ValueError("not a Bitcoin P2PKH address; version byte is {:#04x}".format(ord(version_byte)))
ValueError: not a Bitcoin P2PKH address; version byte is 0x05

Any suggestions how to proceed?

Thanks!

jonathancross commented 6 years ago

I've put together a script combining btcrecover (only to generate passwords) with SegWit code from Electrum to test wallet against a known address. Takes 1-2 seconds per guess, so it only works if you have a very good idea what the passphrase is. https://github.com/jonathancross/segwit-wallet-recovery

gurnec commented 6 years ago

You're right, there's currently no P2SH-P2WPKH support, but it is on the list... it's not super-difficult, but as usual the devil's in the details.

killsto commented 6 years ago

Has work been started on this?

I stupidly created a situation in which my time for working on this enhancement will pay for itself and then some. Want to make sure I don't waste anyone's efforts before I start.

gurnec commented 6 years ago

On mobile so I can't go into details, but yes I've started work on it. I think it's working in seedrecover, I haven't started work on btcrecover (shouldn't be hard since it just calls into the seedrecover code) or unit tests. I think I'll leave address database support for later.

If someone wouldn't mind creating two dummy wallets that I could use in unit tests it would save me some time. Both using the same mnemonic, one without a passphrase and one with the bip39 passphrase btcr-test-password, and posting the mnemonic and the first 5 addresses of each would be great.

killsto commented 6 years ago

Sorry for the delayed response. I can try to do this later if I get time and it hasn't been done yet.

Looking at my calendar, I won't have time to significantly work on this feature for another month now.

jonathancross commented 6 years ago

@gurnec Here you go:

BIP39 Mnemonic: brave connect cheap liar script assist action keep west excite citizen machine frequent shiver mail action hobby hobby can post theme bargain hen flag

no password

BIP39 Seed: cf54701e37f248a119f389f07fcc66c0bc149981b0ab62eded3db49371d233b0e6d0f845f160bdccbd816f486857522d90e998d95a118ea565d4c8938781fc92 Bip32 Root key: yprvABrGsX5C9jantTXVNv5ZBtzxYZM3Whb5xeqW8GvK9ygeHfmNBcDj8WoqsjQjAf1zubcVELvr8aDfVosTaGQbPtWrcr79crJBC1CqEgvKoDb

path address public key private key
m/49'/0'/0'/0/0 3QxqRw38mCwHZBjnXzF4RM8uRe5TkRiLcd 025f720259dba871fad5f6480961b7548632e62e158a7e01333aa10c876c514658 L3Afziq3AmCgiQzqzVEzPFKG3Hw6NQPC3gSjkg2ncius2vsXh6ay
m/49'/0'/0'/0/1 3F9meBz9wr7z3D92aAnvJCwGnu81PfSrY4 02cfd4940f64f5af1a33445a5c4eab92e69c5fef0904f63c5101d657edc4c82108 L2zFdAmVc7qZMS3mPA8wkNVDoTf36gukjQoAKAzZLZpQNzcRdjki
m/49'/0'/0'/0/2 3B19V3bVeWqFBEp7kTbFj64XRDY8AdTMK6 03385c0885ea18cc676766d36d748066f6bc839c91cbc627d4b562ebd1a5a878f8 Ky6K7FJYSpnrkDLPhvFhA5bRtran4ShNackG8VwUnMLjzKXCnrLY
m/49'/0'/0'/0/3 3Luuk4v8RDL8B6FHbdhxV1gcrwUXxaSmu2 0335d1fd59748cd6f8857b606d151ec6421e3e23b787de951d5806be21de362d5a KzBcshKK4gXeGmDSoqsFWTwawmqdChZgrhfD37s8PtFxzWiydHCx
m/49'/0'/0'/0/4 383cxsME4y288z3ZP3kFZX6H2Gep2v7dNF 02409ddc952122612d807ac6d9d4f8da47967a3b3f189dbb8a28607662965733af KzDErzNYzk8EqnXZXEzBFCusGYM1NXkbLoMQvW8veDyrwm6upcH3

password: btcr-test-password

BIP39 Seed: 0144fc250d99dd9e20c25ff4ea3cfa5239df53ddf9868697d5a15abbd99754210181cd248820f1dc86e699312fc945382a3de8c935504e5cf1ad5aee7aab1038

Bip32 Root key: yprvABrGsX5C9janu4KKCGtdg6CYUTNjTdVGtPZXXctAoULvwM5KvL3tvB9GfDwYzNaoRdgiXpLF3q2TtqRPBUFgJMqXLacDPuuLbEznBW6i5XN

path address public key private key
m/49'/0'/0'/0/0 3N9CPc7qMpZkPYMMJ1M18gwRXiMgBzs4RJ 039c10be95fbc66218f696fc6b90e32af0cf3f522fa2c4efb90a0e7a7900030325 L22oeVq2Y5FnrtxW2eCZiV7WLVDsKP2KMekuYEPRgQEjhCE13U6k
m/49'/0'/0'/0/1 37xR81CPxerB5ze6g17GYWXcx6yyFyrJFu 02cdae315ddb7ba644759ca10d3ece097df5f497b6b105a0a06a510a9572e4f61d L5dvLaZtRwZYqJJrgGtezkxPSVLUYtwtLirfTyB84y2TW3QYQN5y
m/49'/0'/0'/0/2 34ZUcHCoa2JJTrhbeJCWPpwbaqkrywbjPe 031bcee819a4cc4f67ff59b4d69daf83b156f7606c62093eaaef461cd73d59ed2a Kz4TEcs63VbddUsziXNE7ExGhpm592U1vpHLrhautTeWJKQUyGT9
m/49'/0'/0'/0/3 3AHbCcndmFS3g3RmJM5KbgDJboioHSN2Kk 02fa4b0aa7b2c9391668b33599da88f95106d21c6ede1fbb37940f30b8625413e2 KzYtqrJ6PWKJ5iUsey7jQYfyxEmsJLgrVX4SXv3mFdWxx38k8v7w
m/49'/0'/0'/0/4 32RvRqsE6DFgoZYYpyRQFaPjYrT1Ybketo 02d7e50557bea952b92547963e31484538b6869ee15d3cfa2f4a2e97ae6f540c37 L5Rru3J8F5KpKkE6xvsv84x1pUF18i42RfPrK6hFJnW9q8YvDTUe
jonathancross commented 6 years ago

@gurnec Anything else needed?

@vly3 Please do us a favor and remove your comments to keep this focused. You can add a "thumbs up" 👍 to the issue if you agree it is important. Thanks.

vamp111 commented 6 years ago

please, when SegWit support, i lost 1 out of 12 words from my mnemonic and it is segwit adress :(

vly3 commented 6 years ago

I recovered my seed phrase with a modification to Ian Coleman's BIP39 tool. Instructions here:

https://s3-us-west-2.amazonaws.com/bip39-seed-recovery/index.html

Today I added a new section to the bottom of my page with instructions to recover a passphrase. It can work with Segwit addresses. You just have to select the correct tab in the derivation path section of Ian Coleman's page. If you select the BIP49 tab in the Derivation Path of Ian Coleman's page, it produces the same addresses from the sample mnemonic and passphrase that you provided.

jonathancross commented 3 years ago

Use this instead: https://github.com/3rdIteration/btcrecover