BriVault

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

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

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

Description

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

contract BriVault is ERC4626, Ownable {
...
function setCountry(string[48] memory countries) public onlyOwner {
@> for (uint256 i = 0; i < countries.length; ++i) {
teams[i] = countries[i];
}
emit CountriesSet(countries);
}
...
}

Risk

Likelihood: Low

Impact: Low/Gas

Recommended Mitigation

  • Store the value of countries.length outside the loop in a local variable countryLength .

contract BriVault is ERC4626, Ownable {
...
function setCountry(string[48] memory countries) public onlyOwner {
- for (uint256 i = 0; i < countries.length; ++i) {
+ uint256 countriesLength=countries.length;
+ for (uint256 i = 0; i < countriesLength; ++i) {
teams[i] = countries[i];
}
emit CountriesSet(countries);
}
...
}
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!