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

The `nonReentrant` modifier should occur before all other modifiers

Summary

It is best practice to use nonReentrant modifier first in a function

Vulnerability Details

This is a best-practice to protect against reentrancy in other modifiers

149 function depositCollateral(address tokenCollateralAddress, uint256 amountCollateral)
150 public
151 moreThanZero(amountCollateral)
152 isAllowedToken(tokenCollateralAddress)
153 nonReentrant
154 {
...
183 function redeemCollateral(address tokenCollateralAddress, uint256 amountCollateral)
184 public
185 moreThanZero(amountCollateral)
186 nonReentrant
187 {
...
197 function mintDsc(uint256 amountDscToMint) public moreThanZero(amountDscToMint) nonReentrant {
...
229 function liquidate(address collateral, address user, uint256 debtToCover)
230 external
231 moreThanZero(debtToCover)
232 nonReentrant
233 {

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

Impact

Informational

Tools Used

Manual review

Recommendations

Use nonReentrant before any other modifier

Support

FAQs

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