Author

Topic: Why does importing a compressed private key result in an uncompressed P2SH Segwi (Read 163 times)

full member
Activity: 161
Merit: 168
very nice thank you  Smiley
legendary
Activity: 2317
Merit: 2318
" The hash of this script is a91a60e23a8ce5654cbefb50cdee7c05acfc82b1"

@achow101 Can you show me how you did it? Please, that would be great and very nice! Smiley

RIPEMD160(HASH256(00146b227b4934af1a8f9648b40c3614dec300abf435)) = a91a60e23a8ce5654cbefb50cdee7c05acfc82b1
full member
Activity: 161
Merit: 168
" The hash of this script is a91a60e23a8ce5654cbefb50cdee7c05acfc82b1"

@achow101 Can you show me how you did it? Please, that would be great and very nice! Smiley
full member
Activity: 161
Merit: 168
pub = 03c49741ee0b1c03ec1478da5157bd41709ae7a23f36fbff8b5c18a5222cc62a9e

h160   = Calc.getHashRIPEMD160(Calc.getHashSHA256(pub));
addr   = "x05" + h160;
hash   = Calc.getHashSHA256(Calc.getHashSHA256(addr));
addr  =  addr + hash.substring(0,8));   

= 2N31hbddcKtjwUyhuN6csz8dNgtYiaXcvZY
staff
Activity: 3458
Merit: 6793
Just writing some code
1. Yes, this version number (5.7.1) is under "help".
Go to Help > About Bitcoin Core not Help > About Qt

Address WIF    mqHRuQJ7yZMTy8rYHSJnmUVWC1eY9UsxRW
That's not WIF, it's not a private key.

Here's an example TestNet:

Priv Hex:       d3751d33f9cd5049c4af2b462735457e4d3baf130bcbb87f389e349fbaeb20b9
Priv WIF:       cUfkJKKBr962B4JcCvKv3TZPgsLn6mGxwqDrANjvrsZZvzim1p9V
Pub Key:        03c49741ee0b1c03ec1478da5157bd41709ae7a23f36fbff8b5c18a5222cc62a9e
Address WIF    mqHRuQJ7yZMTy8rYHSJnmUVWC1eY9UsxRW


-------------- BitCoin Core  -----------------
P2SH Address: 2N8fMnWYo2h9JfZZvYFnPC73baYn5E3oyiU


--------------- My calculation: --------------------
P2SH Address:  2N31hbddcKtjwUyhuN6csz8dNgtYiaXcvZY
How did you compute this P2SH address?

I've imported that private key and it does not produce a P2SH segwit address with an uncompressed pubkey. The address that Core produces (the one that you have listed) has a compressed pubkey. What makes you think that it is uncompressed? That you have calculated a different address?



Your calculated P2SH address is incorrect and will result in lost funds.

You have hashed the public key and just made that hash the hash inside of the P2SH. That is incorrect. The public key is not a script and it is not the redeemScript. The correct thing to do is to produce the Segwit scriptPubKey, hash that, and put that hash inside of the P2SH.

The Segwit scriptPubKey is 00146b227b4934af1a8f9648b40c3614dec300abf435. Note that it contains the pubkey hash but has more to it than just the pubkey hash. The hash of this script is a91a60e23a8ce5654cbefb50cdee7c05acfc82b1 which means that the P2SH scriptPubKey is a914a91a60e23a8ce5654cbefb50cdee7c05acfc82b187. This corresponds to the address of 2N8fMnWYo2h9JfZZvYFnPC73baYn5E3oyiU produced by Bitcoin Core.
full member
Activity: 161
Merit: 168
Here's an example TestNet:

Priv Hex:       d3751d33f9cd5049c4af2b462735457e4d3baf130bcbb87f389e349fbaeb20b9
Priv WIF:       cUfkJKKBr962B4JcCvKv3TZPgsLn6mGxwqDrANjvrsZZvzim1p9V
Pub Key:        03c49741ee0b1c03ec1478da5157bd41709ae7a23f36fbff8b5c18a5222cc62a9e
Address WIF    mqHRuQJ7yZMTy8rYHSJnmUVWC1eY9UsxRW


-------------- BitCoin Core  -----------------
P2SH Address: 2N8fMnWYo2h9JfZZvYFnPC73baYn5E3oyiU


--------------- My calculation: --------------------
P2SH Address:  2N31hbddcKtjwUyhuN6csz8dNgtYiaXcvZY
full member
Activity: 161
Merit: 168
I just can't understand how BitcoinCore generates this P2SH address.
I always come to a different address when I calculate it myself.
full member
Activity: 161
Merit: 168
1. Yes, this version number (5.7.1) is under "help".

2. The public key cannot be recovered from the Bitcoin address, since it is a hash. So it cannot be recognized whether it is a compressed PubKey or not.
full member
Activity: 161
Merit: 168
Version 5.7.1

How should a node recognize whether the address was created from an uncompressed PubKey? They are indistinguishable.
legendary
Activity: 3038
Merit: 4418
Crypto Swap Exchange
Hmm what version are you using?

Segwit Nested in P2SH addresses are not compatible with uncompressed addresses. If a segwit-P2SH address is generated from an uncompressed keypair, it would be rejected by the nodes since it is nonstandard right now.
full member
Activity: 161
Merit: 168
Why does importing a compressed private key result in an uncompressed P2SH Segwit address, the Bitcoin Core?

When I import a private key in compressed form, 3 addresses are generated.

1. WIF address from compressed PubKey
2. SegWit address from uncompressed PubKey
3. Bech32 address from compressed PubKey


Why is the SegWit address (3 ....) generated from an uncompressed Publickey? But the script in the transaction is again in a compressed form.

Why is that so twisted?

Jump to: