wise-foundation / lending-audit

5 stars 4 forks source link

[MHR-04C] Loop Iterator Optimization #52

Open vm06007 opened 1 year ago

vm06007 commented 1 year ago

MHR-04C: Loop Iterator Optimization

Type Severity Location
Gas Optimization MainHelper.sol:L361

Description:

The linked for loop increments / decrements the iterator "safely" due to Solidity's built-in safe arithmetics (post-0.8.X).

Example:

for (uint8 i = 0; i < tokens.length; ++i) {

Recommendation:

We advise the increment / decrement operation to be performed in an unchecked code block as the last statement within the for loop to optimize its execution cost.

vm06007 commented 1 year ago

Should be addressed as part of: https://github.com/wise-foundation/lending-audit/pull/51

vm06007 commented 1 year ago

Note: in this case if to follow the suggestion the unchcked cannot be last statement as this loop contains continue; statement which might skip ++i iteration leading to errors.