CreditLine.liquidate doesn’t transfer borrowed ETH to a lender
The CreditLine.liquidate function does not transfer the borrowed ETH to the lender when autoLiquidation is enabled; instead, the ETH remains in the contract. An attacker could exploit this by liquidating a loan and causing the lender to lose the expected repayment, though the funds are not permanently lost.
Submitted by hyh, also found by 0x0x0x
Impact
Funds that are acquired from a liquidator and should be sent to a lender are left with the contract instead. The funds aren’t lost, but after the fact mitigation will require manual accounting and fund transfer for each CreditLine.liquidate usage.
Proof of Concept
ETH sent to CreditLine.liquidate by an external liquidator when autoLiquidation is enabled remain with the contract and aren’t transferred to the lender: https://github.com/code-423n4/2021-12-sublime/blob/main/contracts/CreditLine/CreditLine.sol#L1015
Recommended Mitigation Steps
Add transfer to a lender for ETH case:
Now:
if (_borrowAsset == address(0)) {
uint256 _returnETH = msg.value.sub(_borrowTokens, 'Insufficient ETH to liquidate');
if (_returnETH != 0) {
(bool success, ) = msg.sender.call{value: _returnETH}('');
require(success, 'Transfer fail');
}
}
To be:
if (_borrowAsset == address(0)) {
uint256 _returnETH = msg.value.sub(_borrowTokens, 'Insufficient ETH to liquidate');
(bool success, ) = _lender.call{value: _borrowTokens}('');
require(success, 'liquidate: Transfer failed');
if (_returnETH != 0) {
(success, ) = msg.sender.call{value: _returnETH}('');
require(success, 'liquidate: Return transfer failed');
}
}
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
Impact
The lender does not receive the borrowed ETH, and the funds remain in the contract, requiring manual accounting and transfer to mitigate.
What the attacker needed
AutoLiquidation enabled; liquidator calls liquidate with ETH
The fix
The code should be modified to transfer the borrowed ETH amount to the lender before returning any excess to the liquidator.
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 a borrower fails to repay a loan, a liquidator can step in to repay the debt and receive collateral. In this case, the liquidator sends ETH to the smart contract, but the code forgets to forward that ETH to the lender who is owed the money. So the lender does not get paid, and the ETH stays stuck in the contract until someone manually fixes 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.