2

I recently saw a smart contract where the user used keccak256(address), is there any reason to do this, instead of just storing the address in the mapping?

1

It can be part of an effort to obfuscate data. For example, in games or scenarios in which players shouldn't know. For example, suppose one wishes to name a beneficiary without actually revealing the details.

Storing hashes in a contract can be part of challenge/response process. There are many ways and reasons, some of them good. :-)

Hope it helps.

3
  • I see. At first I thought it was a way to circumvent some sort of overflow. Now I think it was obfuscation. Apr 15 '18 at 18:32
  • 2
    But it's hashed within the contract, so the actual address is known. If it were hashed off-chain and the hash was submitted, then yes, this would make sense, but doing the hashing on-chain would defeat the purpose of obfuscation.
    – natewelch_
    Apr 15 '18 at 18:59
  • My answer is about good uses in general before you showed us that horrible contract. It's not an opinion about any particular example. Apr 15 '18 at 19:18
0

This would likely be pointless since the address is already the last 160 bits of a keccak256 hash. Were they using the keccak256(address) as the key in the mapping? If so, this would be doubly pointless since a mapping hashes the key anyway. It's hard to say exactly if it's pointless without seeing the contract.

4
  • yeah, it was a byte32 key. The code is here: etherscan.io/address/… . It is on line 67 Apr 15 '18 at 18:18
  • 1
    yeah, looks pointless to me. they likely didn't realize that maps already hash the key or that addresses are already hashes.
    – natewelch_
    Apr 15 '18 at 18:20
  • Alright thank you for checking the code. It was a bit confusing at first. Apr 15 '18 at 18:21
  • Hmmm ... there's much to question in that contract. Apr 15 '18 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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