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

Malicious users can guarantee their Ram NFT is improved

Summary

In ChoosingRam::increaseValuesOfParticipants users can pass the same tokenID.

Vulnerability Details

ChoosingRam::increaseValuesOfParticipants includes a conditional check based on a random value (0 or 1), which determines if the user's Ram NFT is improved or another participants. However, Malicious users can pass the same tokenID for tokenIdOfChallenger and tokenIdOfAnyPerticipent, thus, guaranteeing regardless of the random result, their NFT will be selected to be improved.

Impact

This effectively makes it a gas war for who can call this function the quickest and passing their own token ID for both tokenIdOfChallenger and tokenIdOfAnyPerticipent, rendering the protocol worthless.

Tools Used

Unit test

Code

    function test_increaseValuesOfParticipantsCanPassSameTokenId()
        public
        participants
    {
        vm.startPrank(player1);
        choosingRam.increaseValuesOfParticipants(0, 0);
        choosingRam.increaseValuesOfParticipants(0, 0);
        choosingRam.increaseValuesOfParticipants(0, 0);
        choosingRam.increaseValuesOfParticipants(0, 0);
        choosingRam.increaseValuesOfParticipants(0, 0);
        vm.stopPrank();
    assertEq(ramNFT.getCharacteristics(0).isJitaKrodhah, true);
    assertEq(ramNFT.getCharacteristics(0).isDhyutimaan, true);
    assertEq(ramNFT.getCharacteristics(0).isVidvaan, true);
    assertEq(ramNFT.getCharacteristics(0).isAatmavan, true);
    assertEq(ramNFT.getCharacteristics(0).isSatyavaakyah, true);
}

Recommendations

Add an additional check in ChoosingRam::increaseValuesOfParticipants that the tokenIDs are not the same.

function increaseValuesOfParticipants(
uint256 tokenIdOfChallenger,
uint256 tokenIdOfAnyPerticipent
) public RamIsNotSelected {
if (tokenIdOfChallenger > ramNFT.tokenCounter()) {
revert ChoosingRam__InvalidTokenIdOfChallenger();
}
if (tokenIdOfAnyPerticipent > ramNFT.tokenCounter()) {
revert ChoosingRam__InvalidTokenIdOfPerticipent();
}
+ if (tokenIdOfChallenger == tokenIdOfAnyPerticipent) {
+ revert ChoosingRam__TokenIDsCannotBeTheSame();
+ }
if (ramNFT.getCharacteristics(tokenIdOfChallenger).ram != msg.sender) {
revert ChoosingRam__CallerIsNotChallenger();
}
Updates

Lead Judging Commences

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

Challenge themselves

Support

FAQs

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