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
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:
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.
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).
function liquidate(address account) external {
if (riskEngine.isAccountHealthy(account))
revert Errors.AccountNotLiquidatable();
_liquidate(account);
emit AccountLiquidated(account, registry.ownerFor(account));
}
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.
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
- Consider removing the misleading logic in
AccountManager#settle()andRiskEngine#_valueInWei()that handlesaddress(0)as an asset; - Consider disallowing adding
address(0)asunderlyinginsetLToken().
Sentiment Team
Fixed as recommended. PR here.
Lead Senior Watson
Confirmed fix.
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.