The RapBattle
contract uses randomness based on block.timestamp
, block.prevrandao
and msg.sender
to get a random number and decide the winner of Rap Battle on the basis of that random number.
But using the above 3 params, the random number generated is not really random and can be easily predicted by using a smart contract to get to know the random number in advance and make a call for rap battle only if the outcome of that random number generated is favorable for the caller.
Thus, randomness generated is not really fair for deciding the winner, if it can be predicted before calling the function and therefore it will be always unfair for the defender, as the challenger of the defender will always know the randomness in advance and will only place a call if the outcome is favorable for them, leading to a always win situation.
The vulnerability is present in the RapBattle
contract at line 62 which arises due to use of block.timestamp
, block.prevrandao
and msg.sender
for randomness.
These 3 parameters are always known while a transaction is made, and before calling the actual goOnStageOrBattle
function, one can make an Attack contract which will be used to get the randomness easily. As the call for Battle will me made in the same transaction, timestamp and prevrandao will remain same and msg.sender will always be known.
And as randomness can be easily determined before calling the goOnStageOrBattle
function, therefore the randomness generated is not really random, allowing one to only call the goOnStageOrBattle
function as a challenger only if the randomness is in their favor and always win CredToken.
Thus, it will be unfair for the defender as they will never win. And as challenger knows the random number in advance they will only go for battle only if randomness is in their favor leading a always win.
Challenger knowing the randomness in advanced will make the defender always lose, as they would only go for battle if randomness is in their favor.
Potential front-running situation.
Manual Review, Unit Test in Foundry
Add the Attack
contract in file: test/OneShotTest.t.sol
.
The Attack
contract is utilized to get the randomness in advance before going on the stage.
Add the test in the file: test/OneShotTest.t.sol
Run the test:
Consider using an oracle for randomness like Chainlink VRF.
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.