ETH mistakenly sent over with ERC20 based takeOrders and takeMultipleOneOrders calls will be lost
The takeOrders and takeMultipleOneOrders functions accept ETH even when the order currency is an ERC20 token, and the ETH is not refunded. A user who mistakenly sends ETH with such a call permanently loses those funds.
Submitted by obtarian, also found by 0xsanson, cccz, and VAD37
Vulnerability details
takeOrders() and takeMultipleOneOrders() are the main user facing functionality of the protocol. Both require currency to be fixed for the call and can have it either as a ERC20 token or ETH. This way, the probability of a user sending over a ETH with the call whose currency is a ERC20 token isn’t negligible. However, in this case ETH funds of a user will be permanently lost.
Setting the severity to medium as this is permanent fund freeze scenario conditional on a user mistake, which probability can be deemed high enough as the same functions are used for ETH and ERC20 orders.
Proof of Concept
Both takeOrders() and takeMultipleOneOrders() only check that ETH funds are enough to cover the order’s totalPrice:
// check to ensure that for ETH orders, enough ETH is sent
// for non ETH orders, IERC20 safeTransferFrom will throw error if insufficient amount is sent
if (isMakerSeller && currency == address(0)) {
require(msg.value >= totalPrice, 'invalid total price');
}
// check to ensure that for ETH orders, enough ETH is sent
// for non ETH orders, IERC20 safeTransferFrom will throw error if insufficient amount is sent
if (isMakerSeller && currency == address(0)) {
require(msg.value >= totalPrice, 'invalid total price');
}
When currency is some ERC20 token, while msg.value > 0, the msg.value will be permanently frozen within the contract.
Recommended Mitigation Steps
Consider adding the check for msg.value to be zero for the cases when it is not utilized:
// check to ensure that for ETH orders, enough ETH is sent
// for non ETH orders, IERC20 safeTransferFrom will throw error if insufficient amount is sent
if (isMakerSeller && currency == address(0)) {
require(msg.value >= totalPrice, 'invalid total price');
} else {
require(msg.value == 0, 'non-zero ETH value');
}
nneverlander (Infinity) confirmed
HardlyDifficult (judge) commented:
When accepting an order using ERC20 tokens, any ETH included will be accepted as exchange fees instead of reverting the tx or refunding to the user.
This is a result of user error, but leads to a direct loss of funds. Accepting as a Medium risk submission.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the functions only check that enough ETH is sent for ETH orders, but do not reject ETH when the order currency is an ERC20 token, so the ETH remains stuck in the contract.
Impact
A user who mistakenly sends ETH with an ERC20 order permanently loses that ETH, as it is frozen in the contract.
What the attacker needed
User sends ETH with an ERC20 order
The fix
The functions should be fixed to require that msg.value is zero when the currency is not ETH.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you call a smart contract function, you can send cryptocurrency (ETH) along with it. This report says that if you send ETH to a function that is supposed to handle a different token (an ERC20 token), the contract keeps your ETH and you cannot get it back. The mistake is easy to make because the same function is used for both ETH and token orders.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.