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

Incorrect emit of Battle event (Boundary Condition Oversight + Incorrect Event Information)

Summary

The RapBattle contract emits a Battle event that may incorrectly identify the winner of a battle when the random number generated is exactly equal to the defenderRapperSkill. The conditional logic in the _battle function uses a less than or equal to (<=) comparison to determine if the defender wins. However, the event emission uses a strict less than (<) comparison, leading to a discrepancy where the defender should win (according to the logic), but the event indicates the challenger as the winner.

Impact

This inconsistency can lead to confusion and disputes among players, as the event log will not accurately reflect the outcome determined by the contract's logic. This could undermine trust in the contract and negatively affect the user experience.

Recommendations

Align the conditional check in the event emission with the logic used to determine the winner. Use the same <= comparison for both the logic and the event emission to ensure consistency.
Here's the corrected event emission logic within the _battle function:

// Emit the Battle event with the correct winner
emit Battle(msg.sender, _tokenId, random <= defenderRapperSkill ? _defender : msg.sender);


By making this change, the contract will emit the Battle event with the correct winner, matching the outcome as determined by the contract's logic, and eliminating any ambiguity in the battle results.

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.