Can you get a storage collision in vyper?
The HashMap value is stored at the keccack256
of the key.
So wouldn't this mean storage collisions are possible?
Can you get a storage collision in vyper?
The HashMap value is stored at the keccack256
of the key.
So wouldn't this mean storage collisions are possible?
Yes, storage collisions are possible in Vyper, it's not about Vyper or Solidity, it's about Ethereum Virtual Machine (EVM).
Both languages use the same mechanism, keccak256
to calculate storage locations for their mappings.
Solidity computes the location for a mapping's value as:
keccak256(key, slotPosition);
while Vyper does it as:
keccak256(slotPosition, key)
Here, key
is the HashMap key, and slotPosition
is the storage slot for the HashMap.
Since Keccak-256 is a strong hash function, it's very unlikely for two different keys to have the same storage place.
This means storage collisions are possible but very rare.