15,000 USDC
View results
Submission Details
Severity: gas

Reduce gas costs by removing certain getter functions from DSCEngine.sol and declaring functions in OracleLib.sol as internal

Summary

The functions: getPrecision, getAdditionalFeedPrecision, getLiquidationThreshold, getLiquidationBonus, getMinHealthFactor, getDsc and getCollateralTokenPriceFeed retrieve information that is already visible in the contract or can be shared with the users in other ways.

Tools Used

Visual Studio Code and Foundry.

Recommendations

I recommend removing those getters and declaring the functions in the library as internal to reduce deployment and execution gas costs as shown below.

Before changes:

| src/DSCEngine.sol:DSCEngine contract | | | | | |
|--------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 1015345 | 5500 | | | | |
| Function Name | min | avg | median | max | # calls |
| depositCollateralAndMintDsc | 93153 | 122997 | 122997 | 152841 | 2 |
| getHealthFactor | 9760 | 9760 | 9760 | 9760 | 3 |
| liquidate | 74676 | 74676 | 74676 | 74676 | 1 |

After changes:

| src/DSCEngine.sol:DSCEngine contract | | | | | |
|--------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 937652 | 5105 | | | | |
| Function Name | min | avg | median | max | # calls |
| depositCollateralAndMintDsc | 91614 | 120015 | 120015 | 148417 | 2 |
| getHealthFactor | 7836 | 7836 | 7836 | 7836 | 3 |
| liquidate | 69394 | 69394 | 69394 | 69394 | 1 |

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.