If the user sends ETH (msg.value > 0), but the amount does not exactly match s_buyFee * amount, the function enters the else branch.
In the else branch, the function does not use the sent ETH at all. Instead, it tries to take WETH from the user via safeTransferFrom.
The ETH sent by the user remains in the contract, and is not refunded. This means the user loses their ETH, and also pays in WETH for the same purchase.
Likelihood:
User accidentally sends 1.1 ETH instead of 1 ETH (maybe due to a UI bug or miscalculation). The function enters the else branch, takes WETH from the user, and mints tokens. The 1.1 ETH is stuck in the contract (unless there is a withdraw function for the owner), and the user is overcharged.
We could require(msg.value == 0 || msg.value == s_buyFee * amount) at the top, and revert if the ETH sent is not exactly what is expected.
Or we can refund the difference.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.