`originationFee` may result in the borrower account becoming liquidatable immediately
The borrow function's risk check did not account for the origination fee, so a borrower could receive less than the borrowed amount and become immediately liquidatable. An attacker could exploit this to cause a borrower's account to be liquidated.
Source: https://github.com/sherlock-audit/2022-08-sentiment-judging/tree/main/501-M
Found by
WATCHPUG
Summary
Note: This issue is a part of the extra scope added by Sentiment AFTER the audit contest. This scope was only reviewed by WatchPug and relates to these three PRs:
originationFee may result in the borrower account becoming liquidatable immediately.
Vulnerability Detail
When checking riskEngine.isBorrowAllowed(), the originationFee of the borrow is not considered. Thus, when originationFee is large enough, the borrower account becomes liquidatable immediately.
For example:
Let's say USDC's originationFee is 30%;
Alice has 100 USDC, and 0 debt in her account;
Alice borrowed 400 USDC, received only 280 USDC after the originationFee;
Alice's account is now liquidatable.
Actually, in the case above, Alice's account won't even get liquidated as all the assets are worth (380 USDC) less than the total debt (400 USDC).
Impact
originationFee may result in the borrower account becoming liquidatable immediately.
Code Snippet
function updateOriginationFee(uint _originationFee) external adminOnly {
originationFee = _originationFee;
}
function borrow(address account, address token, uint amt)
external
whenNotPaused
onlyOwner(account)
{
if (registry.LTokenFor(token) == address(0))
revert Errors.LTokenUnavailable();
if (!riskEngine.isBorrowAllowed(account, token, amt))
revert Errors.RiskThresholdBreached();
if (IAccount(account).hasAsset(token) == false)
IAccount(account).addAsset(token);
if (ILToken(registry.LTokenFor(token)).lendTo(account, amt))
IAccount(account).addBorrow(token);
emit Borrow(account, msg.sender, token, amt);
}
function isBorrowAllowed(
address account,
address token,
uint amt
)
external
view
returns (bool)
{
uint borrowValue = _valueInWei(token, amt);
return _isAccountHealthy(
_getBalance(account) + borrowValue,
_getBorrows(account) + borrowValue
);
}
Tool used
Manual Review
Recommendation
Consider asserting riskEngine.isAccountHealthy() after the borrow:
function borrow(address account, address token, uint amt)
external
whenNotPaused
onlyOwner(account)
{
if (registry.LTokenFor(token) == address(0))
revert Errors.LTokenUnavailable();
if (IAccount(account).hasAsset(token) == false)
IAccount(account).addAsset(token);
if (ILToken(registry.LTokenFor(token)).lendTo(account, amt))
IAccount(account).addBorrow(token);
if (!riskEngine.isAccountHealthy(account))
revert Errors.RiskThresholdBreached();
emit Borrow(account, msg.sender, token, amt);
}
Sentiment Team
Fixed as recommended. PR here.
Lead Senior Watson
riskEngine.isBorrowAllowed should be removed as it's no longer needed.
Sentiment Team
Pushed a commit to remove the redundant call to riskEngine, you can find it here.
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 borrow risk check used the full borrow amount instead of the net amount after the origination fee, so the account's health was overestimated.
What the attacker needed
OriginationFee is set high enough
The fix
The borrow function was changed to check account health after the borrow, and the redundant pre-check was removed.
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 borrow, a fee is taken, so you get less than you asked for. The system checked if you could borrow based on the full amount, not the reduced amount you actually receive. This could make your account instantly eligible for liquidation.
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.