BriVault

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

Gas inefficiencies (loop caching, repeated balance calls)

Minor gas inefficiencies: loops and repeated external calls.

Description

  • Repeatedly reading usersAddress.length or calling IERC20(asset()).balanceOf(address(this)) multiple times is marginally wasteful.

// Root cause in the codebase with @> marks to highlight the relevant section

Risk

Likelihood:

  • Reason 1 // Describe WHEN this will occur (avoid using "if" statements)

  • Reason 2

Impact:

  • Higher gas costs (not security-critical) — scales poorly at high user counts.

Proof of Concept


No exploit — suggestion only.

Recommended Mitigation


Cache uint256 len = usersAddress.length; in loops.

• Cache uint256 vaultBal = IERC20(asset()).balanceOf(address(this)); once per function where used multiple times.

- for (uint256 i = 0; i < usersAddress.length; ++i) {
+ uint256 len = usersAddress.length;
+ for (uint256 i = 0; i < len; ++i) {
address user = usersAddress[i];
totalWinnerShares += userSharesToCountry[user][winnerCountryId];
}
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!