The decoupled storage pattern (https://blog.colony.io/writing-upgradeable-contracts-in-solidity-6743f0eecc88) uses a hash function (keccak) to turn arbitrary length values into 32 byte keys for the storage mappings.

Am I supposed to worry about hash collisions? Or is keccak256 magic, and not ever do that? Seems like having a collision could break a lot of things.


It's a good question because it's not impossible.

What we can say is there is no known hash collision, i.e. none has ever been discovered.

I personally defer to those with stronger math credentials and I wouldn't challenge anyone else's view of probability. It's my understanding that most of Ethereum will come apart, not to mention many Dapps if collisions turn out to be more likely than they thought.

In the meantime. No. Not something "we" need to worry about.

Hope it helps.

  • I guess you can really fit a lot of different combinations into 32 bytes.... – jazzhole Apr 10 '18 at 4:18
  • 2
    2^256 (the number of possible keccak-256 hashes) is around the number of atoms in the known observable universe. A collision means picking two atoms at random and having them turn out to be the same atom. – user19510 Apr 10 '18 at 7:54
  • I think that thought experiment oversimplifies it a bit -- you're not just picking two atoms, you're picking millions (billions? trillions? more?) of atoms and hoping that none of them are the same. – jazzhole Apr 24 '18 at 4:33
  • @jazzhole no, it's not oversimplified. The numbers of possible hash outputs is higher than the total amount of atoms in the observable universe. So the argument is not about their composition (1 bytes = 8 bits), but rather about the sheer vastitude of all possible permutations of each of those compositions. – Paul Razvan Berg Sep 23 '19 at 11:58

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.