wise-foundation / lending-audit

5 stars 4 forks source link

[FMH-03C] Inefficient Loop Limit Evaluations #41

Open vm06007 opened 1 year ago

vm06007 commented 1 year ago

FMH-03C: Inefficient Loop Limit Evaluations

Type Severity Location
Gas Optimization FeeManagerHelper.sol:L21, L46

Description:

The linked for loops evaluate their limit inefficiently on each iteration.

Example:

for (i = 0; i < WISE_LENDING.getPositionBorrowTokenLength(_nftId); ++i) {

Recommendation:

We advise the statements within the for loop limits to be relocated outside to a local variable declaration that is consequently utilized for the evaluations to significantly reduce the codebase's gas cost. We should note the same optimization is applicable for storage reads present in those limits as they are newly read on each iteration (i.e. length members of arrays in storage).

vm06007 commented 1 year ago

Resolved as part of: https://github.com/wise-foundation/lending-audit/pull/39