diff --git a/contracts/protocol/lendingpool/LendingPool.sol b/contracts/protocol/lendingpool/LendingPool.sol index 94b924c9..c88aecad 100644 --- a/contracts/protocol/lendingpool/LendingPool.sol +++ b/contracts/protocol/lendingpool/LendingPool.sol @@ -240,6 +240,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage ///@inheritdoc ILendingPool function rebalanceStableBorrowRate(address asset, address user) external override whenNotPaused { + DataTypes.ReserveData storage reserve = _reserves[asset]; DataTypes.ReserveCache memory reserveCache = reserve.cache(); diff --git a/contracts/protocol/libraries/helpers/Errors.sol b/contracts/protocol/libraries/helpers/Errors.sol index 4b0644f5..e0fea7bb 100644 --- a/contracts/protocol/libraries/helpers/Errors.sol +++ b/contracts/protocol/libraries/helpers/Errors.sol @@ -112,6 +112,7 @@ library Errors { string public constant RL_ATOKEN_SUPPLY_NOT_ZERO = '88'; string public constant RL_STABLE_DEBT_NOT_ZERO = '89'; string public constant RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO = '90'; + string public constant LP_CALLER_NOT_EOA = '91'; enum CollateralManagerErrors { NO_ERROR, 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);