BriVault

First Flight #52
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

Gas consumption can be improved saving the array length

Root + Impact

Description

  • In below code the length of the array length is read each time in the loop causing unnesary gas consumption (SLOADs)


@> for (uint256 i = 0; i < usersAddress.length; ++i){
address user = usersAddress[i];
totalWinnerShares += userSharesToCountry[user][winnerCountryId];
}
return totalWinnerShares;
}

Risk

Likelihood:

  • This will occur each time loop runs.

Impact:

  • Unnecesary gas consumption

Recommended Mitigation

function _getWinnerShares () internal returns (uint256) {
+ uint256 aLength = usersAddress.length;
- for (uint256 i = 0; i < usersAddress.length; ++i){
+ for (uint256 i = 0; i < aLength; ++i){
address user = usersAddress[i];
totalWinnerShares += userSharesToCountry[user][winnerCountryId];
}
return totalWinnerShares;
}
Updates

Appeal created

bube Lead Judge 19 days ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Gas optimizations

Gas optimizations are invalid according to the CodeHawks documentation.

Support

FAQs

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

Give us feedback!