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

Incorrect event emission in `RapBattle::_battle()`

Summary

The function RapBattle::_battle() can incorrectly emit the Battle event in a particular case.

Vulnerability Details

In the event, the defender wins if random is strictly less than his skill level.

emit Battle(msg.sender, _tokenId, random < defenderRapperSkill ? _defender : msg.sender);

But, after the event is emitted, the if block uses a <= to determine the winner.

if (random <= defenderRapperSkill) {
// Here defender wins
}

So, if random happens to be equal to the defender skill level, the event will emit the incorrect winner.

Impact

The users and the off-chain detection tools will register the incorrect winner.

Reccomended Mitigation

Simply change the chech condition inside the event to match the correct one used after it:

-emit Battle(msg.sender, _tokenId, random < defenderRapperSkill ? _defender : msg.sender);
+emit Battle(msg.sender, _tokenId, random <= defenderRapperSkill ? _defender : msg.sender);
Updates

Lead Judging Commences

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

Contradictory battle result event

Support

FAQs

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