The ModrianWallet::tokenURI
function returns one of 4 random Mondrian art paintings. Each painting should have equal distribution. But the implementation of the function gives 70%
chance for one of the paintings.
The ModrianWallet::tokenURI
function distributes four art URIs. In the documentation is written:
You'll see the tokenURI function returns one of 4 random Mondrian art paintings. Each should have equal distribution and be random.
But the function doesn't distribute these 4 random Mondrian art painting equally:
The distribution is based on modNumber
. The modNumber
is derived from tokenId % 10
. Then if modNumber
is 0, the user receives ART_ONE
, if it is 1
, the user receives ART_TWO
, if it 2
, the user receives ART_THREE
and if it is another number the user receives ART_FOUR
. That means the user has 10%
chance to receive ART_ONE
, ART_TWO
, or ART_THREE
and 70%
chance to receive ART_FOUR
.
To call MondrianWallet::tokenURI
function the user should have tokenId
. Therefore for the purpose of the test a function mintTo
is created in the MondrianWallet
. This function call the internal ERC721::_mint
function:
The following test case demonstrates the distribution of the 4 hardcoded URIs for 100 tokenIds
. According to the documentation the different URIs should be equally distributed. But the chance the user to receive the one of the first three URIs is 10% and the chance for the fourth is 70%. That means the distribution is not equal. You can add the test to the file MondrianWallet.test.js
.
The distribution of the different URIs for 100 tokenIds
:
Manual Review, Hardhat
You should change tokenId % 10
to tokenId % 4
in order to receive equal distribution for each art URI. It is worth noting that the use of tokenId
is also incorrect, but that is a separated issue and it is described in another report.
If you execute the test after applying the proposed change to the code, you will see that the distribution of the arts is equal. The chance the user to receive one of the four arts URIs is 25%.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.