wise-foundation / lending-audit

5 stars 4 forks source link

[WSH-03C] Inefficient Loop Limit Evaluations #42

Open vm06007 opened 1 year ago

vm06007 commented 1 year ago

WSH-03C: Inefficient Loop Limit Evaluations

Type Severity Location
Gas Optimization WiseSecurityHelper.sol:L26, L68, L101, L136, L321, L348, L380, L430

Description:

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

Example:

for (uint256 i = 0; i < WISE_LENDING.getPositionLendingTokenLength(_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