0

I was testing the hash value of null values for different types and I'm curious how it generates different results for different types. Here are the results.

String = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
Address = 0x5380c7b7ae81a58eb98d9c78de4a1fd7fd9535fc953ed2be602daaa41767312a
Bytes = 0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563
Uint = 0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563

1 Answer 1

4

The results are for hashing different numbers of zero bytes:

  • keccak256('') is the hash of 0 zero bytes.

  • keccak256(address(0)) is the hash of 20 zero bytes

  • keccak256(uint(0)) is the hash of 32 zero bytes (same for bytes32 type)

The way keccak pads the input accounts for the different outputs.

2
  • Oh ok thanks. So the input is converted to bytes and then hashed?
    – arete
    Commented Jan 4, 2018 at 13:41
  • You could look at it like that... but everything is already just bytes under the hood, so no conversion necessary. An address is just a block of 20 bytes. Commented Jan 4, 2018 at 15:35

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.