fix: fixes reentrancy issue on LendingPoolCollateralManager

This commit is contained in:
The3D 2022-03-22 13:56:18 +01:00
parent 61c2273a99
commit 391841190c

View File

@ -150,8 +150,9 @@ contract LendingPoolCollateralManager is
// If the liquidator reclaims the underlying asset, we make sure there is enough available liquidity in the // If the liquidator reclaims the underlying asset, we make sure there is enough available liquidity in the
// collateral reserve // collateral reserve
if (!receiveAToken) { if (!receiveAToken) {
uint256 currentAvailableCollateral = uint256 currentAvailableCollateral = IERC20(collateralAsset).balanceOf(
IERC20(collateralAsset).balanceOf(address(vars.collateralAtoken)); address(vars.collateralAtoken)
);
if (currentAvailableCollateral < vars.maxCollateralToLiquidate) { if (currentAvailableCollateral < vars.maxCollateralToLiquidate) {
return ( return (
uint256(Errors.CollateralManagerErrors.NOT_ENOUGH_LIQUIDITY), uint256(Errors.CollateralManagerErrors.NOT_ENOUGH_LIQUIDITY),
@ -190,6 +191,13 @@ contract LendingPoolCollateralManager is
0 0
); );
// If the collateral being liquidated is equal to the user balance,
// we set the currency as not being used as collateral anymore
if (vars.maxCollateralToLiquidate == vars.userCollateralBalance) {
userConfig.setUsingAsCollateral(collateralReserve.id, false);
emit ReserveUsedAsCollateralDisabled(collateralAsset, user);
}
if (receiveAToken) { if (receiveAToken) {
vars.liquidatorPreviousATokenBalance = IERC20(vars.collateralAtoken).balanceOf(msg.sender); vars.liquidatorPreviousATokenBalance = IERC20(vars.collateralAtoken).balanceOf(msg.sender);
vars.collateralAtoken.transferOnLiquidation(user, msg.sender, vars.maxCollateralToLiquidate); vars.collateralAtoken.transferOnLiquidation(user, msg.sender, vars.maxCollateralToLiquidate);
@ -217,13 +225,6 @@ contract LendingPoolCollateralManager is
); );
} }
// If the collateral being liquidated is equal to the user balance,
// we set the currency as not being used as collateral anymore
if (vars.maxCollateralToLiquidate == vars.userCollateralBalance) {
userConfig.setUsingAsCollateral(collateralReserve.id, false);
emit ReserveUsedAsCollateralDisabled(collateralAsset, user);
}
// Transfers the debt asset being repaid to the aToken, where the liquidity is kept // Transfers the debt asset being repaid to the aToken, where the liquidity is kept
IERC20(debtAsset).safeTransferFrom( IERC20(debtAsset).safeTransferFrom(
msg.sender, msg.sender,