divergencetech / ethier

Golang and Solidity SDK to make Ethereum development ethier
MIT License
217 stars 23 forks source link

Keep source in storage for NextShuffler #47

Closed caffeinum closed 1 year ago

caffeinum commented 2 years ago

https://github.com/divergencetech/ethier/blob/43a72962eccf5b9c4b53e4d13cf1484663b47512/tests/random/TestableNextShuffler.sol#L18-L23

Probably the common pattern would be to initialize the shuffler once and then fetch next() on each user request. What's the reasoning to not store source as a storage variable in NextShuffler?

https://github.com/divergencetech/ethier/blob/43a72962eccf5b9c4b53e4d13cf1484663b47512/contracts/random/NextShuffler.sol#L69-L73

ARR4N commented 2 years ago

If you store the PRNG.Source then the next caller of the function knows with 100% certainty what _next() will return. Although seeding for each use isn't perfect (see: Flashbot bundles) it's definitely less predictable / harder to manipulate than having full knowledge of the internal state of the PRNG before the call.