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

Bad logic implementation in `collectRewards()`

Summary

Bad logic implementation in collectRewards() allowing the callers to collect unlimited rewards through multiple calls of the function

Vulnerability Details

the _collectedRewards[msg.sender] should add amountRewards, not be set to amountRewards.

Impact

_collectedRewards[msg.sender] might never be 0.

Tools Used

Manual analysis

Recommendations

function collectReward() external {
require(!martenitsaToken.isProducer(msg.sender), "You are producer and not eligible for a reward!");
uint256 count = martenitsaToken.getCountMartenitsaTokensOwner(msg.sender);
uint256 amountRewards = (count / requiredMartenitsaTokens) - _collectedRewards[msg.sender];
if (amountRewards > 0) {
+ _collectedRewards[msg.sender] += amountRewards;
- _collectedRewards[msg.sender] = amountRewards;
healthToken.distributeHealthToken(msg.sender, amountRewards);
}
}
Updates

Lead Judging Commences

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

_collectedRewards is not updated correctly

Support

FAQs

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