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

`tokenURI` function doesn't check if an ID exists

Description

The tokenURI function allows any user to retrieve the URI to access metadata for any NFT. However, if an ID does not exist, the function will return the URI for a Common Snek instead of reverting.

def tokenURI(token_id: uint256) -> String[53]:
@>
rarity: uint256 = self.tokenIdToRarity[token_id]
return self.rarityToTokenURI[rarity]

Risk

Likelyhood: Low

  • Occurs each time the function is called with a non-existing ID

Impact: Low

  • Returns the URI for a Common Snek, which may lead to unexpected behavior or confusion for users interacting with the contract

Proof of Concept

PoC to add in `snek_raffle_test.py`
def test_uninitialized_rarity(
raffle_boa
):
# URI for common snek
assert raffle_boa.tokenURI(10000) == "ipfs://QmSQcYNrMGo5ZuGm1PqYtktvg1tWKGR7PJ9hQosKqMz2nD"

Recommended Mitigation

Ensure that the token exists before retrieving its URI.

def tokenURI(token_id: uint256) -> String[53]:
+ assert ERC721._exists(token_id)
rarity: uint256 = self.tokenIdToRarity[token_id]
return self.rarityToTokenURI[rarity]
Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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