code-423n4 / 2021-06-gro-findings

0 stars 1 forks source link

`Allocaiton.calcProtocolExposureDelta` gas optimization #102

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

cmichel

Vulnerability details

Vulnerability Details

Allocaiton.calcProtocolExposureDelta should break out of the loop to save gas after protocolExposedDeltaUsd is set.

if (protocolExposedDeltaUsd == 0 && protocolExposure[i] > sysState.rebalanceThreshold) {
    // ...Calculate the delta between exposure and target
    uint256 target = sysState.rebalanceThreshold.sub(sysState.targetBuffer);
    protocolExposedDeltaUsd = protocolExposure[i].sub(target).mul(sysState.totalCurrentAssetsUsd).div(
        PERCENTAGE_DECIMAL_FACTOR
    );
    protocolExposedIndex = i;
    // @audit break here
}