Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: medium
Valid

Save excessively high gas in for loop

Summary

Save gas from excessive evm call by caching values used in for loops

Vulnerability Details

A typical for loop definition may look like: for (uint256 i; i < arr.length; i++){}. Instead of using array.length, cache the array length before the loop, and use the cached value to safe gas. This will avoid an MLOAD every loop for arrays stored in memory and an SLOAD for arrays stored in storage. This can have significant gas savings for arrays with a large length, especially if the array is stored in storage.

Impact

extremely high gas requirements can render protocol useless for investors

Tools Used

manual review + foundry

Recommendations

cache newPlayers.length to a variable that can be used in permalink 1
cache players.length to a variable that can be used in permalink 2
same for other two loops

Updates

Lead Judging Commences

patrickalphac Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

denial-of-service-in-enter-raffle

Support

FAQs

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