Mistakenly sent eth could be locked
The contract's token transfer helper ignores any ETH sent alongside an ERC20 transfer, so that ETH becomes stuck in the contract. An attacker could cause a user to lose funds by inducing them to send ETH with an ERC20 call, or a user might do so by mistake.
__141345__ Follow with 0xSmartContract, joestakey and 8 others
Originally disclosed on Code4rena
Submitted by 141345, also found by 0xSmartContract, joestakey, rbserver, datapunk, eierina, bin2chen, Tomo, 0xbepresent, aphak5010, and cloudjunky
If ERC20 and eth are transferred at same time, the mistakenly sent eth will be locked.
There are several functions that could be affected and cause user fund lock:
addCollateral()addCredit()increaseCredit()depositAndClose()depositAndRepay()close()
Proof of Concept
In receiveTokenOrETH(), different logic is used to handle ERC20 and eth transfer. However, in the ERC20 if block, mistakenly sent eth will be ignored. This part of eth will be locked in the contract.
// Line-of-Credit/contracts/utils/LineLib.sol
function receiveTokenOrETH(
address token,
address sender,
uint256 amount
)
external
returns (bool)
{
if(token == address(0)) { revert TransferFailed(); }
if(token != Denominations.ETH) { // ERC20
IERC20(token).safeTransferFrom(sender, address(this), amount);
} else { // ETH
if(msg.value < amount) { revert TransferFailed(); }
}
return true;
}
Recommended Mitigation Steps
In the ERC20 part, add check for msg.value to ensure no eth is sent:
if(token != Denominations.ETH) { // ERC20
if (msg.value > 0) { revert TransferFailed(); }
IERC20(token).safeTransferFrom(sender, address(this), amount);
} else { // ETH
kibagateaux (Debt DAO) confirmed
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
The function receiveTokenOrETH does not reject msg.value when the token is an ERC20, so any ETH sent with an ERC20 transfer is trapped in the contract.
Impact
ETH mistakenly sent alongside an ERC20 transfer in several functions could be permanently locked in the contract, causing loss of funds for the sender.
What the attacker needed
User sends ETH with an ERC20 call
The fix
The ERC20 branch should check that msg.value is zero and revert if any ETH is sent, as the report recommends.
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 that moves tokens, you can also attach some ether (the native cryptocurrency). This contract only checks the ether amount when the token is ether itself; if you are sending an ERC20 token, any extra ether you attach is accepted but never used or returned. That ether stays in the contract forever, so the person who sent it loses it.
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.