1

I am a bit confused here. I know that a public address is generated from the private key which you should keep secret, or else, anyone who has it will be able to spend the coins "in that address".

However, when i was checking this link: https://blockchain.info/address/dd9c56410b2e734e551fc34331a056b70e939c98 containing the hash160 address, blockchain.info showed me that the address from which this hash160 was made is the following: 1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1 However, if i navigate to this link: https://blockchain.info/address/3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1 blockchain.info will show me that the hash160 generated from the address : 3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1 is the same as the one generated from 1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1. I know that hashing is not a one to one function, it 'is' a many-to-one function but in this case, My sub-questions are the following:

1) is it possible to get the real address (e.g : 1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1 or 3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1) from the hash160 address (dd9c56410b2e734e551fc34331a056b70e939c98)?

2) why is blockchain.info showing me the the address of the hash160 (dd9c56410b2e734e551fc34331a056b70e939c98) is 1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1 and not 3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1?

1
  • To generate an address from a hash160 you need two inputs. The hash and the version byte. Version byte 0x00 corresponds to a P2PKH address (starting with 1) and version byte 0x05 to a P2SH addres (starting with 3)
    – Mike D
    Commented Jun 4, 2018 at 10:19

2 Answers 2

1

Both P2SH and P2PKH use HASH_160. That's what the h stands for in them.

Each HASH_160 is valid in both addresses. As to which address you need to send your BTC to depends on if you are using a redeem script or a public key to spend it.

If you send it to an address starting with 1, your output is encoded as OP_DUP OP_HASH160 <PubkeyHash> OP_EQUALVERIFY OP_CHECKSIG. To spend this, you require a private key that leads to the public key to which the hash belongs, and sign the tx using that.

If you send it to an address starting with 3, your output is encoded as OP_HASH160 <RedeemScriptHash> OP_EQUAL. In this case, to spend the output, you need to provide a redeem script for which the HASH_160 equals the one used in the address (along with any information that the redeem script might use, such as the signatures for a multisig address, or witness for a segwit address).

Due to this, each HASH160 can effectively be used to generate two addresses. Blockchain.info defaults to showing the 1-address.

DO NOT send any coins to the 1-address if your original address was a 3-address, and vice-versa. You will not be able to recover them.

1
  • thank you raghav! and why is hash160 useful then?
    – Alan Deep
    Commented Jun 4, 2018 at 11:09
0

1) is it possible to get the real address (e.g : 1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1 or 3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1) from the hash160 address (dd9c56410b2e734e551fc34331a056b70e939c98)?

Yes. It is possible and very easy

const QString MyKey20::toString ( ) const
{
  quint8 tmp1 [21];
  tmp1 [0] = NET_BYTE;
  memcpy ( tmp1 + 1, constData ( ), 20 );
  const MyKey32 key ( tmp1, 21 );
  quint8 tmp2 [25];
  memcpy ( tmp2, tmp1, sizeof ( tmp1 ) );
  memcpy ( tmp2 + 21, key.constData ( ), 4 );
  char addr [40];
  memset ( addr, 0, sizeof ( addr ) );
  BASE58::encodeBase58 ( tmp2, sizeof ( tmp2 ), addr, sizeof ( addr ) - 1 );
  return QString ( addr );
}

const QString MyKey20::toStringP2SH ( ) const
{
  quint8 tmp1 [21];
  tmp1 [0] = P2SH_BYTE;
  memcpy ( tmp1 + 1, constData ( ), 20 );
  const MyKey32 key ( tmp1, 21 );
  quint8 tmp2 [25];
  memcpy ( tmp2, tmp1, sizeof ( tmp1 ) );
  memcpy ( tmp2 + 21, key.constData ( ), 4 );
  char addr [40];
  memset ( addr, 0, sizeof ( addr ) );
  BASE58::encodeBase58 ( tmp2, sizeof ( tmp2 ), addr, sizeof ( addr ) - 1 );
  return QString ( addr );
}

2) why is blockchain.info showing me the the address of the hash160 (dd9c56410b2e734e551fc34331a056b70e939c98) is 1MCmcsjzocP68LyBZznA3tjRMvGd4eQRx1 and not 3MtnYRESMWhUDWfch6SkUX6MWSZLcYpRc1?

Because blockchain.info programmers haven't implemented this kind of search request. (In fact it was available several years ago, but later they throw it)

2
  • thank you for your answer however, i don't get it. if i give my friend the hash160 address, the bitcoin will be sent to which address?
    – Alan Deep
    Commented Jun 4, 2018 at 10:20
  • 1
    you should not give 160bit hash because no client would accept it as valid bitcoin address
    – amaclin
    Commented Jun 4, 2018 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.