ChoosingRam::increaseValuesOfParticipants does not set isRamSelected to true. It results in the ChoosingRam::selectRamIfNotSelected overriding any prior selected Ram before the end of the event.Description: The ChoosingRam::increaseValuesOfParticipants function is meant as a game of chance between two participants (a tokenIdOfChallenger and tokenIdOfAnyPerticipent). One of the two receives an increase in characteristics. If enough characteristics have been accumulated, the participant will be selected as the Ram and win half of the fee pool. An additional function ChoosingRam::selectRamIfNotSelected allows the organiser to select a Ram if none has been selected by a certain time.
However, the ChoosingRam::increaseValuesOfParticipants does not set isRamSelected to true when it selects a Ram. As a result:
increaseValuesOfParticipants can continue to select a Ram even if it has already been selected.
selectRamIfNotSelected can overwrite any Ram selected through increaseValuesOfParticipants.
Worse, because the Dussehra::killRavana function checks if ChoosingRam::isRamSelected is true, it forces ChoosingRam::selectRamIfNotSelected to be called. This means that the selected Ram will always be set by the selectRamIfNotSelected function, not the increaseValuesOfParticipants.
In ChoosingRam.sol:
In Dussehra.sol:
Impact: The intended functionality of the protocol is for participants to increase their characteristics through the ChoosingRam::increaseValuesOfParticipants function until they become Ram. Only in the case that no one has been selected as Ram though increaseValuesOfParticipants, does the organiser get to randomly select a Ram. This bug in the protocol breaks its intended logic.
Proof of Concept:
Two participants (player1 and player2) call increaseValuesOfParticipants until one is selected as Ram.
When Dussehra::killRavana is called, it reverts.
When organiser calls selectRamIfNotSelected it does not revert.
The selectedRam is reset to a new address.
When Dussehra::killRavana is called, it does not revert.
Place the following in the CounterTest contract of the Dussehra.t.sol test file.
Recommended Mitigation: The simplest mitigation is to set isRamSelected to true when a ram is selected through the increaseValuesOfParticipants function.
Please note that another mitigation would be to delete the isRamSelected state variable altogether and have the RamIsNotSelected modifier check if selectedRam != address(0). This simplifies the code and reduces chances of errors. This does necessity additional changes to the Dussehra.sol contract.
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.