Bitcoin Forum
May 14, 2024, 02:11:35 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: how many addresses from a single private key  (Read 1137 times)
arulbero (OP)
Legendary
*
Offline Offline

Activity: 1915
Merit: 2074


View Profile
April 14, 2017, 09:11:55 AM
Last edit: April 14, 2017, 09:46:27 AM by arulbero
 #1

I have a doubt about the use of:

Quote
Pay to Pubkey Hash address (P2PKH):  17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem

Pay to script hash address (P2SH) : 3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX  

I know that the starting "1" and "3" are added after sha256 + ripemd160, to get "1" I have to add a "00" prefix and to get "3" a "05" prefix before the Base58 encoding.


So, let's imagine I have a private key k, then I compute the public key kG : (x,y), then I perform
 sha256(ripemd160(x,y)). Now I have a 160bit string s.

My question is: if i made a Base58 encoding of "05+s" instead of "00+s" and I got the address  3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX, I could spend the bitcoin of that address?

In other words: from a single private key k, how many different addresses can we get?

Surely there are at least 2 pubkey hash addresses (compressed and uncompressed public key), but in theory is it possible to get a pay to script address too from a single private key?

1715652695
Hero Member
*
Offline Offline

Posts: 1715652695

View Profile Personal Message (Offline)

Ignore
1715652695
Reply with quote  #2

1715652695
Report to moderator
1715652695
Hero Member
*
Offline Offline

Posts: 1715652695

View Profile Personal Message (Offline)

Ignore
1715652695
Reply with quote  #2

1715652695
Report to moderator
There are several different types of Bitcoin clients. The most secure are full nodes like Bitcoin Core, which will follow the rules of the network no matter what miners do. Even if every miner decided to create 1000 bitcoins per block, full nodes would stick to the rules and reject those blocks.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715652695
Hero Member
*
Offline Offline

Posts: 1715652695

View Profile Personal Message (Offline)

Ignore
1715652695
Reply with quote  #2

1715652695
Report to moderator
1715652695
Hero Member
*
Offline Offline

Posts: 1715652695

View Profile Personal Message (Offline)

Ignore
1715652695
Reply with quote  #2

1715652695
Report to moderator
piotr_n
Legendary
*
Offline Offline

Activity: 2053
Merit: 1354


aka tonikt


View Profile WWW
April 14, 2017, 10:18:53 AM
Merited by ABCbits (1)
 #2

Quote
My question is: if i made a Base58 encoding of "05+s" instead of "00+s" and I got the address  3EktnHQD7RiAE6uzMj2ZifT9YgRrkSgzQX, I could spend the bitcoin of that address?
No, you couldn't spend from that address.
You need hash of a script, not of a public key.


Quote
In other words: from a single private key k, how many different addresses can we get?

You can get virtually unlimited number of P2SH addresses for a single private key.
You just need to hash a script with some kind of nonce.
For instance, it could be 1 of 2 mulitisig, where the second key is a random number.

Check out gocoin - my original project of full bitcoin node & cold wallet written in Go.
PGP fingerprint: AB9E A551 E262 A87A 13BB  9059 1BE7 B545 CDF3 FD0E
arulbero (OP)
Legendary
*
Offline Offline

Activity: 1915
Merit: 2074


View Profile
April 14, 2017, 10:43:33 AM
 #3

Quote
In other words: from a single private key k, how many different addresses can we get?

You can get virtually unlimited number of P2SH addresses for a single private key.
You just need to hash a script with some kind of nonce.
For instance, it could be 1 of 2 mulitisig, where the second key is a random number.

Then in this script:
Code:
 
{1 [pubkey1] [pubkey2] 2 OP_CHECKMULTISIG}

instead of pubkey2 I can put any string with any lenght?
piotr_n
Legendary
*
Offline Offline

Activity: 2053
Merit: 1354


aka tonikt


View Profile WWW
April 14, 2017, 11:00:34 AM
 #4

Quote
In other words: from a single private key k, how many different addresses can we get?

You can get virtually unlimited number of P2SH addresses for a single private key.
You just need to hash a script with some kind of nonce.
For instance, it could be 1 of 2 mulitisig, where the second key is a random number.

Then in this script:
Code:
 
{1 [pubkey1] [pubkey2] 2 OP_CHECKMULTISIG}

instead of pubkey2 I can put any string with any lenght?


No. Put something that has a format of a public key; starts from 2 or 3 and is followed by 32 bytes. The 32 bytes can be anything. As long as they aren't any known public key Smiley

Check out gocoin - my original project of full bitcoin node & cold wallet written in Go.
PGP fingerprint: AB9E A551 E262 A87A 13BB  9059 1BE7 B545 CDF3 FD0E
piotr_n
Legendary
*
Offline Offline

Activity: 2053
Merit: 1354


aka tonikt


