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

'snek_raffle.vy::fulfillRandomWords' does not correctly calculate the rarity of the winners NFT

Summary

The rarity for the 3 different possible snek NFT's is not being calculated correctly.

Vulnerability Details

The rarity of the winners NFT is supposed to be weighted with a 70% chance for a Brown Snek, 25% chance for a Jungle Snek, and 5% chance for a Cosmic Snek. But the rarity is being calculated as an equal 33% chance to get any of the 3 different sneks.

rarity: uint256 = random_words[0] % 3
self.tokenIdToRarity[ERC721._total_supply()] = rarity

Impact

Each of the 3 different NFT varieties have an equal chance of being won.

Tools Used

--Manual Review

Recommendations

Change the way the rarity is calculated so that the percentage chance of getting the 3 different NFT's is correct.

@internal
def fulfillRandomWords(request_id: uint256, random_words: uint256[MAX_ARRAY_SIZE]):
index_of_winner: uint256 = random_words[0] % len(self.players)
recent_winner: address = self.players[index_of_winner]
self.recent_winner = recent_winner
self.players = []
self.raffle_state = RaffleState.OPEN
self.last_timestamp = block.timestamp
- rarity: uint256 = random_words[0] % 3
- self.tokenIdToRarity[ERC721._total_supply()] = rarity
+ rarity: uint256 = random_words[0] % 100
+ if (rarity < 5) {
+ self.tokenIdToRarity[ERC721._total_supply()] = 2
+ }
+ else if (rarity < 25)
+ {
+ self.tokenIdToRarity[ERC721._total_supply()] = 1
+ }
+ else {
+ self.tokenIdToRarity[ERC721._total_supply()] = 0
+ }
log WinnerPicked(recent_winner)
ERC721._mint(recent_winner, ERC721._total_supply())
send(recent_winner, self.balance)
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.