Cyfrin / 2023-07-foundry-defi-stablecoin

38 stars 33 forks source link

Unnecessary Health Factor Check in `burnDsc` Function #1006

Open codehawks-bot opened 1 year ago

codehawks-bot commented 1 year ago

Unnecessary Health Factor Check in burnDsc Function

Severity

Gas Optimization / Informational

Relevant GitHub Links

https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol

The function _revertIfHealthFactorIsBroken within the burnDsc function is not required and can be removed. Burning tokens will allow a user to improve his health factor regardless of the amount chosen to repay. This removal will enhance the deployment cost by around 1800 gas units. Furthermore, this check currently prevents users from repaying a fraction of their debt in the case of an undercollateralized position. If a user chooses to repay a fraction of the debt that does not increase their health factor above the MIN_HEALTH_FACTOR, it should still improve it. However, invoking _revertIfHealthFactorIsBroken stops them from doing so, which is an undesirable side effect. Removing this check would not only optimize gas but also provide a better user experience by allowing more flexibility in debt repayment strategies.