Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: MadGamer on February 24, 2018, 02:13:03 PM



Title: Private keys of SegWit addresses
Post by: MadGamer on February 24, 2018, 02:13:03 PM
I generated a SegWit address (https://segwitaddress.org/), I got the private keys, I went to Bitaddress to type the PK and get the details. I got 1LnhJTGJJLdaUhP34SMHGwDqkfjFGfAzPQ while the real one is 3BVNuVsxgXSgg4WyD1r6rZxXa11VBFQUkW

I want to know, If I ever give the first address to someone and he send me some bitcoin, will I be able to spend it from the second (the SegWit one)? Let's just assume that the first one is from Blockchain.info and the second is from Trezor.


Title: Re: Private keys of SegWit addresses
Post by: aleksej996 on February 24, 2018, 02:54:38 PM
No.

Addresses don't really exist on a protocol level, only transactions.
When someone sends you bitcoins to an address starting with 1, they use a P2PH transaction.
When they send you to the address starting with 3, they use a P2SH transaction.

Since you can't really send coins from an address, just spend UTXO, this question on it's own needs more information to determine what exactly is your concern.


Title: Re: Private keys of SegWit addresses
Post by: ranochigo on February 24, 2018, 03:07:42 PM
I want to know, If I ever give the first address to someone and he send me some bitcoin, will I be able to spend it from the second (the SegWit one)? Let's just assume that the first one is from Blockchain.info and the second is from Trezor.
I don't think Bitaddress recognise P2SH-P2PWKH yet. The private key for P2SH-P2PWKH is similar to the P2PKH and it's able to generate a legacy address from that private key too.

Since P2SH-P2PWKH, bc1, P2PKH can be generated from the same WIF key, you can retrieve your coins as long as you provide the correct addresses that corresponds to your WIF private key. I would definitely be against doing this though.

You CANNOT, however, be spending a coin in your 3xxx address in a wallet that you've defined to only recognise 1xxx address. (The wallet won't recognise your UTXO from 3xxx address).


Title: Re: Private keys of SegWit addresses
Post by: HCP on February 24, 2018, 11:07:07 PM
I generated a SegWit address (https://segwitaddress.org/), I got the private keys, I went to Bitaddress to type the PK and get the details. I got 1LnhJTGJJLdaUhP34SMHGwDqkfjFGfAzPQ while the real one is 3BVNuVsxgXSgg4WyD1r6rZxXa11VBFQUkW
Essentially, private keys are just a very big number. The different address types are then derived from this number in slightly different ways. ie. compressed, uncompressed, SegWit.

So, with the same private key: KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn

Bitaddress.org gives us:
Address (Compressed): 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH
Public Key (compressed, 66 characters [0-9A-F]):
0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798

While segwitaddress.org gives us:
Address: 3JvL6Ymt8MVWiCNHC7oWU6nLeHNJKLZGLN
Public Key: 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
Redeem Script: 0014751e76e8199196d454941c45d1b3a323f1433bd6

Note how the two public keys are the same?

The result of this is that, as always, if you have the correct private key, you will be able to access coins that were assigned to a specific address derived from that private key.


However, to answer your specific question of:
Quote
I want to know, If I ever give the first address to someone and he send me some bitcoin, will I be able to spend it from the second (the SegWit one)? Let's just assume that the first one is from Blockchain.info and the second is from Trezor.
The short answer is NO.

To demonstrate, let us use our private key from above: "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn"

As we've seen, this private key generates the addresses:
"Legacy" - 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH (https://blockchain.info/address/1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH)
"SegWit" - 3JvL6Ymt8MVWiCNHC7oWU6nLeHNJKLZGLN (https://blockchain.info/address/3JvL6Ymt8MVWiCNHC7oWU6nLeHNJKLZGLN)

You can see by looking at the address history... "1" has a bunch of transactions... "3" has nothing.

So, the coins sent to "1" are completely separated from any coins/transactions sent to "3" (and vice versa)... even though both have the same private key.