code-423n4 / 2022-01-openleverage-findings

0 stars 0 forks source link

Optimize `OpenLevV1.sol#addMarket` #250

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

0x0x0x

Vulnerability details

The function is implemented as follows:

function addMarket(
        LPoolInterface pool0,
        LPoolInterface pool1,
        uint16 marginLimit,
        bytes memory dexData
    ) external override returns (uint16) {
        uint16 marketId = numPairs;
        OpenLevV1Lib.addMarket(pool0, pool1, marginLimit, dexData, marketId, markets, calculateConfig, addressConfig, supportDexs, taxes);
        numPairs ++;
        return marketId;
    }

It can be replaced with following codeblock to save gas.


function addMarket(
        LPoolInterface pool0,
        LPoolInterface pool1,
        uint16 marginLimit,
        bytes memory dexData
    ) external override returns (uint16) {
        OpenLevV1Lib.addMarket(pool0, pool1, marginLimit, dexData, numPairs++, markets, calculateConfig, addressConfig, supportDexs, taxes);
        return marketId;
    }