Skip to content
Business logic Audit finding Advanced

Accounts with ETH loans can not be liquidated if LEther's underlying is set to `address(0)`

The protocol allows setting the underlying asset of LEther to the zero address, and its accounting logic treats the zero address as a valid asset. If that configuration occurs, accounts with ETH loans cannot be liquidated because the health check calls a balance function on the zero address and reverts.

Lambda Follow with WATCHPUG, hansfriese and 3 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-08-sentiment-judging/tree/main/034-M

Found by

Lambda, WATCHPUG, hansfriese, rbserver, HonorLt, 0xc0ffEE

Summary

Setting address(0) as LEther's underlying is allowed, and the logic in AccountManager#settle() and RiskEngine#_valueInWei() handles address(0) specially, which implies that address(0) can be an asset.

However, if LEther's underlying is set to address(0), the accounts with ETH loans will become unable to be liquidated.

Vulnerability Detail

https://github.com/sentimentxyz/protocol/blob/4e45871e4540df0f189f6c89deb8d34f24930120/src/core/AccountManager.sol#L318-L326

https://github.com/sentimentxyz/protocol/blob/4e45871e4540df0f189f6c89deb8d34f24930120/src/core/RiskEngine.sol#L178-L188

Given that at AccountManager.sol#L100 in settle() and RiskEngine.sol#L186 in _valueInWei(), they both handled the case that the asset == address(0), and in Registry.sol#setLToken(), underlying == address(0) is allowed:

https://github.com/sentimentxyz/protocol/blob/4e45871e4540df0f189f6c89deb8d34f24930120/src/core/Registry.sol#L95-L105

We assume that address(0) can be set as the underlying of LEther.

In that case, when the user borrows native tokens, address(0) will be added to the user's assets and borrows list.

https://github.com/sentimentxyz/protocol/blob/4e45871e4540df0f189f6c89deb8d34f24930120/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);
}

This will later prevent the user from being liquidated because in riskEngine.isAccountHealthy(), it calls _getBalance() in the for loop of all the assets, which assumes all the assets complies with IERC20. Thus, the transaction will revert at L157 when calling IERC20(address(0)).balanceOf(account).

https://github.com/sentimentxyz/protocol/blob/4e45871e4540df0f189f6c89deb8d34f24930120/src/core/AccountManager.sol#L250-L255

Solidity
function liquidate(address account) external {
    if (riskEngine.isAccountHealthy(account))
        revert Errors.AccountNotLiquidatable();
    _liquidate(account);
    emit AccountLiquidated(account, registry.ownerFor(account));
}

https://github.com/sentimentxyz/protocol/blob/4e45871e4540df0f189f6c89deb8d34f24930120/src/core/RiskEngine.sol#L150-L161

Solidity
function _getBalance(address account) internal view returns (uint) {
    address[] memory assets = IAccount(account).getAssets();
    uint assetsLen = assets.length;
    uint totalBalance;
    for(uint i; i < assetsLen; ++i) {
        totalBalance += _valueInWei(
            assets[i],
            IERC20(assets[i]).balanceOf(account)
        );
    }
    return totalBalance + account.balance;
}

Impact

We noticed that in the deployment documentation, LEther is set to init with WETH as the underlying. Therefore, this should not be an issue if the system is being deployed correctly.

https://github.com/sentimentxyz/protocol/blob/4e45871e4540df0f189f6c89deb8d34f24930120/protocol/deployments/ArbiDeploymentFlow.md#L47-L53

1. ETH
   1. Deploy LEther implementation
   2. Deploy Proxy(LEther)
   3. call init(WETH), "LEther", "LEth", IRegistry, reserveFactor)
   4. call Registry.setLToken(WETH, Proxy)
   5. call accountManager.toggleCollateralStatus(token)
   6. call Proxy.initDep()

But considering that setting address(0) as LEther's underlying is still plausible and the potential damage to the whole protocol is high (all the accounts with ETH loans can not be liquidated), we believe that this should be a medium severity issue.

Code Snippet

Tool used

Manual Review

Recommendation

  1. Consider removing the misleading logic in AccountManager#settle() and RiskEngine#_valueInWei() that handles address(0) as an asset;
  2. Consider disallowing adding address(0) as underlying in setLToken().

Sentiment Team

Fixed as recommended. PR here.

Lead Senior Watson

Confirmed fix.

The original report as published on Sherlock, by Lambda. 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

Likely the registry allows setting the zero address as an LToken's underlying while the risk engine assumes every asset in an account's asset list supports the standard token balance interface.

Impact

If LEther is deployed with the zero address as its underlying, all accounts with ETH loans become impossible to liquidate, though the deployment documentation says WETH should be used instead.

What the attacker needed

LEther underlying set to address(0); user borrows native tokens

The fix

The team removed the misleading zero-address handling and disallowed the zero address as an underlying in setLToken; the fix was confirmed.

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 this lending protocol, each loan token is supposed to be backed by a real asset such as WETH. The code also permits the special zero address to be used as that backing asset, and some parts of the code treat the zero address as if it were a normal token. If that happens, the routine that checks whether a borrower is healthy tries to ask the zero address for a balance, which fails, so the borrower can never be liquidated.

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 Lambda

View all

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