Fujicracy / fuji-v2

Cross-chain money market aggregator
https://fuji-v2-frontend.vercel.app
15 stars 10 forks source link

G-3 Break loop in _isValidProvider #568

Closed 0xdcota closed 1 year ago

0xdcota commented 1 year ago

Description

Consider adding a break in the loop once the validity of the provider is proved inside _isValidProvider

function _isValidProvider(address provider) internal view returns (bool check) {
    uint256 len = _providers.length;
    for (uint256 i = 0; i < len;) {
        if (provider == address(_providers[i])) {
            check = true;
                        <<break here>>
        }
        unchecked {
            ++i;
        }
    }
}

Once the match is found inside the providers array, you can break the loop and return. Doing so would save significant gas costs since no further SLOAD operations would be performed for the remaining providers.