15,000 USDC
View results
Submission Details
Severity: gas
Valid

x - y is more efficient than using -=

Summary

In DSCEngine.sol, the _burnDsc() uses addition assignment which costs more gas

Vulnerability Details

The following code is used in _burnDsc()

function _burnDsc(uint256 amountDscToBurn, address onBehalfOf, address dscFrom) private {
s_DSCMinted[onBehalfOf] -= amountDscToBurn;
bool success = i_dsc.transferFrom(dscFrom, address(this), amountDscToBurn);
// This conditional is hypothtically unreachable
if (!success) {
revert DSCEngine__TransferFailed();
}
i_dsc.burn(amountDscToBurn);
}

Impact

Extra runtime gas is used.

Tools Used

Manual review

Recommendations

Consider using the following:

s_DSCMinted[onBehalfOf] = s_DSCMinted[onBehalfOf] - amountDscToBurn;

Support

FAQs

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