Bitcoin Forum
April 25, 2024, 12:17:11 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   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 146 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?

Unlike traditional banking where clients have only a few account numbers, with Bitcoin people can create an unlimited number of accounts (addresses). This can be used to easily track payments, and it improves anonymity.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
ranochigo
Legendary
*
Offline Offline

Activity: 2954
Merit: 4163


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.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
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: 3374
Merit: 6535


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: 2311
Merit: 2297


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!