15,000 USDC
View results
Submission Details
Severity: gas

function with onlyOwner modifier can be payable

[G-05] Functions guaranteed to revert when called by normal users can be marked payable

If a function modifier such as onlyOwner is used, the function will revert if a normal user tries to pay the function. Marking the function as payable will lower the gas cost for legitimate callers because the compiler will not include checks for whether a payment was provided.

Number Of Instances: 2

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

function mint(address _to, uint256 _amount) external onlyOwner returns (bool) {
//code
}

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

function burn(uint256 _amount) public override onlyOwner {
//code
}

Recommendation:
Make mint and burn function as payable.

Support

FAQs

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