Using MartenitsaToken::transferFrom
(a function MartentisaToken
inherits from ERC721.sol
) users can transfer NFTs between themselves. Since this function is not overriden, the logic responsible for updating internal accounting mapping(address => uint256) public countMartenitsaTokensOwner
is not triggered.
MartenitsaToken::updateCountMartenitsaTokensOwner
is supposed to update mapping(address => uint256) public countMartenitsaTokensOwner
whenever a Marenitsa NFT is minted or changes owners. The mapping countMartenitsaTokensOwner
is used for internal accounting and is supposed to reflect how many Martenitsa NFTs are owned by each address.
However, this internal accounting is not updated when users transfer NFTs via the standard ERC721
method transferFrom
.
Consider the following test that demonstrates this vulnerability:
Internal accounting (martenitsaToken.countMartenitsaTokensOwner()
) will not refelct true ownership status (martenitsaToken.balanceOf()
).
Users whose internal accounting data does not reflect true ownership status will be able to claim either less or more healthToken
rewards from MartenitsaMarketplace::collectRewards
than they are entitled to.
Manual review, Foundry.
Consider the following options and select whichever matches your current and future requirements more appropriately:
Replace the countMartenitsaTokensOwner
with the the standard ERC721
balanceOf()
, as the former appears to duplicate the functionality already provided by the latter (i.e. tracking the number of tokens owned by each address). In this case you can completely remove not only the mapping but also the updateCountMartenitsaTokensOwner
function.
(According to the protocol owner, this is the less favorable option, the protocol prefers to keep the internal accounting.)
Override the standard ERC721
method transferFrom
by modifying MartenitsaToken.sol
as follows. Note that when doing so, other vulnerabilites need to be considered:
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.