BriVault

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

Storage Array Length not Cached in `_getWinnerShares::BriVault`

Root + Impact :Calling .length inside of loop of expensive, wasting gas.

Description

  • In the function _getWinnerShares::BriVault , use of userAddress.length is expensive and waste unnecessary gas.

contract BriVault is ERC4626, Ownable {
...
function _getWinnerShares() internal returns (uint256) {
@> for (uint256 i = 0; i < usersAddress.length; ++i) {
address user = usersAddress[i];
totalWinnerShares += userSharesToCountry[user][winnerCountryId];
}
return totalWinnerShares;
}
...
}

Risk

Likelihood: Low

Impact: Low/Gas

Recommended Mitigation

  • Store the value of userAddress.length outside the loop in a local variable userAddressLength .

contract BriVault is ERC4626, Ownable {
...
function _getWinnerShares() internal returns (uint256) {
- for (uint256 i = 0; i < usersAddress.length; ++i) {
+ uint256 userAddressLength=userAddress.length;
+ for (uint256 i = 0; i < userAddressLength; ++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!