Skip to content
Business logic Audit finding Intermediate

`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.

WatchPug Follow

Originally disclosed on Sherlock

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:

  1. Lending deposit cap
  2. Fee accrual modification
  3. CRV staking

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

https://github.com/sentimentxyz/protocol/blob/f5a9089e87752986af522cc952f95beb037491c8/src/tokens/LToken.sol#L243-L245

Solidity
function updateOriginationFee(uint _originationFee) external adminOnly {
    originationFee = _originationFee;
}

https://github.com/sentimentxyz/protocol/blob/f5a9089e87752986af522cc952f95beb037491c8/src/core/AccountManager.sol#L203-L217

Solidity
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);
}

https://github.com/sentimentxyz/protocol/blob/f5a9089e87752986af522cc952f95beb037491c8/src/core/RiskEngine.sol#L72-L86

Solidity
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:

Solidity
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.

The original report as published on Sherlock, by WATCHPUG. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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.

More by WatchPug

View all

197 more disclosed reports, best first.

More from Sentiment Update #3

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.