Caching the array length is more gas efficient.
This is because access to a local variable in solidity is more efficient than query storage / calldata / memory
We recommend to change from:
for (uint256 i=0; i<array.length; i++) { ... }
uint len = array.length
for (uint256 i=0; i<len; i++) { ... }
OpenLevV1Lib.sol, dexs, 260
GovernorAlpha.sol, targets.proposal, 228
ControllerV1.sol, lpools, 303
FarmingPools.sol, stakeTokens, 132
OLETokenLock.sol, beneficiaries, 33
FarmingPools.sol, stakeTokens, 126
GovernorAlpha.sol, support, 307
UniV3Dex.sol, path, 75
OpenLevV1.sol, _supportDexs, 52
UniV2Dex.sol, tokens, 59
GovernorAlpha.sol, targets.proposal, 280
XOLE.sol, nonce, 362
ControllerV1.sol, marketIds, 375
BscDexAggregatorV1.sol, dexName, 46
FarmingPools.sol, stakeTokens, 164
GovernorAlpha.sol, targets.proposal, 202
EthDexAggregatorV1.sol, dexName, 48
Handle
mics
Vulnerability details
Caching the array length is more gas efficient.
This is because access to a local variable in solidity is more efficient than query storage / calldata / memory
We recommend to change from:
to:
These functions use not using prefix increments (
++x) or not using the unchecked keyword: