MyCut

First Flight #23
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Valid

Lack of check of `Pot::remainingRewards` at the end of `Pot::closePot`, can result in pot not being closed properly

Summary

The Pot::closePot may fail to fully distribute all remaining rewards. This can result in leftover funds within the contract after the pot is closed, potentially leading to unclaimed rewards, incorrect close pot and unexpected behavior.

Vulnerability Details

The Pot::closePot may fail to fully distribute all remaining rewards due to transfer failed or potential precision loss in integer division and incorrectly distribution of Pot::remainingRewards at

function closePot() external onlyOwner {
if (block.timestamp - i_deployedAt < 90 days) {
revert Pot__StillOpenForClaim();
}
if (remainingRewards > 0) {
@> uint256 managerCut = remainingRewards / managerCutPercent;
i_token.transfer(msg.sender, managerCut);
@> uint256 claimantCut = (remainingRewards - managerCut) / i_players.length;
for (uint256 i = 0; i < claimants.length; i++) {
_transferReward(claimants[i], claimantCut);
}
}
}

This can result in leftover funds within the contract after the pot is closed, potentially leading to unclaimed rewards and unexpected behavior.

Impact

The pot is not close correctly, there may have funds in the contract, and if the funds is bigger than player's reward, then an unclaim player can claim cut after the potis closed.

Tools Used

Manual Review

Recommendations

Transfer the rest of funds to the owner, and add a check in Pot::closePot function

function closePot() external onlyOwner {
if (block.timestamp - i_deployedAt < 90 days) {
revert Pot__StillOpenForClaim();
}
if (remainingRewards > 0) {
uint256 managerCut = remainingRewards / managerCutPercent;
i_token.transfer(msg.sender, managerCut);
uint256 claimantCut = (remainingRewards - managerCut) / i_players.length;
for (uint256 i = 0; i < claimants.length; i++) {
_transferReward(claimants[i], claimantCut);
}
+ remainingRewards = 0;
+ if (address(this).balance > 0) {
+ i_token.safeTransfer(msg.sender, address(this).balance);
+ }
}
}
Updates

Lead Judging Commences

equious Lead Judge 12 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Incorrect distribution in closePot()

Support

FAQs

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