Due to how randomness is generated and how the winner is chosen, both defenders and challengers can get an unfair advantage on the other.
Severely compomosises the normal battle functionality of the protocol.
The root cause is found in the fact that the "random" number computed inside RapBattle::_battle()
is moduled with the sum of the two rapper's skill levels.
Firstly, generating a random number on-chain is dangerous, because any challenger can predict the outcome before the transaction is mined and simply revert if they lose.
The, this "random" number is compared with the defender' skill level and, if <=
, the defender wins. This will cause the defender to always have more possibilities to win compared with a challenger in the same situation.
Manual Review
We first need to undestand that the modulo operation, will always return a number between 0 and n-1.
Ex: x % 10 will always return between 0 and 9
For the following scenario we'll consider the worst-case, where one rapper has the default skill level of 50 and the other has the maximum possible of 75:
Both defender and challenger have an equal skill level of 50.
In this case the defender always have 1 more possibility to win due to the <=
condition.
Here, defender has an higher skill level than the challenger.
Here the defender gains 1 more possibility to win!
Here, the challenger has a greated skill level than the defender.
Here the challenger has 1 less possibility to win!
In summary, whatever the case, the defender always have more possibilities to win than normally.
But, due to predictable randomness, the challenger can simply revert if he doesn't win.
First thing first, the random number must be generated using Chainlink VRF so that it can't be predicted before the transaction is mined.
But, even with VRF in place, the winning check should be changed. We provide two possible soulutions:
After generating the random number add +1 to it
Change the <=
with <
, without neding the +1 in this case
More informations about Chainlink VRF here
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.