GemHQ / money-tree

A Ruby implementation of Bitcoin HD Wallets (Hierarchical Deterministic) BIP32
MIT License
185 stars 68 forks source link

BIP49 (SegWit) derivation path #22

Closed cavebring closed 2 years ago

cavebring commented 7 years ago

Address seems to be invalid calculated for BIP49 (SegWit) paths.

BIP49 Spec

Example:

https://iancoleman.github.io/bip39/

BIP39 Mnemonic: romance exercise immense final promote blossom swamp strong village dinner salad target

Gives: BIP44 Derivation Path - BIP32 Extended Public Key: xpub6ENYRtaTwwoFKfA5CYHJ6sM27xRu6NJLjDG2W2ahVP9xQW65VEm4Rtf2grdCcjTvPYYhqqsctWuKgeydCwYnrySpiDMrhfDY8C81YzhjV3B BIP49 Derivation Path - BIP32 Extended Public Key: xpub6FQxoDQx1U5pdzp8CtRAnkoBUcebLrg7xazUZ6YfdyrWdGNEyHs8hZFt54uyKqUwxvjre7rrp2Bni59Ybok5FNmpFQaRRN8n7xBZbiNSBuQ

TEST OF BIP44 Derivation Path

m/44'/0'/0'/0/0 should be address 1NhXS3e19HeQhbzF3wvxSbM5KrEL18eiDF

node = MoneyTree::Node.from_bip32('xpub6ENYRtaTwwoFKfA5CYHJ6sM27xRu6NJLjDG2W2ahVP9xQW65VEm4Rtf2grdCcjTvPYYhqqsctWuKgeydCwYnrySpiDMrhfDY8C81YzhjV3B').node_for_path("0").to_address
=> "1NhXS3e19HeQhbzF3wvxSbM5KrEL18eiDF"

Success!

TEST OF BIP49 Derivation Path

m/49'/0'/0'/0/0 should be address 3HnFEPAxBpDfSMXNvKb3EgaBdkN89zc4gF

 node = MoneyTree::Node.from_bip32('xpub6FQxoDQx1U5pdzp8CtRAnkoBUcebLrg7xazUZ6YfdyrWdGNEyHs8hZFt54uyKqUwxvjre7rrp2Bni59Ybok5FNmpFQaRRN8n7xBZbiNSBuQ').node_for_path("0").to_address
=> "1JNtziN11HdS4HXAMUJzF511R4Cza7EPqA"

Fail! Address missmatch

Issue?

Am I doing / thinking wrong or has the Money Tree GEM a problem calculating BIP49 addresses?

NicosKaralis commented 7 years ago

Having the same problem here.

If you go to https://iancoleman.github.io/bip39/ , go to the bip32 tab and use a custom derivation path you can see the same problem.

m/49'/0'/0'/0/0 generates the same problematic address, 1JNtziN11HdS4HXAMUJzF511R4Cza7EPqA

You have to check Use SegWit addresses (ie P2WPKH Nested In P2SH to actually see the SegWit enabled addresses (3HnFEPAxBpDfSMXNvKb3EgaBdkN89zc4gF)

So the real question is, what do we need to make money-tree generate segwit addresses?

cavebring commented 7 years ago

Ok good, so the question now is how do we do P2WPKH Nested In P2SH in money-tree? I would prefer if someone who know the specs better to jump in, but in worst case we have to fork the gem and try to find a way forward.

martin-lundin commented 7 years ago

+1

krtschmr commented 6 years ago

we also struggle from this

thedoctor commented 6 years ago

Yeah, this repo hasn't been updated to support bip49. PRs welcome; I can't guarantee I'll be able to do this in any timeframe.

krtschmr commented 6 years ago

we lost money because of wrong derivation paths. seems like that the addresses generated are wrong. any chance to recover funds?

Am 24.05.2018 23:38, schrieb Matt Smith:

Yeah, this repo hasn't been updated to support bip49. PRs welcome; I can't guarantee I'll be able to do this in any timeframe.

-- You are receiving this because you commented. Reply to this email directly, view it on GitHub [1], or mute the thread [2].

Links:

[1] https://github.com/GemHQ/money-tree/issues/22#issuecomment-391780906 [2] https://github.com/notifications/unsubscribe-auth/AMv1ugK9XyNk2EIQkcSMOKOUBT_aGOafks5t1uIhgaJpZM4PMPRV

thedoctor commented 6 years ago

@krtschmr That depends on what you did. If you used this repo to derive a key and generate an address, then you can probably recover those funds as long as you still have the seed. Just use this repo to derive the node at the path of the address with the stuck funds and get the private_hex -- you can import that in a traditional bitcoin wallet and send it normally.

NicosKaralis commented 6 years ago

Guys, I've found a solution. ( #30 )

I've added the helpers to_p2wpkh_p2sh and convert_p2wpkh_p2sh so I can finally use the same extended key on my trezor and on my system

If you could, please help me test to see if there is a fringe case or anything that could cause a problem

krtschmr commented 5 years ago

status?

NicosKaralis commented 5 years ago

The owner of this repo still haven't merged the pull request. We are using in production for over a month, without any errors.

If you need this you can use my version, for now:

gem 'money-tree', git: 'https://github.com/NicosKaralis/money-tree'