buySnow is meant to let a caller pay for amount of Snow either in ETH (by sending the exact price in msg.value) or in WETH.
If msg.value is not exactly s_buyFee * amount, execution enters the else branch, which pulls the full price in WETH but never refunds the ETH already sent in msg.value. The caller is charged twice and receives tokens only once.
Likelihood:
Occurs whenever a caller sends a non-zero msg.value that is not exactly s_buyFee * amount (wrong price assumption or rounding mistake).
The price is scaled by 1e18 (s_buyFee = buyFee * PRECISION), so sending a slightly wrong ETH amount is easy.
Impact:
The caller pays the full price in WETH and additionally loses the ETH sent in msg.value, while receiving Snow only once.
The stranded ETH is later withdrawn by the collector via collectFee, so the user's ETH is effectively taken.
This Foundry test sends half the price as ETH, forcing the else branch. The user ends up down both 0.5 ETH and the full WETH price, and the 0.5 ETH is stranded in the contract:
Result: test passes. user ETH after = 0.5e18, user WETH after = 0, contract ETH = 0.5e18.
Reject any ETH in the WETH branch (or refund it), so a caller cannot be charged in both assets:
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.