Beginner FriendlyFoundryGameFi
100 EXP
View results
Submission Details
Severity: high
Valid

Invalid access control in `MartenitsaToken::updateCountMartenitsaTokensOwner`, leading to miscalculation in reward collection

Summary

The function MartenitsaToken::updateCountMartenitsaTokensOwner lacks proper access control, allowing anyone to increase their MartenitsaToken::countMartenitsaTokensOwnervalue. An attacker could invoke MartenitsaMarketplace::collectReward to obtain more rewards with an incorrect value.

Vulnerability Details

There is no access control in MartenitsaToken::updateCountMartenitsaTokensOwner, and every user can increase their MartenitsaToken::countMartenitsaTokensOwner. The proof-of-concept is as follows, add the test in the MartenitsaToken.t.sol and run forge test --mt testBadAccessControlForCountTokenOwner, In this case, Bob does not have any token, but is able to collect reward.

function testBadAccessControlForCountTokenOwner() public {
// Bob can update its value multiple times
vm.startPrank(bob);
martenitsaToken.updateCountMartenitsaTokensOwner(bob, "add");
martenitsaToken.updateCountMartenitsaTokensOwner(bob, "add");
martenitsaToken.updateCountMartenitsaTokensOwner(bob, "add");
vm.stopPrank();
// Bob can collect rewards even though he has zero token balance
vm.prank(bob);
marketplace.collectReward();
uint256 amount = healthToken.balanceOf(bob);
assertEq(amount, 1 ether);
}

Impact

Malicious user can increase their MartenitsaToken::countMartenitsaTokensOwner for unlimited times, and claim a large amount of health token, even though they do not have any Martenitsa token.

Tools Used

Manual Review, Foundry Testing

Recommendations

Restrict the access of MartenitsaToken::updateCountMartenitsaTokensOwner to certain contract. In the current codebase, only the MartenitsaMarketplace contract should have legal access to the operation.

Updates

Lead Judging Commences

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

Missing access control

Support

FAQs

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