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

0 stars 0 forks source link

Gas Optimization: Unnecessary variables #299

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

gzeon

Vulnerability details

Impact

The 3 variable defined in L365-367 are used only once https://github.com/code-423n4/2021-12-yetifinance/blob/5f5bf61209b722ba568623d8446111b1ea5cb61c/packages/contracts/contracts/Dependencies/Whitelist.sol#L365-367

        uint256 price = getPrice(_collateral);
        uint256 decimals = collateralParams[_collateral].decimals;
        uint256 ratio = collateralParams[_collateral].ratio;

We can skip them and do everything inline:

return (getPrice(_collateral).mul(_amount).mul(collateralParams[_collateral].ratio).div(10**(18 + collateralParams[_collateral].decimals)));

Similarly, L352-354

        return getPrice(_collateral).mul(_amount).div(10**collateralParams[_collateral].decimals);
kingyetifinance commented 2 years ago

@LilYeti : Internal note: Provide comment for clarity because this code will be messy