Prevent users from sending more ETH than the premium price in buyOption() #128
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
duplicate
This issue or pull request already exists
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2022-05-cally/blob/main/contracts/src/Cally.sol#L224
Vulnerability details
When calling
buyOption()
, if a buyer accidentally sends more ETH than the premium price, only the current vault beneficiary would be able to withdraw the additional funds. The buyer or owner has no way of recovering the lost funds.Proof of Concept
buyOption()
checks if the amount of ETH sent by the buyer is equal or larger than the premium price:All of the funds is then directly added to the balance of the current vault beneficiary.
Cally.sol:248-250
:Only the beneficiary is able to withdraw the amount added to his
ethBalance
. Thus, only he can recover the additional funds mistakenly sent by the buyer.Recommended Mitigation Steps
Consider changing
>=
to==
inbuyOption()
:This is more logical, especially since
premium
is derived from fixed values inpremiumOptions[]
.Furthermore, it helps to maintain consistency with the check in
exercise()
:The text was updated successfully, but these errors were encountered: