Borrower is not able to compensate his lenders if he is underwater
The compensate function reverts if the borrower is still underwater after a single call, preventing a borrower from using multiple healthy credit positions to gradually improve their collateral ratio. An attacker could not exploit this directly, but the borrower is forced to sell credit positions quickly, potentially at a bad price, to avoid liquidation.
Submitted by ilchovski, also found by 0xAlix2, alix40, dhank, zzebra83, ether_sky, and pkqs90
A borrower of a loan could have other credit positions with borrowers that have healthy CRs which he could use to compensate his lenders to avoid liquidations and improve his CR. However, he is not able to do this via compensate() and he is forced to sell his credit positions via sellCreditMarket() or sellCreditLimit(). The complications of this are described in the example below.
Proof of Concept
Before we start just to have context, repay() repays the whole debt amount of the loan in full and can be called even when the borrower is underwater or past due date.
compensate() is used to either split a loan in smaller parts in order to be more easily repaid with repay() or to repay certain lenders and reduce the debt of the loan by the borrower giving specific lenders some of his own healthy credit positions that he owns.
Here is an example of the issue: Bob has collateral X in place and has 10 different debt positions (he borrowed). With the newly acquired borrow tokens he buys 10 different credit positions.
Some time passes and his collateral value drops significantly (volatile market), his CR is below the healthy threshold. At the moment Bob does not have any more borrow tokens available but he has 10 healthy credit positions that he can use to improve his CR by compensating some of his lenders.
Here comes the important part: He can successfully compensate 1 of his lenders if at the end of the compensate() tx his CR becomes healthy. The problem appears when he must compensate for 3 out of all 10 debt positions (more than 1 position) in order to become with healthy CR.
He will call compensate for the first time and the end of this tx he will face a revert due to this check because he needs to compensate 2 more times to become healthy.
function compensate(CompensateParams calldata params) external payable override(ISize) whenNotPaused {
state.validateCompensate(params);
state.executeCompensate(params);
@> state.validateUserIsNotUnderwater(msg.sender);
}
function isUserUnderwater(State storage state, address account) public view returns (bool) {
@> return collateralRatio(state, account) < state.riskConfig.crLiquidation;
}
function validateUserIsNotUnderwater(State storage state, address account) external view {
@> if (isUserUnderwater(state, account)) {
revert Errors.USER_IS_UNDERWATER(account, collateralRatio(state, account));
}
}
The only option Bob has currently is to sell some of his credit positions via sellCreditMarket or sellCreditLimit. There might not be any buyers at the moment or he might be forced to take a very bad deal for his credit positions because he will be in a rush in order to repay part of his loans on time to not get liquidated.
Recommended Mitigation Steps
The CR check at the end of compensate is important because fragmentation fees could occur and lower the CR and make it under the healthy threshold in some specific situations.
What I propose as a solution is measuring the CR before and after the compensate() logic and it should revert if the CR is becoming worse.
This way Bob will be able to improve his CR by using his credit positions even if he has to compensate multiple times before becoming healthy again.
aviggiano (Size) confirmed and commented:
Fixed in https://github.com/SizeCredit/size-solidity/pull/129
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 compensate function enforces that the borrower is not underwater after the transaction, without allowing a sequence of compensations that would gradually restore health.
Impact
The borrower cannot use compensate to gradually improve their CR and may be forced to sell credit positions quickly, possibly at a bad price, to avoid liquidation.
What the attacker needed
Borrower is underwater; borrower has multiple debt positions; borrower owns healthy credit positions
How it was found
- Borrower has multiple debt positions and healthy credit positions.
- Collateral value drops, making the borrower underwater.
- Borrower calls compensate to repay one lender using a healthy credit position.
- The transaction reverts because the borrower is still underwater after that single compensation.
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.
In a lending system, a borrower's 'collateral ratio' (CR) shows how safe their loan is. If it falls below a threshold, they are 'underwater' and can be liquidated. The compensate function lets a borrower repay lenders using other credit positions, but it checks after each call that the borrower is no longer underwater. This means a borrower who needs several such repayments to become healthy cannot make the first one, because the check fails immediately.
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.