Closed code423n4 closed 2 years ago
Agree with the finding, as a general rule you always want to cache storage values in memory if they are read more than once. Additionally, caching .length saves an extra math operation as the length is stored in a specific storage location that has to be re-calculated every loop
Duplicate of #230
Handle
pauliax
Vulnerability details
Impact
There are loops that iterate over storage arrays. Accessing the length of the array in every iteration is more expensive, so you should cache it and use this local variable when iterating over the storage array.
Recommended Mitigation Steps
Example: uint bProposalWightsLength = bProposal.weights.length; for (uint256 i = 0; i < bProposalWightsLength; i++)