15,000 USDC
View results
Submission Details
Severity: gas

Modifier gas optimization

Summary

It is recommended to move the if + custom error checks from a modifier into an internal virtual function. This reduces the size of compiled contracts that use the modifiers. Putting the check in an internal function decreases contract size when a modifier is used multiple times.

Recommendations

modifier moreThanZero(uint256 amount) {
- if (amount == 0) {
- revert DSCEngine__NeedsMoreThanZero();
- }
+ moreThanZeroCheck(amount);
_;
}
modifier isAllowedToken(address token) {
- if (s_priceFeeds[token] == address(0)) {
- revert DSCEngine__NotAllowedToken();
- }
+ isAllowedTokenCheck(token);
_;
}
+ function moreThanZeroCheck(uint256 amount) internal virtual {
+ if (amount == 0) {
+ revert DSCEngine__NeedsMoreThanZero();
+ }
+ }
+ function isAllowedTokenCheck(address token) internal virtual {
+ if (s_priceFeeds[token] == address(0)) {
+ revert DSCEngine__NotAllowedToken();
+ }
+ }

Support

FAQs

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