ITADN

Range of `GenerateRandomGuid` is too small

#4012OpenOnedgeLee 创建于 2024-12-19
O
OnedgeLeecommented
`Libplanet` offers pseudo-random `GUID` generator on [RandomExtensions](https://github.com/planetarium/libplanet/blob/main/src/Libplanet.Action/RandomExtensions.cs), but its range seems quite small for general use. Above generates `GUID`, which codomain is `16-bytes`, but its range is less than `4-bytes`, since its domain is `int`. `GUID` is designed to be have `2^128` diversity, but with current implementation, it can cover only `2^32` With estimation with `Birthday Problem` `P ~ 1 - e^-(n^2/2N)`, `GUID` collision can happen with 50% probability with 77,163 samples, and 95% probability with 160,416 samples, which is quite easy to happen. We need to generate `GUID` with larger domain, for example, result hash of `SHA-256`. Belows are some candidates. - Proof of VRF (not merged on main branch yet) - PreEvaluationHash - StateRootHash - BlockHash Seems like better to choose from above two, but since impossitility of manipulation is not so important for `GUID` feature, won't be matter so much.
1 条评论