MyCut

AI First Flight #8
Beginner FriendlyFoundry
EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

[L-6] `Pot::closePot` repeatedly looks up storage array length, spending more gas

Root + Impact

Description

Pol::closePot repeatedly calls a storage array's length, costing extra gas.

In src/Pol.sol:

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

Risk

Likelihood:

This will happen every time Pot::closePot is called.

Impact:

The impact is that this for loop will cost extra gas.

Proof of Concept

Recommended Mitigation

We recommend that claimants.length is saved as a local variable within the function Pot::closePot:

+ uint256 claimantsLength = claimants.length;
- for (uint256 i = 0; i < claimants.length; i++) {
+ for (uint256 i = 0; i < claimantsLength; i++) {
Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 1 hour ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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

Give us feedback!