MyCut

First Flight #23
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

Gas Optimization Findings

Summary

The following findings are gas optimizations and have an informative impact. They are grouped this way because the same recommendation applies to all cases. Using .length in a loop is less efficient than using a constant, because otherwise, the code reads the array length each time it loops. It's better to store the length in memory:

  1. Pot::constructor in initialization loop:

for (uint256 i = 0; i < i_players.length; i++) {
playersToRewards[i_players[i]] = i_rewards[i];
}
  1. Pot::closePot

for (uint256 i = 0; i < claimants.length; i++) {
_transferReward(claimants[i], claimantCut);
}

Recommendations

  1. Optimization for Pot::constructor:

+ uint256 playerLength = i_players.length;
+ for (uint256 i = 0; i < playerLength; i++) {
- for (uint256 i = 0; i < i_players.length; i++) {
playersToRewards[i_players[i]] = i_rewards[i];
}
  1. Optimization for Pot::closePot:

+ uint256 claimantsLength = claimants.length;
+ for (uint256 i = 0; i < claimantsLength; i++) {
- for (uint256 i = 0; i < claimants.length; i++) {
_transferReward(claimants[i], claimantCut);
}
Updates

Lead Judging Commences

equious Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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