Anyone can liquidate credit line when autoLiquidation is false without supplying borrow tokens #96
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
harleythedog
Vulnerability details
Impact
It is intended that if a credit line has autoLiquidation as false, then only the lender can be the liquidator (see docs here: https://docs.sublime.finance/sublime-docs/smart-contracts/creditlines). However, this is not correctly implemented, and anyone can liquidate a position that has autoLiquidation set to false.
Even worse, when autoLiquidation is set to false, the liquidator does not have to supply the initial amount of borrow tokens (determined by
_borrowTokensToLiquidate
) that normally have to be transferred when autoLiquidation is true. This means that the liquidator will be sent all of the collateral that is supposed to be sent to the lender, so this represents a huge loss to the lender. Since the lender will lose all of the collateral that they are owed, this is a high severity issue.Proof of Concept
The current implementation of liquidate is here: https://github.com/code-423n4/2021-12-sublime/blob/9df1b7c4247f8631647c7627a8da9bdc16db8b11/contracts/CreditLine/CreditLine.sol#L996.
Notice that the autoLiquidation value is only used in one place within this function, which is in this segment of the code:
So, if
autoLiquidation
is false, the code inside of the if statement will simply not be executed, and there are no further checks that the sender HAS to be the lender ifautoLiquidation
is false. This means that anyone can liquidate a non-autoLiquidation credit line, and receive all of the collateral without first transferring the necessary borrow tokens.For a further proof of concept, consider the test file here: https://github.com/code-423n4/2021-12-sublime/blob/main/test/CreditLines/2.spec.ts. If the code on line 238 is changed from
let _autoLiquidation: boolean = true;
tolet _autoLiquidation: boolean = false;
, all the test cases will still pass. This confirms the issue, as the final test case "Liquidate credit line" has theadmin
as the liquidator, which should not work in non-autoLiquidations since they are not the lender.Tools Used
Inspection and confirmed with Hardhat.
Recommended Mitigation Steps
Add the following require statement somewhere in the
liquidate
function:The text was updated successfully, but these errors were encountered: