MyCut

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

Call inside loop in `Pot::closePot` function may address DOS.

Description:

The Pot::closePot function contains a loop that iterates over all claimants and processes their rewards distribution. Within this loop, there is a call to transfer funds to each claimant. Performing external calls inside a loop can be risky for several reasons:

  1. Gas Limit Exceeded: If the number of claimants is large, the gas required to process all transfers could exceed the block gas limit, causing the transaction to fail.

  2. Denial of Service: A malicious claimant could purposely cause the transfer to revert (e.g., by rejecting the transfer), which would revert the entire transaction, preventing other claimants from receiving their funds.

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);
}
}
}

Impact:

The presence of a call inside the loop could lead to failed transactions, especially in scenarios with a large number of claimants. This could result in the pot remaining unclosed, funds being locked up, and claimants being unable to claim their cut.

Proof of Concept:

In a scenario where there are thousands of claimants, this function could exceed the gas limit and fail the transaction thus not sending any claimant cut to the thousands of claimants

Recommended Mitigation:

Use of Pull Payments: Instead of sending funds directly within the loop, consider implementing a pull payment mechanism where claimants can withdraw their rewards themselves. This approach minimizes the risks associated with external calls inside loops.

Updates

Lead Judging Commences

equious Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Unbound loop in closePot

Support

FAQs

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