RapBattle::_battle()
is not truly random and can be exploited, meaning a participant can always win battlesDescription: The RapBattle::_battle
function utilizes pseudorandom number generation based on block.timestamp
, block.prevrandao
, and msg.sender
for determining the outcome of rap battles. This method of generating randomness is inherently insecure and predictable, as it relies on values that can be influenced or anticipated by participants. Specifically, block.timestamp
is known and can be manipulated by miners to some extent, and msg.sender
is controlled by the user initiating the transaction. Although block.prevrandao
aims to add unpredictability, the overall approach does not provide true randomness. This weakness allows a participant with enough knowledge and resources to predict or influence the outcome of the battle by executing transactions at carefully chosen times or repeatedly until favorable conditions are met.
Impact: The impact of this vulnerability is significant in the context of the RapBattle
contract, as it undermines the fairness and integrity of rap battles. A bad actor with the ability to predict or influence the pseudorandom number generation could manipulate the outcome to ensure they always win, regardless of the skill levels associated with the NFTs involved in the battle. This not only allows the attacker to unfairly accumulate winnings but also damages trust in the system, potentially deterring honest participants from engaging with the platform. Over time, this could lead to a concentration of resources in the hands of attackers and diminish the overall value and utility of the NFTs and the platform.
Proof of Concept:
User initiates a battle
Attacker sets up a contract that copies the weak randomness
Attacker contract checks the winning conditions using the same weak randomness
Attacker contract only executes if they are guaranteed a win and reverts if not
Attacker calls RapBattle::goOnStageOrBattle()
from their attacker contract, winning the battle
Place the following into OneShotTest.t.sol
And this contract as well.
Using on-chain values as a randomness seed is a well-documented attack vector in the blockchain space.
Recommended Mitigation: Implement Chainlink VRF instead.
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.