Borrower can by mistake add own money to credit if credit is in ETH
When a credit line is denominated in ETH, the addCredit function accepts ETH from whoever sends the transaction rather than from the named lender, because the sender argument is never compared with the caller. A borrower could therefore end up funding their own credit by mistake.
Originally disclosed on Code4rena
Submitted by rvierdiiev
Impact
Borrower can mistakenly add own money to credit if credit is in ETH.
Proof of Concept
Function LineOfCredit.addCredit is used to create new credit.
It can be called only after contest of another party.
function addCredit(
uint128 drate,
uint128 frate,
uint256 amount,
address token,
address lender
)
external
payable
override
whileActive
mutualConsent(lender, borrower)
returns (bytes32)
{
LineLib.receiveTokenOrETH(token, lender, amount);
bytes32 id = _createCredit(lender, token, amount);
require(interestRate.setRate(id, drate, frate));
return id;
}
LineLib.receiveTokenOrETH(token, lender, amount) is responsible for getting payment.
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;
}
As you can see in case of native token payment, sender is not checked to be msg.sender, so this makes it’s possible that borrower can mistakenly pay instead of lender. It sounds funny, but it’s possible. What is needed is for the lender to call addCredit first and then borrower calls addCredit and provides value.
Tools Used
VSCode
Recommended Mitigation Steps
Check that if payment in ETH, then lender == msg.sender in addCredit function.
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
Likely the ETH payment path in receiveTokenOrETH never verifies that the declared sender is the account that actually paid, so any caller can supply the funds.
Impact
A borrower could unintentionally fund their own credit line with their own ETH instead of the lender's money.
What the attacker needed
Credit line denominated in ETH; lender consents first; borrower sends ETH by mistake
The fix
The addCredit function should require that, for ETH payments, the lender address equals the caller.
How it was found
- The lender calls addCredit for an ETH-denominated credit, giving consent.
- The borrower then calls addCredit for the same credit and sends ETH with the transaction.
- The contract accepts the borrower's ETH as the lender's contribution.
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.
A credit line lets a lender put money in for a borrower to draw on. Here, when the money is plain ETH, the contract only checks that enough ETH arrived with the call, not who sent it. So if the borrower happens to send the second half of the approval, their own ETH is taken instead of the lender's.
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.