Skip to content

Gas saving by caching state variables #82

@code423n4

Description

@code423n4

Handle

tqts

Vulnerability details

Impact

Gas optimization

Proof of Concept

https://github.com/code-423n4/2022-01-openleverage/blob/501e8f5c7ebaf1242572712626a77a3d65bdd3ad/openleverage-contracts/contracts/ControllerV1.sol#L115-L145
In ControllerV1.LiquidateAllowed(), the state variables oleTokenDistribution.liquidatorMaxPer and oleTokenDistribution.extraBalance are used several times, and could be optimized.

Tools Used

Manual review

Recommended Mitigation Steps

Create a new local variable uint128 _liquidatorMaxPer = oleTokenDistribution.liquidatorMaxPer; and uint _extraBalance = oleTokenDistribution.extraBalance;.
The if block at L141-144 can also be rewritten to:

if (transferOut(liquidator, calcLiquidatorRewards)) {
    _extraBalance = _extraBalance.sub(calcLiquidatorRewards);
    oleTokenDistribution.extraBalance = _extraBalance;
    emit LiquidateReward(marketId, liquidator, calcLiquidatorRewards, _extraBalance);
}

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