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

0 stars 0 forks source link

Function handleFees #L148-L151 and updateIBRatio (Basket.sol) can be refactored for efficiency and clarity #161

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

ye0lde

Vulnerability details

Impact

Eliminating intermediate variables and reducing state variable references can reduce gas usage and improve code clarity.

Proof of Concept

The handleFees function is here: https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L148-L151

I suggest this refactoring for #L148-L151:

        emit NewIBRatio(ibRatio = ibRatio * startSupply / totalSupply());

The updateIBRatio function is here: https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L266-L272

I suggest this refactoring:

    function updateIBRatio(uint256 newRatio) onlyAuction external override returns (uint256) {

        emit NewIBRatio(ibRatio = newRatio);

        return newRatio; 
    }

Tools Used

Visual Studio Code, Remix

Recommended Mitigation Steps

See POC for details.