code-423n4 / 2021-12-yetifinance-findings

0 stars 0 forks source link

Gas Optimization: Struct layout #212

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

gzeon

Vulnerability details

Impact

Can pack non-256bit variables into fewer storage slot. e.g. https://github.com/code-423n4/2021-12-yetifinance/blob/5f5bf61209b722ba568623d8446111b1ea5cb61c/packages/contracts/contracts/BorrowerOperations.sol#L76

    struct LocalVariables_adjustTrove {
        uint256 netDebtChange;
        uint256 collChange;
        uint256 currVC;
        uint256 newVC;
        uint256 debt;
        uint256 oldICR;
        uint256 newICR;
        uint256 newTCR;
        uint256 YUSDFee;
        uint256 variableYUSDFee;
        uint256 newDebt;
        uint256 VCin;
        uint256 VCout;
        uint256 maxFeePercentageFactor;
        bool isCollIncrease;
        address[] currAssets;
        uint256[] currAmounts;
        address[] newAssets;
        uint256[] newAmounts;
    }
kingyetifinance commented 2 years ago

@LilYeti: Packing is all for addresses / uint256 here except that one bool, should be same packing size due to padding.

alcueca commented 2 years ago

Sponsor is right.