EggHuntGame::searchForEgg()
relies on the following code to generate a pseudorandom number between 0 and 99:
Each call of the EggHuntGame::searchForEgg()
function should have an independent, random result, i.e., calling the function multiple times should increase your chances of success. However, this is not the case. As seen above, the randomness relies on 4 variables: block.timestamp
, block.prevrandao
, msg.sender
,and eggCounter
. In case of success, the eggCounter
is increased by 1. The result of a successful search will be different from the next time the function is called. However, in case of a failed search, multiple function calls return the same random number when called in the same block i.e., the probability of a successful search will be lower than the default eggFindThreshold
.
Poor randomness leads to reduced chances of success for the users playing fairly.
Copy the following into the test file and run with forge test --mt testRandomness
.
Expected result:
Manual Review, Slither
An external source of randomness would be the best solution in this case. However, at a minimum, using a nonce would prevent the same pseudorandom number being generated multiple times per block.
Insecure methods to generate pseudo-random numbers
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.