Loops can be implemented more efficiently #157
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
0x0x0x
Vulnerability details
Proof of Concept
Example:
Loading length of array costs gas. Therefore, the length should be cached, if the length of the array doesn't change inside the loop. Furthermore, there is no need to assign the initial value 0. This costs extra gas.
Recommended implementation:
By doing so the length is only loaded once rather than loading it as many times as iterations (Therefore, less gas is spent).
Occurences
The text was updated successfully, but these errors were encountered: