gas

DSC Mint will either return true or revert, thus checking `minted` status in ...

Reward

Total

19.63 USDC

4.46 USDC
4.46 USDC
Selected
6.25 USDC
4.46 USDC
Selected Submission

DSC Mint will either return true or revert, thus checking minted status in mintDcs is unnecessary

Severity

Gas Optimization / Informational

Relevant GitHub Links

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

Summary

DSC Mint will either return true or revert, thus checking minted status in mintDcs is unnecessary

Vulnerability Details

Whe minting DSC via DSCEngine, there is a check status if it's minted or not. If it's return false, then it will revert with DSCEngine__MintFailed.

But if we check on DecentralizedStableCoin contract, the mint function will either return true or revert. So the previous check on mintDsc is useless.

File: DSCEngine.sol
197:     function mintDsc(uint256 amountDscToMint) public moreThanZero(amountDscToMint) nonReentrant {
198:         s_DSCMinted[msg.sender] += amountDscToMint;
199:         // if they minted too much ($150 DSC, $100 ETH)
200:         _revertIfHealthFactorIsBroken(msg.sender);
201:         bool minted = i_dsc.mint(msg.sender, amountDscToMint);
202:         if (!minted) {
203:             revert DSCEngine__MintFailed();
204:         }
205:     }

File: DecentralizedStableCoin.sol
57:     function mint(address _to, uint256 _amount) external onlyOwner returns (bool) {
58:         if (_to == address(0)) {
59:             revert DecentralizedStableCoin__NotZeroAddress();
60:         }
61:         if (_amount <= 0) {
62:             revert DecentralizedStableCoin__MustBeMoreThanZero();
63:         }
64:         _mint(_to, _amount);
65:         return true;
66:     }

Impact

Will save a bit of deployment gas, and cleanup unreachable code

Tools Used

Manual analysis

Recommendations

Remove the minted check, to revert when mint failed