The preLiquidateHook and preSeizeHook functions do not check whether a borrower has exited a market, so a liquidator can seize collateral from a market the user has disabled. This could lead to unjust liquidation of assets that the user no longer considers collateral.
Users might face unjust liquidation of their assets even after exiting a particular market. This could lead to potential financial losses for users, and it might undermine the trust and reputation of the platform.
Proof of Concept
Consider a user with the following financial status:
The user decides to remove their risk from BTC volatility and exits the BTC market. As per the protocol’s rules, exiting the market should remove BTC from their collateral.
Following the user’s exit from the BTC market, a sharp rise in the ETH price occurs, and it surpasses $10,000.
Due to the increase in ETH price, the system identifies that the user’s collateral (now only 10,000 USDT) is insufficient to cover their loan, leading to an insufficient collateralization rate.
Despite the user’s exit from the BTC market, the system still triggers a liquidation process to liquidate BTC as collateral.
In reality, if the BTC was still part of the user’s collateral, the total collateral value would have been $40,000 ($30,000 from BTC and $10,000 from USDT). This total value would be sufficient to cover the ETH loan even with the price surge of ETH. Therefore, the user should not have faced liquidation.
This can be traced back to the missing membership check in preLiquidateHook function which does not consider if the user has exited the market or not.
function preLiquidateHook(
address vTokenBorrowed,
address vTokenCollateral,
address borrower,
uint256 repayAmount,
bool skipLiquidityCheck
) external override {
// Pause Action.LIQUIDATE on BORROWED TOKEN to prevent liquidating it.
// If we want to pause liquidating to vTokenCollateral, we should pause
// Action.SEIZE on it
_checkActionPauseState(vTokenBorrowed, Action.LIQUIDATE);
oracle.updatePrice(vTokenBorrowed);
oracle.updatePrice(vTokenCollateral);
if (!markets[vTokenBorrowed].isListed) {
revert MarketNotListed(address(vTokenBorrowed));
}
if (!markets[vTokenCollateral].isListed) {
revert MarketNotListed(address(vTokenCollateral));
}
uint256 borrowBalance = VToken(vTokenBorrowed).borrowBalanceStored(borrower);
/* Allow accounts to be liquidated if the market is deprecated or it is a forced liquidation */
if (skipLiquidityCheck || isDeprecated(VToken(vTokenBorrowed))) {
if (repayAmount > borrowBalance) {
revert TooMuchRepay();
}
return;
}
/* The borrower must have shortfall and collateral > threshold in order to be liquidatable */
AccountLiquiditySnapshot memory snapshot = _getCurrentLiquiditySnapshot(borrower, _getLiquidationThreshold);
if (snapshot.totalCollateral <= minLiquidatableCollateral) {
/* The liquidator should use either liquidateAccount or healAccount */
revert MinimalCollateralViolated(minLiquidatableCollateral, snapshot.totalCollateral);
}
if (snapshot.shortfall == 0) {
revert InsufficientShortfall();
}
/* The liquidator may not repay more than what is allowed by the closeFactor */
uint256 maxClose = mul_ScalarTruncate(Exp({ mantissa: closeFactorMantissa }), borrowBalance);
if (repayAmount > maxClose) {
revert TooMuchRepay();
}
}
/**
* @notice Checks if the seizing of assets should be allowed to occur
* @param vTokenCollateral Asset which was used as collateral and will be seized
* @param seizerContract Contract that tries to seize the asset (either borrowed vToken or Comptroller)
* @param liquidator The address repaying the borrow and seizing the collateral
* @param borrower The address of the borrower
* @custom:error ActionPaused error is thrown if seizing this type of collateral is paused
* @custom:error MarketNotListed error is thrown if either collateral or borrowed token is not listed
* @custom:error ComptrollerMismatch error is when seizer contract or seized asset belong to different pools
* @custom:access Not restricted
*/
function preSeizeHook(
address vTokenCollateral,
address seizerContract,
address liquidator,
address borrower
) external override {
// Pause Action.SEIZE on COLLATERAL to prevent seizing it.
// If we want to pause liquidating vTokenBorrowed, we should pause
// Action.LIQUIDATE on it
_checkActionPauseState(vTokenCollateral, Action.SEIZE);
if (!markets[vTokenCollateral].isListed) {
revert MarketNotListed(vTokenCollateral);
}
if (seizerContract == address(this)) {
// If Comptroller is the seizer, just check if collateral's comptroller
// is equal to the current address
if (address(VToken(vTokenCollateral).comptroller()) != address(this)) {
revert ComptrollerMismatch();
}
} else {
// If the seizer is not the Comptroller, check that the seizer is a
// listed market, and that the markets' comptrollers match
if (!markets[seizerContract].isListed) {
revert MarketNotListed(seizerContract);
}
if (VToken(vTokenCollateral).comptroller() != VToken(seizerContract).comptroller()) {
revert ComptrollerMismatch();
}
}
// Keep the flywheel moving
uint256 rewardDistributorsCount = rewardsDistributors.length;
for (uint256 i; i < rewardDistributorsCount; ++i) {
rewardsDistributors[i].updateRewardTokenSupplyIndex(vTokenCollateral);
rewardsDistributors[i].distributeSupplierRewardToken(vTokenCollateral, borrower);
rewardsDistributors[i].distributeSupplierRewardToken(vTokenCollateral, liquidator);
}
}
In essence, the user is punished for market volatility, even after they have taken steps to protect themselves (by exiting the BTC market).
Recommended Mitigation Steps
Update the preLiquidateHook function to check if a user has exited a market before proceeding with liquidation.
@chechu - By exiting the market, the user is no longer expecting those assets to be used as collateral.
* @notice Removes asset from sender's account liquidity calculation; disabling them as collateral
So while the user is still expected to maintain a healthy position with the assets they have marked as being part of their collateral, do you agree that assets that are not being used as part of their collateral should not be seized?
We have been reviewing this topic internally. Compound allows the seizing of tokens from markets not enabled as collateral. And our code does the same.
But, we added the sentence disabling them as collateral in the Comptroller.exitMarket function, so we think it’s fair to forbid seizing if the borrower didn’t enable the market as collateral.
So, I would say the issue is valid, and we’ll work to mitigate it (we’ll add the check in the preSeizeHook, which is also used in the healAccount flow).
The original report as published on Code4rena, by 0xcm. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Impact
Users could face unjust liquidation of assets they no longer consider collateral, leading to financial loss and reduced trust in the platform.
What the attacker needed
User has collateral in multiple markets; user exits one collateral market; price volatility triggers liquidation
The fix
The preSeizeHook should be updated to check that the borrower has enabled the market as collateral before allowing seizure; the project confirmed they will add this check.
How it was found
User has BTC and USDT as collateral and an ETH loan.
User exits the BTC market, removing BTC from their collateral.
ETH price rises sharply, making the remaining collateral insufficient.
The system triggers liquidation and seizes BTC as collateral despite the exit.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
In a lending protocol, users deposit assets as collateral and borrow other assets. If the value of the borrowed asset rises or the collateral falls, the user can be liquidated: someone repays the debt and takes the collateral at a discount. Users can 'exit' a market to stop using that asset as collateral, but here the code still allowed that asset to be seized during liquidation, even though it was no longer counted as collateral.
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.