DatingDapp

First Flight #33
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: low
Invalid

Redundant Type Casting in SoulboundProfileNFT Metadata

Summary

The tokenURI function in the SoulboundProfileNFT contract includes a redundant explicit type cast of the age field (stored as uint8) to uint256 before converting it to a string. While functionally harmless, this redundancy adds unnecessary complexity and deviates from Solidity best practices for type handling.


Vulnerability Details

Location

  • Contract: SoulboundProfileNFT.sol

  • Function: tokenURI

Root Cause

  • The age field is stored as a uint8 in the Profile struct.

  • When converting age to a string, the code explicitly casts it to uint256 before calling Strings.toString():

    uint256 profileAge = _profiles[tokenId].age; // Redundant cast
    Strings.toString(profileAge);
  • Why This Is Redundant:

    • Solidity automatically converts smaller integer types (e.g., uint8) to uint256 during operations.

    • The Strings.toString() function accepts uint256 as input, making the explicit cast unnecessary.

Code Snippet

function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
// ... existing checks ...
uint256 profileAge = _profiles[tokenId].age; // Unnecessary cast from uint8 to uint256
// ... rest of the code ...
}

Impact

Severity: Informational

  • No Functional Impact: The code operates correctly, and the cast does not affect the output.

  • Code Quality: Redundant operations reduce readability and may confuse developers during audits or maintenance.

  • Gas Efficiency: The explicit cast consumes a trivial amount of unnecessary gas (minor).


Recommended Mitigation

Fix

Remove the redundant cast by directly passing _profiles[tokenId].age to Strings.toString():

function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
// ... existing checks ...
string memory profileName = _profiles[tokenId].name;
uint8 profileAge = _profiles[tokenId].age; // Use uint8 directly
string memory imageURI = _profiles[tokenId].profileImage;
return string(
abi.encodePacked(
'{"name":"', profileName, '", ',
'"description":"A soulbound dating profile NFT.", ',
'"attributes": [{"trait_type": "Age", "value": ',
Strings.toString(profileAge), // Implicitly cast to uint256
"}], ",
'"image":"', imageURI, '"}'
)
);
}
Updates

Appeal created

n0kto Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Support

FAQs

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