Example: Motoko Playground - DFINITY
I’m taking the sha265 of a string and converting that into a NAT for storage/transport.
When I try to use it in a hash map get an error “losing precision”.
I’m guessing this is from the Hash.hash function which takes a Nat but quickly tries to convert it to a Nat32. I’m guessing that I can Nat.rem my sha256 Nat by 2^32 -1(4_294_967_295) and be ok, but I wanted to check that I’m not doing something wrong here.
Generally, I’m kind of nervous about the HashMaps in Motoko because they seem to be pushing Nat32 as a reliable max number to hash into. This makes sense for one individual hash map with current wasm limits, but if we really want ‘web scale’, collections with over 4.2 billion will be regular(think logs) and collisions over a 4.2 billion space seem likely.
Was there some thinking for not using at least 64 bit Nats which easily puts collisions and saturation pretty far out there(18_446_744_073_709_551_615 ~ 18 quintillions)? 256bits is probably overkill, but it is also pretty compatible with ETH some other crypto concepts.