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

TokenURIs Are Not Distributed Equally

Summary

The tokenURI is not distributed equally as it should be according to the contest ReadMe

"You'll see the tokenURI function returns one of 4 random Mondrian art paintings. Each should have equal distribution and be random."

Vulnerability Details

This issue is an incorrect module operator uint256 modNumber = tokenId % 10; With this current implementation

function tokenURI(uint256 tokenId) public view override returns (string memory) {
if (ownerOf(tokenId) == address(0)) {
revert MondrainWallet__InvalidTokenId();
}
uint256 modNumber = tokenId % 10;
if (modNumber == 0) {
return ART_ONE;
} else if (modNumber == 1) {
return ART_TWO;
} else if (modNumber == 2) {
return ART_THREE;
} else {
return ART_FOUR;
}
}

The distributions of tokens will look like this:

  • ART_ONE for modNumber == 0

  • ART_TWO for modNumber == 1

  • ART_THREE for modNumber == 2

  • ART_FOUR for all other modNumber values (3 to 9)

Impact

ART_FOUR will be assigned to 70% of the tokens, while ART_ONE, ART_TWO, and ART_THREE will each only be assigned to 10%.

Tools Used

Manual Review, Audit Wizard

Recommendations

Change the modulo to 4

function tokenURI(uint256 tokenId) public view override returns (string memory) {
if (ownerOf(tokenId) == address(0)) {
revert MondrainWallet__InvalidTokenId();
}
- uint256 modNumber = tokenId % 10;
+ uint256 modNumber = tokenId % 4;
if (modNumber == 0) {
return ART_ONE;
} else if (modNumber == 1) {
return ART_TWO;
} else if (modNumber == 2) {
return ART_THREE;
} else {
return ART_FOUR;
}
}
Updates

Lead Judging Commences

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

NFT's should have equal distribution

Support

FAQs

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