From cd508a713d3cdd4e09c514fe0c47cf8f51383b07 Mon Sep 17 00:00:00 2001 From: The-3D Date: Mon, 8 Aug 2022 17:13:25 +0200 Subject: [PATCH] fix: reentrancy in liquidationCall --- .../protocol/libraries/logic/LiquidationLogic.sol | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/protocol/libraries/logic/LiquidationLogic.sol b/contracts/protocol/libraries/logic/LiquidationLogic.sol index 7d91d3365..2a0ce11d6 100644 --- a/contracts/protocol/libraries/logic/LiquidationLogic.sol +++ b/contracts/protocol/libraries/logic/LiquidationLogic.sol @@ -165,6 +165,13 @@ library LiquidationLogic { if (vars.userTotalDebt == vars.actualDebtToLiquidate) { userConfig.setBorrowing(debtReserve.id, false); } + + // If the collateral being liquidated is equal to the user balance, + // we set the currency as not being used as collateral anymore + if (vars.actualCollateralToLiquidate == vars.userCollateralBalance) { + userConfig.setUsingAsCollateral(collateralReserve.id, false); + emit ReserveUsedAsCollateralDisabled(params.collateralAsset, params.user); + } _burnDebtTokens(params, vars); @@ -198,13 +205,6 @@ library LiquidationLogic { ); } - // If the collateral being liquidated is equal to the user balance, - // we set the currency as not being used as collateral anymore - if (vars.actualCollateralToLiquidate == vars.userCollateralBalance) { - userConfig.setUsingAsCollateral(collateralReserve.id, false); - emit ReserveUsedAsCollateralDisabled(params.collateralAsset, params.user); - } - // Transfers the debt asset being repaid to the aToken, where the liquidity is kept IERC20(params.debtAsset).safeTransferFrom( msg.sender,