First Flight #12: Kitty Connect

First Flight #12: Kitty Connect
Beginner FriendlyFoundryNFTGameFi
100 EXP
View results
Submission Details
Severity: low
Invalid

Getters does not revert for non-existent values

Description

The provided functions return default values for non-existent token IDs because they do not check if the token ID exists before accessing its information.

function tokenURI(
uint256 tokenId
) public view override returns (string memory) {
@>
CatInfo memory catInfo = s_catInfo[tokenId];
string memory catTokenUri = Base64.encode(
abi.encodePacked(
'{"name": "',
catInfo.catName,
'", "breed": "',
catInfo.breed,
'", "image": "',
catInfo.image,
'", "dob": ',
Strings.toString(catInfo.dob),
', "owner": "',
@> Strings.toHexString(_ownerOf(tokenId)),
'", "shopPartner": "',
Strings.toHexString(catInfo.shopPartner),
'"}'
)
);
return string.concat(_baseURI(), catTokenUri);
}
function getCatAge(uint256 tokenId) external view returns (uint256) {
@>
return block.timestamp - s_catInfo[tokenId].dob;
}
function getCatInfo(
uint256 tokenId
) external view returns (CatInfo memory) {
@>
return s_catInfo[tokenId];
}

Risk

Likelyhood: Low

  • Occurs for any call with a non-existent token ID.

Impact: Low

  • Returns default values instead of reverting. It can lead to confusion of users using these external functions.

Recommended Mitigation

function tokenURI(
uint256 tokenId
) public view override returns (string memory) {
CatInfo memory catInfo = s_catInfo[tokenId];
string memory catTokenUri = Base64.encode(
abi.encodePacked(
'{"name": "',
catInfo.catName,
'", "breed": "',
catInfo.breed,
'", "image": "',
catInfo.image,
'", "dob": ',
Strings.toString(catInfo.dob),
', "owner": "',
- Strings.toHexString(_ownerOf(tokenId)),
+ Strings.toHexString(ownerOf(tokenId)),
'", "shopPartner": "',
Strings.toHexString(catInfo.shopPartner),
'"}'
)
);
return string.concat(_baseURI(), catTokenUri);
}
function getCatAge(uint256 tokenId) external view returns (uint256) {
+ require(_exists(tokenId));
return block.timestamp - s_catInfo[tokenId].dob;
}
function getCatInfo(
uint256 tokenId
) external view returns (CatInfo memory) {
+ require(_exists(tokenId));
return s_catInfo[tokenId];
}
Updates

Lead Judging Commences

inallhonesty Lead Judge about 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.