diff --git a/contracts/protocol/lendingpool/LendingPool.sol b/contracts/protocol/lendingpool/LendingPool.sol index 2c91fb5a..a219e8fc 100644 --- a/contracts/protocol/lendingpool/LendingPool.sol +++ b/contracts/protocol/lendingpool/LendingPool.sol @@ -26,7 +26,6 @@ import {ReserveConfiguration} from '../libraries/configuration/ReserveConfigurat import {UserConfiguration} from '../libraries/configuration/UserConfiguration.sol'; import {DataTypes} from '../libraries/types/DataTypes.sol'; import {LendingPoolStorage} from './LendingPoolStorage.sol'; -import {Address} from '../../dependencies/openzeppelin/contracts/Address.sol'; /** * @title LendingPool contract @@ -51,7 +50,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage using PercentageMath for uint256; using SafeERC20 for IERC20; using ReserveLogic for DataTypes.ReserveCache; - using Address for address; uint256 public constant LENDINGPOOL_REVISION = 0x2; @@ -329,8 +327,6 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage **/ function rebalanceStableBorrowRate(address asset, address user) external override whenNotPaused { - require(!address(msg.sender).isContract(), Errors.LP_CALLER_NOT_EOA); - DataTypes.ReserveData storage reserve = _reserves[asset]; DataTypes.ReserveCache memory reserveCache = reserve.cache(); diff --git a/contracts/protocol/libraries/logic/ValidationLogic.sol b/contracts/protocol/libraries/logic/ValidationLogic.sol index 26388f46..7f64887a 100644 --- a/contracts/protocol/libraries/logic/ValidationLogic.sol +++ b/contracts/protocol/libraries/logic/ValidationLogic.sol @@ -20,6 +20,7 @@ import {IScaledBalanceToken} from '../../../interfaces/IScaledBalanceToken.sol'; import {IAToken} from '../../../interfaces/IAToken.sol'; import {DataTypes} from '../types/DataTypes.sol'; import {IPriceOracleGetter} from '../../../interfaces/IPriceOracleGetter.sol'; +import {Address} from '../../../dependencies/openzeppelin/contracts/Address.sol'; /** * @title ReserveLogic library @@ -34,6 +35,7 @@ library ValidationLogic { using SafeERC20 for IERC20; using ReserveConfiguration for DataTypes.ReserveConfigurationMap; using UserConfiguration for DataTypes.UserConfigurationMap; + using Address for address; uint256 public constant REBALANCE_UP_LIQUIDITY_RATE_THRESHOLD = 4000; uint256 public constant REBALANCE_UP_USAGE_RATIO_THRESHOLD = 0.95 * 1e27; //usage ratio of 95% @@ -283,7 +285,7 @@ library ValidationLogic { /** * @dev Validates a swap of borrow rate mode. * @param reserve The reserve state on which the user is swapping the rate - * @param reserveCache The cached data of the reserve + * @param reserveCache The cached data of the reserve * @param userConfig The user reserves configuration * @param stableDebt The stable debt of the user * @param variableDebt The variable debt of the user @@ -345,6 +347,10 @@ library ValidationLogic { IERC20 variableDebtToken, address aTokenAddress ) external view { + + // to avoid potential abuses using flashloans, the rebalance stable rate must happen through an EOA + require(!address(msg.sender).isContract(), Errors.LP_CALLER_NOT_EOA); + (bool isActive, , , , bool isPaused) = reserveCache.reserveConfiguration.getFlagsMemory(); require(isActive, Errors.VL_NO_ACTIVE_RESERVE);