Updating asset collateral params can lead to liquidate borrowers arbitrarily
The protocol's health factor calculation uses the liquidation threshold to decide if an asset counts as collateral. If the pool admin sets an asset's collateral parameters to zero, all borrowers using that asset as collateral instantly become liquidatable, allowing MEV bots to liquidate them without warning.
Submitted by Ch_301, also found by Ch_301
One of the key concepts in this protocol is Cross Lending when the contract will calculate the health-factor of the account. If it is unhealthy, the liquidator can repay the debt on behalf of the borrower and take their collateral assets at a certain discount price.
The protocol has two main factors to calculate the health-factor for users; the collateralFactor and liquidationThreshold values are unique for each pool and asset. Also, the PoolAdmin can update them at any time by triggering Configurator.sol#setAssetCollateralParams().
The responsibility for computing health-factor is GenericLogic.sol#calculateUserAccountData(), which calculates the user data across the reserves. However, the current logic uses liquidationThreshold value also to check if the asset will not be used as collateral (but still, users can supply/lend it to be borrowed and earn interest).
File: GenericLogic.sol#calculateUserAccountData()
if (currentAssetData.liquidationThreshold != 0) {
/***/
result.totalCollateralInBaseCurrency += vars.userBalanceInBaseCurrency;
/***/
}
The issue is the PoolAdmin can call Configurator.sol#setAssetCollateralParams() at any time to disable accepting an asset as collateral by updating collateralFactor and liquidationThreshold to zero value. So, users suddenly will get liquidated directly by MEV bots.
Impact
- The
PoolAdmincan update the asset collateral params. This will leave borrowers with bad debt and allow the liquidators to liquidate all the loans. - MEV bots will just back-run the
setAssetCollateralParams()transaction to liquidate users; they have no chance to update their positions.
Proof of Concept
Foundry PoC - Please copy the following POC in TestIntCrossLiquidateERC20.t.sol:
function test_Should_LiquidateUSDT_executeSetAssetCollateralParams() public {
prepareUSDT(tsDepositor1);
//? 1- borrower supply tsWETH as collateral
prepareWETH(tsBorrower1);
TestUserAccountData memory accountDataBeforeBorrow = getUserAccountData(address(tsBorrower1), tsCommonPoolId);
// borrow some eth
uint8[] memory borrowGroups = new uint8[](1);
borrowGroups[0] = tsLowRateGroupId;
uint256[] memory borrowAmounts = new uint256[](1);
uint256 usdtCurPrice = tsPriceOracle.getAssetPrice(address(tsUSDT));
borrowAmounts[0] = (accountDataBeforeBorrow.availableBorrowInBase * (10 ** tsUSDT.decimals())) / usdtCurPrice;
//? 2- the borrower call `crossBorrowERC20()` to borrow `tsUSDT`
actionCrossBorrowERC20(
address(tsBorrower1),
tsCommonPoolId,
address(tsUSDT),
borrowGroups,
borrowAmounts,
new bytes(0)
);
// make some interest
advanceTimes(1 days);
//? 3- set `liquidationThreshold` to zero
tsHEVM.startPrank(tsPoolAdmin);
tsConfigurator.setAssetCollateralParams(tsCommonPoolId, address(tsWETH), 0, 0, 0);
tsHEVM.stopPrank();
//? 4- liquidator call `crossLiquidateERC20()` with `collateralAsset == tsWETH`
tsLiquidator1.approveERC20(address(tsUSDT), type(uint256).max);
uint daiBlanceBefore = ERC20(address(tsWETH)).balanceOf(address(tsLiquidator1));
tsHEVM.prank(address(tsLiquidator1));
tsCrossLiquidation.crossLiquidateERC20(
tsCommonPoolId,
address(tsBorrower1),
address(tsWETH),
address(tsUSDT),
borrowAmounts[0],
false
);
uint daiBlanceAfter = ERC20(address(tsWETH)).balanceOf(address(tsLiquidator1));
assertGt(daiBlanceAfter, daiBlanceBefore);
}
Recommended Mitigation Steps
In case the PoolAdmin decides to no longer accept an asset as collateral, users who are using this asset as collateral should have a period of time to update their loans. You can use a buffer period or lock time to do this critical update.
Seems like a valid concern. @thorseldon, could you please provide more context concerning your dispute?
After a second thought, this seems to fall below
Centralisation Risk on Contracts which has Owner or Administratoraccording to theREADME.
After a third thought, this is exceeding centralization risks, since it’s never a good time to change asset collateral params. The params should be cached for ongoing borrows.
thorseldon (BendDAO) commented:
This a parameter configuration which controlled by the DAO governance, any parameters like liquidation threshold should be carefully discussed and reviewed the community and dev team.
We will use timelock to schedule the configuration updating if the proposal voting is passed.
I understand the centralization concern of this issue is out of scope and changes are carefully reviewed. However, on a contract level:
- Even carefully considered changes do directly affect open borrow positions. Therefore, there is never/seldom a good time to change these values.
- It is not ensured on a contract level that e.g. liquidation threshold changes can only happen in favor of the users and not against them.
For these reasons, Medium severity seems justified.
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 health factor calculation uses the liquidation threshold to determine if an asset counts as collateral, so setting it to zero removes the asset's value from the borrower's collateral, making them instantly liquidatable.
Impact
Borrowers can be liquidated immediately after the admin changes collateral parameters, and MEV bots can back-run the transaction to liquidate all affected loans, leaving borrowers with bad debt.
What the attacker needed
Borrower has an open loan using the asset as collateral; pool admin changes collateral params to zero; MEV bot monitors and back-runs the transaction
The fix
The protocol should implement a buffer period or lock time before collateral parameter changes take effect, or cache parameters for ongoing borrows, so users have time to adjust their positions.
How it was found
- Borrower supplies WETH as collateral.
- Borrower calls crossBorrowERC20 to borrow USDT.
- Pool admin calls setAssetCollateralParams with zero values for WETH.
- Liquidator calls crossLiquidateERC20 with WETH as collateral asset and USDT as debt asset.
- Liquidator receives WETH, confirming the liquidation succeeded.
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, borrowers must keep their collateral valuable enough compared to their debt. The health factor is a number that tells if a borrower is safe; if it drops below one, anyone can liquidate them. The problem is that an admin can change a setting that makes an asset stop counting as collateral, which instantly makes many borrowers unhealthy and liquidatable.
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.