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

Wrong NFT rarity calculation in `snek_raffle.vy::fulfillRandomWords`

Summary

Wrong NFT rarity calculation in snek_raffle.vy::fulfillRandomWords, this breaks the business logic of the contract and devalues the rarity of NFTs.

Vulnerability Details

This calculates as rarity: uint256 = random_words[0] % 3, so all rarities will have the same chance ~ 33.(3)%

But according to the docs:
Brown Snek - 70% Chance to get
Jungle Snek - 25% Chance to get
Cosmic Snek - 5% Chance to get

Impact

This breaks the business logic of the contract and devalues the rarity of NFTs

Tools Used

Manual check

Recommendations

We should add a rarity calculation logic, i.e.

- rarity: uint256 = random_words[0] % 3
- self.tokenIdToRarity[ERC721._total_supply()] = rarity
+ rarity: uint256 = random_words[0] % (COMMON_RARITY + RARE_RARITY + LEGENDARY_RARITY)
+ tokenId: uint256 = ERC721._total_supply()
+ if (rarity < COMMON_RARITY):
+ self.tokenIdToRarity[tokenId] = COMMON_RARITY
+ elif (rarity < COMMON_RARITY + RARE_RARITY):
+ self.tokenIdToRarity[tokenId] = RARE_RARITY
+ else:
+ self.tokenIdToRarity[tokenId] = LEGENDARY_RARITY
Updates

Lead Judging Commences

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

Rarity is 1/3 instead of what the docs say

Support

FAQs

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