Skip to content

Caching array length can save gas #15

@code423n4

Description

@code423n4

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:

     for (uint256 i=0; i<array.length; i++) { ... }

to:

     uint len = array.length 
     for (uint256 i=0; i<len; i++) { ... }

These functions use not using prefix increments (++x) or not using the unchecked keyword:

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions