Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Litecoin testnet/regtest addresses? #6

Closed
tkalfigo opened this issue Jul 13, 2018 · 7 comments
Closed

Wrong Litecoin testnet/regtest addresses? #6

tkalfigo opened this issue Jul 13, 2018 · 7 comments

Comments

@tkalfigo
Copy link

tkalfigo commented Jul 13, 2018

I'm on latest from master.

I read online that the prefixes for the LTC testnet (and regtest?) are:

  • for ext.priv.keys ttpv
  • for ext.priv.keys ttub

But the tool gives keys with tprv and tpub:

$ ./hd-wallet-derive.php -g --gen-key --coin='ltc-test'  --numderive=3 --format=jsonpretty
[
    {
        "coin": "ltc-test",
        "seed": "f4e57aa6289d738797dbdb34ac17f3aa359a1e73fc7aefa5cf0a39c73f24937afaa36066f1e1d7778ba2be2a8edb964b210aec646db3319abc4e774a08c800ad",
        "mnemonic": "jaguar next because try craft harbor isolate suspect love pumpkin decade evoke caution path diamond harvest security detect unknown lawsuit thing buddy they pipe install hero artefact you purpose chat green vacant zone exhibit merry stove wedding steel opinion educate carbon other torch install snow decide choose ritual",
        "master_priv_key": "tprv8ZgxMBicQKsPdNS3oW5KUuyJcy4EgCFm7F9TnQoKPgKm5doVQMsEuDJutMrjXpSwa863tzKetApRUsiTW4CfpcDNEiN1mshjLqnYTcyVyU3",
        "path": "m\/44'\/1'\/0'\/0",
        "ext_priv_key": "tprv8i8roVnVEkSJaVQEp5KKsmU3qpSUnWuCLAK2Z1RPVxwdYvTPbjLKWVGinpTUegNdTZHUq23r1PbzdhCMYMnRGKuxp27qEb1XzpAFcRYcfUn",
        "ext_pub_key": "tpubDEptwupjP87yTxS2hiyvHB8AQqxQwr66uTuoqXTgvEk2PQiAE89ugytaxw3ys7i7SYsXpHJaXEDN5w4qi4FHLSKX46E5bJV7yPnxc4SLoxy"
    }
]

Also tried using an existing LTC-regtest extended key generated with another tool (pycoin's ku).

$ ./hd-wallet-derive.php -g --key=ttub4bHD6aQ1QZjFkiNE9MMeN8xCWFRx3x9JmKi39aahPjTX1e1sXy8QP29Zk2gL9mAcpwMp6HqVUyduDCWFVKLboqssZ6c9dHnjsqBumvLUYoJ --coin='LTC-regtest'  --numderive=3

which throws error:

#1: InvalidArgumentException. code: 0. HD key magic bytes do not match network magic bytes

/home/User/hd-wallet-derive/vendor/bitwasp/bitcoin/src/Serializer/Key/HierarchicalKey/ExtendedKeySerializer.php : 105

Stack Trace:
#0 /home/User/hd-wallet-derive/vendor/bitwasp/bitcoin/src/Serializer/Key/HierarchicalKey/ExtendedKeySerializer.php(142): BitWasp\Bitcoin\Serializer\Key\HierarchicalKey\ExtendedKeySerializer->fromParser(Object(App\Utils\FlexNetwork), Object(BitWasp\Buffertools\Parser))
#1 /home/User/hd-wallet-derive/vendor/bitwasp/bitcoin/src/Serializer/Key/HierarchicalKey/Base58ExtendedKeySerializer.php(41): BitWasp\Bitcoin\Serializer\Key\HierarchicalKey\ExtendedKeySerializer->parse(Object(App\Utils\FlexNetwork), Object(BitWasp\Buffertools\Buffer))
#2 /home/User/hd-wallet-derive/vendor/bitwasp/bitcoin/src/Key/Deterministic/HierarchicalKeyFactory.php(69): BitWasp\Bitcoin\Serializer\Key\HierarchicalKey\Base58ExtendedKeySerializer->parse(Object(App\Utils\FlexNetwork), 'ttub4bHD6aQ1QZj...')
#3 /home/User/hd-wallet-derive/src/WalletDerive.php(69): BitWasp\Bitcoin\Key\Deterministic\HierarchicalKeyFactory::fromExtended('ttub4bHD6aQ1QZj...', Object(App\Utils\FlexNetwork))
#4 /home/User/hd-wallet-derive/src/WalletDerive.php(55): App\WalletDerive->derive_keys_worker(Array, 'ttub4bHD6aQ1QZj...')
#5 /home/User/hd-wallet-derive/hd-wallet-derive.php(65): App\WalletDerive->derive_keys('ttub4bHD6aQ1QZj...')
#6 /home/User/hd-wallet-derive/hd-wallet-derive.php(84): main()
#7 {main}

As per this SO answer the extended key prefixes for LTC testnet (and regtest?) are 0x0436ef7d (ext.priv) and 0x0436f6e1 (ext.pub).

But I see in vendor/dan-da/coinparams/coinparams.json that the LTC testnet and regtest actually borrow the prefixes from bitcoin testnet, 0x04358394 and 0x043587cf respectively which also explain the tool giving keys with tprv and tpub.

Only one must be correct I guess. Am I missing something?

@dan-da
Copy link
Owner

dan-da commented Jul 14, 2018

hmm, I'm not sure what is going on here yet. The values in coinparams.json are taken directly from the latest litecoin source code in master branch.

        base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
        base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};

note: I verified the values are the same in latest 0.16 tag.

So I don't know where ttpv and ttub are coming from. But I take the source code as the final truth, so unless it can be shown that this is somehow the wrong code to look at, it seems the values in coinparams.json are correct.

@dan-da
Copy link
Owner

dan-da commented Jul 14, 2018

I checked the bitwasp/bitcoin-php library source code and it uses the same values as are found in coinparams.json.

        self::BIP32_PREFIX_XPUB => "043587cf",
        self::BIP32_PREFIX_XPRV => "04358394",

Added to the chainParams.cpp code from litecoin github, that's good enough for me.

Closing this. Feel free to re-open if you find compelling counter-evidence.

@dan-da
Copy link
Owner

dan-da commented Jul 14, 2018

hmm, I'm re-opening this. It also applies to LTC Mainnet.

It seems that Ltpv / Ltub are in (somewhat?) wide use by wallets, even if they are not in the LTC codebase.

Slip132 lists them.

Also, Iancoleman's Bip39 tool provides a checkbox option:

[ ] Use Ltpv / Ltub instead of xprv / xpub

Seems like a mess.

@dan-da dan-da reopened this Jul 14, 2018
@dan-da
Copy link
Owner

dan-da commented Jul 14, 2018

Ok, I found these quotes that shed light on the matter:

From: pooler/electrum-ltc#52

Officially Litecoin uses the same BIP32 prefixes as Bitcoin (see here). This is on purpose, as it makes sense to generate addresses for multiple cryptocurrencies from a single master key.

The Ltub/Ltpv prefixes were independently made up by the author of the website bip32.org before BIP32 was even discussed by the Litecoin development team. As far as I know they were never officially supported, but unfortunately some developers who believed they were official used them in their software, contributing to the confusion.

and from iancoleman/bip39#96

Looks like litecoin has been a bit inconsistent with the different options, but in the end litecoin core seems to be using xprv xpub so I'll change the default litecoin network constants to reflect that with an option to switch to Ltub. It's a bit of a mess since there's a lot of implementations out there using Ltpv Ltub.

Although when I test LTC on iancoleman's tool today, it defaults to LTub, so I'm not sure what's up with that.

Anyway, I'm leaving this open because I might add some sort of switch for LTC LTub usage, but for just now am busy with other things, and it seems like the code is doing the right thing.

Anyone that needs LTub right away can use Iancoleman's tool for that.

For testnet you could just replace the corresponding values under LTC/test/prefixes/bip32 in vendor/dan-da/coinparams/coinparams.json.

@dan-da
Copy link
Owner

dan-da commented Jul 14, 2018

A final thought. The easiest/best way to implement support for this may be to just add a new "coin" LTC-L to coinparams.json.

@dan-da
Copy link
Owner

dan-da commented Jul 18, 2018

Ltub,Mtub,ttub, etc are working in v0.4.0 with a flag to enable them. The readme provides several examples.

The default is still btc style extended keys (xpub and friends). I may revisit that in the future.

regtest is not presently supported on LTC due to a parsing error encountered by coinparams source parsing tool. if anyone cares, open an issue for it please.

closing this.

@dan-da dan-da closed this as completed Jul 18, 2018
@tkalfigo
Copy link
Author

Thanks for the prompt response and for accommodating with a fix! Much appreciated 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants