name_update change is sent to pubkey, not address

Namecoin, NMControl
Post Reply
domob
Posts: 1129
Joined: Mon Jun 24, 2013 11:27 am
Contact:

name_update change is sent to pubkey, not address

Post by domob »

While working on the raw transactions for atomic name trading, I stumbled across the situation that change from name_update operations is sent to pubkeys not addresses (pubkey hash). Usually, addresses should be preferred, because they provide additional protection of the output offered by the hashing (for the unlikely case that ECDSA is broken and if the address is not reused, also a preimage attack on the hashing would need to be found in order to steal the funds).

I think this is due to the code around namecoin.cpp:349:

Code: Select all

// -------------- Fill a vout to ourself, using same address type as the payment
// Now sending always to hash160 (GetBitcoinAddressHash160 will return hash160, even if pubkey is used)
CScript scriptChange;
if (vecSend[0].first.GetBitcoinAddressHash160() != 0)
  scriptChange.SetBitcoinAddress(vchPubKey);
else
  scriptChange << vchPubKey << OP_CHECKSIG;
vecSend[0] is the transaction output containing the OP_NAME_UPDATE, for which GetBitcoinAddress() fails since it doesn't handle the preceding name operation properly. Thus always the "else" branch is executed, resulting in send-to-pubkey. Is there a reason why we do not simply always send to the address as in the "if" branch? I think that should be fine.
BTC: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS
Use your Namecoin identity as OpenID: https://nameid.org/

phelix
Posts: 1634
Joined: Thu Aug 18, 2011 6:59 am

Re: name_update change is sent to pubkey, not address

Post by phelix »

This is odd. I wonder why that is implemented at all.
nx.bit - some namecoin stats
nf.bit - shortcut to this forum

biolizard89
Posts: 2001
Joined: Tue Jun 05, 2012 6:25 am
os: linux

Re: name_update change is sent to pubkey, not address

Post by biolizard89 »

domob wrote:While working on the raw transactions for atomic name trading, I stumbled across the situation that change from name_update operations is sent to pubkeys not addresses (pubkey hash). Usually, addresses should be preferred, because they provide additional protection of the output offered by the hashing (for the unlikely case that ECDSA is broken and if the address is not reused, also a preimage attack on the hashing would need to be found in order to steal the funds).

I think this is due to the code around namecoin.cpp:349:

Code: Select all

// -------------- Fill a vout to ourself, using same address type as the payment
// Now sending always to hash160 (GetBitcoinAddressHash160 will return hash160, even if pubkey is used)
CScript scriptChange;
if (vecSend[0].first.GetBitcoinAddressHash160() != 0)
  scriptChange.SetBitcoinAddress(vchPubKey);
else
  scriptChange << vchPubKey << OP_CHECKSIG;
vecSend[0] is the transaction output containing the OP_NAME_UPDATE, for which GetBitcoinAddress() fails since it doesn't handle the preceding name operation properly. Thus always the "else" branch is executed, resulting in send-to-pubkey. Is there a reason why we do not simply always send to the address as in the "if" branch? I think that should be fine.
Are there nonstandard scripts which will malfunction if you use the hash instead of pubkey?

Also, I know older versions of bitcoind would use pubkeys instead of pubkey hashes in certain circumstances (e.g. sending to yourself, and coinbase transactions)... I know the former was blamed for a lot of privacy leaks.
Jeremy Rand, Lead Namecoin Application Engineer
NameID: id/jeremy
DyName: Dynamic DNS update client for .bit domains.

Donations: BTC 1EcUWRa9H6ZuWPkF3BDj6k4k1vCgv41ab8 ; NMC NFqbaS7ReiQ9MBmsowwcDSmp4iDznjmEh5

domob
Posts: 1129
Joined: Mon Jun 24, 2013 11:27 am
Contact:

Re: name_update change is sent to pubkey, not address

Post by domob »

biolizard89 wrote:Are there nonstandard scripts which will malfunction if you use the hash instead of pubkey?
I'm not aware of anything which may rely on send-to-pubkey. But of course I may be missing something. Any ideas?
BTC: 1domobKsPZ5cWk2kXssD8p8ES1qffGUCm | NMC: NCdomobcmcmVdxC5yxMitojQ4tvAtv99pY
BM-GtQnWM3vcdorfqpKXsmfHQ4rVYPG5pKS
Use your Namecoin identity as OpenID: https://nameid.org/

phelix
Posts: 1634
Joined: Thu Aug 18, 2011 6:59 am

Re: name_update change is sent to pubkey, not address

Post by phelix »

IMHO it should always be sent to an address.
nx.bit - some namecoin stats
nf.bit - shortcut to this forum

Post Reply