The current implementation of the TokenDivider::buyOrder()
function does not refund any excessive ETH sent by the buyer. If the buyer sends more ETH than necessary to cover the price and associated fees, the contract will not return the excess amount to the buyer. This can result in unintended loss of funds for the buyer and can lead to potential trust issues with the contract.
The function buyOrder()
accepts ETH payments from the buyer but lacks a mechanism to detect and refund excess ETH sent by the buyer. The current logic assumes the buyer sends an exact amount matching the order.price + fee
, but there is no check for overpayment or refund process for surplus ETH.
Consider the follwoing example:
buyer sends 2 ETH
= 2e18
order.price: 1.5 ETH
= 1.5e18
fee: 1%
of order.price
= 1.5e16
sellerFee: 0.5%
of order.price
= 7.5e15
The seller receives 1.5e18 - 7.5e15
(sellerFee is substracted) and owner receives 1.5e16
ETH.
The leftover ETH is 2e18 - 1.5e18 - 1.5e16 = 0.485e18 = 0.485 ETH
(including sellerFee which is substracted from the price and stays in the contract).
If the buyer sends 2.0 ETH
(more than 1.515 ETH
required), the transaction will not revert, but the excess 0.485 ETH
(or 4.85e17
) will be lost since the contract has no refund logic.
Even if this is a design choice, there is still no way to transfer the excessive ETH out of the TokenDivider
contract, locking the ETH forever.
Add the following test to the TokenDividerTest.t.sol
:
The test reverts with => "Failing tests:
Encountered 1 failing test in test/unit/TokenDividerTest.t.sol:TokenDiverTest
[FAIL: assertion failed: 8000000000000000000 != 8485000000000000000] test_BuyErc20KeepingExcessiveETH() (gas: 1038447)" meaning that the user was not refunded for the excessive ETH.
This vulnerability can lead to unintended loss of funds for the buyer if they accidentally send more ETH than necessary. While the transaction will not revert (unless insufficient ETH is sent), the buyer will lose the extra ETH. This can harm the reputation of the contract and reduce trust in the system, especially in high-value transactions.
Excess ETH sent is lost, causing financial harm to the buyer.
The absence of a refund mechanism might discourage users from interacting with the contract.
Even if such behavior is intended, the excessive ETH it will be locked forever since there is no function to transfer the ETH out of the contract, leading to loss of funds.
Manual review
Foundry
Implement a refund mechanism that checks for excess ETH sent by the buyer and sends it back.
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.