Bitcoin Forum
November 16, 2024, 04:39:04 AM *
News: Check out the artwork 1Dq created to commemorate this forum's 15th anniversary
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Why does importing a compressed private key result in an uncompressed P2SH Segwi  (Read 163 times)
MixMAx123 (OP)
Full Member
***
Offline Offline

Activity: 161
Merit: 168


View Profile
February 17, 2020, 04:54:37 PM
Merited by ABCbits (1)
 #1

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?

ranochigo
Legendary
*
Offline Offline

Activity: 3038
Merit: 4420


Crypto Swap Exchange


View Profile
February 17, 2020, 05:08:00 PM
 #2

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.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
MixMAx123 (OP)
Full Member
***
Offline Offline

Activity: 161
Merit: 168


View Profile
February 17, 2020, 05:10:15 PM
 #3

Version 5.7.1

How should a node recognize whether the address was created from an uncompressed PubKey? They are indistinguishable.
MixMAx123 (OP)
Full Member
***
Offline Offline

Activity: 161
Merit: 168


View Profile
February 17, 2020, 05:54:19 PM
 #4

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.
MixMAx123 (OP)
Full Member
***
Offline Offline

Activity: 161
Merit: 168


View Profile
February 17, 2020, 05:57:37 PM
 #5

I just can't understand how BitcoinCore generates this P2SH address.
I always come to a different address when I calculate it myself.
MixMAx123 (OP)
Full Member
***
Offline Offline

Activity: 161
Merit: 168


View Profile
February 17, 2020, 06:02:45 PM
 #6

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
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3542
Merit: 6886


Just writing some code


View Profile WWW
February 17, 2020, 06:08:24 PM
Merited by ABCbits (1)
 #7

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.

MixMAx123 (OP)
Full Member
***
Offline Offline

Activity: 161
Merit: 168


View Profile
February 17, 2020, 06:17:26 PM
 #8

pub = 03c49741ee0b1c03ec1478da5157bd41709ae7a23f36fbff8b5c18a5222cc62a9e

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

= 2N31hbddcKtjwUyhuN6csz8dNgtYiaXcvZY
MixMAx123 (OP)
Full Member
***
Offline Offline

Activity: 161
Merit: 168


View Profile
February 17, 2020, 06:27:50 PM
 #9

" 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
A-Bolt
Legendary
*
Offline Offline

Activity: 2335
Merit: 2384


View Profile
February 17, 2020, 06:35:42 PM
Merited by ABCbits (1)
 #10

" 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
MixMAx123 (OP)
Full Member
***
Offline Offline

Activity: 161
Merit: 168


View Profile
February 17, 2020, 06:38:58 PM
 #11

very nice thank you  Smiley
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!