gas

`DSCEngine` should deploy its own `DecentralizedStableCoin`

Reward

Total

22.48 USDC

6.61 USDC
6.61 USDC
Selected
9.26 USDC
Selected Submission

DSCEngine should deploy its own DecentralizedStableCoin

Severity

Gas Optimization / Informational

Relevant GitHub Links

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

Summary

DSCEngine should deploy its own DecentralizedStableCoin instead of accepting an address upon construction.

Vulnerability Details

There is a perfect 1:1 correspondence between DSCEngine and DecentralizedStableCoin:

  • DSCEngine tracks a single, immutable i_dsc address.
  • DecentralizedStableCoin has a single owner with the power to mint() and burn() tokens.

Therefore, it is needless to deploy the DecentralizedStableCoin prior to deployment of a DSCEngine and only serves to add extra steps to the process, including migration of the owner.

Impact

Unnecessary gas/deployment UX burden.

Tools Used

Manual review.

Recommendations

Consider changing the DSCEngine constructor like this:

-         i_dsc = DecentralizedStableCoin(dscAddress);
+         i_dsc = new DecentralizedStableCoin();