Description The TokenDivider
contract currently handles Ether payments for ERC-20 token purchases but fails to manage overpayment situations effectively. The TokenDivider::buyOrder
function in the contract accepts Ether via msg.value
to facilitate the purchase of ERC-20 tokens from a seller. However, buyOrder
lacks the check for if the user sends more ether than required.
When a user overpays (sending more Ether than the required amount), the contract processes the transaction without returning the excess Ether to the user.
Impact When a user sends a higher value of Ether than what is necessary for the transaction (i.e., the price of the tokens plus any associated fees) by calling buyOrder
, the contract only processes the token transfer and related fee deductions but does not handle the excess Ether. This results in the user losing the excess Ether, which is never refunded or handled by the contract.
Since there is no built-in mechanism to handle overpayments, the contract does not offer any way for users to recover their lost funds.
Proof of Concepts
USER sells tokens at a price of 1 ETH. The contract includes a fee of 0.01%
USER2 sends 3 ETH to purchase the tokens, which are priced at 1 ETH plus the fee
USER2 should receive the requested tokens, and the contract should only deduct 1 ETH for the tokens and a small fee. The excess Ether (1.99 ETH) should be refunded to USER2.
However, the contract fails to return the overpaid Ether to USER2. Instead, USER2 experiences a financial loss by losing the excess Ether.
Insert the following test in TokenDividerTest.t.sol
:
the following test fails and returns:
which proves that the user lost the excess ether he overpaid.
Recommended mitigation
You could implement a check to refund in case of overpayment:
Alternatively, you can revert the transaction if an overpayment is detected:
The first solution (refund mechanism) ensures the user is refunded any excess funds, preventing financial loss. The second solution (revert mechanism) prevents overpayment from being accepted in the first place, ensuring that users cannot accidentally overpay.
The extra eth sent by the user in the buy order will be locked in the contract forever
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.