View Profile WWW
April 14, 2017, 11:06:34 AM
Last edit: April 14, 2017, 11:26:54 AM by piotr_n
 #5

However this is not a very elegant solution, as it wastes precious block chain space.

I'd rather go for a smaller nonce  

Something like:

Code:
0x04 <4 random bytes> OP_DROP <pubkey> OP_CHECKSIGVERIFY

Check out gocoin - my original project of full bitcoin node & cold wallet written in Go.
PGP fingerprint: AB9E A551 E262 A87A 13BB  9059 1BE7 B545 CDF3 FD0E
DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4653



View Profile
April 14, 2017, 03:55:42 PM
Merited by ABCbits (2)
 #6

The point here is that there are NO ADDRESSES in the blockchain or in transactions.  Addresses are an abstraction that wallets use to make it easier for us humans to talk about exchanging control over value.  The wallets convert those addresses into scripts.  If we want another script type, we can just create a new "address" representation of that script.  As far as I'm aware, we currently have 3 "standard" script types:

  • Pay2PubKeyHash
  • Pay2PubKey
  • Pay2ScriptHash


A given private key will have 2 Pay2PubKeyHash scripts (one compressed and one uncompressed).

I'm not certain if the Pay2PubKey script supports compressed keys, but I think it does. In that case, A given private key will also have 2 Pay2PubKey scripts (one compressed and one uncompressed).

Pay2ScriptHash scripts don't need a private key at all (although it is generally best to use one if you don't want the bitcoins taken by anyone that knows the script).  I'm not certain, but I think the hash portion of the Pay2ScriptHash is RIPEMD160.  As such, while there are practically an unlimited number of scripts that you could create, you are limited to no more than 2160 Pay2ScriptHash "addresses".

You could also create a nonstandard, but valid, scripts that are none of the above. There is no standard way to represent such scripts as "addresses".
arulbero (OP)
Legendary
*
Offline Offline

Activity: 1915
Merit: 2074


View Profile
April 14, 2017, 05:00:27 PM
 #7

The point here is that there are NO ADDRESSES in the blockchain or in transactions.  Addresses are an abstraction that wallets use to make it easier for us humans to talk about exchanging control over value.  The wallets convert those addresses into scripts.  If we want another script type, we can just create a new "address" representation of that script.  As far as I'm aware, we currently have 3 "standard" script types:

  • Pay2PubKeyHash
  • Pay2PubKey
  • Pay2ScriptHash


If we look at the first transaction of the bitcoin history (it should be a Pay2PubKey transaction)  this is the script:

Code:
0496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858ee OP_CHECKSIG

and this is the abstraction-address: 12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX

How can I distinguish between this address and an address that is related to a Pay2PubKeyHash?

The wallets convert those addresses into scripts.

How do the wallets know if the address 12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX should be converted in a Pay2PubKey script or in a Pay2PubKeyHash script?
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6637


Just writing some code


View Profile WWW
April 14, 2017, 05:08:14 PM
Merited by ABCbits (1)
 #8

If we look at the first transaction of the bitcoin history (it should be a Pay2PubKey transaction)  this is the script:

Code:
0496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858ee OP_CHECKSIG

and this is the abstraction-address: 12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX

How can I distinguish between this address and an address that is related to a Pay2PubKeyHash?

The wallets convert those addresses into scripts.

How do the wallets know if the address 12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX should be converted in a Pay2PubKey script or in a Pay2PubKeyHash script?

There are no addresses for P2PK. Most wallets and block explorers will just show them as a normal P2PKH address because it is easy to make that address and sending to that address will still allow the owner of that public key to spend their Bitcoin. Since the address is based on the hash of the public key, you can't make a P2PK script with just an address, you need the full public key.

DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4653



View Profile
April 14, 2017, 05:13:29 PM
 #9

If we look at the first transaction of the bitcoin history (it should be a Pay2PubKey transaction)  this is the script:

Code:
0496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858ee OP_CHECKSIG

and this is the abstraction-address: 12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX

That depends on where you look.

There is no standard way of converting a Pay2PubKey script into an address.  Some block explorers choose to treat it like a Pay2PubKeyHash address.

They hash the pubkey, put a 0x00 byte in front of it, and use bease58check encoding.  This is just a choice they've made in how they want to display the script to you on their website.

If you were to try to send to that address (12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX) it would NOT be a Pay2PubKey output.  Any Bitcoin wallet would convert that address into a Pay2PubKeyHash output script when it built the transaction.


How can I distinguish between this address and an address that is related to a Pay2PubKeyHash?

That address IS a Pay2PubKeyHash.  The block explorers that you are using are just misrepresenting the output script to you.

How do the wallets know if the address 12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX should be converted in a Pay2PubKey script or in a Pay2PubKeyHash script?

They don't.  They will always convert that address into the associated Pay2PubKeyHash script.
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!